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 #include "volFields.H"
00029 #include "surfaceFields.H"
00030 #include "emptyFvPatchField.H"
00031
00032
00033
00034 template<class Type>
00035 void Foam::fvMeshAdder::map
00036 (
00037 const Field<Type>& oldFld,
00038 const labelList& oldToNew,
00039 Field<Type>& fld
00040 )
00041 {
00042 forAll(oldFld, cellI)
00043 {
00044 label newCellI = oldToNew[cellI];
00045
00046 if (newCellI >= 0 && newCellI < fld.size())
00047 {
00048 fld[newCellI] = oldFld[cellI];
00049 }
00050 }
00051 }
00052
00053
00054 template<class Type>
00055 void Foam::fvMeshAdder::MapVolField
00056 (
00057 const mapAddedPolyMesh& meshMap,
00058
00059 GeometricField<Type, fvPatchField, volMesh>& fld,
00060 const GeometricField<Type, fvPatchField, volMesh>& fldToAdd
00061 )
00062 {
00063 const fvMesh& mesh = fld.mesh();
00064
00065
00066
00067
00068 {
00069
00070 Field<Type> oldInternalField(fld.internalField());
00071
00072
00073 Field<Type>& intFld = fld.internalField();
00074
00075 intFld.setSize(mesh.nCells());
00076
00077 map(oldInternalField, meshMap.oldCellMap(), intFld);
00078 map(fldToAdd.internalField(), meshMap.addedCellMap(), intFld);
00079 }
00080
00081
00082
00083
00084
00085 {
00086 const labelList& oldPatchMap = meshMap.oldPatchMap();
00087 const labelList& oldPatchStarts = meshMap.oldPatchStarts();
00088 const labelList& oldPatchSizes = meshMap.oldPatchSizes();
00089
00090
00091
00092 label unusedPatchI = 0;
00093
00094 forAll(oldPatchMap, patchI)
00095 {
00096 label newPatchI = oldPatchMap[patchI];
00097
00098 if (newPatchI != -1)
00099 {
00100 unusedPatchI++;
00101 }
00102 }
00103
00104 label nUsedPatches = unusedPatchI;
00105
00106
00107 labelList oldToNew(oldPatchMap.size());
00108
00109 forAll(oldPatchMap, patchI)
00110 {
00111 label newPatchI = oldPatchMap[patchI];
00112
00113 if (newPatchI != -1)
00114 {
00115 oldToNew[patchI] = newPatchI;
00116 }
00117 else
00118 {
00119 oldToNew[patchI] = unusedPatchI++;
00120 }
00121 }
00122
00123
00124
00125 fld.boundaryField().reorder(oldToNew);
00126
00127 fld.boundaryField().setSize(mesh.boundaryMesh().size());
00128
00129 for
00130 (
00131 label newPatchI = nUsedPatches;
00132 newPatchI < fld.boundaryField().size();
00133 newPatchI++
00134 )
00135 {
00136 fld.boundaryField().set(newPatchI, NULL);
00137 }
00138
00139
00140
00141
00142
00143 forAll(oldPatchMap, patchI)
00144 {
00145 label newPatchI = oldPatchMap[patchI];
00146
00147 if (newPatchI != -1)
00148 {
00149 labelList newToOld
00150 (
00151 calcPatchMap
00152 (
00153 oldPatchStarts[patchI],
00154 oldPatchSizes[patchI],
00155 meshMap.oldFaceMap(),
00156 mesh.boundaryMesh()[newPatchI],
00157 0
00158 )
00159 );
00160
00161 directFvPatchFieldMapper patchMapper(newToOld);
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 fld.boundaryField().set
00172 (
00173 newPatchI,
00174 fvPatchField<Type>::New
00175 (
00176 fld.boundaryField()[newPatchI],
00177 mesh.boundary()[newPatchI],
00178 fld.dimensionedInternalField(),
00179 patchMapper
00180 )
00181 );
00182 }
00183 }
00184 }
00185
00186
00187
00188
00189
00190
00191 {
00192 const labelList& addedPatchMap = meshMap.addedPatchMap();
00193
00194
00195 forAll(addedPatchMap, patchI)
00196 {
00197 label newPatchI = addedPatchMap[patchI];
00198
00199 if (newPatchI != -1)
00200 {
00201 const polyPatch& newPatch = mesh.boundaryMesh()[newPatchI];
00202 const polyPatch& oldPatch =
00203 fldToAdd.mesh().boundaryMesh()[patchI];
00204
00205 if (!fld.boundaryField()(newPatchI))
00206 {
00207
00208
00209
00210
00211 labelList newToAdded
00212 (
00213 calcPatchMap
00214 (
00215 oldPatch.start(),
00216 oldPatch.size(),
00217 meshMap.addedFaceMap(),
00218 newPatch,
00219 0
00220 )
00221 );
00222
00223 directFvPatchFieldMapper patchMapper(newToAdded);
00224
00225 fld.boundaryField().set
00226 (
00227 newPatchI,
00228 fvPatchField<Type>::New
00229 (
00230 fldToAdd.boundaryField()[patchI],
00231 mesh.boundary()[newPatchI],
00232 fld.dimensionedInternalField(),
00233 patchMapper
00234 )
00235 );
00236 }
00237 else
00238 {
00239
00240
00241
00242
00243
00244 labelList newToAdded
00245 (
00246 calcPatchMap
00247 (
00248 oldPatch.start(),
00249 oldPatch.size(),
00250 meshMap.addedFaceMap(),
00251 newPatch,
00252 -1
00253 )
00254 );
00255
00256 const fvPatchField<Type>& addedFld =
00257 fldToAdd.boundaryField()[patchI];
00258
00259 fvPatchField<Type>& newFld = fld.boundaryField()[newPatchI];
00260
00261 forAll(newFld, i)
00262 {
00263 label oldFaceI = newToAdded[i];
00264
00265 if (oldFaceI >= 0 && oldFaceI < addedFld.size())
00266 {
00267 newFld[i] = addedFld[oldFaceI];
00268 }
00269 }
00270 }
00271 }
00272 }
00273 }
00274 }
00275
00276
00277 template<class Type>
00278 void Foam::fvMeshAdder::MapVolFields
00279 (
00280 const mapAddedPolyMesh& meshMap,
00281 const fvMesh& mesh,
00282 const fvMesh& meshToAdd
00283 )
00284 {
00285 HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fields
00286 (
00287 mesh.objectRegistry::lookupClass
00288 <GeometricField<Type, fvPatchField, volMesh> >
00289 ()
00290 );
00291
00292 HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fieldsToAdd
00293 (
00294 meshToAdd.objectRegistry::lookupClass
00295 <GeometricField<Type, fvPatchField, volMesh> >
00296 ()
00297 );
00298
00299
00300
00301
00302
00303
00304 for
00305 (
00306 typename HashTable<const GeometricField<Type, fvPatchField, volMesh>*>::
00307 iterator fieldIter = fields.begin();
00308 fieldIter != fields.end();
00309 ++fieldIter
00310 )
00311 {
00312 const_cast<GeometricField<Type, fvPatchField, volMesh>*>(fieldIter())
00313 ->storeOldTimes();
00314 }
00315
00316
00317 for
00318 (
00319 typename HashTable<const GeometricField<Type, fvPatchField, volMesh>*>::
00320 iterator fieldIter = fields.begin();
00321 fieldIter != fields.end();
00322 ++fieldIter
00323 )
00324 {
00325 GeometricField<Type, fvPatchField, volMesh>& fld =
00326 const_cast<GeometricField<Type, fvPatchField, volMesh>&>
00327 (
00328 *fieldIter()
00329 );
00330
00331 if (fieldsToAdd.found(fld.name()))
00332 {
00333 Pout<< "Mapping field " << fld.name() << endl;
00334
00335 const GeometricField<Type, fvPatchField, volMesh>& fldToAdd =
00336 *fieldsToAdd[fld.name()];
00337
00338 MapVolField<Type>(meshMap, fld, fldToAdd);
00339 }
00340 else
00341 {
00342 WarningIn("fvMeshAdder::MapVolFields")
00343 << "Not mapping field " << fld.name()
00344 << " since not present on mesh to add"
00345 << endl;
00346 }
00347 }
00348 }
00349
00350
00351 template<class Type>
00352 void Foam::fvMeshAdder::MapSurfaceField
00353 (
00354 const mapAddedPolyMesh& meshMap,
00355
00356 GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
00357 const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd
00358 )
00359 {
00360 const fvMesh& mesh = fld.mesh();
00361 const labelList& oldPatchStarts = meshMap.oldPatchStarts();
00362
00363
00364
00365
00366
00367 {
00368 Field<Type> oldField(fld);
00369
00370
00371 Field<Type>& intFld = fld.internalField();
00372
00373 intFld.setSize(mesh.nInternalFaces());
00374
00375 map(oldField, meshMap.oldFaceMap(), intFld);
00376 map(fldToAdd, meshMap.addedFaceMap(), intFld);
00377
00378
00379
00380
00381 forAll(fld.boundaryField(), patchI)
00382 {
00383 const fvsPatchField<Type>& pf = fld.boundaryField()[patchI];
00384
00385 label start = oldPatchStarts[patchI];
00386
00387 forAll(pf, i)
00388 {
00389 label newFaceI = meshMap.oldFaceMap()[start + i];
00390
00391 if (newFaceI >= 0 && newFaceI < mesh.nInternalFaces())
00392 {
00393 intFld[newFaceI] = pf[i];
00394 }
00395 }
00396 }
00397 }
00398
00399
00400
00401
00402
00403 {
00404 const labelList& oldPatchMap = meshMap.oldPatchMap();
00405 const labelList& oldPatchSizes = meshMap.oldPatchSizes();
00406
00407
00408
00409 label unusedPatchI = 0;
00410
00411 forAll(oldPatchMap, patchI)
00412 {
00413 label newPatchI = oldPatchMap[patchI];
00414
00415 if (newPatchI != -1)
00416 {
00417 unusedPatchI++;
00418 }
00419 }
00420
00421 label nUsedPatches = unusedPatchI;
00422
00423
00424 labelList oldToNew(oldPatchMap.size());
00425
00426 forAll(oldPatchMap, patchI)
00427 {
00428 label newPatchI = oldPatchMap[patchI];
00429
00430 if (newPatchI != -1)
00431 {
00432 oldToNew[patchI] = newPatchI;
00433 }
00434 else
00435 {
00436 oldToNew[patchI] = unusedPatchI++;
00437 }
00438 }
00439
00440
00441
00442 fld.boundaryField().reorder(oldToNew);
00443
00444 fld.boundaryField().setSize(mesh.boundaryMesh().size());
00445
00446 for
00447 (
00448 label newPatchI = nUsedPatches;
00449 newPatchI < fld.boundaryField().size();
00450 newPatchI++
00451 )
00452 {
00453 fld.boundaryField().set(newPatchI, NULL);
00454 }
00455
00456
00457
00458
00459
00460 forAll(oldPatchMap, patchI)
00461 {
00462 label newPatchI = oldPatchMap[patchI];
00463
00464 if (newPatchI != -1)
00465 {
00466 labelList newToOld
00467 (
00468 calcPatchMap
00469 (
00470 oldPatchStarts[patchI],
00471 oldPatchSizes[patchI],
00472 meshMap.oldFaceMap(),
00473 mesh.boundaryMesh()[newPatchI],
00474 0
00475 )
00476 );
00477
00478 directFvPatchFieldMapper patchMapper(newToOld);
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 fld.boundaryField().set
00489 (
00490 newPatchI,
00491 fvsPatchField<Type>::New
00492 (
00493 fld.boundaryField()[newPatchI],
00494 mesh.boundary()[newPatchI],
00495 fld.dimensionedInternalField(),
00496 patchMapper
00497 )
00498 );
00499 }
00500 }
00501 }
00502
00503
00504
00505
00506
00507
00508 {
00509 const labelList& addedPatchMap = meshMap.addedPatchMap();
00510
00511
00512 forAll(addedPatchMap, patchI)
00513 {
00514 label newPatchI = addedPatchMap[patchI];
00515
00516 if (newPatchI != -1)
00517 {
00518 const polyPatch& newPatch = mesh.boundaryMesh()[newPatchI];
00519 const polyPatch& oldPatch =
00520 fldToAdd.mesh().boundaryMesh()[patchI];
00521
00522 if (!fld.boundaryField()(newPatchI))
00523 {
00524
00525
00526
00527
00528 labelList newToAdded
00529 (
00530 calcPatchMap
00531 (
00532 oldPatch.start(),
00533 oldPatch.size(),
00534 meshMap.addedFaceMap(),
00535 newPatch,
00536 0
00537 )
00538 );
00539
00540 directFvPatchFieldMapper patchMapper(newToAdded);
00541
00542 fld.boundaryField().set
00543 (
00544 newPatchI,
00545 fvsPatchField<Type>::New
00546 (
00547 fldToAdd.boundaryField()[patchI],
00548 mesh.boundary()[newPatchI],
00549 fld.dimensionedInternalField(),
00550 patchMapper
00551 )
00552 );
00553 }
00554 else
00555 {
00556
00557
00558
00559
00560
00561 labelList newToAdded
00562 (
00563 calcPatchMap
00564 (
00565 oldPatch.start(),
00566 oldPatch.size(),
00567 meshMap.addedFaceMap(),
00568 newPatch,
00569 -1
00570 )
00571 );
00572
00573 const fvsPatchField<Type>& addedFld =
00574 fldToAdd.boundaryField()[patchI];
00575
00576 fvsPatchField<Type>& newFld =
00577 fld.boundaryField()[newPatchI];
00578
00579 forAll(newFld, i)
00580 {
00581 label oldFaceI = newToAdded[i];
00582
00583 if (oldFaceI >= 0 && oldFaceI < addedFld.size())
00584 {
00585 newFld[i] = addedFld[oldFaceI];
00586 }
00587 }
00588 }
00589 }
00590 }
00591 }
00592 }
00593
00594
00595 template<class Type>
00596 void Foam::fvMeshAdder::MapSurfaceFields
00597 (
00598 const mapAddedPolyMesh& meshMap,
00599 const fvMesh& mesh,
00600 const fvMesh& meshToAdd
00601 )
00602 {
00603 typedef GeometricField<Type, fvsPatchField, surfaceMesh> fldType;
00604
00605 HashTable<const fldType*> fields
00606 (
00607 mesh.objectRegistry::lookupClass<fldType>()
00608 );
00609
00610 HashTable<const fldType*> fieldsToAdd
00611 (
00612 meshToAdd.objectRegistry::lookupClass<fldType>()
00613 );
00614
00615
00616
00617
00618
00619
00620 for
00621 (
00622 typename HashTable<const fldType*>::
00623 iterator fieldIter = fields.begin();
00624 fieldIter != fields.end();
00625 ++fieldIter
00626 )
00627 {
00628 const_cast<fldType*>(fieldIter())
00629 ->storeOldTimes();
00630 }
00631
00632
00633 for
00634 (
00635 typename HashTable<const fldType*>::
00636 iterator fieldIter = fields.begin();
00637 fieldIter != fields.end();
00638 ++fieldIter
00639 )
00640 {
00641 fldType& fld = const_cast<fldType&>(*fieldIter());
00642
00643 if (fieldsToAdd.found(fld.name()))
00644 {
00645 Pout<< "Mapping field " << fld.name() << endl;
00646
00647 const fldType& fldToAdd = *fieldsToAdd[fld.name()];
00648
00649 MapSurfaceField<Type>(meshMap, fld, fldToAdd);
00650 }
00651 else
00652 {
00653 WarningIn("fvMeshAdder::MapSurfaceFields")
00654 << "Not mapping field " << fld.name()
00655 << " since not present on mesh to add"
00656 << endl;
00657 }
00658 }
00659 }
00660
00661
00662