OpenLB 1.7
Loading...
Searching...
No Matches
solverParameters.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Julius Jessberger, Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24
25#ifndef SOLVER_PARAMETERS_H
26#define SOLVER_PARAMETERS_H
27
28
29#include <iostream>
30
31#include "io/ostreamManager.h"
32#include "io/xmlReader.h"
34#include "names.h"
35#include "utilities/typeMap.h"
36
37namespace olb {
38
39namespace parameters {
40
42 virtual void initialize() { }
43};
44
45// ------------------------------ Simulation ----------------------------------
46
53template<typename T>
55{
56 using BT = BaseType<T>;
57
62
63 bool pressureFilter {false};
64
65 // no of cuboids per mpi process
66 int noC {1};
67 int overlap {3};
68
69 virtual void initialize() { }
70};
71
73template<typename T, typename LATTICES>
74struct XmlSimulation : public SimulationBase<T> {
75
76 XMLreader const* xml;
77
78 using NAME = typename LATTICES::keys_t::template get<0>;
79 using descriptor = typename LATTICES::template value<NAME>;
80 std::shared_ptr<UnitConverter<T,descriptor> const> converter;
81};
82
83
84// ------------------------------ Stationarity --------------------------------
85
87{ };
88
95template<typename T, typename... STAT_LATTICES>
97{
98 constexpr static unsigned numberOfArguments = sizeof...(STAT_LATTICES);
99 // list of lattices for which stationarity is to be checked
100 using stat_lattices = std::conditional_t <(numberOfArguments == 0),
103 constexpr static unsigned numberOfStationaryLattices = stat_lattices::size;
104
106
107 std::array <ConvergenceType,numberOfStationaryLattices> convergenceType {MaxLatticeVelocity};
108 std::array <T,numberOfStationaryLattices> physInterval {1};
109 std::array <T,numberOfStationaryLattices> epsilon {1e-3};
110
111 Stationarity() = default;
112
113 Stationarity(ConvergenceType type, T interval_, T epsilon_)
114 {
115 std::fill(convergenceType.begin(), convergenceType.end(), type);
116 std::fill(physInterval.begin(), physInterval.end(), interval_);
117 std::fill(epsilon.begin(), epsilon.end(), epsilon_);
118 }
119
121 std::array <ConvergenceType,numberOfStationaryLattices> type,
122 std::array <T,numberOfStationaryLattices> interval_,
123 std::array <T,numberOfStationaryLattices> epsilon_)
124 : convergenceType(type), physInterval(interval_), epsilon(epsilon_)
125 { }
126};
127
128
129// ------------------------------ Output --------------------------------------
130
136template<typename T, typename LatticeLog= names::NavierStokes>
138{
140 std::string name {"unnamed"};
141 std::string olbDir {"../../../"};
142 std::string outputDir {"./tmp/"};
143
144 bool verbose {true};
145 bool printLogConverter {true};
147
149
151
152 OutputGeneral() = default;
153
155 std::string name_,
156 std::string olbDir_,
157 std::string outputDir_,
158
159 bool verbose_,
160 bool printLogConverter_,
161
162 BT logT_,
163
164 int timerPrintMode_
165 ) : name(name_), olbDir(olbDir_), outputDir(outputDir_), verbose(verbose_),
166 printLogConverter(printLogConverter_), logT(logT_),
167 timerPrintMode(timerPrintMode_)
168 { }
169
170
176};
177
178
179
180template <typename T>
182{
184 // pO for print Output to avoid name clashes using off and final as keywords
186
187 OutputPlot() = default;
188
189 std::string output {"off"};
190 std::string filename {"unnamed"};
193
194 OutputPlot(std::string out, std::string name, BT savetime) {
195 if(out == "off"){
197 } else if (out == "intervals"){
199 } else if (out == "final"){
201 }
202 filename = name;
203 saveTime = savetime;
204 }
205};
206
207
208// ------------------------------ Results -------------------------------------
209
214struct ResultsBase : public ParameterBase { };
215
216
217// ------------------ Parameter reading functionality ------------------------
218
219template<typename PARAMETERS>
221{
222 mutable OstreamManager clout {std::cout, "ParameterReader"};
223 std::shared_ptr<PARAMETERS> params;
224
225 ReaderBase(std::shared_ptr<PARAMETERS> params_) : params(params_)
226 { }
227};
228
237template<typename PARAMETERS, typename TAG>
238struct Reader : public ReaderBase<PARAMETERS> {
239 Reader(std::shared_ptr<PARAMETERS> params_) : Reader::ReaderBase(params_)
240 { }
241
242 virtual void read(XMLreader const& xml) { }
243};
244
245
246template<typename PARAMETERS, typename TAG>
247Reader(std::shared_ptr<PARAMETERS> params_, TAG tag) -> Reader<PARAMETERS, TAG>;
248
249
250template<typename PARAMETERS>
251Reader(std::shared_ptr<PARAMETERS> params_) -> Reader<PARAMETERS, void>;
252
253
254template<typename T, typename LatticeLog, typename TAG>
255struct Reader<OutputGeneral<T,LatticeLog>, TAG> : public ReaderBase<OutputGeneral<T,LatticeLog>>
256{
258
259 void read(XMLreader const& xml)
260 {
261 // Filenames
262 xml.readOrWarn<std::string>("Application", "Name", "", this->params->name, true, true, true);
263 xml.readOrWarn<std::string>("Application", "OlbDir", "", this->params->olbDir, true, true, true);
264 xml.readOrWarn<std::string>("Output", "OutputDir", "", this->params->outputDir, true, true, true);
265
266 // For Console Output
267 xml.readOrWarn<bool>("Output", "Log", "VerboseLog", this->params->verbose, true, false, true);
268 xml.readOrWarn<bool>("Output", "PrintLogConverter", "", this->params->printLogConverter, true, false, false);
269 xml.readOrWarn<BaseType<T>>("Output", "Log", "SaveTime", this->params->logT, true, false, true);
270 xml.readOrWarn<int>("Output", "Timer", "PrintMode", this->params->timerPrintMode, true, false, false);
271 }
272};
273
274
275
276template<typename T, typename TAG>
277struct Reader<OutputPlot<T>, TAG> : public ReaderBase<OutputPlot<T>>
278{
280
281 void read(XMLreader const& xml)
282 {
283 std::string tag {TAG().name};
284 xml.readOrWarn<std::string>("Output", tag, "Output", this->params->output, true, false, true);
285 if (this->params->output != "off") {
286 xml.readOrWarn<std::string>("Output", tag, "Filename", this->params->filename, true, false, false);
287 xml.readOrWarn<BaseType<T>>("Output", tag, "SaveTime", this->params->saveTime, true, false, true);
288 }
289 if(this->params->output == "off"){
291 } else if (this->params->output == "intervals"){
293 } else if (this->params->output == "final"){
295 }
296 }
297};
298
299template<typename T, typename TAG>
300struct Reader<SimulationBase<T>, TAG> : public ReaderBase<SimulationBase<T>>
301{
303
304 void read(XMLreader const& xml)
305 {
306 using BT = BaseType<T>;
307
308 xml.readOrWarn<BT>("Application", "PhysParameters", "StartUpTime", this->params->startUpTime, false, false, false);
309 xml.readOrWarn<BT>("Application", "PhysParameters", "PhysMaxTime", this->params->maxTime, false, true, true);
310 xml.readOrWarn<int>("Application", "Mesh", "noCuboidsPerProcess", this->params->noC, true, false, true);
311 xml.readOrWarn<bool>("Application", "PressureFilter", "", this->params->pressureFilter, true, false, false);
312
313 this->params->physBoundaryValueUpdateTime = this->params->maxTime / BT(100); // 1% of max. time as default value
314 xml.readOrWarn<BT>("Application", "PhysParameters", "BoundaryValueUpdateTime", this->params->physBoundaryValueUpdateTime, true, false, true);
315 this->params->physTimeStabilityCheck = this->params->maxTime / BT(100);
316 xml.readOrWarn<BT>("Application", "PhysParameters", "TimeStabilityCheck", this->params->physTimeStabilityCheck, true, false, true);
317 }
318};
319
320template<typename T, typename TAG>
321struct Reader<Stationarity<T>, TAG> : public ReaderBase<Stationarity<T>>
322{
324
325 void read(XMLreader const& xml)
326 {
327 std::string type = "MaxLatticeVelocity";
328 xml.readOrWarn<std::string>("Application", "ConvergenceCheck", "Type", type, true, false, true);
329 this->params->convergenceType[0] = (type == "AverageEnergy") ? Stationarity<T>::AverageEnergy : Stationarity<T>::MaxLatticeVelocity;
330 BaseType<T> help; // needed to prevent typecast errors with util::ADf data type
331 xml.readOrWarn<BaseType<T>>("Application", "ConvergenceCheck", "Interval", help, true, false, true);
332 this->params->physInterval[0] = help;
333 xml.readOrWarn<BaseType<T>>("Application", "ConvergenceCheck", "Residuum", help, true, false, true);
334 this->params->epsilon[0] = help;
335 }
336};
337
338template<typename T, typename LATTICES, typename TAG>
339struct Reader<XmlSimulation<T,LATTICES>, TAG> : public ReaderBase<XmlSimulation<T,LATTICES>>
340{
342
343 void read(XMLreader const& xml_)
344 {
345 Reader<SimulationBase<T>, TAG>(this->params).read(xml_);
346 this->params->xml = &xml_;
347
348 using NAME = typename LATTICES::keys_t::template get<0>;
349 using descriptor = typename LATTICES::template value<NAME>;
350 this->params->converter = std::shared_ptr<UnitConverter<T,descriptor>>(createUnitConverter<T,descriptor>(xml_));
351 }
352};
353
354} // namespace parameters
355
356
357// ------------------ Creator functions for XML interface ---------------------
358
359template <typename PARAMETERS, typename TAG>
360std::shared_ptr<PARAMETERS> createParameters(XMLreader const& xml)
361{
362 auto result = std::make_shared<PARAMETERS>();
364 result->initialize();
365 return result;
366}
367
368template <class parameters_map>
370{
372 meta::tuple_for_each(paramsTuple.tuple, [&xml](auto& element, auto index) {
373 using parameter_type = typename std::remove_reference_t<decltype(element)>::element_type;
374 using tag = typename parameters_map::keys_t::template get<index()>;
375 element = createParameters<parameter_type,tag>(xml);
376 });
377 return paramsTuple;
378}
379
380} // namespace olb
381
382#endif
class for marking output with some text
bool readOrWarn(std::string name_parameter_1, std::string name_parameter_2, std::string name_parameter_3, ParameterType &var, bool defaultAvailable=true, bool exitIfMissing=false, bool showWarning=true) const
This wrapper function reads the given parameter from the "type_parameter" and "name_parameter_1" or "...
Definition xmlReader.h:178
void setOutputDir(std::string outputDir)
Definition singleton.h:51
void setOlbDir(std::string olbDir_)
Definition singleton.h:46
void tuple_for_each(TUPLE &tuple, F &&f)
Apply F to each element of TUPLE.
Definition meta.h:369
Reader(std::shared_ptr< PARAMETERS > params_, TAG tag) -> Reader< PARAMETERS, TAG >
Directories & directories()
Definition singleton.h:150
Top level namespace for all of OpenLB.
std::shared_ptr< PARAMETERS > createParameters(XMLreader const &xml)
typename util::BaseTypeHelper< T >::type BaseType
Definition baseType.h:59
auto createParametersTuple(XMLreader const &xml)
Plain wrapper for list of types.
Definition meta.h:276
Structs to keep parameters which characterize the output.
virtual void initialize() override
OutputGeneral(std::string name_, std::string olbDir_, std::string outputDir_, bool verbose_, bool printLogConverter_, BT logT_, int timerPrintMode_)
OutputPlot(std::string out, std::string name, BT savetime)
ReaderBase(std::shared_ptr< PARAMETERS > params_)
std::shared_ptr< PARAMETERS > params
Base struct for reading parameters from files.
Reader(std::shared_ptr< PARAMETERS > params_)
virtual void read(XMLreader const &xml)
Struct to keep results of the simulation in order to provide communication with other parts of the pr...
Base struct to keep the parameters that are necessary for the simulation.
All parameters that are necessary for checking whether the simulation became stationary.
std::array< T, numberOfStationaryLattices > epsilon
static constexpr unsigned numberOfStationaryLattices
Stationarity(std::array< ConvergenceType, numberOfStationaryLattices > type, std::array< T, numberOfStationaryLattices > interval_, std::array< T, numberOfStationaryLattices > epsilon_)
std::conditional_t<(numberOfArguments==0), meta::list< names::NavierStokes >, meta::list< STAT_LATTICES... > > stat_lattices
std::array< ConvergenceType, numberOfStationaryLattices > convergenceType
Stationarity(ConvergenceType type, T interval_, T epsilon_)
static constexpr unsigned numberOfArguments
std::array< T, numberOfStationaryLattices > physInterval
All the simulation parameters are read directly from an xml file.
typename LATTICES::template value< NAME > descriptor
typename LATTICES::keys_t::template get< 0 > NAME
std::shared_ptr< UnitConverter< T, descriptor > const > converter
Mapping between KEYs and instances of type VALUEs.
Input/Output in XML format – header file.