35template<
typename T,
typename PARAMETERS,
typename LATTICES>
39 clout <<
"Start initialization" << std::endl;
42 this->prepareGeometry();
46 this->geometry().innerClean(this->parameters(
names::Output()).verbose);
47 geometry().checkForErrors(this->parameters(
names::Output()).verbose);
49 geometry().getStatistics().print();
52 this->_isInitialized =
true;
55 clout <<
"Finished initialization" << std::endl;
59template<
typename T,
typename PARAMETERS,
typename LATTICES>
62 if (! this->_isInitialized) {
69template<
typename T,
typename PARAMETERS,
typename LATTICES>
76 _timer = std::make_unique<util::Timer<BaseType<T>>>(
77 converter().getLatticeTime(this->parameters(names::Simulation()).maxTime),
78 _sGeometry->getStatistics().getNvoxel(),
81 if constexpr (isStationary){
82 for (
unsigned i = 0; i < getNumberStationaryLattices(); ++i) {
83 _convergenceCheck[i] = std::make_unique<util::ValueTracer<T>>(
84 converter().getLatticeTime(this->parameters(names::Stationarity()).physInterval[i]),
85 this->parameters(names::Stationarity()).epsilon[i]);
90 converter().getLatticeTime(this->parameters(names::Simulation()).physBoundaryValueUpdateTime),
93 converter().getLatticeTime(this->parameters(names::Simulation()).physTimeStabilityCheck),
99template<
typename T,
typename PARAMETERS,
typename LATTICES>
103 clout <<
"Start prepareSimulation" << std::endl;
113 lattice->initialize();
114 lattice->getStatistics().reset();
115 lattice->getStatistics().initialize();
119 if constexpr (outputVTK) {
126 clout <<
"Finished prepareSimulation" << std::endl;
127 clout <<
"Start collide-and-stream loop" << std::endl;
133template<
typename T,
typename PARAMETERS,
typename LATTICES>
136 if (iT % _itBoundaryUpdate == 0) {
137 setBoundaryValues(iT);
142 lattice->communicate();
146 if constexpr (outputVTK) {
152 if constexpr (outputImages) {
158 if constexpr (outputGnuplot) {
165 && iT % converter().getLatticeTime(this->parameters(
names::Output()).logT) == 0) {
172 lattice->collideAndStream();
177 std::get<0>(_sLattices)->stripeOffDensityOffset(std::get<0>(_sLattices)->getStatistics().getAverageRho() - T(1));
180 if constexpr (isStationary){
181 unsigned counter = 0;
182 using parameters_t =
typename PARAMETERS::template value<names::Stationarity>;
183 parameters_t::stat_lattices::for_each( [&](
auto Id) {
185 if (this->parameters(
names::Stationarity()).convergenceType[counter] == parameters_t::MaxLatticeVelocity){
186 _convergenceCheck[counter]->takeValue( this->lattice(Id).getStatistics().getMaxU());
188 else if (this->parameters(
names::Stationarity()).convergenceType[counter] == parameters_t::AverageEnergy){
189 _convergenceCheck[counter]->takeValue( this->lattice(Id).getStatistics().getAverageEnergy() );
191 else if (this->parameters(
names::Stationarity()).convergenceType[counter] == parameters_t::AverageRho){
192 _convergenceCheck[counter]->takeValue( this->lattice(Id).getStatistics().getAverageRho());
195 throw std::invalid_argument(
"Convergence type is not supported.\n");
201 if (iT % _itCheckStability == 0) {
206template<
typename T,
typename PARAMETERS,
typename LATTICES>
211 lattice->communicate();
217 if constexpr (outputVTK) {
222 if constexpr (outputImages) {
224 writeImages(this->_iT);
227 if constexpr (outputGnuplot) {
229 writeGnuplot(this->_iT);
232 getResults(this->_iT);
236 clout <<
"Finished collide-and-stream loop" << std::endl;
237 clout <<
"Start postprocessing" << std::endl;
242 _timer->printSummary();
251 clout <<
"Finished postprocessing" << std::endl;
255template<
typename T,
typename PARAMETERS,
typename LATTICES>
258 if (iT > this->converter().getLatticeTime(this->parameters(
names::Simulation()).maxTime)){
262 if constexpr (isStationary){
263 if (std::all_of(_convergenceCheck.cbegin(), _convergenceCheck.cend(), [](
auto& c){
264 return c->hasConverged();
267 clout <<
"Simulation converged." << std::endl;
276template<
typename T,
typename PARAMETERS,
typename LATTICES>
281 if (lattice->getStatistics().getMaxU() > this->parameters(
names::Simulation()).boundMaxU) {
282 clout <<
"PROBLEM uMax=" << lattice->getStatistics().getMaxU() << std::endl;
283 lattice->getStatistics().print(iT, converter().getPhysTime(iT));
293template<
typename T,
typename PARAMETERS,
typename LATTICES>
297 using lattice_type =
typename std::remove_reference_t<
decltype(lattice)>::element_type;
298 lattice = std::make_shared<lattice_type>(geometry());
304template<
typename T,
typename PARAMETERS,
typename LATTICES>
307 using OutputParameters_t =
typename PARAMETERS::template value<names::Output>;
308 OutputParameters_t::printLatticeStatistics::for_each( [&](
auto type){
309 lattice(type.get()).getStatistics().print(iT, converter().getPhysTime(iT));
312 _timer->print(iT, this->parameters(
names::Output()).timerPrintMode);
315template<
typename T,
typename PARAMETERS,
typename LATTICES>
322template<
typename T,
typename PARAMETERS,
typename LATTICES>
327 auto& lattice = *std::get<0>(_sLattices);
328 using DESCRIPTOR =
typename LATTICES::values_t::template get<0>;
336 vtmWriter.write( cuboid );
337 vtmWriter.write( rank );
338 vtmWriter.createMasterFile();
LbSolver is a generic solver for Lattice-Boltzmann problems.
void buildAndReturn()
Build geometry, lattice.
virtual void printLog(std::size_t iT) const
void prepareSimulation() override
Set up lattice and initialize fields.
void timeStep(std::size_t iT) override
Collide-and-stream + additional computations.
virtual void prepareVTK() const
Write geometric information for vtk output The default version writes geometry, cuboid,...
virtual void writeLogConverter() const
virtual bool checkStability(std::size_t iT)
check stability: maxU should be <= _boundMaxU for a stable simulation Returns true if this fulfilled
virtual bool exitCondition(std::size_t iT) const override
Condition, when to exit the time-stepping loop Returns true if the loop shall be continued.
void postSimulation() override
Evaluate results.
void initialize() override
Set up geometry.
Top level namespace for all of OpenLB.
std::conditional_t< DESCRIPTOR::d==2, SuperLatticeRank2D< T, DESCRIPTOR >, SuperLatticeRank3D< T, DESCRIPTOR > > SuperLatticeRank
std::conditional_t< DIM==2, SuperVTMwriter2D< T, OUT_T, W >, SuperVTMwriter3D< T, OUT_T, W > > SuperVTMwriter
void initialize(int *argc, char ***argv, bool multiOutput, bool verbose)
Initialize OpenLB.
std::conditional_t< DESCRIPTOR::d==2, SuperLatticeCuboid2D< T, DESCRIPTOR >, SuperLatticeCuboid3D< T, DESCRIPTOR > > SuperLatticeCuboid
void writeVTK(SuperF2D< T, W > &f, int iT=0)
Write out functor F to VTK file (helper)