OpenLB 1.8.1
Loading...
Searching...
No Matches
superLatticePointCoupling.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 SUPER_PARTICLE_LATTICE_COUPLING_H
26#define SUPER_PARTICLE_LATTICE_COUPLING_H
27
28#include "operator.h"
29#include "superLattice.h"
30
31#include "utilities/typeMap.h"
32#include "solver/names.h"
33
34namespace olb {
35
36template <typename COUPLER, typename COUPLEES, Platform PLATFORM>
38 final : public AbstractCouplingO<COUPLEES> {
39private:
40 template <typename VALUED_DESCRIPTOR>
41 using ptr_to_lattice = std::conditional_t<
42 VALUED_DESCRIPTOR::descriptor_t::template provides<descriptors::POPULATION>(),
43 ConcreteBlockLattice<typename VALUED_DESCRIPTOR::value_t,
44 typename VALUED_DESCRIPTOR::descriptor_t,
45 PLATFORM>,
46 ConcreteBlockD<typename VALUED_DESCRIPTOR::value_t,
47 typename VALUED_DESCRIPTOR::descriptor_t,
48 PLATFORM>
49 >*;
50
51 utilities::TypeIndexedTuple<typename COUPLEES::template map_values<
52 ptr_to_lattice
53 >> _lattices;
54
57
59 typename meta::merge<
60 typename COUPLER::parameters,
64 >
65 >
66 > _parameters;
67
68public:
69 template <typename LATTICES>
70 ConcreteBlockPointCouplingO(LATTICES&& lattices,
73 _lattices{lattices},
74 _cuboid{cuboid},
75 _parameters{}
76 { }
77
78 std::type_index id() const override {
79 return typeid(COUPLER);
80 }
81
83 return _parameters;
84 }
85
86 void execute() override
87 {
88 using V = typename AbstractCouplingO<COUPLEES>::value_t;
89 using DESCRIPTOR = typename AbstractCouplingO<COUPLEES>::descriptor_t;
90 auto* points = _lattices.get(meta::id<names::Points>{});
91 const auto originR = _parameters.template get<fields::BLOCK_LOWER>();
92 const auto deltaX = _parameters.template get<fields::converter::PHYS_DELTA_X>();
93 #ifdef PARALLEL_MODE_OMP
94 #pragma omp parallel for schedule(static)
95 #endif
96 for (CellID iP=0; iP < points->getNcells(); ++iP) {
97 const auto physR = points->template getField<fields::PHYS_R>().get(iP);
98 const LatticeR<DESCRIPTOR::d> latticeR = util::floor((physR - originR) / deltaX + V{0.5});
99 const CellID iCell = _lattices.template get<0>()->getCellId(latticeR);
100 auto cells = _lattices.exchange_values([&](auto name) -> auto {
101 if constexpr (std::is_same_v<typename decltype(name)::type, names::Points>) {
102 return cpu::Row{*_lattices.get(name), iP};
103 } else {
104 return cpu::Cell{*_lattices.get(name), iCell};
105 }
106 });
107 COUPLER().apply(cells, _parameters);
108 }
109 }
110
111 void set(CellID iCell, bool state) override {
112 throw std::bad_function_call();
113 }
114
115};
116
117
119template <typename COUPLER, typename COUPLEES>
121private:
122 template <typename VALUED_DESCRIPTOR>
123 using ptr_to_lattice = std::conditional_t<
124 VALUED_DESCRIPTOR::descriptor_t::template provides<descriptors::POPULATION>(),
125 SuperLattice<typename VALUED_DESCRIPTOR::value_t,
126 typename VALUED_DESCRIPTOR::descriptor_t>,
127 SuperD<typename VALUED_DESCRIPTOR::value_t,
128 typename VALUED_DESCRIPTOR::descriptor_t>
129 >*;
130
131 utilities::TypeIndexedTuple<typename COUPLEES::template map_values<
132 ptr_to_lattice
133 >> _lattices;
134
135 std::vector<std::unique_ptr<AbstractCouplingO<COUPLEES>>> _block;
136
137 template <Platform PLATFORM>
138 auto constructConcreteBlockPointCoupling(int iC)
139 {
140 auto block = _lattices.exchange_values([&](auto name) -> auto {
141 using NAME = typename decltype(name)::type;
142 using T = typename COUPLEES::template value<NAME>::value_t;
143 using DESCRIPTOR = typename COUPLEES::template value<NAME>::descriptor_t;
144 if constexpr (DESCRIPTOR::template provides<descriptors::POPULATION>()) {
146 &_lattices.get(name)->getBlock(iC));
147 } else {
148 return dynamic_cast<ConcreteBlockD<T,DESCRIPTOR,PLATFORM>*>(
149 &_lattices.get(name)->getBlock(iC));
150 }
151 });
152 return std::make_unique<ConcreteBlockPointCouplingO<COUPLEES,PLATFORM,COUPLER,COUPLER::scope>>(
153 block,
154 _lattices.template get<0>()->getCuboidDecomposition().get(
155 _lattices.template get<0>()->getLoadBalancer().glob(iC)));
156 }
157
158public:
159 template <typename... MAP>
160 SuperLatticePointCoupling(COUPLER, MAP&&... args)
161 {
162 auto map = std::make_tuple(&args...);
163 COUPLEES::keys_t::for_each([&](auto id) {
164 using name_t = typename decltype(id)::type;
165 constexpr unsigned idx = COUPLEES::keys_t::template index<name_t>();
166 _lattices.template set<name_t>(std::get<2*idx+1>(map));
167 });
168
169 auto& load = _lattices.template get<0>()->getLoadBalancer();
170 auto& cGeometry = _lattices.template get<0>()->getCuboidDecomposition();
171
172 for (int iC = 0; iC < load.size(); ++iC) {
173 Platform reference = _lattices.template get<0>()->getBlock(iC).getPlatform();
174
175 _lattices.for_each([&](auto name, auto lattice) {
176 if (lattice->getBlock(iC).getPlatform() != reference) {
177 throw std::runtime_error("Platforms of coupled block lattices must match");
178 }
179 });
180
182 [&](auto platform) {
183 _block.emplace_back(constructConcreteBlockPointCoupling<platform.value>(iC));
184 });
185 }
186
187 for (int iC = 0; iC < load.size(); ++iC) {
188 const auto origin = cGeometry.get(load.glob(iC)).getOrigin();
189 const auto deltaX = cGeometry.get(load.glob(iC)).getDeltaR();
190 _block[iC]->getParameters().template set<fields::BLOCK_LOWER>(origin);
191 _block[iC]->getParameters().template set<fields::converter::PHYS_DELTA_X>(deltaX);
192 }
193 }
194
196 void execute()
197 {
198 auto& load = _lattices.template get<0>()->getLoadBalancer();
199 #ifdef PARALLEL_MODE_OMP
200 #pragma omp taskloop
201 #endif
202 for (int iC = 0; iC < load.size(); ++iC) {
203 _block[iC]->execute();
204 }
205 }
206
208 template <typename FIELD>
210 {
211 auto& load = _lattices.template get<0>()->getLoadBalancer();
212 for (int iC = 0; iC < load.size(); ++iC) {
213 _block[iC]->getParameters().template set<FIELD>(std::forward<decltype(field)>(field));
214 }
215 }
216
218
224 {
225 return *_block[iC];
226 }
227
228};
229
231template <typename COUPLER, typename... MAP>
234 COUPLER,
235 typename meta::map<MAP...>::template map_values<descriptors::extract_valued_descriptor_t>
236>;
237
238}
239
240#endif
Implementation of BlockD on a concrete PLATFORM.
Definition cell.h:32
Implementation of BlockLattice on a concrete PLATFORM.
AbstractCouplingO< COUPLEES >::AbstractParameters & getParameters() override
Return reference to parameters of coupling operator.
ConcreteBlockPointCouplingO(LATTICES &&lattices, Cuboid< typename AbstractCouplingO< COUPLEES >::value_t, AbstractCouplingO< COUPLEES >::descriptor_t::d > &cuboid)
void set(CellID iCell, bool state) override
Set whether iCell is covered by the present coupling.
Particle coupling of COUPLEES using concrete OPERATOR with SCOPE on PLATFORM lattices.
Definition operator.h:139
Coupling operator COUPLER on named COUPLEES.
AbstractCouplingO< COUPLEES > & getBlock(int iC)
Return block-level abstract coupling operator.
SuperLatticePointCoupling(COUPLER, MAP &&... args)
void execute()
Execute coupling operation on all blocks.
void setParameter(typename AbstractCouplingO< COUPLEES >::template FieldD< FIELD > &&field)
Set coupling parameter FIELD.
Super class maintaining block lattices for a cuboid decomposition.
Plain old scalar vector.
Cell concept for concrete block lattices on CPU platforms.
Definition cell.h:141
Row concept for concrete non-LBM lattices on CPU platforms.
Definition cell.h:85
typename LIST_A::template decompose_into< LIST_B::template include > merge
Merge elements of LIST_A and LIST_B into new list.
Definition meta.h:344
ADf< T, DIM > floor(const ADf< T, DIM > &a)
Definition aDiff.h:869
Top level namespace for all of OpenLB.
auto callUsingConcretePlatform(Platform platform, typename CONCRETIZABLE::base_t *ptr, F f)
Dispatcher for concrete platform access.
Definition dispatch.h:41
std::uint32_t CellID
Type for sequential block-local cell indices.
Platform
OpenLB execution targets.
Definition platform.h:35
SuperLatticePointCoupling(COUPLER, MAP &&...) -> SuperLatticePointCoupling< COUPLER, typename meta::map< MAP... >::template map_values< descriptors::extract_valued_descriptor_t > >
SuperPointLatticeCoupling.
OperatorScope
Block-wide operator application scopes.
@ PerCellWithParameters
Per-cell application with parameters, i.e. OPERATOR::apply is passed a CELL concept implementation an...
Base of block-wide coupling operators executed by SuperLatticeCoupling.
Definition operator.h:108
typename COUPLEES::values_t::template get< 0 >::descriptor_t descriptor_t
Descriptor type used for coupling parameters.
Definition operator.h:112
typename COUPLEES::values_t::template get< 0 >::value_t value_t
Value type used for coupling parameters.
Definition operator.h:110
Dynamic access interface for FIELD-valued parameters.
Identity type to pass non-constructible types as value.
Definition meta.h:79
Plain wrapper for list of types.
Definition meta.h:276
Mapping between KEYs and instances of type VALUEs.
constexpr auto exchange_values(F f) any_platform
Returns new TypeIndexedTuple with same keys but values generated by f(key)