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();
173 lattice->executeCoupling();
178 std::get<0>(_sLattices)->stripeOffDensityOffset(std::get<0>(_sLattices)->getStatistics().getAverageRho() - T(1));
181 if constexpr (isStationary){
182 unsigned counter = 0;
183 using parameters_t =
typename PARAMETERS::template value<names::Stationarity>;
184 parameters_t::stat_lattices::for_each( [&](
auto Id) {
186 if (this->parameters(
names::Stationarity()).convergenceType[counter] == parameters_t::MaxLatticeVelocity){
187 _convergenceCheck[counter]->takeValue( this->lattice(Id).getStatistics().getMaxU());
189 else if (this->parameters(
names::Stationarity()).convergenceType[counter] == parameters_t::AverageEnergy){
190 _convergenceCheck[counter]->takeValue( this->lattice(Id).getStatistics().getAverageEnergy() );
192 else if (this->parameters(
names::Stationarity()).convergenceType[counter] == parameters_t::AverageRho){
193 _convergenceCheck[counter]->takeValue( this->lattice(Id).getStatistics().getAverageRho());
196 throw std::invalid_argument(
"Convergence type is not supported.\n");
202 if (iT % _itCheckStability == 0) {
207template<
typename T,
typename PARAMETERS,
typename LATTICES>
212 lattice->communicate();
218 if constexpr (outputVTK) {
223 if constexpr (outputImages) {
225 writeImages(this->_iT);
228 if constexpr (outputGnuplot) {
230 writeGnuplot(this->_iT);
233 getResults(this->_iT);
237 clout <<
"Finished collide-and-stream loop" << std::endl;
238 clout <<
"Start postprocessing" << std::endl;
243 _timer->printSummary();
252 clout <<
"Finished postprocessing" << std::endl;
256template<
typename T,
typename PARAMETERS,
typename LATTICES>
259 if (iT > this->converter().getLatticeTime(this->parameters(
names::Simulation()).maxTime)){
263 if constexpr (isStationary){
264 if (std::all_of(_convergenceCheck.cbegin(), _convergenceCheck.cend(), [](
auto& c){
265 return c->hasConverged();
268 clout <<
"Simulation converged." << std::endl;
277template<
typename T,
typename PARAMETERS,
typename LATTICES>
282 if (lattice->getStatistics().getMaxU() > _boundMaxU) {
283 clout <<
"PROBLEM uMax=" << lattice->getStatistics().getMaxU() << std::endl;
284 lattice->getStatistics().print(iT, converter().getPhysTime(iT));
294template<
typename T,
typename PARAMETERS,
typename LATTICES>
295void LbSolver<T,PARAMETERS,LATTICES>::renewLattices()
297 meta::tuple_for_each(_sLattices, [&](
auto& lattice){
298 using lattice_type =
typename std::remove_reference_t<
decltype(lattice)>::element_type;
299 lattice = std::make_shared<lattice_type>(geometry());
305template<
typename T,
typename PARAMETERS,
typename LATTICES>
308 using OutputParameters_t =
typename PARAMETERS::template value<names::Output>;
309 OutputParameters_t::printLatticeStatistics::for_each( [&](
auto type){
310 lattice(type.get()).getStatistics().print(iT, converter().getPhysTime(iT));
313 _timer->print(iT, this->parameters(
names::Output()).timerPrintMode);
316template<
typename T,
typename PARAMETERS,
typename LATTICES>
323template<
typename T,
typename PARAMETERS,
typename LATTICES>
328 auto& lattice = *std::get<0>(_sLattices);
329 using DESCRIPTOR =
typename LATTICES::values_t::template get<0>;
339 vtmWriter.write( cuboid );
340 vtmWriter.write( geometry );
341 vtmWriter.write( rank );
342 vtmWriter.createMasterFile();
LbSolver is a generic solver for Lattice-Boltzmann problems.
void buildAndReturn()
Build geometry, lattice and call computeResults.
void prepareSimulation() override
Set up lattice and initialize fields.
void timeStep(std::size_t iT) override
Collide-and-stream + additional computations.
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.
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Top level namespace for all of OpenLB.
std::conditional_t< DESCRIPTOR::d==2, SuperLatticeRank2D< T, DESCRIPTOR >, SuperLatticeRank3D< T, DESCRIPTOR > > SuperLatticeRank
std::conditional_t< DESCRIPTOR::d==2, SuperLatticeGeometry2D< T, DESCRIPTOR >, SuperLatticeGeometry3D< T, DESCRIPTOR > > SuperLatticeGeometry
std::conditional_t< DIM==2, SuperVTMwriter2D< T, OUT_T, W >, SuperVTMwriter3D< T, OUT_T, W > > SuperVTMwriter
std::conditional_t< DESCRIPTOR::d==2, SuperLatticeCuboid2D< T, DESCRIPTOR >, SuperLatticeCuboid3D< T, DESCRIPTOR > > SuperLatticeCuboid