From b4e63e18ea36c01bd9b039800645f4cd1aad1d55 Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Tue, 28 May 2024 15:00:05 -0400 Subject: [PATCH] refactor vector util functions --- CMakeLists.txt | 4 +-- include/viennals/lsCalculateNormalVectors.hpp | 6 ++--- include/viennals/lsConvexHull.hpp | 6 ++--- include/viennals/lsDetectFeatures.hpp | 6 ++--- include/viennals/lsEnquistOsher.hpp | 6 ++--- include/viennals/lsExtrude.hpp | 14 +++++----- .../lsGeometricAdvectDistributions.hpp | 26 +++++++++---------- include/viennals/lsLaxFriedrichs.hpp | 6 ++--- include/viennals/lsLocalLaxFriedrichs.hpp | 10 +++---- .../lsLocalLaxFriedrichsAnalytical.hpp | 8 +++--- .../viennals/lsLocalLocalLaxFriedrichs.hpp | 6 ++--- include/viennals/lsMesh.hpp | 16 ++++++------ include/viennals/lsVelocityField.hpp | 15 +++++------ 13 files changed, 64 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3d328da..0cd90a5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,11 +105,11 @@ CPMAddPackage( NAME ViennaCore GIT_TAG main # TODO: Create Tag GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore" - OPTIONS "VIENNA_CORE_FORMAT_EXCLUDE docs/") + OPTIONS "VIENNACORE_FORMAT_EXCLUDE docs/") CPMAddPackage( NAME PackageProject - VERSION 1.12.0 + VERSION 1.11.1 GIT_REPOSITORY "https://github.com/TheLartians/PackageProject.cmake" EXCLUDE_FROM_ALL ${VIENNALS_BUILD_PYTHON}) diff --git a/include/viennals/lsCalculateNormalVectors.hpp b/include/viennals/lsCalculateNormalVectors.hpp index 99ab16a3..7681c4ca 100644 --- a/include/viennals/lsCalculateNormalVectors.hpp +++ b/include/viennals/lsCalculateNormalVectors.hpp @@ -57,7 +57,7 @@ template class CalculateNormalVectors { .print(); } - std::vector>> normalVectorsVector( + std::vector>> normalVectorsVector( levelSet->getNumberOfSegments()); double pointsPerSegment = double(2 * levelSet->getDomain().getNumberOfPoints()) / @@ -94,12 +94,12 @@ template class CalculateNormalVectors { continue; } else if (std::abs(center.getValue()) > maxValue) { // push an empty vector to keep ordering correct - Triple tmp = {}; + Vec3D tmp = {}; normalVectors.push_back(tmp); continue; } - Triple n; + Vec3D n; T denominator = 0; for (int i = 0; i < D; i++) { diff --git a/include/viennals/lsConvexHull.hpp b/include/viennals/lsConvexHull.hpp index c8a2d80e..8426007e 100644 --- a/include/viennals/lsConvexHull.hpp +++ b/include/viennals/lsConvexHull.hpp @@ -407,9 +407,9 @@ template class ConvexHull { // if insertion took place, add the point to the nodes if (insertion.second) { - Triple node{points[hullElements[i][j]][0], - points[hullElements[i][j]][1], - (D == 2) ? T(0.) : points[hullElements[i][j]][2]}; + Vec3D node{points[hullElements[i][j]][0], + points[hullElements[i][j]][1], + (D == 2) ? T(0.) : points[hullElements[i][j]][2]}; mesh->nodes.push_back(node); } diff --git a/include/viennals/lsDetectFeatures.hpp b/include/viennals/lsDetectFeatures.hpp index b12ec74d..335ba7ab 100644 --- a/include/viennals/lsDetectFeatures.hpp +++ b/include/viennals/lsDetectFeatures.hpp @@ -176,7 +176,7 @@ template class DetectFeatures { p = omp_get_thread_num(); #endif - Triple zeroVector{}; + Vec3D zeroVector{}; std::vector &flagsSegment = flagsReserve[p]; flagsSegment.reserve( @@ -200,12 +200,12 @@ template class DetectFeatures { continue; } - Triple centerNormal = normals[neighborIt.getCenter().getPointId()]; + Vec3D centerNormal = normals[neighborIt.getCenter().getPointId()]; bool flag = false; for (unsigned dir = 0; dir < (D * D * D); dir++) { - Triple currentNormal = + Vec3D currentNormal = normals[neighborIt.getNeighbor(dir).getPointId()]; if (currentNormal != zeroVector) { diff --git a/include/viennals/lsEnquistOsher.hpp b/include/viennals/lsEnquistOsher.hpp index 1e80d7ee..43fae596 100644 --- a/include/viennals/lsEnquistOsher.hpp +++ b/include/viennals/lsEnquistOsher.hpp @@ -118,7 +118,7 @@ template class EnquistOsher { // Calculate normal vector for velocity calculation // use std::array since it will be exposed to interface - Triple normalVector = {}; + Vec3D normalVector = {}; if (calculateNormalVectors) { T denominator = 0; for (int i = 0; i < D; i++) { @@ -136,12 +136,12 @@ template class EnquistOsher { } // convert coordinate to std array for interface - Triple coordArray = {coordinate[0], coordinate[1], coordinate[2]}; + Vec3D coordArray = {coordinate[0], coordinate[1], coordinate[2]}; double scalarVelocity = velocities->getScalarVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); - Triple vectorVelocity = velocities->getVectorVelocity( + Vec3D vectorVelocity = velocities->getVectorVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); diff --git a/include/viennals/lsExtrude.hpp b/include/viennals/lsExtrude.hpp index 499d8428..d1de56c1 100644 --- a/include/viennals/lsExtrude.hpp +++ b/include/viennals/lsExtrude.hpp @@ -14,16 +14,16 @@ using namespace viennacore; template class Extrude { SmartPointer> inputLevelSet = nullptr; SmartPointer> outputLevelSet = nullptr; - Pair extent = {0., 0.}; + Vec2D extent = {0., 0.}; int extrudeDim = 0; - Triple> boundaryConds; + std::array, 3> boundaryConds; public: Extrude() {} Extrude(SmartPointer> passedInputLS, - SmartPointer> passedOutputLS, Pair passedExtent, + SmartPointer> passedOutputLS, Vec2D passedExtent, const int passedExtrudeDim, - Triple> passedBoundaryConds) + std::array, 3> passedBoundaryConds) : inputLevelSet(passedInputLS), outputLevelSet(passedOutputLS), extent(passedExtent), extrudeDim(passedExtrudeDim), boundaryConds(passedBoundaryConds) {} @@ -38,15 +38,15 @@ template class Extrude { } // Set the min and max extent in the extruded dimension - void setExtent(Pair passedExtent) { extent = passedExtent; } + void setExtent(Vec2D passedExtent) { extent = passedExtent; } // Set which index of the added dimension (x: 0, y: 1, z: 2) void setExtrudeDimension(const int passedExtrudeDim) { extrudeDim = passedExtrudeDim; } - void - setBoundaryConditions(Triple> passedBoundaryConds) { + void setBoundaryConditions( + std::array, 3> passedBoundaryConds) { boundaryConds = passedBoundaryConds; } diff --git a/include/viennals/lsGeometricAdvectDistributions.hpp b/include/viennals/lsGeometricAdvectDistributions.hpp index d4c06b85..297c8174 100644 --- a/include/viennals/lsGeometricAdvectDistributions.hpp +++ b/include/viennals/lsGeometricAdvectDistributions.hpp @@ -20,8 +20,8 @@ template class GeometricAdvectDistribution { /// center is inside the distribution. If there is no quick /// check due to the complexity of the distribution, always /// return true or do not overload this function. - virtual bool isInside(const Triple &initial, - const Triple &candidate, + virtual bool isInside(const Vec3D &initial, + const Vec3D &candidate, double eps = 0.) const { return true; } @@ -29,8 +29,8 @@ template class GeometricAdvectDistribution { /// Returns the signed distance of a point relative to the distributions /// center. This is the signed manhatten distance to the nearest surface /// point. - virtual T getSignedDistance(const Triple &initial, - const Triple &candidate, + virtual T getSignedDistance(const Vec3D &initial, + const Vec3D &candidate, unsigned long initialPointId) const = 0; /// Sets bounds to the bounding box of the distribution. @@ -51,8 +51,8 @@ class SphereDistribution : public GeometricAdvectDistribution { SphereDistribution(const T passedRadius, const T delta) : radius(passedRadius), radius2(radius * radius), gridDelta(delta) {} - bool isInside(const Triple &initial, - const Triple &candidate, + bool isInside(const Vec3D &initial, + const Vec3D &candidate, double eps = 0.) const override { hrleCoordType dot = 0.; for (unsigned i = 0; i < D; ++i) { @@ -66,11 +66,11 @@ class SphereDistribution : public GeometricAdvectDistribution { return false; } - T getSignedDistance(const Triple &initial, - const Triple &candidate, + T getSignedDistance(const Vec3D &initial, + const Vec3D &candidate, unsigned long /*initialPointId*/) const override { T distance = std::numeric_limits::max(); - Triple v{}; + Vec3D v{}; for (unsigned i = 0; i < D; ++i) { v[i] = candidate[i] - initial[i]; } @@ -132,8 +132,8 @@ class BoxDistribution : public GeometricAdvectDistribution { } } - bool isInside(const Triple &initial, - const Triple &candidate, + bool isInside(const Vec3D &initial, + const Vec3D &candidate, double eps = 0.) const override { for (unsigned i = 0; i < D; ++i) { if (std::abs(candidate[i] - initial[i]) > @@ -144,8 +144,8 @@ class BoxDistribution : public GeometricAdvectDistribution { return true; } - T getSignedDistance(const Triple &initial, - const Triple &candidate, + T getSignedDistance(const Vec3D &initial, + const Vec3D &candidate, unsigned long /*initialPointId*/) const override { T distance = std::numeric_limits::lowest(); for (unsigned i = 0; i < D; ++i) { diff --git a/include/viennals/lsLaxFriedrichs.hpp b/include/viennals/lsLaxFriedrichs.hpp index d8040645..53aa7092 100644 --- a/include/viennals/lsLaxFriedrichs.hpp +++ b/include/viennals/lsLaxFriedrichs.hpp @@ -58,7 +58,7 @@ template class LaxFriedrichs { T grad = 0.; T dissipation = 0.; - Triple normalVector = {}; + Vec3D normalVector = {}; T normalModulus = 0; const bool calcNormals = calculateNormalVectors; @@ -133,12 +133,12 @@ template class LaxFriedrichs { } // convert coordinate to std array for interface - Triple coordArray = {coordinate[0], coordinate[1], coordinate[2]}; + Vec3D coordArray = {coordinate[0], coordinate[1], coordinate[2]}; double scalarVelocity = velocities->getScalarVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); - Triple vectorVelocity = velocities->getVectorVelocity( + Vec3D vectorVelocity = velocities->getVectorVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); diff --git a/include/viennals/lsLocalLaxFriedrichs.hpp b/include/viennals/lsLocalLaxFriedrichs.hpp index df59a2e9..061dc9d2 100644 --- a/include/viennals/lsLocalLaxFriedrichs.hpp +++ b/include/viennals/lsLocalLaxFriedrichs.hpp @@ -70,7 +70,7 @@ template class LocalLaxFriedrichs { neighborIterator.goToIndicesSequential(indices); // convert coordinate to std array for interface - Triple coordArray = {coordinate[0], coordinate[1], coordinate[2]}; + Vec3D coordArray = {coordinate[0], coordinate[1], coordinate[2]}; T gradPos[D]; T gradNeg[D]; @@ -78,7 +78,7 @@ template class LocalLaxFriedrichs { T grad = 0.; T dissipation = 0.; - Triple normalVector = {}; + Vec3D normalVector = {}; T normalModulus = 0; for (int i = 0; i < D; i++) { // iterate over dimensions @@ -156,7 +156,7 @@ template class LocalLaxFriedrichs { double scalarVelocity = velocities->getScalarVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); - Triple vectorVelocity = velocities->getVectorVelocity( + Vec3D vectorVelocity = velocities->getVectorVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); @@ -184,11 +184,11 @@ template class LocalLaxFriedrichs { hrleVectorType neighborIndex(minIndex); for (unsigned i = 0; i < numNeighbors; ++i) { - Triple coords; + Vec3D coords; for (unsigned dir = 0; dir < D; ++dir) { coords[dir] = coordinate[dir] + neighborIndex[dir] * gridDelta; } - Triple normal = {}; + Vec3D normal = {}; double normalModulus = 0.; auto center = neighborIterator.getNeighbor(neighborIndex).getValue(); for (unsigned dir = 0; dir < D; ++dir) { diff --git a/include/viennals/lsLocalLaxFriedrichsAnalytical.hpp b/include/viennals/lsLocalLaxFriedrichsAnalytical.hpp index 0c4eae98..5eebd992 100644 --- a/include/viennals/lsLocalLaxFriedrichsAnalytical.hpp +++ b/include/viennals/lsLocalLaxFriedrichsAnalytical.hpp @@ -69,7 +69,7 @@ template class LocalLaxFriedrichsAnalytical { neighborIterator.goToIndicesSequential(indices); // convert coordinate to std array for interface - Triple coordArray = {coordinate[0], coordinate[1], coordinate[2]}; + Vec3D coordArray = {coordinate[0], coordinate[1], coordinate[2]}; T gradPos[D]; T gradNeg[D]; @@ -77,7 +77,7 @@ template class LocalLaxFriedrichsAnalytical { T grad = 0.; T dissipation = 0.; - Triple normalVector = {}; + Vec3D normalVector = {}; T normalModulus = 0; for (int i = 0; i < D; i++) { // iterate over dimensions @@ -155,7 +155,7 @@ template class LocalLaxFriedrichsAnalytical { double scalarVelocity = velocities->getScalarVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); - Triple vectorVelocity = velocities->getVectorVelocity( + Vec3D vectorVelocity = velocities->getVectorVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); @@ -184,7 +184,7 @@ template class LocalLaxFriedrichsAnalytical { hrleVectorType neighborIndex(minIndex); for (unsigned i = 0; i < numNeighbors; ++i) { - Triple normal = {}; + Vec3D normal = {}; auto center = neighborIterator.getNeighbor(neighborIndex).getValue(); for (unsigned dir = 0; dir < D; ++dir) { hrleVectorType unity(0); diff --git a/include/viennals/lsLocalLocalLaxFriedrichs.hpp b/include/viennals/lsLocalLocalLaxFriedrichs.hpp index 2b2ff73c..e2095c14 100644 --- a/include/viennals/lsLocalLocalLaxFriedrichs.hpp +++ b/include/viennals/lsLocalLocalLaxFriedrichs.hpp @@ -50,7 +50,7 @@ template class LocalLocalLaxFriedrichs { neighborIterator.goToIndicesSequential(indices); // convert coordinate to std array for interface - Triple coordArray = {coordinate[0], coordinate[1], coordinate[2]}; + Vec3D coordArray = {coordinate[0], coordinate[1], coordinate[2]}; T gradPos[D]; T gradNeg[D]; @@ -58,7 +58,7 @@ template class LocalLocalLaxFriedrichs { T grad = 0.; T dissipation = 0.; - Triple normalVector = {}; + Vec3D normalVector = {}; T normalModulus = 0; for (int i = 0; i < D; i++) { // iterate over dimensions @@ -131,7 +131,7 @@ template class LocalLocalLaxFriedrichs { double scalarVelocity = velocities->getScalarVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); - Triple vectorVelocity = velocities->getVectorVelocity( + Vec3D vectorVelocity = velocities->getVectorVelocity( coordArray, material, normalVector, neighborIterator.getCenter().getPointId()); diff --git a/include/viennals/lsMesh.hpp b/include/viennals/lsMesh.hpp index 82a011bb..682252a1 100644 --- a/include/viennals/lsMesh.hpp +++ b/include/viennals/lsMesh.hpp @@ -20,7 +20,7 @@ using namespace viennacore; /// elements. template class Mesh { public: - std::vector> nodes; + std::vector> nodes; std::vector> vertices; std::vector> lines; std::vector> triangles; @@ -28,14 +28,14 @@ template class Mesh { std::vector> hexas; PointData pointData; PointData cellData; - Triple minimumExtent; - Triple maximumExtent; + Vec3D minimumExtent; + Vec3D maximumExtent; private: // iterator typedef using VectorIt = typename PointData::VectorDataType::iterator; // find function to avoid including the whole algorithm header - VectorIt find(VectorIt first, VectorIt last, const Triple &value) { + VectorIt find(VectorIt first, VectorIt last, const Vec3D &value) { for (; first != last; ++first) { if (*first == value) { return first; @@ -57,9 +57,9 @@ template class Mesh { }; public: - const std::vector> &getNodes() const { return nodes; } + const std::vector> &getNodes() const { return nodes; } - std::vector> &getNodes() { return nodes; } + std::vector> &getNodes() { return nodes; } template ::type = 0> std::vector> &getElements() { @@ -94,7 +94,7 @@ template class Mesh { const PointData &getCellData() const { return cellData; } - unsigned insertNextNode(const Triple &node) { + unsigned insertNextNode(const Vec3D &node) { nodes.push_back(node); return nodes.size() - 1; } @@ -150,7 +150,7 @@ template class Mesh { } void removeDuplicateNodes() { - std::vector> newNodes; + std::vector> newNodes; // can just push first point since it cannot be duplicate newNodes.push_back(nodes[0]); // now check for duplicates diff --git a/include/viennals/lsVelocityField.hpp b/include/viennals/lsVelocityField.hpp index 0e37f4ef..c931d096 100644 --- a/include/viennals/lsVelocityField.hpp +++ b/include/viennals/lsVelocityField.hpp @@ -16,19 +16,18 @@ template class VelocityField { /// Should return a scalar value for the velocity at coordinate /// for a point of material with the given normalVector. - virtual T getScalarVelocity(const Triple & /*coordinate*/, - int /*material*/, - const Triple & /*normalVector*/, + virtual T getScalarVelocity(const Vec3D & /*coordinate*/, int /*material*/, + const Vec3D & /*normalVector*/, unsigned long /*pointId*/) { return 0; } /// Like getScalarVelocity, but returns a velocity value for each /// cartesian direction. - virtual Triple getVectorVelocity(const Triple & /*coordinate*/, - int /*material*/, - const Triple & /*normalVector*/, - unsigned long /*pointId*/) { + virtual Vec3D getVectorVelocity(const Vec3D & /*coordinate*/, + int /*material*/, + const Vec3D & /*normalVector*/, + unsigned long /*pointId*/) { return {0, 0, 0}; } @@ -36,7 +35,7 @@ template class VelocityField { /// this is called to provide the analytical solution for the alpha /// values, needed for stable integration. virtual T getDissipationAlpha(int /*direction*/, int /*material*/, - const Triple & /*centralDifferences*/) { + const Vec3D & /*centralDifferences*/) { return 0; }