mapFieldsPar.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-2025 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 Application
25  mapFieldsPar
26 
27 Description
28  Maps volume fields from one mesh to another, reading and
29  interpolating all fields present in the time directory of both cases.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "argList.H"
34 #include "fvMeshToFvMesh.H"
35 #include "mapGeometricFields.H"
36 #include "mapClouds.H"
38 
39 using namespace Foam;
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
44 (
45  const fvMesh& srcMesh,
46  const fvMesh& tgtMesh,
47  const word& mapMethod,
48  const HashSet<word>& selectedFields,
49  const bool noLagrangian
50 )
51 {
52  Info<< nl << "Consistently creating and mapping fields for time "
53  << srcMesh.time().name() << nl << endl;
54 
55  fvMeshToFvMesh interp(srcMesh, tgtMesh, mapMethod);
56 
57  Info<< nl << "Mapping geometric fields" << endl;
58 
59  mapGeometricFields(interp, wordReList(), selectedFields, noLagrangian);
60 
61  if (!noLagrangian)
62  {
63  mapClouds(interp);
64  }
65 }
66 
67 
68 void mapMesh
69 (
70  const fvMesh& srcMesh,
71  const fvMesh& tgtMesh,
72  const HashTable<word>& patchMap,
73  const wordReList& cuttingPatches,
74  const word& mapMethod,
75  const HashSet<word>& selectedFields,
76  const bool noLagrangian
77 )
78 {
79  Info<< nl << "Creating and mapping fields for time "
80  << srcMesh.time().name() << nl << endl;
81 
82  fvMeshToFvMesh interp(srcMesh, tgtMesh, mapMethod, patchMap);
83 
84  Info<< nl << "Mapping geometric fields" << endl;
85 
86  mapGeometricFields(interp, cuttingPatches, selectedFields, noLagrangian);
87 
88  if (!noLagrangian)
89  {
90  mapClouds(interp);
91  }
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
96 
97 int main(int argc, char *argv[])
98 {
100  (
101  "map volume fields from one mesh to another"
102  );
103 
104  argList::validArgs.append("sourceCase");
105 
107  (
108  "sourceTime",
109  "scalar|'latestTime'",
110  "specify the source time"
111  );
113  (
114  "sourceRegion",
115  "word",
116  "specify the source region"
117  );
119  (
120  "targetRegion",
121  "word",
122  "specify the target region"
123  );
125  (
126  "consistent",
127  "source and target geometry and boundary conditions identical"
128  );
130  (
131  "mapMethod",
132  "word",
133  "specify the mapping method"
134  );
136  (
137  "fields",
138  "list",
139  "specify a list of fields to be mapped. Eg, '(U T p)' - "
140  "regular expressions not currently supported"
141  );
143  (
144  "noLagrangian",
145  "skip mapping lagrangian positions and fields"
146  );
147 
148  #include "setRootCase.H"
149 
150  fileName rootDirTarget(args.rootPath());
151  fileName caseDirTarget(args.globalCaseName());
152 
153  const fileName casePath = args[1];
154  const fileName rootDirSource = casePath.path();
155  const fileName caseDirSource = casePath.name();
156 
157  Info<< "Source: " << rootDirSource << " " << caseDirSource << endl;
158  word sourceRegion = fvMesh::defaultRegion;
159  if (args.optionFound("sourceRegion"))
160  {
161  sourceRegion = args["sourceRegion"];
162  Info<< "Source region: " << sourceRegion << endl;
163  }
164 
165  Info<< "Target: " << rootDirTarget << " " << caseDirTarget << endl;
166  word targetRegion = fvMesh::defaultRegion;
167  if (args.optionFound("targetRegion"))
168  {
169  targetRegion = args["targetRegion"];
170  Info<< "Target region: " << targetRegion << endl;
171  }
172 
173  const bool consistent = args.optionFound("consistent");
174 
175  const word mapMethod
176  (
178  (
179  "mapMethod",
180  cellsToCellss::intersection::typeName
181  )
182  );
183  Info<< "Mapping method: " << mapMethod << endl;
184 
185  HashSet<word> selectedFields;
186  if (args.optionFound("fields"))
187  {
188  args.optionLookup("fields")() >> selectedFields;
189  }
190 
191  const bool noLagrangian = args.optionFound("noLagrangian");
192 
193  #include "createTimes.H"
194 
195  HashTable<word> patchMap;
196  wordReList cuttingPatches;
197 
198  if (!consistent)
199  {
200  IOdictionary mapFieldsDict
201  (
202  IOobject
203  (
204  "mapFieldsDict",
209  false
210  )
211  );
212 
213  mapFieldsDict.lookup("patchMap") >> patchMap;
214  mapFieldsDict.lookup("cuttingPatches") >> cuttingPatches;
215  }
216 
217  #include "setTimeIndex.H"
218 
219  Info<< "\nCreate meshes\n" << endl;
220 
221  fvMesh srcMesh
222  (
223  IOobject
224  (
225  sourceRegion,
228  ),
229  false
230  );
231 
232  srcMesh.postConstruct(false, false, fvMesh::stitchType::nonGeometric);
233 
234  fvMesh tgtMesh
235  (
236  IOobject
237  (
238  targetRegion,
241  ),
242  false
243  );
244 
245  tgtMesh.postConstruct(false, false, fvMesh::stitchType::nonGeometric);
246 
247  Info<< "Source mesh size: "
248  << returnReduce(srcMesh.nCells(), sumOp<label>())
249  << ", Target mesh size: "
250  << returnReduce(tgtMesh.nCells(), sumOp<label>())
251  << endl;
252 
253  if (consistent)
254  {
256  (
257  srcMesh,
258  tgtMesh,
259  mapMethod,
260  selectedFields,
261  noLagrangian
262  );
263  }
264  else
265  {
266  mapMesh
267  (
268  srcMesh,
269  tgtMesh,
270  patchMap,
271  cuttingPatches,
272  mapMethod,
273  selectedFields,
274  noLagrangian
275  );
276  }
277 
278  Info<< "\nEnd\n" << endl;
279 
280  return 0;
281 }
282 
283 
284 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:62
An STL-conforming hash table.
Definition: HashTable.H:127
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:119
static const word & system()
Return system name.
Definition: TimePaths.H:112
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:128
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
const fileName & globalCaseName() const
Return case name.
Definition: argListI.H:54
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
const fileName & rootPath() const
Return root path.
Definition: argListI.H:42
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.
Definition: argListI.H:120
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
Definition: argListI.H:294
const word & name() const
Return const reference to name.
A class for handling file names.
Definition: fileName.H:82
word name() const
Return file name (part beyond last /)
Definition: fileName.C:195
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:284
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:420
void postConstruct(const bool changers, const bool zones, const stitchType stitch)
Complete construction of the mesh.
Definition: fvMesh.C:634
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:270
label nCells() const
A class for handling words, derived from string.
Definition: word.H:62
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Maps Lagrangian clouds.
Time runTimeSource(Time::controlDictName, argsSrc)
Time runTimeTarget(Time::controlDictName, args)
Maps geometric fields.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
void mapClouds(const fvMeshToFvMesh &interp)
messageStream Info
void mapConsistentMesh(const fvMesh &meshSource, const fvMesh &meshTarget, const meshToMesh0::order &mapOrder)
void mapGeometricFields(const fvMeshToFvMesh &interp, const wordReList &cuttingPatches, const HashSet< word > &selectedFields, const bool noLagrangian)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
static const char nl
Definition: Ostream.H:267
Foam::argList args(argc, argv)