Skip to content

Commit

Permalink
Add namespace in geometry functions and domain
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed May 23, 2024
1 parent 9d8af59 commit 5f1cb24
Show file tree
Hide file tree
Showing 21 changed files with 362 additions and 483 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ CPMAddPackage(
CPMFindPackage(
NAME ViennaRay
VERSION 2.1.2
GIT_TAG viennacore
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaRay"
EXCLUDE_FROM_ALL ${VIENNAPS_BUILD_PYTHON})

Expand Down
4 changes: 2 additions & 2 deletions include/viennaps/cellSet/csBoundingVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ template <class T, int D> class csBoundingVolume {

private:
void buildBounds2D(const BoundsType &outerBound) {
auto xExt = (outerBound[1][0] - outerBound[0][0]) / 2.;
auto yExt = (outerBound[1][1] - outerBound[0][1]) / 2.;
T xExt = (outerBound[1][0] - outerBound[0][0]) / 2.;
T yExt = (outerBound[1][1] - outerBound[0][1]) / 2.;

const auto BVH1 =
csPair<csPair<T>>{outerBound[0][0], outerBound[0][1],
Expand Down
90 changes: 48 additions & 42 deletions include/viennaps/cellSet/csDenseCellSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,38 @@
#include "csTracePath.hpp"
#include "csUtil.hpp"

#include "../psLogger.hpp"
#include "../psMaterials.hpp"
#include "../psSmartPointer.hpp"
#include "../psVTKWriter.hpp"

#include <lsDomain.hpp>
#include <lsMakeGeometry.hpp>
#include <lsMesh.hpp>
#include <lsToSurfaceMesh.hpp>
#include <lsToVoxelMesh.hpp>
#include <lsVTKWriter.hpp>

#include <vcLogger.hpp>
#include <vcSmartPointer.hpp>

#include <bitset>

namespace viennacs {

using namespace viennacore;

/**
This class represents a cell-based voxel implementation of a volume. The
depth of the cell set in z-direction can be specified.
*/
template <class T, int D> class csDenseCellSet {
template <class T, int D> class DenseCellSet {
private:
using gridType = psSmartPointer<lsMesh<T>>;
using levelSetsType =
psSmartPointer<std::vector<psSmartPointer<lsDomain<T, D>>>>;
using materialMapType = psSmartPointer<psMaterialMap>;
using gridType = SmartPointer<lsMesh<T>>;
using levelSetsType = SmartPointer<std::vector<SmartPointer<lsDomain<T, D>>>>;
using materialMapType = SmartPointer<viennaps::MaterialMap>;

levelSetsType levelSets = nullptr;
gridType cellGrid = nullptr;
psSmartPointer<lsDomain<T, D>> surface = nullptr;
psSmartPointer<csBVH<T, D>> BVH = nullptr;
SmartPointer<lsDomain<T, D>> surface = nullptr;
SmartPointer<csBVH<T, D>> BVH = nullptr;
materialMapType materialMap = nullptr;

T gridDelta;
Expand All @@ -43,18 +47,18 @@ template <class T, int D> class csDenseCellSet {
hrleVectorType<hrleIndexType, D> minIndex, maxIndex;

bool cellSetAboveSurface = false;
psMaterial coverMaterial = psMaterial::None;
viennaps::Material coverMaterial = viennaps::Material::None;
std::bitset<D> periodicBoundary;

std::vector<T> *fillingFractions;
const T eps = 1e-4;

public:
csDenseCellSet() {}
DenseCellSet() {}

csDenseCellSet(levelSetsType passedLevelSets,
materialMapType passedMaterialMap = nullptr,
T passedDepth = 0., bool passedCellSetPosition = false)
DenseCellSet(levelSetsType passedLevelSets,
materialMapType passedMaterialMap = nullptr, T passedDepth = 0.,
bool passedCellSetPosition = false)
: levelSets(passedLevelSets), cellSetAboveSurface(passedCellSetPosition) {
fromLevelSets(passedLevelSets, passedMaterialMap, passedDepth);
}
Expand All @@ -66,25 +70,25 @@ template <class T, int D> class csDenseCellSet {
materialMap = passedMaterialMap;

if (cellGrid == nullptr)
cellGrid = psSmartPointer<lsMesh<T>>::New();
cellGrid = SmartPointer<lsMesh<T>>::New();

if (surface == nullptr)
surface = psSmartPointer<lsDomain<T, D>>::New(levelSets->back());
surface = SmartPointer<lsDomain<T, D>>::New(levelSets->back());
else
surface->deepCopy(levelSets->back());

gridDelta = surface->getGrid().getGridDelta();

depth = passedDepth;
std::vector<psSmartPointer<lsDomain<T, D>>> levelSetsInOrder;
auto plane = psSmartPointer<lsDomain<T, D>>::New(surface->getGrid());
std::vector<lsSmartPointer<lsDomain<T, D>>> levelSetsInOrder;
auto plane = SmartPointer<lsDomain<T, D>>::New(surface->getGrid());
{
T origin[D] = {0.};
T normal[D] = {0.};
origin[D - 1] = depth;
normal[D - 1] = 1.;
lsMakeGeometry<T, D>(plane,
psSmartPointer<lsPlane<T, D>>::New(origin, normal))
lsSmartPointer<lsPlane<T, D>>::New(origin, normal))
.apply();
}
if (!cellSetAboveSurface)
Expand All @@ -102,12 +106,12 @@ template <class T, int D> class csDenseCellSet {
#ifndef NDEBUG
int db_ls = 0;
for (auto &ls : levelSetsInOrder) {
auto mesh = psSmartPointer<lsMesh<T>>::New();
auto mesh = SmartPointer<lsMesh<T>>::New();
lsToSurfaceMesh<T, D>(ls, mesh).apply();
psVTKWriter<T>(mesh, "cellSet_debug_" + std::to_string(db_ls++) + ".vtp")
lsVTKWriter<T>(mesh, "cellSet_debug_" + std::to_string(db_ls++) + ".vtp")
.apply();
}
psVTKWriter<T>(cellGrid, "cellSet_debug_init.vtu").apply();
lsVTKWriter<T>(cellGrid, "cellSet_debug_init.vtu").apply();
#endif

adjustMaterialIds();
Expand Down Expand Up @@ -138,7 +142,7 @@ template <class T, int D> class csDenseCellSet {
minExtent /= 2;
}

BVH = psSmartPointer<csBVH<T, D>>::New(getBoundingBox(), BVHlayers);
BVH = SmartPointer<csBVH<T, D>>::New(getBoundingBox(), BVHlayers);
buildBVH();
}

Expand Down Expand Up @@ -191,9 +195,9 @@ template <class T, int D> class csDenseCellSet {
return cellGrid->template getElements<(1 << D)>()[idx];
}

psSmartPointer<lsDomain<T, D>> getSurface() { return surface; }
SmartPointer<lsDomain<T, D>> getSurface() { return surface; }

psSmartPointer<lsMesh<T>> getCellGrid() { return cellGrid; }
SmartPointer<lsMesh<T>> getCellGrid() { return cellGrid; }

levelSetsType getLevelSets() const { return levelSets; }

Expand Down Expand Up @@ -259,7 +263,7 @@ template <class T, int D> class csDenseCellSet {
cellSetAboveSurface = passedCellSetPosition;
}

void setCoverMaterial(const psMaterial passedCoverMaterial) {
void setCoverMaterial(const viennaps::Material passedCoverMaterial) {
coverMaterial = passedCoverMaterial;
}

Expand Down Expand Up @@ -308,7 +312,7 @@ template <class T, int D> class csDenseCellSet {

// Write the cell set as .vtu file
void writeVTU(std::string fileName) {
psVTKWriter<T>(cellGrid, fileName).apply();
lsVTKWriter<T>(cellGrid, fileName).apply();
}

// Save cell set data in simple text format
Expand Down Expand Up @@ -339,15 +343,15 @@ template <class T, int D> class csDenseCellSet {
std::string line;

if (!file.is_open()) {
psLogger::getInstance()
Logger::getInstance()
.addWarning("Could not open file " + fileName)
.print();
return;
}

std::getline(file, line);
if (std::stoi(line) != numberOfCells) {
psLogger::getInstance().addWarning("Incompatible cell set data.").print();
Logger::getInstance().addWarning("Incompatible cell set data.").print();
return;
}

Expand Down Expand Up @@ -402,15 +406,15 @@ template <class T, int D> class csDenseCellSet {
auto materialIds = getScalarData("Material");

// create overlay material
std::vector<psSmartPointer<lsDomain<T, D>>> levelSetsInOrder;
auto plane = psSmartPointer<lsDomain<T, D>>::New(surface->getGrid());
std::vector<SmartPointer<lsDomain<T, D>>> levelSetsInOrder;
auto plane = SmartPointer<lsDomain<T, D>>::New(surface->getGrid());
{
T origin[D] = {0.};
T normal[D] = {0.};
origin[D - 1] = depth;
normal[D - 1] = 1.;
lsMakeGeometry<T, D>(plane,
psSmartPointer<lsPlane<T, D>>::New(origin, normal))
SmartPointer<lsPlane<T, D>>::New(origin, normal))
.apply();
}
if (!cellSetAboveSurface)
Expand Down Expand Up @@ -486,18 +490,18 @@ template <class T, int D> class csDenseCellSet {
// Updates the surface of the cell set. The new surface should be below the
// old surface as this function can only remove cells from the cell set.
void updateSurface() {
auto updateCellGrid = psSmartPointer<lsMesh<T>>::New();
auto updateCellGrid = SmartPointer<lsMesh<T>>::New();

lsToVoxelMesh<T, D> voxelConverter(updateCellGrid);
{
auto plane = psSmartPointer<lsDomain<T, D>>::New(surface->getGrid());
auto plane = SmartPointer<lsDomain<T, D>>::New(surface->getGrid());
T origin[D] = {0.};
T normal[D] = {0.};
origin[D - 1] = depth;
normal[D - 1] = 1.;

lsMakeGeometry<T, D>(plane,
psSmartPointer<lsPlane<T, D>>::New(origin, normal))
SmartPointer<lsPlane<T, D>>::New(origin, normal))
.apply();
voxelConverter.insertNextLevelSet(plane);
}
Expand Down Expand Up @@ -549,7 +553,7 @@ template <class T, int D> class csDenseCellSet {
if (!cellNeighbors.empty() && !forceRebuild)
return;

psUtils::Timer timer;
Timer timer;
timer.start();
const auto &cells = cellGrid->template getElements<(1 << D)>();
const auto &nodes = cellGrid->getNodes();
Expand Down Expand Up @@ -625,7 +629,7 @@ template <class T, int D> class csDenseCellSet {
}
}
timer.finish();
psLogger::getInstance()
Logger::getInstance()
.addTiming("Building cell set neighborhood structure took",
timer.currentDuration * 1e-9)
.print();
Expand Down Expand Up @@ -713,7 +717,7 @@ template <class T, int D> class csDenseCellSet {
}

void buildBVH() {
psUtils::Timer timer;
Timer timer;
timer.start();
auto &elems = cellGrid->template getElements<(1 << D)>();
auto &nodes = cellGrid->getNodes();
Expand All @@ -724,19 +728,19 @@ template <class T, int D> class csDenseCellSet {
auto &node = nodes[elems[elemIdx][n]];
auto cell = BVH->getCellIds(node);
if (cell == nullptr) {
psLogger::getInstance().addError("BVH building error.").print();
Logger::getInstance().addError("BVH building error.").print();
}
cell->insert(elemIdx);
}
}
timer.finish();
psLogger::getInstance()
Logger::getInstance()
.addTiming("Building cell set BVH took", timer.currentDuration * 1e-9)
.print();
}

void calculateMinMaxIndex(
const std::vector<psSmartPointer<lsDomain<T, D>>> &levelSetsInOrder) {
const std::vector<lsSmartPointer<lsDomain<T, D>>> &levelSetsInOrder) {
// set to zero
for (unsigned i = 0; i < D; ++i) {
minIndex[i] = std::numeric_limits<hrleIndexType>::max();
Expand Down Expand Up @@ -774,3 +778,5 @@ template <class T, int D> class csDenseCellSet {
return onBoundary;
}
};

} // namespace viennacs
25 changes: 16 additions & 9 deletions include/viennaps/compact/psKDTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@
#include <omp.h>
#endif

#include "../psLogger.hpp"
#include "psQueues.hpp"

#include <vcLogger.hpp>

namespace viennaps {

using namespace viennacore;

template <class NumericType, class ValueType = std::vector<NumericType>>
class psKDTree {
class KDTree {
typedef typename std::vector<NumericType>::size_type SizeType;

struct Node;
Expand All @@ -54,9 +59,9 @@ class psKDTree {
Node *rootNode = nullptr;

public:
psKDTree() {}
KDTree() {}

psKDTree(const std::vector<ValueType> &passedPoints) {
KDTree(const std::vector<ValueType> &passedPoints) {
if (!passedPoints.empty()) {
// The first row determins the data dimension
D = passedPoints[0].size();
Expand All @@ -72,8 +77,8 @@ class psKDTree {
}
}
} else {
psLogger::getInstance()
.addWarning("psKDTree: the provided points vector is empty.")
Logger::getInstance()
.addWarning("KDTree: the provided points vector is empty.")
.print();
return;
}
Expand All @@ -82,8 +87,8 @@ class psKDTree {
void setPoints(const std::vector<ValueType> &passedPoints,
const std::vector<NumericType> &passedScalingFactors = {}) {
if (passedPoints.empty()) {
psLogger::getInstance()
.addWarning("psKDTree: the provided points vector is empty.")
Logger::getInstance()
.addWarning("KDTree: the provided points vector is empty.")
.print();
return;
}
Expand Down Expand Up @@ -161,7 +166,7 @@ class psKDTree {

void build() {
if (nodes.size() == 0) {
psLogger::getInstance().addWarning("KDTree: No points provided!").print();
Logger::getInstance().addWarning("KDTree: No points provided!").print();
return;
}

Expand Down Expand Up @@ -449,3 +454,5 @@ class psKDTree {
}
};
};

} // namespace viennaps
Loading

0 comments on commit 5f1cb24

Please sign in to comment.