Loading...
Searching...
No Matches
mapFields.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::functionObjects::mapFields
28
29Group
30 grpFieldFunctionObjects
31
32Description
33 Maps input fields from local mesh to secondary mesh at runtime.
34
35 Operands:
36 \table
37 Operand | Type | Location
38 input | {vol,surface}<Type>Field | <time>/inputField
39 output file | - | -
40 output field | {vol,surface}<Type>Field | <time>/outputField
41 \endtable
42
43 where \c Type can be one of:
44 \c Scalar, \c Vector, \c SphericalTensor, \c SymmTensor, or \c Tensor.
45
46Usage
47 Minimal example by using \c system/controlDict.functions:
48 \verbatim
49 mapFieldsFO
50 {
51 // Mandatory entries
52 type mapFields;
53 libs (fieldFunctionObjects);
54 fields <wordList>; // (<field1> <field2> ... <fieldN>);
55 mapRegion <word>; // coarseMesh;
56 mapMethod <word>; // cellVolumeWeight;
57 consistent <bool>;;
58
59 // Optional entries
60 patchMapMethod direct; // AMI-related entry
61
62 // Conditional entries
63
64 // when consistent=false
65
66 // Manual: createPatchMap false;
67 // patchMap (<patchSrc> <patchTgt>);
68 // cuttingPatches (<patchTgt1> <patchTgt2> ... <patchTgtN>);
69
70 // Automatic: createPatchMap true;
71 // Creates the patchMap and cuttingPatches automatically
72
73 // Inherited entries
74 ...
75 }
76 \endverbatim
77
78 where the entries mean:
79 \table
80 Property | Description | Type | Reqd | Deflt
81 type | Type name: mapFields | word | yes | -
82 libs | Library name: fieldFunctionObjects | word | yes | -
83 fields | Names of operand fields | wordList | yes | -
84 mapRegion | Name of region to map to | word | yes | -
85 mapMethod | Mapping method | word | yes | -
86 consistent | Mapping meshes have consistent boundaries | bool | yes | -
87 patchMapMethod | Patch mapping method for AMI cases | word | no | -
88 createPatchMap | Automatically create patchMap and cuttingPatches| <!--
89 --> | bool | no | -
90 patchMap | Mapping between coincident source and target patches <!--
91 --> | wordHashTable | no | -
92 cuttingPatches | Target patches cutting the source domain <!--
93 --> | wordList | no | -
94 \endtable
95
96 Options for the \c mapMethod entry:
97 \verbatim
98 direct
99 mapNearest
100 cellVolumeWeight
101 correctedCellVolumeWeight
102 \endverbatim
103
104 Options for the \c patchMapMethod entry:
105 \verbatim
106 nearestFaceAMI
107 faceAreaWeightAMI
108 \endverbatim
109
110 The inherited entries are elaborated in:
111 - \link functionObject.H \endlink
112
113SourceFiles
114 mapFields.C
115 mapFieldsTemplates.C
116
117\*---------------------------------------------------------------------------*/
118
119#ifndef Foam_functionObjects_mapFields_H
120#define Foam_functionObjects_mapFields_H
121
122#include "fvMeshFunctionObject.H"
123#include "volFieldsFwd.H"
124
125// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126
127namespace Foam
128{
129
130class meshToMesh;
131
132namespace functionObjects
133{
134
135/*---------------------------------------------------------------------------*\
136 Class mapFields Declaration
137\*---------------------------------------------------------------------------*/
138
139class mapFields
140:
142{
143 // Private Data
144
145 //- Input dictionary
146 dictionary dict_;
147
148 // //- Locally cached map region mesh (map to this mesh)
149 // autoPtr<fvMesh> mapRegionPtr_;
150
151 //- Mesh-to-mesh interpolation
152 autoPtr<meshToMesh> interpPtr_;
153
154 //- List of field names to interpolate
155 wordRes fieldNames_;
156
157
158 // Private Member Functions
159
160 //- On-the-fly lookup or load of the map region mesh
161 const fvMesh& lookupMapRegion() const;
162
163 //- Helper function to create the mesh-to-mesh interpolation
164 void createInterpolation
165 (
166 const dictionary& dict,
167 const fvMesh& meshTarget,
168 const fvMesh& mapRegion
169 );
170
171 // //- Helper function to create the mesh-to-mesh interpolation
172 // void createInterpolation(const dictionary& dict);
173
174 //- Helper function to evaluate constraint patches after mapping
175 template<class Type>
176 void evaluateConstraintTypes
177 (
178 GeometricField<Type, fvPatchField, volMesh>& fld
179 ) const;
180
181 //- Helper function to map the <Type> fields
182 template<class Type>
183 bool mapFieldType() const;
184
185 //- Helper function to write the <Type> fields
186 template<class Type>
187 bool writeFieldType() const;
188
189
190public:
191
192 //- Runtime type information
193 TypeName("mapFields");
194
195
196 // Constructors
197
198 //- Construct from name, Time and dictionary
200 (
201 const word& name,
202 const Time& runTime,
203 const dictionary& dict
204 );
205
206 //- No copy construct
207 mapFields(const mapFields&) = delete;
208
209 //- No copy assignment
210 void operator=(const mapFields&) = delete;
211
212
213 //- Destructor
214 virtual ~mapFields() = default;
215
216
217 // Member Functions
218
219 //- Read the function-object dictionary
220 virtual bool read(const dictionary& dict);
221
222 //- Execute the function-object operations
223 virtual bool execute();
224
225 //- Write the function-object results
226 virtual bool write();
227};
228
229
230// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231
232} // End namespace functionObjects
233} // End namespace Foam
234
235// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236
237#ifdef NoRepository
238 #include "mapFieldsTemplates.C"
239#endif
240
241// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242
243#endif
244
245// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic GeometricField class.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const word & name() const noexcept
Return the name of this functionObject.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
Maps input fields from local mesh to secondary mesh at runtime.
Definition mapFields.H:226
mapFields(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
Definition mapFields.C:263
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition mapFields.C:279
mapFields(const mapFields &)=delete
No copy construct.
void operator=(const mapFields &)=delete
No copy assignment.
virtual bool execute()
Execute the function-object operations.
Definition mapFields.C:295
virtual bool write()
Write the function-object results.
Definition mapFields.C:328
virtual ~mapFields()=default
Destructor.
TypeName("mapFields")
Runtime type information.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Class to calculate the cell-addressing between two overlapping meshes.
Definition meshToMesh.H:61
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68
Forwards and collection of common volume field types.