Skip to content

Commit

Permalink
Point IDs in lsVelocityField (#40)
Browse files Browse the repository at this point in the history
* Made velocity a member of integration schemes.

* Added pointId parameter to lsVelocityField.

* Set ViennaLS version to 2.0 since the pointId addition is a breaking change.

* Fixed lsConcepts for precompiled libraries.

* Added advectionbenchmark to test whether a templated velocity field is better. There was no runtime difference observed between the base class and template approaches.
  • Loading branch information
XaverKlemenschits authored Mar 29, 2021
1 parent c4b55af commit 6b75c9d
Show file tree
Hide file tree
Showing 198 changed files with 1,370 additions and 990 deletions.
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ cmake_minimum_required(VERSION 3.4)

project(
"ViennaLS"
VERSION 1.3.0)
VERSION 2.0.0)

add_definitions(-DVIENNALS_VERSION=${PROJECT_VERSION})

include(GNUInstallDirs)

# needed because g++ optimizes away the T(constexpr)
# workaround for passing references
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(CMAKE_CXX_STANDARD "17")
endif()
# c++17 for inlince constexpr variables
SET(CMAKE_CXX_STANDARD "17")

# set default build type
SET(DEFAULT_BUILD_TYPE "Release")
Expand Down
6 changes: 4 additions & 2 deletions Examples/AirGapDeposition/AirGapDeposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class velocityField : public lsVelocityField<NumericType> {
NumericType
getScalarVelocity(const std::array<NumericType, 3> & /*coordinate*/,
int /*material*/,
const std::array<NumericType, 3> &normalVector) {
const std::array<NumericType, 3> &normalVector,
unsigned long /*pointId*/) {
// velocity is proportional to the normal vector
NumericType velocity =
std::abs(normalVector[0]) + std::abs(normalVector[1]);
Expand All @@ -34,7 +35,8 @@ class velocityField : public lsVelocityField<NumericType> {
std::array<NumericType, 3>
getVectorVelocity(const std::array<NumericType, 3> & /*coordinate*/,
int /*material*/,
const std::array<NumericType, 3> & /*normalVector*/) {
const std::array<NumericType, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<NumericType, 3>({});
}
};
Expand Down
4 changes: 2 additions & 2 deletions Examples/AirGapDeposition/AirGapDeposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class velocityField(vls.lsVelocityField):
# coord and normalVec are lists with 3 elements
# in 2D coord[2] and normalVec[2] are zero
# getScalarVelocity must return a scalar
def getScalarVelocity(self, coord, material, normal):
def getScalarVelocity(self, coord, material, normal, pointId):
return abs(normal[0]) + abs(normal[1])

def getVectorVelocity(self, coord, material, normal):
def getVectorVelocity(self, coord, material, normal, pointId):
return (0,0,0)

extent = 30
Expand Down
18 changes: 10 additions & 8 deletions Examples/Deposition/Deposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@ using NumericType = float;
// implement own velocity field
class velocityField : public lsVelocityField<NumericType> {
public:
NumericType getScalarVelocity(
const std::array<NumericType, 3> & /*coordinate*/, int /*material*/,
const std::array<NumericType, 3>
& /*normalVector = hrleVectorType<NumericType, 3>(0.)*/) {
NumericType
getScalarVelocity(const std::array<NumericType, 3> & /*coordinate*/,
int /*material*/,
const std::array<NumericType, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
// Some arbitrary velocity function of your liking
// (try changing it and see what happens :)
NumericType velocity = 1.;
return velocity;
}

std::array<NumericType, 3> getVectorVelocity(
const std::array<NumericType, 3> & /*coordinate*/, int /*material*/,
const std::array<NumericType, 3>
& /*normalVector = hrleVectorType<NumericType, 3>(0.)*/) {
std::array<NumericType, 3>
getVectorVelocity(const std::array<NumericType, 3> & /*coordinate*/,
int /*material*/,
const std::array<NumericType, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<NumericType, 3>({}); // initialise to zero
}
};
Expand Down
4 changes: 2 additions & 2 deletions Examples/Deposition/Deposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class velocityField(vls.lsVelocityField):
# coord and normalVec are lists with 3 elements
# in 2D coord[2] and normalVec[2] are zero
# getScalarVelocity must return a scalar
def getScalarVelocity(self, coord, material, normal):
def getScalarVelocity(self, coord, material, normal, pointId):
# some arbitrary velocity function of your liking
# (try changing it and see what happens :)
velocity = 1
return velocity

def getVectorVelocity(self, coord, material, normal):
def getVectorVelocity(self, coord, material, normal, pointId):
return (0,0,0)

extent = 30
Expand Down
12 changes: 8 additions & 4 deletions Examples/PatternedSubstrate/PatternedSubstrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class directionalEtch : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int material,
const std::array<double, 3> &normalVector) {
const std::array<double, 3> &normalVector,
unsigned long /*pointId*/) {
// etch directionally
if (material > 0) {
return (normalVector[2] > 0.) ? -normalVector[2] : 0;
Expand All @@ -40,7 +41,8 @@ class directionalEtch : public lsVelocityField<double> {
std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<double, 3>({});
}
};
Expand All @@ -50,15 +52,17 @@ class isotropicDepo : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
// deposit isotropically everywhere
return 1;
}

std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<double, 3>({});
}
};
Expand Down
6 changes: 4 additions & 2 deletions Examples/PeriodicBoundary/PeriodicBoundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ class velocityField : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
// isotropic etch rate
return 1;
}

std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<double, 3>({});
}
};
Expand Down
6 changes: 4 additions & 2 deletions Examples/SquareEtch/SquareEtch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class velocityField : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int material,
const std::array<double, 3> &normalVector) {
const std::array<double, 3> &normalVector,
unsigned long /*pointId*/) {
// if the surface of material 1 is facing upwards, etch it anisotropically
if (material == 1 && normalVector[1] > 0.) {
return -std::abs(normalVector[1]);
Expand All @@ -44,7 +45,8 @@ class analyticalField : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int material,
const std::array<double, 3> &normalVector) {
const std::array<double, 3> &normalVector,
unsigned long /*pointId*/) {
if (material != 1)
return 0.;

Expand Down
6 changes: 4 additions & 2 deletions Examples/VoidEtching/VoidEtching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ class velocityField : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
// isotropic etch rate
return -1;
}

std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<double, 3>({});
}
};
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Releases are tagged on the maser branch and available in the [releases section](

### System Requirements

* C++ Compiler with OpenMP support
* C++17 Compiler with OpenMP support

* [ViennaHRLE](https://github.com/ViennaTools/viennahrle)

Expand Down
6 changes: 4 additions & 2 deletions Tests/Advection/Advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class velocityField : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> &normalVector) {
const std::array<double, 3> &normalVector,
unsigned long /*pointId*/) {
// Some arbitrary velocity function of your liking
// (try changing it and see what happens :)
double velocity = 1. + ((normalVector[0] > 0) ? 2.3 : 0.5) *
Expand All @@ -30,7 +31,8 @@ class velocityField : public lsVelocityField<double> {
std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<double, 3>({});
}
};
Expand Down
6 changes: 4 additions & 2 deletions Tests/Advection2D/Advection2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ class velocityField : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return 1.;
}

std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<double, 3>({});
}
};
Expand Down
111 changes: 111 additions & 0 deletions Tests/AdvectionBenchmark/AdvectionBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <chrono>
#include <iostream>

#include <lsAdvect.hpp>
#include <lsDomain.hpp>
#include <lsExpand.hpp>
#include <lsMakeGeometry.hpp>
#include <lsPrune.hpp>
#include <lsToSurfaceMesh.hpp>
#include <lsVTKWriter.hpp>

/**
This example measures the time it takes for several advection steps to run.
\example AdvectionBenchmark.cpp
*/

// implement own velocity field
class velocityField : public lsVelocityField<double> {
std::vector<double> &data_;

public:
velocityField(std::vector<double> &data) : data_(data) {}

double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/,
unsigned long pointId) {
// Some arbitrary velocity function of your liking
// (try changing it and see what happens :)
// double velocity = 1. + ((normalVector[0] > 0) ? 2.3 : 0.5) *
// std::abs(normalVector[0] * normalVector[0]);
// return velocity;
return data_[pointId];
}

std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<double, 3>({});
}

double
getDissipationAlpha(int /*direction*/, int /*material*/,
const std::array<double, 3> & /*centralDifferences*/) {
return 0;
}
};

int main() {

constexpr int D = 3;
omp_set_num_threads(1);

double gridDelta = 0.25;

auto sphere1 = lsSmartPointer<lsDomain<double, D>>::New(gridDelta);

double origin[3] = {5., 0., 0.};
double radius = 7.3;

lsMakeGeometry<double, D>(
sphere1, lsSmartPointer<lsSphere<double, D>>::New(origin, radius))
.apply();

{
std::cout << "Extracting..." << std::endl;
auto mesh = lsSmartPointer<lsMesh<>>::New();
lsToSurfaceMesh<double, D>(sphere1, mesh).apply();
lsVTKWriter<double>(mesh, "before.vtk").apply();
}

// instantiate velocities
std::vector<double> vels(sphere1->getNumberOfPoints() * 100, 0.31415);
auto velocities = lsSmartPointer<velocityField>::New(vels);

std::cout << "Advecting" << std::endl;

const unsigned numberOfSteps = 500;
// run several adveciton steps with different number of threads
for (unsigned cores = 1; cores < 33; cores *= 2) {
omp_set_num_threads(cores);

auto levelSet = lsSmartPointer<lsDomain<double, D>>::New(gridDelta);
levelSet->deepCopy(sphere1);

levelSet->getDomain().segment();

lsAdvect<double, D> advectionKernel;
advectionKernel.insertNextLevelSet(levelSet);
advectionKernel.setVelocityField(velocities);

const auto start = std::chrono::high_resolution_clock::now();
for (unsigned i = 0; i < numberOfSteps; ++i) {
advectionKernel.apply();
}
const auto stop = std::chrono::high_resolution_clock::now();
std::cout << "Advection with " << cores << ": "
<< std::chrono::duration_cast<std::chrono::milliseconds>(stop -
start)
.count()
<< "\n";

auto mesh = lsSmartPointer<lsMesh<>>::New();
lsToSurfaceMesh<double, D>(levelSet, mesh).apply();
lsVTKWriter<double>(mesh, "cores" + std::to_string(cores) + ".vtk").apply();
}

return 0;
}
10 changes: 10 additions & 0 deletions Tests/AdvectionBenchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.4)

project("AdvectionBenchmark")

find_package(ViennaHRLE REQUIRED)
find_package(ViennaLS REQUIRED)

add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${VIENNALS_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${VIENNALS_LIBRARIES})
6 changes: 4 additions & 2 deletions Tests/AdvectionPlane/AdvectionPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ class velocityField : public lsVelocityField<double> {
public:
double getScalarVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return 1.;
}

std::array<double, 3>
getVectorVelocity(const std::array<double, 3> & /*coordinate*/,
int /*material*/,
const std::array<double, 3> & /*normalVector*/) {
const std::array<double, 3> & /*normalVector*/,
unsigned long /*pointId*/) {
return std::array<double, 3>({});
}
};
Expand Down
Loading

0 comments on commit 6b75c9d

Please sign in to comment.