mapGeometricFields.C
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 \*---------------------------------------------------------------------------*/
25 
26 #include "mapGeometricFields.H"
27 #include "fvMeshToFvMesh.H"
28 #include "pointMesh.H"
29 #include "IOobjectList.H"
30 #include "OSspecific.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 template<class Type>
38 void mapVolTypeFields
39 (
40  const fvMeshToFvMesh& interp,
41  const wordReList& cuttingPatches,
42  const HashSet<word>& selectedFields,
43  const IOobjectList& objects
44 )
45 {
46  const fvMesh& srcMesh = static_cast<const fvMesh&>(interp.srcMesh());
47  const fvMesh& tgtMesh = static_cast<const fvMesh&>(interp.tgtMesh());
48 
49  IOobjectList fields = objects.lookupClass(VolField<Type>::typeName);
50 
51  forAllIter(IOobjectList, fields, fieldIter)
52  {
53  const word& fieldName = fieldIter()->name();
54 
55  if (!selectedFields.empty() && !selectedFields.found(fieldName))
56  {
57  continue;
58  }
59 
60  const VolField<Type> fieldSource(*fieldIter(), srcMesh);
61 
62  typeIOobject<VolField<Type>> targetIO
63  (
64  fieldName,
65  tgtMesh.time().name(),
66  tgtMesh,
68  );
69 
70  // Warnings about inconsistent execution
71  if (targetIO.headerOk() && interp.consistent())
72  {
74  << "Mapping of field " << fieldName << " will not utilise "
75  << "the corresponding field in the target case, as the map is "
76  << "consistent (i.e., all patches are mapped)" << endl;
77  }
78  if (!targetIO.headerOk() && !interp.consistent())
79  {
81  << "Cannot map field " << fieldName << " because the "
82  << "map is not consistent (i.e., not all patches are "
83  << "mapped), and there is no corresponding field in "
84  << "the target case" << endl;
85  continue;
86  }
87  if (!targetIO.headerOk() && !cuttingPatches.empty())
88  {
90  << "Cutting patches will not be used for field " << fieldName
91  << " because no there is no corresponding field in the target "
92  << "case" << endl;
93  }
94 
95  if (targetIO.headerOk())
96  {
97  Info<< " mapping into existing field " << fieldName << endl;
98 
99  VolField<Type> fieldTarget(targetIO, tgtMesh);
100 
101  fieldTarget.reset
102  (
103  interp.srcToTgt(fieldSource, fieldTarget, cuttingPatches)
104  );
105 
106  fieldTarget.write();
107  }
108  else
109  {
110  Info<< " creating new field " << fieldName << endl;
111 
112  VolField<Type>(targetIO, interp.srcToTgt(fieldSource)).write();
113  }
114  }
115 }
116 
117 }
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
122 (
123  const fvMeshToFvMesh& interp,
124  const wordReList& cuttingPatches,
125  const HashSet<word>& selectedFields,
126  const bool noLagrangian
127 )
128 {
129  // Search for list of source objects for this time
130  const polyMesh& srcMesh = interp.srcMesh();
131  IOobjectList objects(srcMesh, srcMesh.time().name());
132 
133  // Map the fields
134  #define MapVolTypeFields(Type, nullArg) \
135  mapVolTypeFields<Type> \
136  ( \
137  interp, \
138  cuttingPatches, \
139  selectedFields, \
140  objects \
141  );
142  FOR_ALL_FIELD_TYPES(MapVolTypeFields);
143  #undef MapVolTypeFields
144 }
145 
146 
147 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:474
virtual Ostream & write(const token &)
Write token.
Definition: Ostream.C:51
#define FOR_ALL_FIELD_TYPES(Macro,...)
Definition: fieldTypes.H:51
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:234
Maps geometric fields.
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
messageStream Info
void mapGeometricFields(const fvMeshToFvMesh &interp, const wordReList &cuttingPatches, const HashSet< word > &selectedFields, const bool noLagrangian)
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
objects