Skip to content

Commit b5d705b

Browse files
Adaptive time stepping feature in ViennaLS (#187)
* Added removeMaterial info when removing top LS layer * Added WENO 5th order advection scheme * Reverted back to install script, with ViennaLS default version 5.2.1 * Add option to enable adaptive time stepping during advection * Add adptive time step threshold * Update ViennaLS version --------- Co-authored-by: filipovic <filipovic@iue.tuwien.ac.at>
1 parent d977704 commit b5d705b

File tree

16 files changed

+106
-37
lines changed

16 files changed

+106
-37
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ CPMFindPackage(
120120

121121
CPMFindPackage(
122122
NAME ViennaLS
123-
VERSION 5.2.1
123+
VERSION 5.3.0
124124
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaLS"
125125
EXCLUDE_FROM_ALL ${VIENNAPS_BUILD_PYTHON})
126126

examples/boschProcess/boschProcessSimulate.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
using namespace viennaps;
99
constexpr int D = 2;
1010
using NumericType = double;
11+
const std::string name = "boschProcessSimulate_";
1112

12-
void etch(SmartPointer<Domain<NumericType, D>> domain,
13-
util::Parameters &params) {
13+
void etch(SmartPointer<Domain<NumericType, D>> domain, util::Parameters &params,
14+
int &n) {
1415
std::cout << " - Etching - " << std::endl;
1516
auto etchModel = SmartPointer<MultiParticleProcess<NumericType, D>>::New();
1617
etchModel->addNeutralParticle(params.get("neutralStickingProbability"));
@@ -29,10 +30,11 @@ void etch(SmartPointer<Domain<NumericType, D>> domain,
2930
return rate;
3031
});
3132
Process<NumericType, D>(domain, etchModel, params.get("etchTime")).apply();
33+
domain->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
3234
}
3335

3436
void punchThrough(SmartPointer<Domain<NumericType, D>> domain,
35-
util::Parameters &params) {
37+
util::Parameters &params, int &n) {
3638
std::cout << " - Punching through - " << std::endl;
3739
NumericType depositionThickness = params.get("depositionThickness");
3840

@@ -41,22 +43,25 @@ void punchThrough(SmartPointer<Domain<NumericType, D>> domain,
4143
-depositionThickness, 1. /* sticking */, params.get("ionSourceExponent"),
4244
Material::Mask);
4345
Process<NumericType, D>(domain, depoRemoval, 1.).apply();
46+
domain->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
4447
}
4548

4649
void deposit(SmartPointer<Domain<NumericType, D>> domain,
47-
util::Parameters &params) {
50+
util::Parameters &params, int &n) {
4851
std::cout << " - Deposition - " << std::endl;
4952
NumericType depositionThickness = params.get("depositionThickness");
5053
NumericType depositionSticking = params.get("depositionStickingProbability");
5154
domain->duplicateTopLevelSet(Material::Polymer);
5255
auto model = SmartPointer<SingleParticleProcess<NumericType, D>>::New(
5356
depositionThickness, depositionSticking);
5457
Process<NumericType, D>(domain, model, 1.).apply();
58+
domain->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
5559
}
5660

57-
void ash(SmartPointer<Domain<NumericType, D>> domain) {
61+
void ash(SmartPointer<Domain<NumericType, D>> domain, int &n) {
5862
domain->removeTopLevelSet();
5963
domain->removeStrayPoints();
64+
domain->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
6065
}
6166

6267
int main(int argc, char **argv) {
@@ -87,25 +92,18 @@ int main(int argc, char **argv) {
8792
params.get("maskHeight"))
8893
.apply();
8994

90-
const NumericType depositionThickness = params.get("depositionThickness");
9195
const int numCycles = params.get<int>("numCycles");
92-
const std::string name = "boschProcessSimulate_";
9396

9497
int n = 0;
9598
geometry->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
96-
etch(geometry, params);
97-
geometry->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
99+
etch(geometry, params, n);
98100

99101
for (int i = 0; i < numCycles; ++i) {
100102
std::cout << "Cycle " << i + 1 << std::endl;
101-
deposit(geometry, params);
102-
geometry->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
103-
punchThrough(geometry, params);
104-
geometry->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
105-
etch(geometry, params);
106-
geometry->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
107-
ash(geometry);
108-
geometry->saveSurfaceMesh(name + std::to_string(n++) + ".vtp");
103+
deposit(geometry, params, n);
104+
punchThrough(geometry, params, n);
105+
etch(geometry, params, n);
106+
ash(geometry, n);
109107
}
110108

111109
geometry->saveVolumeMesh(name + "final");

examples/boschProcess/boschProcessSimulate.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,25 @@ def rateFunction(fluxes, material):
6565

6666
etchModel.setRateFunction(rateFunction)
6767
etchTime = params["etchTime"]
68-
6968
n = 0
7069

7170

72-
def runProcess(model, name, time=1.0):
71+
def saveGeometry(geometry):
7372
global n
73+
geometry.saveSurfaceMesh("boschProcessSimulate_{}".format(n), addInterfaces=True)
74+
n += 1
75+
76+
77+
def runProcess(model, name, time=1.0):
7478
print(" - {} - ".format(name))
7579
ps.Process(geometry, model, time).apply()
76-
geometry.saveSurfaceMesh("boschProcessSimulate_{}".format(n))
77-
n += 1
80+
saveGeometry(geometry)
7881

7982

8083
numCycles = int(params["numCycles"])
8184

8285
# Initial geometry
83-
geometry.saveSurfaceMesh("boschProcessSimulate_{}".format(n))
84-
n += 1
86+
saveGeometry(geometry)
8587

8688
runProcess(etchModel, "Etching", etchTime)
8789

@@ -101,8 +103,7 @@ def runProcess(model, name, time=1.0):
101103
# Ash (remove) the polymer
102104
geometry.removeTopLevelSet()
103105
geometry.removeStrayPoints()
104-
geometry.saveSurfaceMesh("boschProcessSimulate_{}".format(n))
105-
n += 1
106+
saveGeometry(geometry)
106107

107108
# save the final geometry
108109
geometry.saveVolumeMesh("boschProcessSimulate_final")

include/viennaps/process/psAdvectionHandler.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ template <typename NumericType, int D> class AdvectionHandler {
2929
(intSchem != IntegrationScheme::ENGQUIST_OSHER_1ST_ORDER &&
3030
intSchem != IntegrationScheme::ENGQUIST_OSHER_2ND_ORDER &&
3131
intSchem != IntegrationScheme::LOCAL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER &&
32-
intSchem != IntegrationScheme::LOCAL_LOCAL_LAX_FRIEDRICHS_2ND_ORDER)) {
32+
intSchem != IntegrationScheme::LOCAL_LOCAL_LAX_FRIEDRICHS_2ND_ORDER &&
33+
intSchem != IntegrationScheme::WENO_5TH_ORDER)) {
3334
VIENNACORE_LOG_WARNING(
3435
"Translation field method not supported in combination "
3536
"with integration scheme.");
@@ -50,6 +51,11 @@ template <typename NumericType, int D> class AdvectionHandler {
5051
advectionKernel_.setIgnoreVoids(context.advectionParams.ignoreVoids);
5152
advectionKernel_.setCheckDissipation(
5253
context.advectionParams.checkDissipation);
54+
advectionKernel_.setAdaptiveTimeStepping(
55+
context.advectionParams.adaptiveTimeStepping);
56+
advectionKernel_.setAdaptiveTimeStepThreshold(
57+
context.advectionParams.adaptiveTimeStepThreshold);
58+
5359
// normals vectors are only necessary for analytical velocity fields
5460
if (translationMethod > 0)
5561
advectionKernel_.setCalculateNormalVectors(false);

include/viennaps/process/psProcess.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ template <typename NumericType, int D> class Process {
4141
Process(SmartPointer<Domain<NumericType, D>> domain) : context_{domain} {
4242
initializeStrategies();
4343
}
44+
template <typename... ParamArgs>
4445
Process(SmartPointer<Domain<NumericType, D>> domain,
4546
SmartPointer<ProcessModelBase<NumericType, D>> model,
46-
NumericType processDuration = 0.)
47+
NumericType processDuration = 0., ParamArgs... params)
4748
: context_{domain, model, processDuration} {
49+
(setParameters(params), ...);
4850
initializeStrategies();
4951
}
5052

include/viennaps/process/psProcessParams.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ struct AdvectionParameters {
5555
IntegrationScheme::ENGQUIST_OSHER_1ST_ORDER;
5656
double timeStepRatio = 0.4999;
5757
double dissipationAlpha = 1.0;
58+
double adaptiveTimeStepThreshold = 0.05;
5859
bool checkDissipation = true;
5960
bool velocityOutput = false;
6061
bool ignoreVoids = false;
62+
bool adaptiveTimeStepping = false;
6163

6264
auto toMetaData() const {
6365
std::unordered_map<std::string, std::vector<double>> metaData;

include/viennaps/psDomain.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ template <class NumericType, int D> class Domain {
234234

235235
levelSets_.pop_back();
236236
if (materialMap_) {
237-
auto newMatMap = MaterialMapType::New();
238-
for (std::size_t i = 0; i < levelSets_.size(); i++) {
239-
newMatMap->insertNextMaterial(materialMap_->getMaterialAtIdx(i));
240-
}
241-
materialMap_ = newMatMap;
237+
materialMap_->removeMaterial();
242238
}
243239
}
244240

include/viennaps/psMaterials.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ class MaterialMap {
182182
map_->insertNextMaterial(static_cast<int>(material));
183183
}
184184

185+
void removeMaterial() {
186+
if (map_) {
187+
map_->removeLastMaterial();
188+
}
189+
}
190+
185191
// Returns the material at the given index. If the index is out of bounds, it
186192
// returns Material::GAS.
187193
[[nodiscard]] Material getMaterialAtIdx(std::size_t idx) const {

include/viennaps/psUtil.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ convertIntegrationScheme(const std::string &s) {
3636
if (s == "STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER" || s == "SLLF_1")
3737
return viennals::IntegrationSchemeEnum::
3838
STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER;
39+
if (s == "WENO_5TH_ORDER" || s == "WENO_5")
40+
return viennals::IntegrationSchemeEnum::WENO_5TH_ORDER;
3941
throw std::invalid_argument(
4042
"The value must be one of the following: "
4143
"ENGQUIST_OSHER_1ST_ORDER, ENGQUIST_OSHER_2ND_ORDER, "
@@ -45,7 +47,8 @@ convertIntegrationScheme(const std::string &s) {
4547
"LOCAL_LOCAL_LAX_FRIEDRICHS_2ND_ORDER, "
4648
"LOCAL_LAX_FRIEDRICHS_1ST_ORDER, "
4749
"LOCAL_LAX_FRIEDRICHS_2ND_ORDER, "
48-
"STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER");
50+
"STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER, "
51+
"WENO_5TH_ORDER");
4952
}
5053

5154
[[nodiscard]] inline std::string
@@ -72,6 +75,8 @@ convertIntegrationSchemeToString(viennals::IntegrationSchemeEnum scheme) {
7275
return "LOCAL_LAX_FRIEDRICHS_2ND_ORDER";
7376
case viennals::IntegrationSchemeEnum::STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER:
7477
return "STENCIL_LOCAL_LAX_FRIEDRICHS_1ST_ORDER";
78+
case viennals::IntegrationSchemeEnum::WENO_5TH_ORDER:
79+
return "WENO_5TH_ORDER";
7580
default:
7681
throw std::invalid_argument("Unknown integration scheme.");
7782
}

python/pyWrap.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ PYBIND11_MODULE(VIENNAPS_MODULE_NAME, module) {
462462
.def_readwrite("checkDissipation", &AdvectionParameters::checkDissipation)
463463
.def_readwrite("velocityOutput", &AdvectionParameters::velocityOutput)
464464
.def_readwrite("ignoreVoids", &AdvectionParameters::ignoreVoids)
465+
.def_readwrite("adaptiveTimeStepping",
466+
&AdvectionParameters::adaptiveTimeStepping)
467+
.def_readwrite("adaptiveTimeStepThreshold",
468+
&AdvectionParameters::adaptiveTimeStepThreshold)
465469
.def("toMetaData", &AdvectionParameters::toMetaData,
466470
"Convert the advection parameters to a metadata dict.")
467471
.def("toMetaDataString", &AdvectionParameters::toMetaDataString,

0 commit comments

Comments
 (0)