00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "fvCFD.H"
00037 #include "meshToMesh.H"
00038 #include "MapVolFields.H"
00039 #include "MapConsistentVolFields.H"
00040 #include "UnMapped.H"
00041 #include "processorFvPatch.H"
00042 #include "mapLagrangian.H"
00043
00044
00045
00046 void mapConsistentMesh
00047 (
00048 const fvMesh& meshSource,
00049 const fvMesh& meshTarget
00050 )
00051 {
00052
00053 meshToMesh meshToMeshInterp(meshSource, meshTarget);
00054
00055 Info<< nl
00056 << "Consistently creating and mapping fields for time "
00057 << meshSource.time().timeName() << nl << endl;
00058
00059 {
00060
00061 IOobjectList objects(meshSource, meshSource.time().timeName());
00062
00063
00064
00065 MapConsistentVolFields<scalar>(objects, meshToMeshInterp);
00066 MapConsistentVolFields<vector>(objects, meshToMeshInterp);
00067 MapConsistentVolFields<sphericalTensor>(objects, meshToMeshInterp);
00068 MapConsistentVolFields<symmTensor>(objects, meshToMeshInterp);
00069 MapConsistentVolFields<tensor>(objects, meshToMeshInterp);
00070 }
00071
00072 {
00073
00074 IOobjectList objects(meshTarget, meshTarget.time().timeName());
00075
00076
00077
00078 UnMapped<surfaceScalarField>(objects);
00079 UnMapped<surfaceVectorField>(objects);
00080 UnMapped<surfaceSphericalTensorField>(objects);
00081 UnMapped<surfaceSymmTensorField>(objects);
00082 UnMapped<surfaceTensorField>(objects);
00083
00084
00085
00086 UnMapped<pointScalarField>(objects);
00087 UnMapped<pointVectorField>(objects);
00088 UnMapped<pointSphericalTensorField>(objects);
00089 UnMapped<pointSymmTensorField>(objects);
00090 UnMapped<pointTensorField>(objects);
00091 }
00092
00093 mapLagrangian(meshToMeshInterp);
00094 }
00095
00096
00097 void mapSubMesh
00098 (
00099 const fvMesh& meshSource,
00100 const fvMesh& meshTarget,
00101 const HashTable<word>& patchMap,
00102 const wordList& cuttingPatches
00103 )
00104 {
00105
00106 meshToMesh meshToMeshInterp
00107 (
00108 meshSource,
00109 meshTarget,
00110 patchMap,
00111 cuttingPatches
00112 );
00113
00114 Info<< nl
00115 << "Mapping fields for time " << meshSource.time().timeName()
00116 << nl << endl;
00117
00118 {
00119
00120 IOobjectList objects(meshSource, meshSource.time().timeName());
00121
00122
00123
00124 MapVolFields<scalar>(objects, meshToMeshInterp);
00125 MapVolFields<vector>(objects, meshToMeshInterp);
00126 MapVolFields<sphericalTensor>(objects, meshToMeshInterp);
00127 MapVolFields<symmTensor>(objects, meshToMeshInterp);
00128 MapVolFields<tensor>(objects, meshToMeshInterp);
00129 }
00130
00131 {
00132
00133 IOobjectList objects(meshTarget, meshTarget.time().timeName());
00134
00135
00136
00137 UnMapped<surfaceScalarField>(objects);
00138 UnMapped<surfaceVectorField>(objects);
00139 UnMapped<surfaceSphericalTensorField>(objects);
00140 UnMapped<surfaceSymmTensorField>(objects);
00141 UnMapped<surfaceTensorField>(objects);
00142
00143
00144
00145 UnMapped<pointScalarField>(objects);
00146 UnMapped<pointVectorField>(objects);
00147 UnMapped<pointSphericalTensorField>(objects);
00148 UnMapped<pointSymmTensorField>(objects);
00149 UnMapped<pointTensorField>(objects);
00150 }
00151
00152 mapLagrangian(meshToMeshInterp);
00153 }
00154
00155
00156 void mapConsistentSubMesh
00157 (
00158 const fvMesh& meshSource,
00159 const fvMesh& meshTarget
00160 )
00161 {
00162 HashTable<word> patchMap;
00163 HashTable<label> cuttingPatchTable;
00164
00165 forAll(meshTarget.boundary(), patchi)
00166 {
00167 if (typeid(meshTarget.boundary()[patchi]) != typeid(processorFvPatch))
00168 {
00169 patchMap.insert
00170 (
00171 meshTarget.boundary()[patchi].name(),
00172 meshTarget.boundary()[patchi].name()
00173 );
00174 }
00175 else
00176 {
00177 cuttingPatchTable.insert
00178 (
00179 meshTarget.boundaryMesh()[patchi].name(),
00180 -1
00181 );
00182 }
00183 }
00184
00185 mapSubMesh(meshSource, meshTarget, patchMap, cuttingPatchTable.toc());
00186 }
00187
00188
00189 wordList addProcessorPatches
00190 (
00191 const fvMesh& meshTarget,
00192 const wordList& cuttingPatches
00193 )
00194 {
00195
00196 HashTable<label> cuttingPatchTable;
00197 forAll (cuttingPatches, i)
00198 {
00199 cuttingPatchTable.insert(cuttingPatches[i], i);
00200 }
00201
00202 forAll (meshTarget.boundary(), patchi)
00203 {
00204 if (typeid(meshTarget.boundary()[patchi]) == typeid(processorFvPatch))
00205 {
00206 if
00207 (
00208 !cuttingPatchTable.found
00209 (
00210 meshTarget.boundaryMesh()[patchi].name()
00211 )
00212 )
00213 {
00214 cuttingPatchTable.insert
00215 (
00216 meshTarget.boundaryMesh()[patchi].name(),
00217 -1
00218 );
00219 }
00220 }
00221 }
00222
00223 return cuttingPatchTable.toc();
00224 }
00225
00226
00227
00228
00229 int main(int argc, char *argv[])
00230 {
00231 # include "setRoots.H"
00232 # include "createTimes.H"
00233 # include "setTimeIndex.H"
00234
00235 runTimeSource.setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex);
00236
00237 Info<< "\nSource time: " << runTimeSource.value()
00238 << "\nTarget time: " << runTimeTarget.value()
00239 << endl;
00240
00241 HashTable<word> patchMap;
00242 wordList cuttingPatches;
00243
00244 if (!consistent)
00245 {
00246 IOdictionary mapFieldsDict
00247 (
00248 IOobject
00249 (
00250 "mapFieldsDict",
00251 runTimeTarget.system(),
00252 runTimeTarget,
00253 IOobject::MUST_READ,
00254 IOobject::NO_WRITE,
00255 false
00256 )
00257 );
00258
00259 mapFieldsDict.lookup("patchMap") >> patchMap;
00260
00261 mapFieldsDict.lookup("cuttingPatches") >> cuttingPatches;
00262 }
00263
00264 if (parallelSource && !parallelTarget)
00265 {
00266 IOdictionary decompositionDict
00267 (
00268 IOobject
00269 (
00270 "decomposeParDict",
00271 runTimeSource.system(),
00272 runTimeSource,
00273 IOobject::MUST_READ,
00274 IOobject::NO_WRITE
00275 )
00276 );
00277
00278 int nProcs(readInt(decompositionDict.lookup("numberOfSubdomains")));
00279
00280 Info<< "Create target mesh\n" << endl;
00281
00282 fvMesh meshTarget
00283 (
00284 IOobject
00285 (
00286 fvMesh::defaultRegion,
00287 runTimeTarget.timeName(),
00288 runTimeTarget
00289 )
00290 );
00291
00292 Info<< "Target mesh size: " << meshTarget.nCells() << endl;
00293
00294 for (int procI=0; procI<nProcs; procI++)
00295 {
00296 Info<< nl << "Source processor " << procI << endl;
00297
00298 Time runTimeSource
00299 (
00300 Time::controlDictName,
00301 rootDirSource,
00302 caseDirSource/fileName(word("processor") + name(procI))
00303 );
00304
00305 runTimeSource.setTime
00306 (
00307 sourceTimes[sourceTimeIndex],
00308 sourceTimeIndex
00309 );
00310
00311 fvMesh meshSource
00312 (
00313 IOobject
00314 (
00315 fvMesh::defaultRegion,
00316 runTimeSource.timeName(),
00317 runTimeSource
00318 )
00319 );
00320
00321 Info<< "mesh size: " << meshSource.nCells() << endl;
00322
00323 if (consistent)
00324 {
00325 mapConsistentSubMesh(meshSource, meshTarget);
00326 }
00327 else
00328 {
00329 mapSubMesh(meshSource, meshTarget, patchMap, cuttingPatches);
00330 }
00331 }
00332 }
00333 else if (!parallelSource && parallelTarget)
00334 {
00335 IOdictionary decompositionDict
00336 (
00337 IOobject
00338 (
00339 "decomposeParDict",
00340 runTimeTarget.system(),
00341 runTimeTarget,
00342 IOobject::MUST_READ,
00343 IOobject::NO_WRITE
00344 )
00345 );
00346
00347 int nProcs(readInt(decompositionDict.lookup("numberOfSubdomains")));
00348
00349 Info<< "Create source mesh\n" << endl;
00350
00351 fvMesh meshSource
00352 (
00353 IOobject
00354 (
00355 fvMesh::defaultRegion,
00356 runTimeSource.timeName(),
00357 runTimeSource
00358 )
00359 );
00360
00361 Info<< "Source mesh size: " << meshSource.nCells() << endl;
00362
00363 for (int procI=0; procI<nProcs; procI++)
00364 {
00365 Info<< nl << "Target processor " << procI << endl;
00366
00367 Time runTimeTarget
00368 (
00369 Time::controlDictName,
00370 rootDirTarget,
00371 caseDirTarget/fileName(word("processor") + name(procI))
00372 );
00373
00374 fvMesh meshTarget
00375 (
00376 IOobject
00377 (
00378 fvMesh::defaultRegion,
00379 runTimeTarget.timeName(),
00380 runTimeTarget
00381 )
00382 );
00383
00384 Info<< "mesh size: " << meshTarget.nCells() << endl;
00385
00386 if (consistent)
00387 {
00388 mapConsistentSubMesh(meshSource, meshTarget);
00389 }
00390 else
00391 {
00392 mapSubMesh
00393 (
00394 meshSource,
00395 meshTarget,
00396 patchMap,
00397 addProcessorPatches(meshTarget, cuttingPatches)
00398 );
00399 }
00400 }
00401 }
00402 else if (parallelSource && parallelTarget)
00403 {
00404 IOdictionary decompositionDictSource
00405 (
00406 IOobject
00407 (
00408 "decomposeParDict",
00409 runTimeSource.system(),
00410 runTimeSource,
00411 IOobject::MUST_READ,
00412 IOobject::NO_WRITE
00413 )
00414 );
00415
00416 int nProcsSource
00417 (
00418 readInt(decompositionDictSource.lookup("numberOfSubdomains"))
00419 );
00420
00421
00422 IOdictionary decompositionDictTarget
00423 (
00424 IOobject
00425 (
00426 "decomposeParDict",
00427 runTimeTarget.system(),
00428 runTimeTarget,
00429 IOobject::MUST_READ,
00430 IOobject::NO_WRITE
00431 )
00432 );
00433
00434 int nProcsTarget
00435 (
00436 readInt(decompositionDictTarget.lookup("numberOfSubdomains"))
00437 );
00438
00439 List<boundBox> bbsTarget(nProcsTarget);
00440 List<bool> bbsTargetSet(nProcsTarget, false);
00441
00442 for (int procISource=0; procISource<nProcsSource; procISource++)
00443 {
00444 Info<< nl << "Source processor " << procISource << endl;
00445
00446 Time runTimeSource
00447 (
00448 Time::controlDictName,
00449 rootDirSource,
00450 caseDirSource/fileName(word("processor") + name(procISource))
00451 );
00452
00453 runTimeSource.setTime
00454 (
00455 sourceTimes[sourceTimeIndex],
00456 sourceTimeIndex
00457 );
00458
00459 fvMesh meshSource
00460 (
00461 IOobject
00462 (
00463 fvMesh::defaultRegion,
00464 runTimeSource.timeName(),
00465 runTimeSource
00466 )
00467 );
00468
00469 Info<< "mesh size: " << meshSource.nCells() << endl;
00470
00471 boundBox bbSource(meshSource.bounds());
00472
00473 for (int procITarget=0; procITarget<nProcsTarget; procITarget++)
00474 {
00475 if
00476 (
00477 !bbsTargetSet[procITarget]
00478 || (
00479 bbsTargetSet[procITarget]
00480 && bbsTarget[procITarget].overlaps(bbSource)
00481 )
00482 )
00483 {
00484 Info<< nl << "Target processor " << procITarget << endl;
00485
00486 Time runTimeTarget
00487 (
00488 Time::controlDictName,
00489 rootDirTarget,
00490 caseDirTarget/fileName(word("processor")
00491 + name(procITarget))
00492 );
00493
00494 fvMesh meshTarget
00495 (
00496 IOobject
00497 (
00498 fvMesh::defaultRegion,
00499 runTimeTarget.timeName(),
00500 runTimeTarget
00501 )
00502 );
00503
00504 Info<< "mesh size: " << meshTarget.nCells() << endl;
00505
00506 bbsTarget[procITarget] = meshTarget.bounds();
00507 bbsTargetSet[procITarget] = true;
00508
00509 if (bbsTarget[procITarget].overlaps(bbSource))
00510 {
00511 if (consistent)
00512 {
00513 mapConsistentSubMesh(meshSource, meshTarget);
00514 }
00515 else
00516 {
00517 mapSubMesh
00518 (
00519 meshSource,
00520 meshTarget,
00521 patchMap,
00522 addProcessorPatches(meshTarget, cuttingPatches)
00523 );
00524 }
00525 }
00526 }
00527 }
00528 }
00529 }
00530 else
00531 {
00532 Info<< "Create meshes\n" << endl;
00533
00534 fvMesh meshSource
00535 (
00536 IOobject
00537 (
00538 fvMesh::defaultRegion,
00539 runTimeSource.timeName(),
00540 runTimeSource
00541 )
00542 );
00543
00544 fvMesh meshTarget
00545 (
00546 IOobject
00547 (
00548 fvMesh::defaultRegion,
00549 runTimeTarget.timeName(),
00550 runTimeTarget
00551 )
00552 );
00553
00554 Info<< "Source mesh size: " << meshSource.nCells() << tab
00555 << "Target mesh size: " << meshTarget.nCells() << nl << endl;
00556
00557 if (consistent)
00558 {
00559 mapConsistentMesh(meshSource, meshTarget);
00560 }
00561 else
00562 {
00563 mapSubMesh(meshSource, meshTarget, patchMap, cuttingPatches);
00564 }
00565 }
00566
00567 Info<< "\nEnd\n" << endl;
00568
00569 return 0;
00570 }
00571
00572
00573