OpenLB 1.8.1
Loading...
Searching...
No Matches
operatorPromise.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2024 Adrian Kummerlaender
4 *
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 REFINEMENT_OPERATOR_PROMISE_H
26#define REFINEMENT_OPERATOR_PROMISE_H
27
28#include "operator.h"
29
30namespace olb {
31
32template <typename T, typename DESCRIPTOR>
34private:
35 std::function<void(BlockRefinementContextD<T,DESCRIPTOR>&)> _executor;
36 std::function<std::set<FieldTypePromise<T,refinement::DATA_DESCRIPTOR<DESCRIPTOR>>>()> _requiredData;
37 bool _requiresContextNeigborAccess;
38 std::type_index _operatorId;
39
40public:
41 template <typename OPERATOR>
43 _executor([](BlockRefinementContextD<T,DESCRIPTOR>& context) {
44 switch (context.getPlatform()) {
45#ifdef PLATFORM_CPU_SISD
46 case Platform::CPU_SISD:
47 ConcreteBlockRefinementO<T,DESCRIPTOR,Platform::CPU_SISD,OPERATOR>().apply(
48 context.template asConcrete<Platform::CPU_SISD>());
49 break;
50#endif
51#ifdef PLATFORM_CPU_SIMD
52 case Platform::CPU_SIMD:
53 ConcreteBlockRefinementO<T,DESCRIPTOR,Platform::CPU_SIMD,OPERATOR>().apply(
54 context.template asConcrete<Platform::CPU_SIMD>());
55 break;
56#endif
57#ifdef PLATFORM_GPU_CUDA
58 case Platform::GPU_CUDA:
59 ConcreteBlockRefinementO<T,DESCRIPTOR,Platform::GPU_CUDA,OPERATOR>().apply(
60 context.template asConcrete<Platform::GPU_CUDA>());
61 break;
62#endif
63 default:
64 throw std::runtime_error("Refinement executor not implemented for PLATFORM");
65 }
66 }),
67 _requiredData([]() -> std::set<FieldTypePromise<T,refinement::DATA_DESCRIPTOR<DESCRIPTOR>>> {
68 std::set<FieldTypePromise<T,refinement::DATA_DESCRIPTOR<DESCRIPTOR>>> fields;
69 OPERATOR::data::for_each([&fields](auto id) {
70 fields.emplace(meta::id<Array<decltype(id.get())>>{});
71 });
72 return fields;
73 }),
74 _requiresContextNeigborAccess{
75 OPERATOR::data::template contains<fields::refinement::CONTEXT_NEIGHBORS>()
76 },
77 _operatorId{typeid(OPERATOR)}
78 { }
79
80 std::set<FieldTypePromise<T,refinement::DATA_DESCRIPTOR<DESCRIPTOR>>> requiredData() const {
81 return _requiredData();
82 }
83
85 return _requiresContextNeigborAccess;
86 }
87
88 std::type_index id() const {
89 return _operatorId;
90 }
91
93 for (auto promise : requiredData()) {
94 promise.ensureAvailabilityIn(context.getData());
95 }
96 _executor(context);
97 }
98
99};
100
101}
102
103#endif
#define OPERATOR(OP, rhs)
Definition aDiffTape.h:64
Untyped promise to execute some block refinement operator.
BlockRefinementOperatorPromise(meta::id< OPERATOR >)
std::set< FieldTypePromise< T, refinement::DATA_DESCRIPTOR< DESCRIPTOR > > > requiredData() const
void apply(BlockRefinementContextD< T, DESCRIPTOR > &context)
Helper for conveying the ability for operations on FIELD_TYPE.
Definition data.h:95
Top level namespace for all of OpenLB.
Describe FieldArray of a FIELD in Data.
Definition data.h:50
Interface for the contextual data of a block refinement.
Definition operator.h:48
virtual Data & getData()=0
Return reference to contextual data.
Base descriptor of a D-dimensional lattice with Q directions and a list of additional fields.
Definition base.h:95
Identity type to pass non-constructible types as value.
Definition meta.h:79