fieldMapper.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::fieldMapper
26 
27 Description
28  Abstract base class for field mapping
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef fieldMapper_H
33 #define fieldMapper_H
34 
35 #include "Field.H"
36 #include "fieldTypes.H"
37 #include "fieldMapperM.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 /*---------------------------------------------------------------------------*\
45  Class fieldMapper Declaration
46 \*---------------------------------------------------------------------------*/
47 
48 class fieldMapper
49 {
50 public:
51 
52  // Public Classes
53 
54  //- Class used to lazily evaluate fields
55  template<class Type>
56  class FieldFunctor;
57 
58  //- Class used to lazily evaluate field-generating operators
59  template<class Type, class FieldOp>
60  class FieldOpFunctor;
61 
62 
63 private:
64 
65  // Private Typedefs
66 
67  //- Alias for tmp<Field<Type>> if the other argument passed is an
68  // operator (i.e., not a field). Disambiguates calls that take
69  // operators from those that take field arguments.
70  template<class Type, class FieldOp>
71  using TmpFieldTypeIfFieldOp =
72  typename std::enable_if
73  <
74  !std::is_base_of<Field<Type>, FieldOp>::value,
76  >::type;
77 
78 
79  // Private Member Functions
80 
81  //- Map or assign a field in-place
82  template<class Type>
83  void mapOrAssign
84  (
85  Field<Type>& f,
86  const Field<Type>& mapF,
87  const Type& unmappedVal
88  ) const;
89 
90  //- Map or assign a field and return the result
91  template<class Type>
92  tmp<Field<Type>> mapOrAssign
93  (
94  const Field<Type>& mapF,
95  const Type& unmappedVal
96  ) const;
97 
98  //- Map or assign a field in-place
99  template<class Type>
100  void mapOrAssign
101  (
102  Field<Type>& f,
103  const Field<Type>& mapF,
104  const FieldFunctor<Type>& unmappedFunc
105  ) const;
106 
107  //- Map or assign a field and return the result
108  template<class Type>
109  tmp<Field<Type>> mapOrAssign
110  (
111  const Field<Type>& mapF,
112  const FieldFunctor<Type>& unmappedFunc
113  ) const;
114 
115 
116 public:
117 
118  // Constructors
119 
120  //- Null constructor
121  fieldMapper()
122  {}
123 
124 
125  //- Destructor
126  virtual ~fieldMapper()
127  {}
128 
129 
130  // Member Operators
131 
132  //- Map a field
134 
135  //- Map a label field
137 
138  //- Map a temporary field
139  template<class Type>
140  void operator()(Field<Type>& f, const tmp<Field<Type>>& tmapF) const;
141 
142  //- Map a temporary field
143  template<class Type>
144  tmp<Field<Type>> operator()(const tmp<Field<Type>>& tmapF) const;
145 
146  //- Map or assign a field
148 
149  //- Map or assign a label field
151 
152  //- Map or assign a field from an operator in-place
153  template<class Type, class FieldOp>
154  void operator()
155  (
156  Field<Type>& f,
157  const Field<Type>& mapF,
158  const FieldOp& unmappedOp
159  ) const;
160 
161  //- Map or assign a field from an operator and return the result
162  template<class Type, class FieldOp>
163  TmpFieldTypeIfFieldOp<Type, FieldOp> operator()
164  (
165  const Field<Type>& mapF,
166  const FieldOp& unmappedOp
167  ) const;
168 };
169 
170 
171 /*---------------------------------------------------------------------------*\
172  Class fieldMapper::FieldFunctor Declaration
173 \*---------------------------------------------------------------------------*/
174 
175 template<class Type>
177 {
178 public:
179 
180  // Constructors
181 
182  //- Construct null
183  FieldFunctor()
184  {}
185 
186 
187  //- Destructor
188  virtual ~FieldFunctor()
189  {}
190 
191 
192  // Member Operators
193 
194  //- Evaluate the field
195  virtual tmp<Field<Type>> operator()() const = 0;
196 };
197 
198 
199 /*---------------------------------------------------------------------------*\
200  Class fieldMapper::FieldOpFunctor Declaration
201 \*---------------------------------------------------------------------------*/
202 
203 template<class Type, class FieldOp>
205 :
206  public FieldFunctor<Type>
207 {
208  // Private Member Data
209 
210  //- The operator
211  FieldOp op_;
212 
213 
214 public:
215 
216  // Constructors
217 
218  //- Construct from an operator
219  FieldOpFunctor(const FieldOp& op)
220  :
221  FieldFunctor<Type>(),
222  op_(op)
223  {}
224 
225 
226  //- Destructor
227  virtual ~FieldOpFunctor()
228  {}
229 
230 
231  // Member Operators
232 
233  //- Evaluate the field
234  virtual tmp<Field<Type>> operator()() const
235  {
236  return op_();
237  }
238 };
239 
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 } // End namespace Foam
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #ifdef NoRepository
248  #include "fieldMapperTemplates.C"
249 #endif
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 #endif
254 
255 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
Class used to lazily evaluate fields.
Definition: fieldMapper.H:176
virtual tmp< Field< Type > > operator()() const =0
Evaluate the field.
virtual ~FieldFunctor()
Destructor.
Definition: fieldMapper.H:187
Class used to lazily evaluate field-generating operators.
Definition: fieldMapper.H:206
FieldOpFunctor(const FieldOp &op)
Construct from an operator.
Definition: fieldMapper.H:218
virtual tmp< Field< Type > > operator()() const
Evaluate the field.
Definition: fieldMapper.H:233
virtual ~FieldOpFunctor()
Destructor.
Definition: fieldMapper.H:226
Abstract base class for field mapping.
Definition: fieldMapper.H:48
FOR_ALL_FIELD_TYPES(DEFINE_FIELD_MAPPER_MAP_OPERATOR,=0)
Map a field.
virtual void operator()(Field< label > &f, const Field< label > &mapF) const =0
Map a label field.
fieldMapper()
Null constructor.
Definition: fieldMapper.H:120
virtual ~fieldMapper()
Destructor.
Definition: fieldMapper.H:125
A class for managing temporary objects.
Definition: tmp.H:55
#define DEFINE_FIELD_MAPPER_MAP_OR_ASSIGN_OPERATOR(Type, Modifier)
Definition: fieldMapperM.H:40
#define DEFINE_FIELD_MAPPER_MAP_OPERATOR(Type, Modifier)
Definition: fieldMapperM.H:26
Include the header files for all the primitive types that Fields are instantiated for.
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
labelList f(nPoints)