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-2022 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 "mapMeshes.H"
35 #include "cellVolumeWeightMethod.H"
36 
37 using namespace Foam;
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 int main(int argc, char *argv[])
42 {
44  (
45  "map volume fields from one mesh to another"
46  );
47 
48  argList::validArgs.append("sourceCase");
49 
51  (
52  "sourceTime",
53  "scalar|'latestTime'",
54  "specify the source time"
55  );
57  (
58  "sourceRegion",
59  "word",
60  "specify the source region"
61  );
63  (
64  "targetRegion",
65  "word",
66  "specify the target region"
67  );
69  (
70  "consistent",
71  "source and target geometry and boundary conditions identical"
72  );
74  (
75  "mapMethod",
76  "word",
77  "specify the mapping method"
78  );
80  (
81  "fields",
82  "list",
83  "specify a list of fields to be mapped. Eg, '(U T p)' - "
84  "regular expressions not currently supported"
85  );
87  (
88  "noLagrangian",
89  "skip mapping lagrangian positions and fields"
90  );
91 
92  #include "setRootCase.H"
93 
94  fileName rootDirTarget(args.rootPath());
95  fileName caseDirTarget(args.globalCaseName());
96 
97  const fileName casePath = args[1];
98  const fileName rootDirSource = casePath.path();
99  const fileName caseDirSource = casePath.name();
100 
101  Info<< "Source: " << rootDirSource << " " << caseDirSource << endl;
102  word sourceRegion = fvMesh::defaultRegion;
103  if (args.optionFound("sourceRegion"))
104  {
105  sourceRegion = args["sourceRegion"];
106  Info<< "Source region: " << sourceRegion << endl;
107  }
108 
109  Info<< "Target: " << rootDirTarget << " " << caseDirTarget << endl;
110  word targetRegion = fvMesh::defaultRegion;
111  if (args.optionFound("targetRegion"))
112  {
113  targetRegion = args["targetRegion"];
114  Info<< "Target region: " << targetRegion << endl;
115  }
116 
117  const bool consistent = args.optionFound("consistent");
118 
119  const word mapMethod
120  (
122  (
123  "mapMethod",
124  cellVolumeWeightMethod::typeName
125  )
126  );
127  Info<< "Mapping method: " << mapMethod << endl;
128 
129  HashSet<word> selectedFields;
130  if (args.optionFound("fields"))
131  {
132  args.optionLookup("fields")() >> selectedFields;
133  }
134 
135  const bool noLagrangian = args.optionFound("noLagrangian");
136 
137  #include "createTimes.H"
138 
139  HashTable<word> patchMap;
140  wordList cuttingPatches;
141 
142  if (!consistent)
143  {
144  IOdictionary mapFieldsDict
145  (
146  IOobject
147  (
148  "mapFieldsDict",
153  false
154  )
155  );
156 
157  mapFieldsDict.lookup("patchMap") >> patchMap;
158  mapFieldsDict.lookup("cuttingPatches") >> cuttingPatches;
159  }
160 
161  #include "setTimeIndex.H"
162 
163  Info<< "\nCreate meshes\n" << endl;
164 
165  fvMesh meshSource
166  (
167  IOobject
168  (
169  sourceRegion,
172  ),
173  false
174  );
175 
176  fvMesh meshTarget
177  (
178  IOobject
179  (
180  targetRegion,
183  ),
184  false
185  );
186 
187  Info<< "Source mesh size: " << meshSource.nCells() << tab
188  << "Target mesh size: " << meshTarget.nCells() << nl << endl;
189 
190  if (consistent)
191  {
193  (
194  meshSource,
195  meshTarget,
196  mapMethod,
197  selectedFields,
198  noLagrangian
199  );
200  }
201  else
202  {
203  mapSubMesh
204  (
205  meshSource,
206  meshTarget,
207  patchMap,
208  cuttingPatches,
209  mapMethod,
210  selectedFields,
211  noLagrangian
212  );
213  }
214 
215  Info<< "\nEnd\n" << endl;
216 
217  return 0;
218 }
219 
220 
221 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:59
A class for handling file names.
Definition: fileName.H:79
const fileName & globalCaseName() const
Return case name.
Definition: argListI.H:54
static const char tab
Definition: Ostream.H:259
void mapSubMesh(const fvMesh &meshSource, const fvMesh &meshTarget, const HashTable< word > &patchMap, const wordList &cuttingPatches, const meshToMesh0::order &mapOrder)
const fileName & rootPath() const
Return root path.
Definition: argListI.H:42
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:325
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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
Time runTimeTarget(Time::controlDictName, args)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
Definition: argListI.H:243
Time runTimeSource(Time::controlDictName, argsSrc)
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
A class for handling words, derived from string.
Definition: word.H:59
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
word name() const
Return file name (part beyond last /)
Definition: fileName.C:195
An STL-conforming hash table.
Definition: HashTable.H:61
const word & system() const
Return system name.
Definition: TimePaths.H:113
static const char nl
Definition: Ostream.H:260
void mapConsistentMesh(const fvMesh &meshSource, const fvMesh &meshTarget, const meshToMesh0::order &mapOrder)
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
messageStream Info
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:265
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
Namespace for OpenFOAM.
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.
Definition: argListI.H:120