38 #include "MapMeshes.H" 42 void mapConsistentMesh
44 const fvMesh& meshSource,
45 const fvMesh& meshTarget,
46 const meshToMesh0::order& mapOrder,
52 MapConsistentMesh<minusEqOp>
61 MapConsistentMesh<eqOp>
73 const fvMesh& meshSource,
74 const fvMesh& meshTarget,
75 const HashTable<word>& patchMap,
77 const meshToMesh0::order& mapOrder,
106 void mapConsistentSubMesh
108 const fvMesh& meshSource,
109 const fvMesh& meshTarget,
110 const meshToMesh0::order& mapOrder,
116 MapConsistentSubMesh<minusEqOp>
125 MapConsistentSubMesh<eqOp>
137 const fvMesh& meshTarget,
142 HashTable<label> cuttingPatchTable;
145 cuttingPatchTable.insert(cuttingPatches[i], i);
150 if (isA<processorFvPatch>(meshTarget.boundary()[
patchi]))
154 !cuttingPatchTable.found
156 meshTarget.boundaryMesh()[
patchi].name()
160 cuttingPatchTable.insert
162 meshTarget.boundaryMesh()[
patchi].name(),
169 return cuttingPatchTable.toc();
175 int main(
int argc,
char *argv[])
179 "map volume fields from one mesh to another" 181 argList::noParallel();
182 argList::validArgs.append(
"sourceCase");
187 "scalar|'latestTime'",
188 "specify the source time" 194 "specify the source region" 200 "specify the target region" 202 argList::addBoolOption
205 "the source is decomposed" 207 argList::addBoolOption
210 "the target is decomposed" 212 argList::addBoolOption
215 "source and target geometry and boundary conditions identical" 221 "specify the mapping method" 223 argList::addBoolOption
226 "subtract mapped source from target" 229 argList
args(argc, argv);
239 fileName casePath =
args[1];
241 const fileName caseDirSource = casePath.
name();
243 Info<<
"Source: " << rootDirSource <<
" " << caseDirSource <<
endl;
244 word sourceRegion = fvMesh::defaultRegion;
247 sourceRegion =
args[
"sourceRegion"];
248 Info<<
"Source region: " << sourceRegion <<
endl;
251 Info<<
"Target: " << rootDirTarget <<
" " << caseDirTarget <<
endl;
252 word targetRegion = fvMesh::defaultRegion;
255 targetRegion =
args[
"targetRegion"];
256 Info<<
"Target region: " << targetRegion <<
endl;
263 meshToMesh0::order mapOrder = meshToMesh0::INTERPOLATE;
266 const word mapMethod(
args[
"mapMethod"]);
267 if (mapMethod ==
"mapNearest")
269 mapOrder = meshToMesh0::MAP;
271 else if (mapMethod ==
"interpolate")
273 mapOrder = meshToMesh0::INTERPOLATE;
275 else if (mapMethod ==
"cellPointInterpolate")
277 mapOrder = meshToMesh0::CELL_POINT_INTERPOLATE;
282 <<
"Unknown mapMethod " << mapMethod <<
". Valid options are: " 283 <<
"mapNearest, interpolate and cellPointInterpolate" 287 Info<<
"Mapping method: " << mapMethod <<
endl;
293 Info<<
"Subtracting mapped source field from target" <<
endl;
297 #include "createTimes.H" 299 HashTable<word> patchMap;
304 IOdictionary mapFieldsDict
311 IOobject::MUST_READ_IF_MODIFIED,
317 mapFieldsDict.lookup(
"patchMap") >> patchMap;
318 mapFieldsDict.lookup(
"cuttingPatches") >> cuttingPatches;
321 if (parallelSource && !parallelTarget)
323 IOdictionary decompositionDict
330 IOobject::MUST_READ_IF_MODIFIED,
335 const int nProcs(decompositionDict.lookup<
int>(
"numberOfSubdomains"));
337 Info<<
"Create target mesh\n" <<
endl;
349 Info<<
"Target mesh size: " << meshTarget.nCells() <<
endl;
351 for (
int proci=0; proci<nProcs; proci++)
353 Info<<
nl <<
"Source processor " << proci <<
endl;
357 Time::controlDictName,
359 caseDirSource/fileName(word(
"processor") +
name(proci))
362 #include "setTimeIndex.H" 374 Info<<
"mesh size: " << meshSource.nCells() <<
endl;
400 else if (!parallelSource && parallelTarget)
402 IOdictionary decompositionDict
409 IOobject::MUST_READ_IF_MODIFIED,
414 const int nProcs(decompositionDict.lookup<
int>(
"numberOfSubdomains"));
416 Info<<
"Create source mesh\n" <<
endl;
418 #include "setTimeIndex.H" 430 Info<<
"Source mesh size: " << meshSource.nCells() <<
endl;
432 for (
int proci=0; proci<nProcs; proci++)
434 Info<<
nl <<
"Target processor " << proci <<
endl;
438 Time::controlDictName,
440 caseDirTarget/fileName(word(
"processor") +
name(proci))
453 Info<<
"mesh size: " << meshTarget.nCells() <<
endl;
472 addProcessorPatches(meshTarget, cuttingPatches),
479 else if (parallelSource && parallelTarget)
481 IOdictionary decompositionDictSource
488 IOobject::MUST_READ_IF_MODIFIED,
493 const int nProcsSource
495 decompositionDictSource.lookup<
int>(
"numberOfSubdomains")
499 IOdictionary decompositionDictTarget
506 IOobject::MUST_READ_IF_MODIFIED,
511 const int nProcsTarget
513 decompositionDictTarget.lookup<
int>(
"numberOfSubdomains")
516 List<boundBox> bbsTarget(nProcsTarget);
517 List<bool> bbsTargetSet(nProcsTarget,
false);
519 for (
int procISource=0; procISource<nProcsSource; procISource++)
521 Info<<
nl <<
"Source processor " << procISource <<
endl;
525 Time::controlDictName,
527 caseDirSource/fileName(word(
"processor") +
name(procISource))
530 #include "setTimeIndex.H" 542 Info<<
"mesh size: " << meshSource.nCells() <<
endl;
544 boundBox bbSource(meshSource.bounds());
546 for (
int procITarget=0; procITarget<nProcsTarget; procITarget++)
550 !bbsTargetSet[procITarget]
552 bbsTargetSet[procITarget]
553 && bbsTarget[procITarget].overlaps(bbSource)
557 Info<<
nl <<
"Target processor " << procITarget <<
endl;
561 Time::controlDictName,
563 caseDirTarget/fileName(word(
"processor")
577 Info<<
"mesh size: " << meshTarget.nCells() <<
endl;
579 bbsTarget[procITarget] = meshTarget.bounds();
580 bbsTargetSet[procITarget] =
true;
582 if (bbsTarget[procITarget].overlaps(bbSource))
601 addProcessorPatches(meshTarget, cuttingPatches),
613 #include "setTimeIndex.H" 637 Info<<
"Source mesh size: " << meshSource.nCells() <<
tab 638 <<
"Target mesh size: " << meshTarget.nCells() <<
nl <<
endl;
642 mapConsistentMesh(meshSource, meshTarget, mapOrder, subtract);
#define forAll(list, i)
Loop across all elements in list.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const fileName & globalCaseName() const
Return case name.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const fileName & rootPath() const
Return root path.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool optionFound(const word &opt) const
Return true if the named option is found.
Time runTimeTarget(Time::controlDictName, args)
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Time runTimeSource(Time::controlDictName, argsSrc)
word name() const
Return file name (part beyond last /)
fileName & toAbsolute()
Convert from relative to absolute.
word name(const complex &)
Return a string representation of a complex.
fileName path() const
Return the path to the caseName.
List< word > wordList
A List of words.
bool check(bool checkArgs=true, bool checkOpts=true) const
Check argument list.
Foam::argList args(argc, argv)