25#ifndef SUPER_LATTICE_H
26#define SUPER_LATTICE_H
45template <
typename T,
typename DESCRIPTOR>
46class SuperLattice final :
public SuperStructure<T,DESCRIPTOR::d>
47 ,
public BufferSerializable {
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;
63 LatticeStatistics<T> _statistics;
68 bool _statisticsEnabled;
70 void collectStatistics();
72 bool _initialized =
false;
75 constexpr static unsigned d = DESCRIPTOR::d;
86 unsigned overlap = 3);
92 :
SuperLattice(cuboidDecomposition, loadBalancer, overlap)
94 _converter = &converter;
110 throw std::runtime_error(
"Unit converter not provided");
117 return *_block[locC];
123 template <
typename BLOCK>
126 return *
dynamic_cast<BLOCK*
>(_block[locC].get());
131 return *_block[locC];
134 template <
typename BLOCK>
137 return *
dynamic_cast<const BLOCK*
>(_block[locIC].get());
141 template <Platform PLATFORM,
typename F>
144 if (_block[iC]->getPlatform() == PLATFORM) {
162 _block[iC]->setProcessingContext(context);
170 template <
typename FIELD_TYPE>
174 if (_block[iC]->
template hasData<FIELD_TYPE>()) {
175 _block[iC]->template getData<FIELD_TYPE>().setProcessingContext(context);
181 template <
typename STAGE>
194 template <
typename... R>
211 void writeSummary(std::string fileName =
"lattice")
const;
214 template <
typename DYNAMICS>
217 template <
template<
typename...>
typename DYNAMICS>
219 template <
typename DYNAMICS>
222 template <
typename DYNAMICS>
226 template <
template<
typename...>
typename DYNAMICS>
229 template <
template<
typename...>
typename DYNAMICS>
286 template <
typename FIELD>
290 template <
typename FIELD>
294 template <
typename FIELD>
298 template <
typename FIELD>
302 template <
typename FIELD>
307 template <
typename FIELD>
318 template <
typename PARAMETER>
322 template <
typename PARAMETER,
typename DYNAMICS>
325 template <
typename PARAMETER,
template<
typename...>
typename DYNAMICS>
335 template <
typename PARAMETER,
typename _DESCRIPTOR,
typename FIELD>
388 _statisticsEnabled =
true;
390 _block[iC]->setStatisticsEnabled(
true);
399 _statisticsEnabled =
false;
401 _block[iC]->setStatisticsEnabled(
false);
406 template <
typename STAGE=stage::PostStream>
410 template <
typename STAGE=stage::PostStream>
418 template <
typename STAGE=stage::PostStream>
422 template <
typename STAGE>
424 _customTasks[
typeid(STAGE)].emplace_back(f);
427 template <
typename STAGE>
431 template <
typename STAGE,
typename F>
434 template <
typename F>
441 template <
typename CONTEXT>
444 template <
typename STAGE>
452 bool*
getBlock(std::size_t iBlock, std::size_t& sizeBlock,
bool loadingMode)
override;
Platform-agnostic interface to concrete host-side field arrays.
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.
Base class for all LoadBalancer.
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 addCustomTask(std::function< void()> f)
Schedules f for execution during every invocation of STAGE.
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.
LoadBalancer< T > & getLoadBalancer()
LoadBalancer< T > & _loadBalancer
CuboidDecomposition< T, D > & getCuboidDecomposition()
Conversion between physical and lattice units, as well as discretization.
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
std::conditional_t< D==2, SuperF2D< T, U >, SuperF3D< T, U > > SuperF
std::conditional_t< D==2, IndicatorF2D< T >, IndicatorF3D< T > > IndicatorF
std::conditional_t< D==2, SuperIndicatorF2D< T >, SuperIndicatorF3D< T > > SuperIndicatorF
Curried ConcreteBlockLattice template for use in callUsingConcretePlatform.
Representation of a parallel 2D geometry – header file.
Unit conversion handling – header file.