OpenLB 1.7
Loading...
Searching...
No Matches
groupedFieldF.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen, Mathias J. Krause,
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef GROUPED_FIELD_F_HH
25#define GROUPED_FIELD_F_HH
26
28
29namespace olb {
30
31
32template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
34 Container<T,DESCRIPTOR,FIELD_ARRAY_TYPE>& container, int targetDim )
35 : GenericF<W,int>( targetDim, 1), _container(container)
36{
37 this->getName() = "ContainerF";
38}
39
40template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
46
47template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
50 OLB_ASSERT(_container.size() < INT32_MAX,
51 "cast from std::size_t to int unsafe");
52 return _container.size();
53}
55template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
57{
58 return true; //TODO: add Error handling using true/false
59}
60
61
62template <typename T, typename DESCRIPTOR, typename GROUP, typename FIELD>
65 : ContainerF<T,DESCRIPTOR,DynamicFieldGroupsD<T,typename DESCRIPTOR::fields_t>,T>( container,
66 DESCRIPTOR::template size<typename meta::derived_type_in_nested<DESCRIPTOR,GROUP,FIELD>::type>() )
67{
68 this->getName() = std::string(typeid(FIELD).name());
69}
70
71template <typename T, typename DESCRIPTOR, typename GROUP, typename FIELD>
72bool GroupedFieldF<T,DESCRIPTOR,GROUP,FIELD>::operator()(T output[], const int input[])
73{
74 using namespace olb::descriptors;
75 using GROUP_EVAL = typename DESCRIPTOR::template derivedField<GROUP>;
76 using FIELD_EVAL = typename GROUP_EVAL::template derivedField<FIELD>;
77 auto fieldValue = this->getContainer().data().template get<GROUP_EVAL>()
78 .template getFieldPointer<FIELD_EVAL>(input[0]);
79
80 for (int iDim=0; iDim<this->getTargetDim(); ++iDim){
81 output[iDim] = fieldValue[iDim];
82 }
83 return true; //TODO: add Error handling using true/false
84}
85
87
88
89//TODO: Prototype edition for now!
90//
91
92template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
94 : GenericF<W,int>(targetDim,1), _loadBalancer(loadBalancer)
95{ }
96
97template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
100 return _loadBalancer;
102
103template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
105{
106 OLB_ASSERT(_containerF.size() < INT32_MAX,
107 "cast from std::size_t to int unsafe");
108 return _containerF.size();
109}
110
111template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
113{
114 OLB_ASSERT(iCloc < int(_containerF.size()) && iCloc >= 0,
115 "block functor index outside bounds");
116 return *(_containerF[iCloc]);
117}
118
119template <typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE, typename W>
121{
122 if (_loadBalancer.isLocal(input[0])) {
123 const int loc = _loadBalancer.loc(input[0]);
124 return this->getContainerF(loc)(output, &input[1]);
125 }
126 else {
127 return false;
128 }
129}
130
131
132template <typename T, typename DESCRIPTOR, typename GROUP, typename FIELD, typename W>
135 : SuperContainerF<T,DESCRIPTOR,DynamicFieldGroupsD<T,typename DESCRIPTOR::fields_t>,W>(
136 sParticleSystem.getSuperStructure().getLoadBalancer(),
137 DESCRIPTOR::template size<typename meta::derived_type_in_nested<DESCRIPTOR,GROUP,FIELD>::type>() ),
138 _sParticleSystem(sParticleSystem)
139{
140 this->getName() = std::string(typeid(FIELD).name());
141
142 int maxC = this->_sParticleSystem.getSuperStructure().getLoadBalancer().size();
143 this->_containerF.reserve(maxC);
144 for (int iC = 0; iC < maxC; iC++) {
145
146 auto bParticleSystems = _sParticleSystem.getBlockParticleSystems();
147 auto& particleSystem = *bParticleSystems[iC];
148 auto& container = particleSystem.get();
149
150 this->_containerF.emplace_back(new GroupedFieldF<T,DESCRIPTOR,GROUP,FIELD>( container ) );
151 }
152}
153
154
155
156
157
158} //namespace olb
159
160#endif
ContainerF is a NON-PARALLELIZED (no block/super differentiation) functor intended to extract data fr...
bool operator()(W output[], const int input[])
int getContainerSize() const
Container< T, DESCRIPTOR, FIELD_ARRAY_TYPE > & getContainer()
ContainerF(Container< T, DESCRIPTOR, FIELD_ARRAY_TYPE > &container, int targetDim)
Container is a std::vector inspired data wrapper that allows for simple content manipulation of its o...
Definition container.h:44
Storage for dynamic field groups (Prototype for ParticleSystem)
GenericF is a base class, that can represent continuous as well as discrete functions.
Definition genericF.h:50
std::string & getName()
read and write access to name
Definition genericF.hh:51
GroupedFieldF is a NON-PARALLELIZED (no block/super differentiation) functor.
GroupedFieldF(Container< T, DESCRIPTOR, DynamicFieldGroupsD< T, typename DESCRIPTOR::fields_t > > &container)
bool operator()(T output[], const int input[])
Base class for all LoadBalancer.
ContainerF< T, DESCRIPTOR, FIELD_ARRAY_TYPE > & getContainerF(int iCloc)
LoadBalancer< T > & getLoadBalancer()
SuperContainerF(LoadBalancer< T > &loadBalancer, int targetDim)
int getContainerSize() const
std::vector< std::unique_ptr< ContainerF< T, DESCRIPTOR, FIELD_ARRAY_TYPE > > > _containerF
bool operator()(W output[], const int input[])
SuperParticleGroupedFieldF(particles::SuperParticleSystem< T, DESCRIPTOR > &sParticleSystem)
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
SuperStructure< T, PARTICLETYPE::d > & getSuperStructure()
std::vector< ParticleSystem< T, PARTICLETYPE > * > & getBlockParticleSystems()
Descriptors for the 2D and 3D lattices.
Top level namespace for all of OpenLB.
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45