OpenLB 1.7
Loading...
Searching...
No Matches
particleDescriptorUtilities.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 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 PARTICLE_DESCRIPTOR_UTILITIES_H
25#define PARTICLE_DESCRIPTOR_UTILITIES_H
26
27namespace olb {
28
29namespace descriptors {
30
31
33// For usage examples, please look at
34// - printGenericParticleInfo() in particleIoFunctions.h
35// - initializeParticle() in particleDynamicsFunctions.h
36//
37// TODO: as this implementation currently includes
38// - heavy template use
39// - partial template specialization
40// - recursive calls
41// - lambda functions
42// it surely can be simplified eventually.
43//
44template <typename F, typename T, typename DESCRIPTOR, typename FIELDS>
46
47//Recursive retrieval of type names
48//
49//TODO: can be used properly with template-lambda function F as soon as changing to c++20.
50// until then, some intermediate predefined types are necessary.
51// As the same issue makes a proper initialization of field entries in the lampda function impossible,
52// as the fieldContent cannot be passed.
53// Therefore, until using c++20, this ugly boolean trickery has to be used
54// for initializaiton. Thus, for now, every F has to provide the resetField bool.
55//
56template <typename F, typename T, typename DESCRIPTOR, typename ARRAYTYPE, typename HEAD, typename ...FIELDS>
57void getFieldContent( F f, ARRAYTYPE& multiFieldArray, std::size_t iP )
58{
59 auto& field = multiFieldArray.template get<HEAD>();
60 auto fieldContent = field.getRowPointer(iP);
61 int fieldSize = fieldContent.getSize();
62 std::stringstream fieldContentStream; //Necessary until c++20
63 fieldContentStream << fieldContent; //Necessary until c++20
64 if constexpr (!sizeof...(FIELDS)) {
65 bool resetField = f( typeid(HEAD), fieldSize, fieldContentStream.str() );
66 if (resetField) {
67 fieldContent = HEAD::template getInitialValue<T,DESCRIPTOR>();
68 }
69 }
70 else {
71 bool resetField = f( typeid(HEAD), fieldSize, fieldContentStream.str() );
72 if (resetField) {
73 fieldContent = HEAD::template getInitialValue<T,DESCRIPTOR>();
74 }
75 getFieldContent<F,T,DESCRIPTOR,ARRAYTYPE,FIELDS...>( f, multiFieldArray, iP );
76 }
77}
78
79//Recursive traversing and retrieval of nested type names (level two)
80template <typename F, typename T, typename DESCRIPTOR, typename HEAD, typename ...FIELDS>
82{
83 if constexpr (!sizeof...(FIELDS)) {
84 auto& fieldL2 = dynamicFieldGroups.template get<HEAD>();
86 }
87 else {
88 auto& fieldL2 = dynamicFieldGroups.template get<HEAD>();
90 getFieldContentL2<F,T, DESCRIPTOR, FIELDS...>( f, dynamicFieldGroups, iP );
91 }
92}
93
94//Recursive traversing and retrieval of nested type names (level one)
95template <typename F, typename T, typename DESCRIPTOR, typename... FIELDS>
96struct access_field_content<F,T,DESCRIPTOR, meta::list<FIELDS...>> {
97 using arrayType = MultiFieldArrayD<T,DESCRIPTOR,Platform::CPU_SISD,FIELDS...>; //ensure fixed type during recursion
98 static constexpr void fields( F f, MultiFieldArrayD<T,DESCRIPTOR,Platform::CPU_SISD,FIELDS...>& multiFieldArray,
99 std::size_t iP )
100 {
101 return getFieldContent<F,T,DESCRIPTOR,arrayType,FIELDS...>( f, multiFieldArray, iP );
102 }
103 static constexpr void fieldsL2( F f, DynamicFieldGroupsD<T, typename DESCRIPTOR::fields_t>& dynamicFieldGroups,
104 std::size_t iP )
105 {
106 return getFieldContentL2<F,T,DESCRIPTOR,FIELDS...>( f, dynamicFieldGroups, iP );
107 }
108};
109
110} //namespace descriptors
111
112} //namespace olb
113
114
115#endif
Storage for dynamic field groups (Prototype for ParticleSystem)
Storage for a fixed set of static FIELDS and arbitrary custom fields.
void getFieldContent(F f, ARRAYTYPE &multiFieldArray, std::size_t iP)
void getFieldContentL2(F f, DynamicFieldGroupsD< T, typename DESCRIPTOR::fields_t > &dynamicFieldGroups, std::size_t iP)
Top level namespace for all of OpenLB.
static constexpr void fields(F f, MultiFieldArrayD< T, DESCRIPTOR, Platform::CPU_SISD, FIELDS... > &multiFieldArray, std::size_t iP)
static constexpr void fieldsL2(F f, DynamicFieldGroupsD< T, typename DESCRIPTOR::fields_t > &dynamicFieldGroups, std::size_t iP)
Traversal of nested field contents for output and initialization.