24#ifndef BLOCK_POST_PROCESSOR_MAP_H
25#define BLOCK_POST_PROCESSOR_MAP_H
47template <
typename T,
typename DESCRIPTOR>
56 template <
typename POST_PROCESSOR>
58 _id(typeid(POST_PROCESSOR)),
59 _priority(POST_PROCESSOR().getPriority()),
63 #ifdef PLATFORM_CPU_SISD
67 #ifdef PLATFORM_CPU_SIMD
71 #ifdef PLATFORM_GPU_CUDA
76 throw std::invalid_argument(
"Invalid PLATFORM");
82 std::type_index
id()
const {
94 template <Platform PLATFORM>
102template <
typename PP>
104 typename PP::descriptor_t>;
107template <
typename T,
typename DESCRIPTOR, Platform PLATFORM>
111 std::vector<std::unique_ptr<PostProcessor<T,DESCRIPTOR>>> _postProcessors;
114 std::type_index
id()
const override
121 throw std::logic_error(
"Invalid legacy post processor setter");
128 #ifdef PLATFORM_GPU_CUDA
130 if (!_postProcessors.empty()) {
131 throw std::runtime_error(
"Legacy post processors not supported on GPU_CUDA");
135 #ifdef PARALLEL_MODE_OMP
136 #pragma omp parallel for schedule(dynamic)
138 for (std::size_t i=0; i < _postProcessors.size(); ++i) {
139 if constexpr (DESCRIPTOR::d == 3) {
140 _postProcessors[i]->processSubDomain(block, 0, block.
getNx()-1, 0, block.
getNy()-1, 0, block.
getNz()-1);
142 _postProcessors[i]->processSubDomain(block, 0, block.
getNx()-1, 0, block.
getNy()-1);
150 _postProcessors.emplace_back(postProcessor);
159template<
typename T,
typename DESCRIPTOR, Platform PLATFORM>
169 std::map<std::type_index,
170 std::unique_ptr<BlockO<T,DESCRIPTOR,PLATFORM>>> _map;
181 auto iter = _map.find(promise.id());
182 if (iter == _map.end()) {
183 iter = _map.emplace(std::piecewise_construct,
184 std::forward_as_tuple(promise.id()),
185 std::forward_as_tuple(promise.template realize<PLATFORM>())).first;
186 iter->second->
setup(_lattice);
188 return *(iter->second);
198 _legacyPostProcessors.
add(postProcessor);
204 resolve(std::forward<
decltype(promise)>(promise)).set(iCell,
true);
210 resolve(std::forward<
decltype(promise)>(promise));
216 return _map.find(promise.id()) != _map.end();
233 _legacyPostProcessors.
apply(_lattice);
235 for (
auto& [_, postProcessor] : _map) {
236 postProcessor->apply(_lattice);
239 #ifdef PLATFORM_GPU_CUDA
Map of post processors of a single priority and stage.
void add(PostProcessorPromise< T, DESCRIPTOR > &&promise)
Add post processor to map, do nothing if it already exists.
BlockPostProcessorMap(ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > *lattice)
bool contains(PostProcessorPromise< T, DESCRIPTOR > &&promise) const
Returns true if map contains post processor.
void addLegacy(PostProcessor< T, DESCRIPTOR > *postProcessor)
void apply()
Apply all managed post processors to lattice.
void add(std::size_t iCell, PostProcessorPromise< T, DESCRIPTOR > &&promise)
Schedule post processor for application at iCell.
int getNy() const
Read only access to block height.
int getNx() const
Read only access to block width.
int getNz() const
Read only access to block height.
Implementation of BlockLattice on a concrete PLATFORM.
Block application of concrete OPERATOR called using SCOPE on PLATFORM.
Block operator for supporting legacy post processor in the new operator-centric framework.
void add(PostProcessor< T, DESCRIPTOR > *postProcessor)
void setup(ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > &block) override
Setup operator context.
void set(CellID iCell, bool state) override
Set whether iCell is covered by the operator (optional)
void apply(ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > &block) override
Apply operator on block.
std::type_index id() const override
Factory for instances of a specific POST_PROCESSOR type.
std::function< AbstractBlockO *(Platform)> _constructor
std::type_index id() const
Returns type index of the promised POST_PROCESSOR.
OperatorScope scope() const
BlockO< T, DESCRIPTOR, PLATFORM > * realize()
PostProcessorPromise(meta::id< POST_PROCESSOR > id=meta::id< POST_PROCESSOR >{})
void synchronize()
Synchronize device.
Top level namespace for all of OpenLB.
std::uint32_t CellID
Type for sequential block-local cell indices.
Platform
OpenLB execution targets.
@ CPU_SIMD
Basic scalar CPU.
@ GPU_CUDA
Vector CPU (AVX2 / AVX-512 collision)
PostProcessorPromise(meta::id< PP >) -> PostProcessorPromise< typename PP::value_t, typename PP::descriptor_t >
std::conditional_t< DESCRIPTOR::d==2, PostProcessor2D< T, DESCRIPTOR >, PostProcessor3D< T, DESCRIPTOR > > PostProcessor
OperatorScope
Block-wide operator application scopes.
Interface for post-processing steps – header file.
Base of any block operator.
Base of block-wide operators such as post processors.
virtual void setup(ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > &block)=0
Setup operator context.