OpenLB 1.7
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 "stages.h"
31#include "cellD.h"
32#include "blockLattice.hh"
34#include "postProcessing.hh"
35#include "serializer.h"
39
40namespace olb {
41
42
44template <typename T, typename DESCRIPTOR>
45class SuperLattice final : public SuperStructure<T,DESCRIPTOR::d>
46 , public BufferSerializable {
47private:
49 std::vector<std::unique_ptr<BlockLattice<T,DESCRIPTOR>>> _block;
51 std::map<std::type_index,std::unique_ptr<SuperCommunicator<T,SuperLattice>>> _communicator;
53 bool _communicationNeeded;
55 std::map<std::type_index,std::vector<std::function<void()>>> _customTasks;
57 std::map<std::type_index,std::vector<std::future<void>>> _backgroundTasks;
58
60 LatticeStatistics<T> _statistics;
62
65 bool _statisticsEnabled;
67 void collectStatistics();
68
69public:
70 constexpr static unsigned d = DESCRIPTOR::d;
71
73 using value_t = T;
75 using descriptor_t = DESCRIPTOR;
76
78
81 SuperLattice(const SuperLattice&) = delete;
82 ~SuperLattice() = default;
83
86 {
87 return *_block[locC];
88 };
90
93 template <typename BLOCK>
94 BLOCK& getBlock(int locC)
95 {
96 return *dynamic_cast<BLOCK*>(_block[locC].get());
97 };
99 const BlockLattice<T,DESCRIPTOR>& getBlock(int locC) const
100 {
101 return *_block[locC];
102 };
104 template <typename BLOCK>
105 const BLOCK& getBlock(int locIC) const
106 {
107 return *dynamic_cast<const BLOCK*>(_block[locIC].get());
108 };
109
111 template <Platform PLATFORM, typename F>
113 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
114 if (_block[iC]->getPlatform() == PLATFORM) {
115 f(static_cast<ConcreteBlockLattice<T,DESCRIPTOR,PLATFORM>&>(*_block[iC]));
116 }
117 }
118 };
119
121
125 {
126 // Communicate overlap prior to evaluation
127 if (context == ProcessingContext::Evaluation) {
128 communicate();
129 waitForBackgroundTasks<stage::PreContextSwitchTo<ProcessingContext::Evaluation>>();
130 }
131 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
132 _block[iC]->setProcessingContext(context);
133 }
134 };
135
137
140 template <typename FIELD_TYPE>
142 {
143 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
144 if (_block[iC]->template hasData<FIELD_TYPE>()) {
145 _block[iC]->template getData<FIELD_TYPE>().setProcessingContext(context);
146 }
147 }
148 };
149
151 template <typename STAGE>
154 void communicate() override;
155
159 LatticeStatistics<T> const& getStatistics() const;
160
164 template <typename... R>
165 std::enable_if_t<sizeof...(R) == DESCRIPTOR::d+1, Cell<T,DESCRIPTOR>>
166 get(R... latticeR);
167
169
173 void initialize();
174
176 template <typename DYNAMICS>
179 template <typename DYNAMICS>
180 void defineDynamics(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material);
181
183 template <template<typename...> typename DYNAMICS>
186 template <template<typename...> typename DYNAMICS>
187 void defineDynamics(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material);
188
192 void defineDynamics(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
193 Dynamics<T,DESCRIPTOR>* dynamics);
194
196
203
205
212
214
222 void defineRhoU(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
224
226
233 void definePopulations(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
242 void definePopulations(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
244
246 template <typename FIELD>
250 template <typename FIELD>
254 template <typename FIELD>
255 void defineField(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
258 template <typename FIELD>
259 void defineField(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
262 template <typename FIELD>
265 template <typename FIELD>
268
270
275 template <typename PARAMETER>
277
279 template <typename PARAMETER, typename DYNAMICS>
282 template <typename PARAMETER, template<typename...> typename DYNAMICS>
284
286
292 template <typename PARAMETER, Platform PLATFORM, typename FIELD>
294
296
304 void iniEquilibrium(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
308 void iniEquilibrium(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
311
321 void iniRegularized(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
324
326
337 void collideAndStream();
338
340 void stripeOffDensityOffset(T offset);
341
344 {
345 _statisticsEnabled = true;
346 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
347 _block[iC]->setStatisticsEnabled(true);
348 }
349 };
351
355 {
356 _statisticsEnabled = false;
357 for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
358 _block[iC]->setStatisticsEnabled(false);
359 }
360 };
361
363 template <typename STAGE=stage::PostStream>
366 template <typename STAGE=stage::PostStream>
370 template <typename STAGE=stage::PostStream>
371 void addPostProcessor(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
374 template <typename STAGE=stage::PostStream>
378 template <typename STAGE=stage::PostStream>
380
382
386 template <typename STAGE=stage::PostStream>
387 void executePostProcessors(STAGE stage=STAGE());
388
390 template <typename PARTNER_DESCRIPTOR>
392 std::vector<SuperLattice<T,PARTNER_DESCRIPTOR>*> partnerLattices);
394 template <typename PARTNER_DESCRIPTOR>
397 std::vector<SuperLattice<T,PARTNER_DESCRIPTOR>*> partnerLattices);
399 template <typename PARTNER_DESCRIPTOR>
400 void addLatticeCoupling(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
402 std::vector<SuperLattice<T,PARTNER_DESCRIPTOR>*> partnerLattices);
404 template <typename... PARTNER_DESCRIPTORS>
406 PARTNER_DESCRIPTORS&... partnerLattices);
408 template <typename... PARTNER_DESCRIPTORS>
411 PARTNER_DESCRIPTORS&... partnerLattices);
413 template <typename... PARTNER_DESCRIPTORS>
414 void addLatticeCoupling(SuperGeometry<T,DESCRIPTOR::d>& sGeometry, int material,
416 PARTNER_DESCRIPTORS&... partnerLattices);
417
419
424 void executeCoupling();
425
427 template <typename STAGE>
428 void addCustomTask(std::function<void()> f) {
429 _customTasks[typeid(STAGE)].emplace_back(f);
430 }
432 template <typename STAGE>
433 void executeCustomTasks(STAGE stage=STAGE());
434
436 template <typename STAGE, typename F>
437 void scheduleBackgroundTask(F&& f);
439 template <typename F>
440 void scheduleBackgroundOutput(F&& f);
442
446 template <typename CONTEXT>
447 void scheduleBackgroundOutputVTK(CONTEXT&& vtkContext);
449 template <typename STAGE>
450 void waitForBackgroundTasks(STAGE stage=STAGE{});
451
453 std::size_t getNblock() const override;
455 std::size_t getSerializableSize() const override;
457 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
458 void postLoad() override;
459
460};
461
462
463}
464
465#endif
AnalyticalF are applications from DD to XD, where X is set by the constructor.
Platform-abstracted block lattice for external access and inter-block interaction.
Base class for serializable objects of dynamic size
Definition serializer.h:299
Highest-level interface to Cell data.
Definition cell.h:148
Implementation of BlockLattice on a concrete PLATFORM.
SoA storage for instances of a single FIELD.
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
IndicatorF2D is an application from .
IndicatorF3D is an application from .
Factory for instances of a specific POST_PROCESSOR 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 communicate() override
Perform full overlap communication if needed.
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 addPostProcessor(PostProcessorGenerator< T, DESCRIPTOR > const &ppGen)
Add a non-local post-processing step (legacy)
void executeCoupling()
Executes coupling with partner lattices (legacy)
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 addLatticeCoupling(LatticeCouplingGenerator< T, DESCRIPTOR > const &lcGen, std::vector< SuperLattice< T, PARTNER_DESCRIPTOR > * > partnerLattices)
Adds a coupling generator for a vector of partner superLattice (legacy)
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)
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)
SuperLattice(SuperGeometry< T, DESCRIPTOR::d > &superGeometry)
Construct lattice for the cuboid decomposition of superGeometry.
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.
void initialize()
Initialize lattice to be ready for simulation.
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 scheduleBackgroundTask(F &&f)
Schedule F for one-off background execution to be finished by STAGE.
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 > & _loadBalancer
Distribution of the cuboids of the cuboid structure.
Plain old scalar vector.
Definition vector.h:47
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
Definition platform.h:55
std::conditional_t< DESCRIPTOR::d==2, LatticeCouplingGenerator2D< T, DESCRIPTOR >, LatticeCouplingGenerator3D< T, DESCRIPTOR > > LatticeCouplingGenerator
Definition aliases.h:168
std::conditional_t< D==2, SuperF2D< T, U >, SuperF3D< T, U > > SuperF
Definition aliases.h:198
std::conditional_t< DESCRIPTOR::d==2, PostProcessorGenerator2D< T, DESCRIPTOR >, PostProcessorGenerator3D< T, DESCRIPTOR > > PostProcessorGenerator
Definition aliases.h:77
std::conditional_t< D==2, SuperIndicatorF2D< T >, SuperIndicatorF3D< T > > SuperIndicatorF
Definition aliases.h:208
Curried ConcreteBlockLattice template for use in callUsingConcretePlatform.
Interface for per-cell dynamics.
Definition interface.h:54
Representation of a parallel 2D geometry – header file.