Skip to content

Commit

Permalink
refactor vector util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed May 28, 2024
1 parent b73b685 commit b4e63e1
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 65 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
6 changes: 3 additions & 3 deletions include/viennals/lsCalculateNormalVectors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ template <class T, int D> class CalculateNormalVectors {
.print();
}

std::vector<std::vector<Triple<T>>> normalVectorsVector(
std::vector<std::vector<Vec3D<T>>> normalVectorsVector(
levelSet->getNumberOfSegments());
double pointsPerSegment =
double(2 * levelSet->getDomain().getNumberOfPoints()) /
Expand Down Expand Up @@ -94,12 +94,12 @@ template <class T, int D> class CalculateNormalVectors {
continue;
} else if (std::abs(center.getValue()) > maxValue) {
// push an empty vector to keep ordering correct
Triple<T> tmp = {};
Vec3D<T> tmp = {};
normalVectors.push_back(tmp);
continue;
}

Triple<T> n;
Vec3D<T> n;

T denominator = 0;
for (int i = 0; i < D; i++) {
Expand Down
6 changes: 3 additions & 3 deletions include/viennals/lsConvexHull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ template <class T, int D> class ConvexHull {

// if insertion took place, add the point to the nodes
if (insertion.second) {
Triple<T> node{points[hullElements[i][j]][0],
points[hullElements[i][j]][1],
(D == 2) ? T(0.) : points[hullElements[i][j]][2]};
Vec3D<T> 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);
}

Expand Down
6 changes: 3 additions & 3 deletions include/viennals/lsDetectFeatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ template <class T, int D> class DetectFeatures {
p = omp_get_thread_num();
#endif

Triple<T> zeroVector{};
Vec3D<T> zeroVector{};

std::vector<T> &flagsSegment = flagsReserve[p];
flagsSegment.reserve(
Expand All @@ -200,12 +200,12 @@ template <class T, int D> class DetectFeatures {
continue;
}

Triple<T> centerNormal = normals[neighborIt.getCenter().getPointId()];
Vec3D<T> centerNormal = normals[neighborIt.getCenter().getPointId()];

bool flag = false;

for (unsigned dir = 0; dir < (D * D * D); dir++) {
Triple<T> currentNormal =
Vec3D<T> currentNormal =
normals[neighborIt.getNeighbor(dir).getPointId()];

if (currentNormal != zeroVector) {
Expand Down
6 changes: 3 additions & 3 deletions include/viennals/lsEnquistOsher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ template <class T, int D, int order> class EnquistOsher {

// Calculate normal vector for velocity calculation
// use std::array since it will be exposed to interface
Triple<T> normalVector = {};
Vec3D<T> normalVector = {};
if (calculateNormalVectors) {
T denominator = 0;
for (int i = 0; i < D; i++) {
Expand All @@ -136,12 +136,12 @@ template <class T, int D, int order> class EnquistOsher {
}

// convert coordinate to std array for interface
Triple<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};

double scalarVelocity = velocities->getScalarVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());
Triple<T> vectorVelocity = velocities->getVectorVelocity(
Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());

Expand Down
14 changes: 7 additions & 7 deletions include/viennals/lsExtrude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ using namespace viennacore;
template <class T> class Extrude {
SmartPointer<Domain<T, 2>> inputLevelSet = nullptr;
SmartPointer<Domain<T, 3>> outputLevelSet = nullptr;
Pair<T> extent = {0., 0.};
Vec2D<T> extent = {0., 0.};
int extrudeDim = 0;
Triple<BoundaryConditionEnum<3>> boundaryConds;
std::array<BoundaryConditionEnum<3>, 3> boundaryConds;

public:
Extrude() {}
Extrude(SmartPointer<Domain<T, 2>> passedInputLS,
SmartPointer<Domain<T, 3>> passedOutputLS, Pair<T> passedExtent,
SmartPointer<Domain<T, 3>> passedOutputLS, Vec2D<T> passedExtent,
const int passedExtrudeDim,
Triple<BoundaryConditionEnum<3>> passedBoundaryConds)
std::array<BoundaryConditionEnum<3>, 3> passedBoundaryConds)
: inputLevelSet(passedInputLS), outputLevelSet(passedOutputLS),
extent(passedExtent), extrudeDim(passedExtrudeDim),
boundaryConds(passedBoundaryConds) {}
Expand All @@ -38,15 +38,15 @@ template <class T> class Extrude {
}

// Set the min and max extent in the extruded dimension
void setExtent(Pair<T> passedExtent) { extent = passedExtent; }
void setExtent(Vec2D<T> 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<BoundaryConditionEnum<3>> passedBoundaryConds) {
void setBoundaryConditions(
std::array<BoundaryConditionEnum<3>, 3> passedBoundaryConds) {
boundaryConds = passedBoundaryConds;
}

Expand Down
26 changes: 13 additions & 13 deletions include/viennals/lsGeometricAdvectDistributions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ template <class T, int D> 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<hrleCoordType> &initial,
const Triple<hrleCoordType> &candidate,
virtual bool isInside(const Vec3D<hrleCoordType> &initial,
const Vec3D<hrleCoordType> &candidate,
double eps = 0.) const {
return true;
}

/// 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<hrleCoordType> &initial,
const Triple<hrleCoordType> &candidate,
virtual T getSignedDistance(const Vec3D<hrleCoordType> &initial,
const Vec3D<hrleCoordType> &candidate,
unsigned long initialPointId) const = 0;

/// Sets bounds to the bounding box of the distribution.
Expand All @@ -51,8 +51,8 @@ class SphereDistribution : public GeometricAdvectDistribution<T, D> {
SphereDistribution(const T passedRadius, const T delta)
: radius(passedRadius), radius2(radius * radius), gridDelta(delta) {}

bool isInside(const Triple<hrleCoordType> &initial,
const Triple<hrleCoordType> &candidate,
bool isInside(const Vec3D<hrleCoordType> &initial,
const Vec3D<hrleCoordType> &candidate,
double eps = 0.) const override {
hrleCoordType dot = 0.;
for (unsigned i = 0; i < D; ++i) {
Expand All @@ -66,11 +66,11 @@ class SphereDistribution : public GeometricAdvectDistribution<T, D> {
return false;
}

T getSignedDistance(const Triple<hrleCoordType> &initial,
const Triple<hrleCoordType> &candidate,
T getSignedDistance(const Vec3D<hrleCoordType> &initial,
const Vec3D<hrleCoordType> &candidate,
unsigned long /*initialPointId*/) const override {
T distance = std::numeric_limits<T>::max();
Triple<hrleCoordType> v{};
Vec3D<hrleCoordType> v{};
for (unsigned i = 0; i < D; ++i) {
v[i] = candidate[i] - initial[i];
}
Expand Down Expand Up @@ -132,8 +132,8 @@ class BoxDistribution : public GeometricAdvectDistribution<T, D> {
}
}

bool isInside(const Triple<hrleCoordType> &initial,
const Triple<hrleCoordType> &candidate,
bool isInside(const Vec3D<hrleCoordType> &initial,
const Vec3D<hrleCoordType> &candidate,
double eps = 0.) const override {
for (unsigned i = 0; i < D; ++i) {
if (std::abs(candidate[i] - initial[i]) >
Expand All @@ -144,8 +144,8 @@ class BoxDistribution : public GeometricAdvectDistribution<T, D> {
return true;
}

T getSignedDistance(const Triple<hrleCoordType> &initial,
const Triple<hrleCoordType> &candidate,
T getSignedDistance(const Vec3D<hrleCoordType> &initial,
const Vec3D<hrleCoordType> &candidate,
unsigned long /*initialPointId*/) const override {
T distance = std::numeric_limits<T>::lowest();
for (unsigned i = 0; i < D; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions include/viennals/lsLaxFriedrichs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ template <class T, int D, int order> class LaxFriedrichs {
T grad = 0.;
T dissipation = 0.;

Triple<T> normalVector = {};
Vec3D<T> normalVector = {};
T normalModulus = 0;
const bool calcNormals = calculateNormalVectors;

Expand Down Expand Up @@ -133,12 +133,12 @@ template <class T, int D, int order> class LaxFriedrichs {
}

// convert coordinate to std array for interface
Triple<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};

double scalarVelocity = velocities->getScalarVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());
Triple<T> vectorVelocity = velocities->getVectorVelocity(
Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());

Expand Down
10 changes: 5 additions & 5 deletions include/viennals/lsLocalLaxFriedrichs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ template <class T, int D, int order> class LocalLaxFriedrichs {
neighborIterator.goToIndicesSequential(indices);

// convert coordinate to std array for interface
Triple<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};

T gradPos[D];
T gradNeg[D];

T grad = 0.;
T dissipation = 0.;

Triple<T> normalVector = {};
Vec3D<T> normalVector = {};
T normalModulus = 0;

for (int i = 0; i < D; i++) { // iterate over dimensions
Expand Down Expand Up @@ -156,7 +156,7 @@ template <class T, int D, int order> class LocalLaxFriedrichs {
double scalarVelocity = velocities->getScalarVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());
Triple<T> vectorVelocity = velocities->getVectorVelocity(
Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());

Expand Down Expand Up @@ -184,11 +184,11 @@ template <class T, int D, int order> class LocalLaxFriedrichs {

hrleVectorType<hrleIndexType, D> neighborIndex(minIndex);
for (unsigned i = 0; i < numNeighbors; ++i) {
Triple<T> coords;
Vec3D<T> coords;
for (unsigned dir = 0; dir < D; ++dir) {
coords[dir] = coordinate[dir] + neighborIndex[dir] * gridDelta;
}
Triple<T> normal = {};
Vec3D<T> normal = {};
double normalModulus = 0.;
auto center = neighborIterator.getNeighbor(neighborIndex).getValue();
for (unsigned dir = 0; dir < D; ++dir) {
Expand Down
8 changes: 4 additions & 4 deletions include/viennals/lsLocalLaxFriedrichsAnalytical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ template <class T, int D, int order> class LocalLaxFriedrichsAnalytical {
neighborIterator.goToIndicesSequential(indices);

// convert coordinate to std array for interface
Triple<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};

T gradPos[D];
T gradNeg[D];

T grad = 0.;
T dissipation = 0.;

Triple<T> normalVector = {};
Vec3D<T> normalVector = {};
T normalModulus = 0;

for (int i = 0; i < D; i++) { // iterate over dimensions
Expand Down Expand Up @@ -155,7 +155,7 @@ template <class T, int D, int order> class LocalLaxFriedrichsAnalytical {
double scalarVelocity = velocities->getScalarVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());
Triple<T> vectorVelocity = velocities->getVectorVelocity(
Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());

Expand Down Expand Up @@ -184,7 +184,7 @@ template <class T, int D, int order> class LocalLaxFriedrichsAnalytical {
hrleVectorType<hrleIndexType, D> neighborIndex(minIndex);
for (unsigned i = 0; i < numNeighbors; ++i) {

Triple<T> normal = {};
Vec3D<T> normal = {};
auto center = neighborIterator.getNeighbor(neighborIndex).getValue();
for (unsigned dir = 0; dir < D; ++dir) {
hrleVectorType<hrleIndexType, D> unity(0);
Expand Down
6 changes: 3 additions & 3 deletions include/viennals/lsLocalLocalLaxFriedrichs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ template <class T, int D, int order> class LocalLocalLaxFriedrichs {
neighborIterator.goToIndicesSequential(indices);

// convert coordinate to std array for interface
Triple<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};

T gradPos[D];
T gradNeg[D];

T grad = 0.;
T dissipation = 0.;

Triple<T> normalVector = {};
Vec3D<T> normalVector = {};
T normalModulus = 0;

for (int i = 0; i < D; i++) { // iterate over dimensions
Expand Down Expand Up @@ -131,7 +131,7 @@ template <class T, int D, int order> class LocalLocalLaxFriedrichs {
double scalarVelocity = velocities->getScalarVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());
Triple<T> vectorVelocity = velocities->getVectorVelocity(
Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
coordArray, material, normalVector,
neighborIterator.getCenter().getPointId());

Expand Down
16 changes: 8 additions & 8 deletions include/viennals/lsMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ using namespace viennacore;
/// elements.
template <class T = double> class Mesh {
public:
std::vector<Triple<T>> nodes;
std::vector<Vec3D<T>> nodes;
std::vector<std::array<unsigned, 1>> vertices;
std::vector<std::array<unsigned, 2>> lines;
std::vector<std::array<unsigned, 3>> triangles;
std::vector<std::array<unsigned, 4>> tetras;
std::vector<std::array<unsigned, 8>> hexas;
PointData<T> pointData;
PointData<T> cellData;
Triple<T> minimumExtent;
Triple<T> maximumExtent;
Vec3D<T> minimumExtent;
Vec3D<T> maximumExtent;

private:
// iterator typedef
using VectorIt = typename PointData<T>::VectorDataType::iterator;
// find function to avoid including the whole algorithm header
VectorIt find(VectorIt first, VectorIt last, const Triple<T> &value) {
VectorIt find(VectorIt first, VectorIt last, const Vec3D<T> &value) {
for (; first != last; ++first) {
if (*first == value) {
return first;
Expand All @@ -57,9 +57,9 @@ template <class T = double> class Mesh {
};

public:
const std::vector<Triple<T>> &getNodes() const { return nodes; }
const std::vector<Vec3D<T>> &getNodes() const { return nodes; }

std::vector<Triple<T>> &getNodes() { return nodes; }
std::vector<Vec3D<T>> &getNodes() { return nodes; }

template <int D, typename std::enable_if<D == 1, int>::type = 0>
std::vector<std::array<unsigned, D>> &getElements() {
Expand Down Expand Up @@ -94,7 +94,7 @@ template <class T = double> class Mesh {

const PointData<T> &getCellData() const { return cellData; }

unsigned insertNextNode(const Triple<T> &node) {
unsigned insertNextNode(const Vec3D<T> &node) {
nodes.push_back(node);
return nodes.size() - 1;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ template <class T = double> class Mesh {
}

void removeDuplicateNodes() {
std::vector<Triple<T>> newNodes;
std::vector<Vec3D<T>> newNodes;
// can just push first point since it cannot be duplicate
newNodes.push_back(nodes[0]);
// now check for duplicates
Expand Down
Loading

0 comments on commit b4e63e1

Please sign in to comment.