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-2026 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 Functions
131 
132  //- Is the mapper direct?
133  virtual bool direct() const
134  {
135  return true;
136  }
137 
138 
139  // Member Operators
140 
141  //- Map a field
143 
144  //- Map a label field
146 
147  //- Map a temporary field
148  template<class Type>
149  void operator()(Field<Type>& f, const tmp<Field<Type>>& tmapF) const;
150 
151  //- Map a temporary field
152  template<class Type>
153  tmp<Field<Type>> operator()(const tmp<Field<Type>>& tmapF) const;
154 
155  //- Map or assign a field
157 
158  //- Map or assign a label field
160 
161  //- Map or assign a field from an operator in-place
162  template<class Type, class FieldOp>
163  void operator()
164  (
165  Field<Type>& f,
166  const Field<Type>& mapF,
167  const FieldOp& unmappedOp
168  ) const;
169 
170  //- Map or assign a field from an operator and return the result
171  template<class Type, class FieldOp>
172  TmpFieldTypeIfFieldOp<Type, FieldOp> operator()
173  (
174  const Field<Type>& mapF,
175  const FieldOp& unmappedOp
176  ) const;
177 };
178 
179 
180 /*---------------------------------------------------------------------------*\
181  Class fieldMapper::FieldFunctor Declaration
182 \*---------------------------------------------------------------------------*/
183 
184 template<class Type>
186 {
187 public:
188 
189  // Constructors
190 
191  //- Construct null
192  FieldFunctor()
193  {}
194 
195 
196  //- Destructor
197  virtual ~FieldFunctor()
198  {}
199 
200 
201  // Member Operators
202 
203  //- Evaluate the field
204  virtual tmp<Field<Type>> operator()() const = 0;
205 };
206 
207 
208 /*---------------------------------------------------------------------------*\
209  Class fieldMapper::FieldOpFunctor Declaration
210 \*---------------------------------------------------------------------------*/
211 
212 template<class Type, class FieldOp>
214 :
215  public FieldFunctor<Type>
216 {
217  // Private Data
218 
219  //- The operator
220  FieldOp op_;
221 
222 
223 public:
224 
225  // Constructors
226 
227  //- Construct from an operator
228  FieldOpFunctor(const FieldOp& op)
229  :
230  FieldFunctor<Type>(),
231  op_(op)
232  {}
233 
234 
235  //- Destructor
236  virtual ~FieldOpFunctor()
237  {}
238 
239 
240  // Member Operators
241 
242  //- Evaluate the field
243  virtual tmp<Field<Type>> operator()() const
244  {
245  return op_();
246  }
247 };
248 
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 } // End namespace Foam
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 #ifdef NoRepository
257  #include "fieldMapperTemplates.C"
258 #endif
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 #endif
263 
264 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
Class used to lazily evaluate fields.
Definition: fieldMapper.H:185
virtual tmp< Field< Type > > operator()() const =0
Evaluate the field.
virtual ~FieldFunctor()
Destructor.
Definition: fieldMapper.H:196
Class used to lazily evaluate field-generating operators.
Definition: fieldMapper.H:215
FieldOpFunctor(const FieldOp &op)
Construct from an operator.
Definition: fieldMapper.H:227
virtual tmp< Field< Type > > operator()() const
Evaluate the field.
Definition: fieldMapper.H:242
virtual ~FieldOpFunctor()
Destructor.
Definition: fieldMapper.H:235
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 bool direct() const
Is the mapper direct?
Definition: fieldMapper.H:132
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)