forwardOrAssignFieldMapper.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) 2019-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::forwardOrAssignFieldMapper
26 
27 Description
28  Forward field mapper that permits assigning a value on unmapped elements
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef forwardOrAssignFieldMapper_H
33 #define forwardOrAssignFieldMapper_H
34 
35 #include "fieldMapper.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 /*---------------------------------------------------------------------------*\
43  Class forwardOrAssignFieldMapper Declaration
44 \*---------------------------------------------------------------------------*/
45 
47 :
48  public fieldMapper
49 {
50  // Private Data
51 
52  //- Addressing from new back to old
53  const labelUList& addressing_;
54 
55  //- Are any values unmapped?
56  bool hasUnmapped_;
57 
58 
59  // Private Member Functions
60 
61  //- Generate an error when parts of the field are unmapped, but no
62  // value has been provided for them
63  virtual void unmappedError() const;
64 
65  //- Map a field in-place
66  template<class Type>
67  void map(Field<Type>& f, const Field<Type>& mapF) const;
68 
69  //- Map a field and return the result
70  template<class Type>
71  tmp<Field<Type>> map(const Field<Type>& f) const;
72 
73  //- Map or assign a field in-place
74  template<class Type>
75  void mapOrAssign
76  (
77  Field<Type>& f,
78  const Field<Type>& mapF,
79  const Type& unmappedVal
80  ) const;
81 
82  //- Map or assign a field and return the result
83  template<class Type>
84  tmp<Field<Type>> mapOrAssign
85  (
86  const Field<Type>& mapF,
87  const Type& unmappedVal
88  ) const;
89 
90  //- Map or assign a field in-place
91  template<class Type>
92  void mapOrAssign
93  (
94  Field<Type>& f,
95  const Field<Type>& mapF,
96  const FieldFunctor<Type>& unmappedFunc
97  ) const;
98 
99  //- Map or assign a field and return the result
100  template<class Type>
101  tmp<Field<Type>> mapOrAssign
102  (
103  const Field<Type>& mapF,
104  const FieldFunctor<Type>& unmappedFunc
105  ) const;
106 
107 
108 public:
109 
110  // Constructors
111 
112  //- Construct given addressing
113  forwardOrAssignFieldMapper(const labelUList& addressing)
114  :
115  addressing_(addressing),
116  hasUnmapped_(!addressing.empty() && min(addressing) < 0)
117  {}
118 
119 
120  //- Destructor
122  {}
123 
124 
125  // Member Operators
126 
127  //- Map a field
129 
130  //- Map a label field
132 
133  //- Map or assign a field
135 
136  //- Map or assign a label field
138 };
139 
140 
141 /*---------------------------------------------------------------------------*\
142  Class forwardOrAssignPatchFieldMapper Declaration
143 \*---------------------------------------------------------------------------*/
144 
146 :
148 {
149  // Private Data
150 
151  //- Field base type name
152  const word& fieldBaseTypeName_;
153 
154  //- Field type name
155  const word& fieldTypeName_;
156 
157  //- Patch name
158  const word& patchName_;
159 
160  //- Internal patch name
161  const word& internalFieldName_;
162 
163 
164  // Private Member Functions
165 
166  //- Generate an error when parts of the field are unmapped, but no
167  // value has been provided for them
168  virtual void unmappedError() const;
169 
170 
171 public:
172 
173  // Constructors
174 
175  //- Construct given a field and addressing
176  template<class FieldType>
178  (
179  const FieldType& field,
180  const labelUList& addressing
181  )
182  :
183  forwardOrAssignFieldMapper(addressing),
184  fieldBaseTypeName_(FieldType::typeName),
185  fieldTypeName_(field.type()),
186  patchName_(field.patch().name()),
187  internalFieldName_(field.internalField().name())
188  {}
189 
190 
191  //- Destructor
193  {}
194 };
195 
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 } // End namespace Foam
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #endif
204 
205 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
Class used to lazily evaluate fields.
Definition: fieldMapper.H:176
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Forward field mapper that permits assigning a value on unmapped elements.
DEFINE_FIELD_MAPPER_MAP_OPERATOR(label,)
Map a label field.
DEFINE_FIELD_MAPPER_MAP_OR_ASSIGN_OPERATOR(label,)
Map or assign a label field.
FOR_ALL_FIELD_TYPES(DEFINE_FIELD_MAPPER_MAP_OPERATOR,)
Map a field.
forwardOrAssignFieldMapper(const labelUList &addressing)
Construct given addressing.
forwardOrAssignPatchFieldMapper(const FieldType &field, const labelUList &addressing)
Construct given a field and addressing.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
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)