25#ifndef REFINEMENT_SUPER_LATTICE_REFINEMENT_H
26#define REFINEMENT_SUPER_LATTICE_REFINEMENT_H
35template <
typename T,
typename DESCRIPTOR, Platform PLATFORM>
41 std::map<CellID, CellID> _dataIndex;
43 bool _dataIndexChanged;
48 void updateContextNeighborIndices() {
49 using namespace fields::refinement;
50 const auto& cellIdFine = _data.template getField<CELL_ID_FINE>();
51 for (std::size_t i=0; i < cellIdFine.getSize(); ++i) {
52 auto latticeR = _fLattice.
getLatticeR(cellIdFine[0][i]);
54 for (
unsigned iN=0; iN < CONTEXT_NEIGHBORS::count<DESCRIPTOR>(); ++iN) {
55 if (
auto index =
getDataIndex(latticeR + CONTEXT_NEIGHBORS::c<DESCRIPTOR>(iN))) {
56 neighbors[iN] = *index;
59 _data.template getField<CONTEXT_NEIGHBORS>().set(i, neighbors);
69 , _dataIndexChanged{true}
75 for (
unsigned iD=1; iD < DESCRIPTOR::d; ++iD) {
107 if (_dataIndex.find(iCell) == _dataIndex.end()) {
108 _dataIndexChanged =
true;
115 _data.template getField<fields::refinement::CELL_ID_FINE>().set(_dataIndex[iCell], iCell);
117 bool coIncident =
true;
118 for (
unsigned iD=0; iD < DESCRIPTOR::d; ++iD) {
119 coIncident &= latticeR[iD] % 2 == 0;
122 _data.template getField<fields::refinement::CELL_ID_COARSE>().set(
123 _dataIndex[iCell], _cLattice.
getCellId(latticeR / 2));
125 _data.template getField<fields::refinement::CELL_ID_COARSE>().set(_dataIndex[iCell], 0);
131 auto iter = _dataIndex.find(_fLattice.
getCellId(latticeR));
132 if (iter != _dataIndex.end()) {
133 return std::get<1>(*iter);
140 if (_dataIndexChanged && promise.requiresContextNeighborAccess()) {
141 updateContextNeighborIndices();
142 _data.template getField<fields::refinement::CONTEXT_NEIGHBORS>()
144 _dataIndexChanged =
false;
146 promise.apply(*
this);
151template <
typename T,
typename DESCRIPTOR>
161 std::vector<std::unique_ptr<BlockRefinementContextD<T,DESCRIPTOR>>> _context;
163 template <Platform PLATFORM>
164 auto constructConcreteBlockContext(
int fineC) {
165 const int coarseC = _balancer.
cloc(fineC);
166 return std::make_unique<ConcreteBlockRefinementContextD<T,DESCRIPTOR,PLATFORM>>(
167 _cLattice.
getBlock(coarseC).
template asConcrete<PLATFORM>()
168 , _fLattice.
getBlock(fineC).template asConcrete<PLATFORM>()
169 , _data.
getBlock(fineC).template asConcrete<PLATFORM>());
172 std::map<std::type_index,
173 std::unique_ptr<SuperCommunicator<T,SuperLattice<T,DESCRIPTOR>>>> _cCommunicator;
174 std::map<std::type_index,
175 std::unique_ptr<SuperCommunicator<T,SuperLattice<T,DESCRIPTOR>>>> _fCommunicator;
182 , _cLattice(cLattice)
183 , _fLattice(fLattice)
186 for (
int iC = 0; iC < _balancer.
size(); ++iC) {
189 _context.emplace_back(constructConcreteBlockContext<platform.value>(iC));
195 return *_context[iC];
201 auto iter = _cCommunicator.find(promise.id());
202 if (iter != _cCommunicator.end()) {
203 std::get<1>(*iter)->communicate();
207 auto iter = _fCommunicator.find(promise.id());
208 if (iter != _fCommunicator.end()) {
209 std::get<1>(*iter)->communicate();
213 #ifdef PARALLEL_MODE_OMP
216 for (
int iC = 0; iC < _balancer.
size(); ++iC) {
222 for (
int iC = 0; iC < _balancer.
size(); ++iC) {
223 _context[iC]->setProcessingContext(context);
229 auto iter = _cCommunicator.find(promise.id());
230 if (iter == _cCommunicator.end()) {
231 iter = std::get<0>(_cCommunicator.emplace(promise.id(),
234 return *std::get<1>(*iter);
239 auto iter = _fCommunicator.find(promise.id());
240 if (iter == _fCommunicator.end()) {
241 iter = std::get<0>(_fCommunicator.emplace(promise.id(),
244 return *std::get<1>(*iter);
Untyped promise to execute some block refinement operator.
std::size_t getNcells() const
Get number of cells.
LatticeR< D > getLatticeR(CellID iCell) const
CellID getCellId(LatticeR< D > latticeR) const
Get 1D cell ID.
Implementation of BlockD on a concrete PLATFORM.
void resize(Vector< int, DESCRIPTOR::d > size) override
void setProcessingContext(ProcessingContext context) override
Set processing context.
Implementation of BlockLattice on a concrete PLATFORM.
Context for the execution of block refinement operators.
BlockRefinementContextD< T, DESCRIPTOR >::Data & getData() override
Return reference to contextual data.
ConcreteBlockRefinementContextD(ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > &cLattice, ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > &fLattice, ConcreteBlockD< T, refinement::DATA_DESCRIPTOR< DESCRIPTOR >, PLATFORM > &data)
auto & getCoarseLattice()
void apply(BlockRefinementOperatorPromise< T, DESCRIPTOR > &&promise) override
Apply promised algorithm step to the previously added connection points.
std::optional< std::size_t > getDataIndex(LatticeR< DESCRIPTOR::d > latticeR) const override
Return index where contextual data of connection point latticeR is stored.
void add(LatticeR< DESCRIPTOR::d > latticeR) override
Connect the coarse and fine lattice at position latticeR.
Platform getPlatform() const override
void setProcessingContext(ProcessingContext context) override
Base class for all LoadBalancer.
virtual Platform platform(int loc) const
Load balancer for refined lattice hierarchies.
int cloc(int fineLoc) const
Returns coarse loc for given fine loc.
Generic communicator for overlaps between blocks of SUPER.
BlockD< T, DESCRIPTOR > & getBlock(unsigned iB)
void setProcessingContext(ProcessingContext context)
SuperLatticeRefinement(SuperLattice< T, DESCRIPTOR > &cLattice, SuperLattice< T, DESCRIPTOR > &fLattice, const LoadBalancer< T > &balancer)
BlockRefinementContextD< T, DESCRIPTOR > & getBlock(int iC)
void apply(BlockRefinementOperatorPromise< T, DESCRIPTOR > &&promise)
Apply coupling operation on all blocks.
SuperCommunicator< T, SuperLattice< T, DESCRIPTOR > > & getCoarseCommunicator(BlockRefinementOperatorPromise< T, DESCRIPTOR > &&promise)
SuperCommunicator< T, SuperLattice< T, DESCRIPTOR > > & getFineCommunicator(BlockRefinementOperatorPromise< T, DESCRIPTOR > &&promise)
Super class maintaining block lattices for a cuboid decomposition.
BlockLattice< T, DESCRIPTOR > & getBlock(int locC)
Return BlockLattice with local index locC.
Top level namespace for all of OpenLB.
auto callUsingConcretePlatform(Platform platform, typename CONCRETIZABLE::base_t *ptr, F f)
Dispatcher for concrete platform access.
std::uint32_t CellID
Type for sequential block-local cell indices.
ProcessingContext
OpenLB processing contexts.
@ Simulation
Data available on host for e.g. functor evaluation.
Platform
OpenLB execution targets.
Interface for the contextual data of a block refinement.
Base descriptor of a D-dimensional lattice with Q directions and a list of additional fields.