45 #include "MapMeshes.H"
53 const word& optionName,
57 return decompositionMethod::nDomains
65 decompositionModel::canonicalName,
79 void mapConsistentMesh
81 const fvMesh& meshSource,
82 const fvMesh& meshTarget,
83 const meshToMesh0::order& mapOrder,
89 MapConsistentMesh<minusEqOp>
98 MapConsistentMesh<eqOp>
110 const fvMesh& meshSource,
111 const fvMesh& meshTarget,
112 const HashTable<word>& patchMap,
114 const meshToMesh0::order& mapOrder,
120 MapSubMesh<minusEqOp>
143 void mapConsistentSubMesh
145 const fvMesh& meshSource,
146 const fvMesh& meshTarget,
147 const meshToMesh0::order& mapOrder,
153 MapConsistentSubMesh<minusEqOp>
162 MapConsistentSubMesh<eqOp>
174 const fvMesh& meshTarget,
179 HashTable<label> cuttingPatchTable;
182 cuttingPatchTable.insert(cuttingPatches[i], i);
185 forAll(meshTarget.boundary(), patchi)
187 if (isA<processorFvPatch>(meshTarget.boundary()[patchi]))
191 !cuttingPatchTable.found
193 meshTarget.boundaryMesh()[patchi].name()
197 cuttingPatchTable.insert
199 meshTarget.boundaryMesh()[patchi].name(),
206 return cuttingPatchTable.toc();
212 int main(
int argc,
char *argv[])
216 "Map volume fields from one mesh to another"
218 argList::noParallel();
219 argList::addArgument(
"sourceCase");
224 "scalar|'latestTime'",
225 "Specify the source time"
231 "Specify the source region"
237 "Specify the target region"
239 argList::addBoolOption
242 "The source is decomposed"
244 argList::addBoolOption
247 "The target is decomposed"
249 argList::addBoolOption
252 "Source and target geometry and boundary conditions identical"
258 "Specify the mapping method"
260 argList::addBoolOption
263 "Subtract mapped source from target"
267 "sourceDecomposeParDict",
269 "Read decomposePar dictionary from specified location"
273 "targetDecomposeParDict",
275 "Read decomposePar dictionary from specified location"
279 argList
args(argc, argv);
289 const auto casePath =
args.
get<fileName>(1);
290 const fileName rootDirSource = casePath.path().toAbsolute();
291 const fileName caseDirSource = casePath.name();
293 Info<<
"Source: " << rootDirSource <<
" " << caseDirSource <<
endl;
294 word sourceRegion = polyMesh::defaultRegion;
297 sourceRegion =
args[
"sourceRegion"];
298 Info<<
"Source region: " << sourceRegion <<
endl;
301 Info<<
"Target: " << rootDirTarget <<
" " << caseDirTarget <<
endl;
302 word targetRegion = polyMesh::defaultRegion;
305 targetRegion =
args[
"targetRegion"];
306 Info<<
"Target region: " << targetRegion <<
endl;
309 const bool parallelSource =
args.
found(
"parallelSource");
310 const bool parallelTarget =
args.
found(
"parallelTarget");
311 const bool consistent =
args.
found(
"consistent");
313 meshToMesh0::order mapOrder = meshToMesh0::INTERPOLATE;
316 const word mapMethod(
args[
"mapMethod"]);
317 if (mapMethod ==
"mapNearest")
319 mapOrder = meshToMesh0::MAP;
321 else if (mapMethod ==
"interpolate")
323 mapOrder = meshToMesh0::INTERPOLATE;
325 else if (mapMethod ==
"cellPointInterpolate")
327 mapOrder = meshToMesh0::CELL_POINT_INTERPOLATE;
332 <<
"Unknown mapMethod " << mapMethod <<
". Valid options are: "
333 <<
"mapNearest, interpolate and cellPointInterpolate"
337 Info<<
"Mapping method: " << mapMethod <<
endl;
343 Info<<
"Subtracting mapped source field from target" <<
endl;
347 #include "createTimes.H"
349 HashTable<word> patchMap;
354 IOdictionary mapFieldsDict
361 IOobject::MUST_READ_IF_MODIFIED,
367 mapFieldsDict.readEntry(
"patchMap", patchMap);
368 mapFieldsDict.readEntry(
"cuttingPatches", cuttingPatches);
371 if (parallelSource && !parallelTarget)
373 const int nProcs = readNumProcs
376 "sourceDecomposeParDict",
380 Info<<
"Create target mesh\n" <<
endl;
392 Info<<
"Target mesh size: " << meshTarget.nCells() <<
endl;
394 for (
int proci=0; proci<nProcs; proci++)
396 Info<<
nl <<
"Source processor " << proci <<
endl;
400 Time::controlDictName,
402 caseDirSource/(
"processor" +
Foam::name(proci))
405 #include "setTimeIndex.H"
417 Info<<
"mesh size: " << meshSource.nCells() <<
endl;
443 else if (!parallelSource && parallelTarget)
445 const int nProcs = readNumProcs
448 "targetDecomposeParDict",
453 Info<<
"Create source mesh\n" <<
endl;
455 #include "setTimeIndex.H"
467 Info<<
"Source mesh size: " << meshSource.nCells() <<
endl;
469 for (
int proci=0; proci<nProcs; proci++)
471 Info<<
nl <<
"Target processor " << proci <<
endl;
475 Time::controlDictName,
477 caseDirTarget/(
"processor" +
Foam::name(proci))
490 Info<<
"mesh size: " << meshTarget.nCells() <<
endl;
509 addProcessorPatches(meshTarget, cuttingPatches),
516 else if (parallelSource && parallelTarget)
518 const int nProcsSource = readNumProcs
521 "sourceDecomposeParDict",
524 const int nProcsTarget = readNumProcs
527 "targetDecomposeParDict",
531 List<boundBox> bbsTarget(nProcsTarget);
532 List<bool> bbsTargetSet(nProcsTarget,
false);
534 for (
int procISource=0; procISource<nProcsSource; procISource++)
536 Info<<
nl <<
"Source processor " << procISource <<
endl;
540 Time::controlDictName,
542 caseDirSource/(
"processor" +
Foam::name(procISource))
545 #include "setTimeIndex.H"
557 Info<<
"mesh size: " << meshSource.nCells() <<
endl;
559 boundBox bbSource(meshSource.bounds());
561 for (
int procITarget=0; procITarget<nProcsTarget; procITarget++)
565 !bbsTargetSet[procITarget]
567 bbsTargetSet[procITarget]
568 && bbsTarget[procITarget].overlaps(bbSource)
572 Info<<
nl <<
"Target processor " << procITarget <<
endl;
576 Time::controlDictName,
578 caseDirTarget/(
"processor" +
Foam::name(procITarget))
591 Info<<
"mesh size: " << meshTarget.nCells() <<
endl;
593 bbsTarget[procITarget] = meshTarget.bounds();
594 bbsTargetSet[procITarget] =
true;
596 if (bbsTarget[procITarget].overlaps(bbSource))
615 addProcessorPatches(meshTarget, cuttingPatches),
627 #include "setTimeIndex.H"
651 Info<<
"Source mesh size: " << meshSource.nCells() <<
tab
652 <<
"Target mesh size: " << meshTarget.nCells() <<
nl <<
endl;
656 mapConsistentMesh(meshSource, meshTarget, mapOrder,
subtract);