OpenLB 1.8.1
Loading...
Searching...
No Matches
superLattice.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2007 Mathias J. Krause
4 * 2021 Adrian Kummerlaender
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25#ifndef SUPER_LATTICE_H
26#define SUPER_LATTICE_H
27
28#include "utilities/aliases.h"
29
30#include "unitConverter.h"
31#include "stages.h"
32#include "cellD.h"
33#include "blockLattice.hh"
35#include "postProcessing.hh"
36#include "serializer.h"
40
41namespace olb {
42
43
45template <typename T, typename DESCRIPTOR>
46class SuperLattice final : public SuperStructure<T,DESCRIPTOR::d>
47 , public BufferSerializable {
48private:
50 std::optional<const UnitConverter<T,DESCRIPTOR>*> _converter;
52 std::vector<std::unique_ptr<BlockLattice<T,DESCRIPTOR>>> _block;
54 std::map<std::type_index,std::unique_ptr<SuperCommunicator<T,SuperLattice>>> _communicator;
56 bool _communicationNeeded;
58 std::map<std::type_index,std::vector<std::function<void()>>> _customTasks;
60 std::map<std::type_index,std::vector<std::future<void>>> _backgroundTasks;
61
63 LatticeStatistics<T> _statistics;
65
68 bool _statisticsEnabled;
70 void collectStatistics();
72 bool _initialized = false;
73
74public:
75 constexpr static unsigned d = DESCRIPTOR::d;
76
78 using value_t = T;
80 using descriptor_t = DESCRIPTOR;
81
83
85 LoadBalancer<T>& loadBalancer,
86 unsigned overlap = 3);
87
89 LoadBalancer<T>& loadBalancer,
90 unsigned overlap,
91 const UnitConverter<T,DESCRIPTOR>& converter)
92 : SuperLattice(cuboidDecomposition, loadBalancer, overlap)
93 {
94 _converter = &converter;
95 }
96
99 sGeometry.getLoadBalancer(),
100 sGeometry.getOverlap())
101 { }
102
103 SuperLattice(const SuperLattice&) = delete;
104 ~SuperLattice() = default;
105
107 if (_converter) {
108 return **_converter;
109 } else {
110 throw std::runtime_error("Unit converter not provided");
111 }
112 }
113
116 {
117 return *_block[locC];
118 };
120
123 template <typename BLOCK>
124 BLOCK& getBlock(int locC)
125 {
126 return *dynamic_cast<BLOCK*>(_block[locC].get());
127 };
130 {
131 return *_block[locC];
132 };
134 template <typename BLOCK>
135 const BLOCK& getBlock(int locIC) const
136 {
137 return *dynamic_cast<const BLOCK*>(_block[locIC].get());
138 };
139
141 template <Platform PLATFORM, typename F>
143 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
144 if (_block[iC]->getPlatform() == PLATFORM) {
145 f(static_cast<ConcreteBlockLattice<T,DESCRIPTOR,PLATFORM>&>(*_block[iC]));
146 }
147 }
148 };
149
151
155 {
156 // Communicate overlap prior to evaluation
157 if (context == ProcessingContext::Evaluation) {
158 communicate();
160 }
161 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
162 _block[iC]->setProcessingContext(context);
163 }
164 };
165
167
170 template <typename FIELD_TYPE>
172 {
173 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
174 if (_block[iC]->template hasData<FIELD_TYPE>()) {
175 _block[iC]->template getData<FIELD_TYPE>().setProcessingContext(context);
176 }
177 }
178 };
179
181 template <typename STAGE>
184 void communicate() override;
185
189 LatticeStatistics<T> const& getStatistics() const;
190
194 template <typename... R>
195 std::enable_if_t<sizeof...(R) == DESCRIPTOR::d+1, Cell<T,DESCRIPTOR>>
196 get(R... latticeR);
197
199
203 void initialize();
204
206
209 void printSummary() const;
211 void writeSummary(std::string fileName = "lattice") const;
212
214 template <typename DYNAMICS>
215 void defineDynamics();
217 template <template<typename...> typename DYNAMICS>
219 template <typename DYNAMICS>
222 template <typename DYNAMICS>
223 void defineDynamics(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material);
224
226 template <template<typename...> typename DYNAMICS>
229 template <template<typename...> typename DYNAMICS>
230 void defineDynamics(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material);
231
232 //Define the dynamics on a domain with indicator and promise
234
236
243
245
252
254
262 void defineRhoU(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
264
266
273 void definePopulations(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
282 void definePopulations(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
284
286 template <typename FIELD>
290 template <typename FIELD>
294 template <typename FIELD>
295 void defineField(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
298 template <typename FIELD>
299 void defineField(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
302 template <typename FIELD>
307 template <typename FIELD>
311
313
318 template <typename PARAMETER>
320
322 template <typename PARAMETER, typename DYNAMICS>
325 template <typename PARAMETER, template<typename...> typename DYNAMICS>
327
329
335 template <typename PARAMETER, typename _DESCRIPTOR, typename FIELD>
337
339
347 void iniEquilibrium(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
351 void iniEquilibrium(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
354
364 void iniRegularized(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
367
369
380 void collideAndStream();
381
383 void stripeOffDensityOffset(T offset);
384
387 {
388 _statisticsEnabled = true;
389 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
390 _block[iC]->setStatisticsEnabled(true);
391 }
392 };
394
398 {
399 _statisticsEnabled = false;
400 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
401 _block[iC]->setStatisticsEnabled(false);
402 }
403 };
404
406 template <typename STAGE=stage::PostStream>
410 template <typename STAGE=stage::PostStream>
412
414
418 template <typename STAGE=stage::PostStream>
419 void executePostProcessors(STAGE stage=STAGE());
420
422 template <typename STAGE>
423 void addCustomTask(std::function<void()> f) {
424 _customTasks[typeid(STAGE)].emplace_back(f);
425 }
427 template <typename STAGE>
428 void executeCustomTasks(STAGE stage=STAGE());
429
431 template <typename STAGE, typename F>
432 void scheduleBackgroundTask(F&& f);
434 template <typename F>
435 void scheduleBackgroundOutput(F&& f);
437
441 template <typename CONTEXT>
442 void scheduleBackgroundOutputVTK(CONTEXT&& vtkContext);
444 template <typename STAGE>
445 void waitForBackgroundTasks(STAGE stage=STAGE{});
446
448 std::size_t getNblock() const override;
450 std::size_t getSerializableSize() const override;
452 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
453 void postLoad() override;
454
455};
456
457
458}
459
460#endif
Platform-agnostic interface to concrete host-side field arrays.
Definition fieldArrayD.h:49
AnalyticalF are applications from DD to XD, where X is set by the constructor.
Implementation of BlockLattice on a concrete PLATFORM.
Decomposition of a physical volume into a set of disjoint cuboids.
Factory for instances of a specific Dynamics type.
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
Base class for all LoadBalancer.
Definition vtiWriter.h:42
Factory for instances of a specific OPERATOR type.
Generic communicator for overlaps between blocks of SUPER.
Representation of a statistic for a parallel 2D geometry.
Super class maintaining block lattices for a cuboid decomposition.
void addPostProcessor(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&indicator, PostProcessorPromise< T, DESCRIPTOR > &&promise)
Add a non-local post-processing step.
void communicate() override
Perform full overlap communication if needed.
SuperLattice(CuboidDecomposition< T, DESCRIPTOR::d > &cuboidDecomposition, LoadBalancer< T > &loadBalancer, unsigned overlap, const UnitConverter< T, DESCRIPTOR > &converter)
SuperCommunicator< T, SuperLattice > & getCommunicator(STAGE stage=STAGE())
Return communicator for given communication stage.
DESCRIPTOR descriptor_t
Descriptor / discrete velocity set of the lattice.
void waitForBackgroundTasks(STAGE stage=STAGE{})
Block until all background tasks scheduled for STAGE are completed.
LatticeStatistics< T > & getStatistics()
Return a handle to the LatticeStatistics object.
void iniRegularized(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&indicator, AnalyticalF< DESCRIPTOR::d, T, T > &rho, AnalyticalF< DESCRIPTOR::d, T, T > &u, AnalyticalF< DESCRIPTOR::d, T, T > &pi)
Initialize by non- and equilibrium on a domain described by an indicator.
T value_t
Base value type of the lattice.
void forBlocksOnPlatform(F f)
Apply f to every ConcreteBlockLattice of PLATFORM.
void defineDynamics(SuperGeometry< T, DESCRIPTOR::d > &sGeometry, int material)
Set dynamics of indicated cells to DYNAMICS<T,DESCRIPTOR>
void collideAndStream()
Core implementation of a single iteration of the collide and stream loop.
BLOCK & getBlock(int locC)
Return locC-th block lattice casted to BLOCK.
void printSummary() const
Prints a summary of all dynamics and post processors.
void defineField(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&indicator, FunctorPtr< SuperF< DESCRIPTOR::d, T, T > > &&field)
Define an external field on a domain described by an indicator.
void defineRho(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&, AnalyticalF< DESCRIPTOR::d, T, T > &rho)
Define rho on a domain described by an indicator.
void setParameter(FieldD< T, DESCRIPTOR, PARAMETER > field)
Update PARAMETER in all dynamics and post processors.
void setProcessingContext(ProcessingContext context)
Set processing context of FIELD_TYPE in block lattices.
void stripeOffDensityOffset(T offset)
Subtract constant offset from the density.
void statisticsOff()
Switch Statistics off (default on)
const UnitConverter< T, DESCRIPTOR > & getConverter() const
static constexpr unsigned d
void definePopulations(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&indicator, AnalyticalF< DESCRIPTOR::d, T, T > &Pop)
Define a population on a domain described by an indicator.
void setProcessingContext(ProcessingContext context)
Set processing context of block lattices.
std::size_t getSerializableSize() const override
Binary size for the serializer.
const BlockLattice< T, DESCRIPTOR > & getBlock(int locC) const
Return read-only BlockLattice with local index locC.
std::size_t getNblock() const override
Number of data blocks for the serializable interface.
void iniEquilibrium(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&indicator, AnalyticalF< DESCRIPTOR::d, T, T > &rho, AnalyticalF< DESCRIPTOR::d, T, T > &u)
Initialize by equilibrium on a domain described by an indicator.
void statisticsOn()
Switch Statistics on (default on)
const BLOCK & getBlock(int locIC) const
Return locC-th block lattice casted to BLOCK (read-only)
void postLoad() override
void addCustomTask(std::function< void()> f)
Schedules f for execution during every invocation of STAGE.
~SuperLattice()=default
void executeCustomTasks(STAGE stage=STAGE())
Executes custom tasks assigned to STAGE.
void defineDynamics(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&indicator)
Set dynamics of indicated cells to DYNAMICS<T,DESCRIPTOR>
void initialize()
Initialize lattice to be ready for simulation.
void defineDynamics()
Set dynamics of all cells to DYNAMICS.
SuperLattice(CuboidDecomposition< T, DESCRIPTOR::d > &cuboidDecomposition, LoadBalancer< T > &loadBalancer, unsigned overlap=3)
BlockLattice< T, DESCRIPTOR > & getBlock(int locC)
Return BlockLattice with local index locC.
void defineU(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&indicator, AnalyticalF< DESCRIPTOR::d, T, T > &u)
Define u on a domain described by an indicator.
void defineRhoU(FunctorPtr< SuperIndicatorF< T, DESCRIPTOR::d > > &&indicator, AnalyticalF< DESCRIPTOR::d, T, T > &rho, AnalyticalF< DESCRIPTOR::d, T, T > &u)
Define rho and u on a domain described by an indicator.
void scheduleBackgroundOutput(F &&f)
Schedule F(iC) for one-off background output of block data.
void scheduleBackgroundOutputVTK(CONTEXT &&vtkContext)
Schedule one-off background output of given VTK CONTEXT.
void setParameterOfDynamics(FieldD< T, DESCRIPTOR, PARAMETER > &&field)
Update PARAMETER in DYNAMICS.
void writeSummary(std::string fileName="lattice") const
Writes a summary of all dynamics and post processors.
void scheduleBackgroundTask(F &&f)
Schedule F for one-off background execution to be finished by STAGE.
SuperLattice(SuperGeometry< T, DESCRIPTOR::d > &sGeometry)
SuperLattice(const SuperLattice &)=delete
Cell< T, DESCRIPTOR > get(LatticeR< DESCRIPTOR::d+1 > latticeR)
Get local cell interface.
void executePostProcessors(STAGE stage=STAGE())
Executes post processors for STAGE.
CuboidDecomposition< T, D > & getCuboidDecomposition()
Conversion between physical and lattice units, as well as discretization.
Plain old scalar vector.
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
Definition platform.h:54
std::conditional_t< D==2, SuperF2D< T, U >, SuperF3D< T, U > > SuperF
Definition aliases.h:187
std::conditional_t< D==2, IndicatorF2D< T >, IndicatorF3D< T > > IndicatorF
Definition aliases.h:247
std::conditional_t< D==2, SuperIndicatorF2D< T >, SuperIndicatorF3D< T > > SuperIndicatorF
Definition aliases.h:197
Curried ConcreteBlockLattice template for use in callUsingConcretePlatform.
Representation of a parallel 2D geometry – header file.
Unit conversion handling – header file.