37 void Foam::fvMeshAdder::MapVolField
39 const mapAddedPolyMesh& meshMap,
41 GeometricField<Type, fvPatchField, volMesh>&
fld,
42 const GeometricField<Type, fvPatchField, volMesh>& fldToAdd,
43 const bool fullyMapped
46 const fvMesh&
mesh =
fld.mesh();
53 const Field<Type> oldInternalField(
fld.primitiveField());
56 Field<Type>& intFld =
fld.primitiveFieldRef();
58 intFld.setSize(
mesh.nCells());
60 intFld.rmap(oldInternalField, meshMap.oldCellMap());
61 intFld.rmap(fldToAdd.primitiveField(), meshMap.addedCellMap());
68 auto& bfld =
fld.boundaryFieldRef();
71 const labelList& oldPatchMap = meshMap.oldPatchMap();
72 const labelList& oldPatchStarts = meshMap.oldPatchStarts();
73 const labelList& oldPatchSizes = meshMap.oldPatchSizes();
77 label unusedPatchi = 0;
79 forAll(oldPatchMap, patchi)
81 label newPatchi = oldPatchMap[patchi];
89 label nUsedPatches = unusedPatchi;
94 forAll(oldPatchMap, patchi)
96 const label newPatchi = oldPatchMap[patchi];
100 oldToNew[patchi] = newPatchi;
104 oldToNew[patchi] = unusedPatchi++;
110 bfld.reorder(oldToNew);
112 bfld.setSize(
mesh.boundaryMesh().size());
116 label newPatchi = nUsedPatches;
117 newPatchi < bfld.size();
121 bfld.set(newPatchi,
nullptr);
128 forAll(oldPatchMap, patchi)
130 const label newPatchi = oldPatchMap[patchi];
138 oldPatchStarts[patchi],
139 oldPatchSizes[patchi],
140 meshMap.oldFaceMap(),
141 mesh.boundaryMesh()[newPatchi],
152 patchMapper.hasUnmapped() =
false;
168 mesh.boundary()[newPatchi],
183 const labelList& addedPatchMap = meshMap.addedPatchMap();
186 forAll(addedPatchMap, patchi)
188 const label newPatchi = addedPatchMap[patchi];
192 const polyPatch& newPatch =
mesh.boundaryMesh()[newPatchi];
193 const polyPatch& oldPatch =
194 fldToAdd.mesh().boundaryMesh()[patchi];
196 if (!bfld.set(newPatchi))
208 meshMap.addedFaceMap(),
220 patchMapper.hasUnmapped() =
false;
228 fldToAdd.boundaryField()[patchi],
229 mesh.boundary()[newPatchi],
240 labelList addedToNew(oldPatch.size(), -1);
243 label addedFacei = oldPatch.start()+i;
244 label newFacei = meshMap.addedFaceMap()[addedFacei];
245 label patchFacei = newFacei-newPatch.start();
246 if (patchFacei >= 0 && patchFacei < newPatch.size())
248 addedToNew[i] = patchFacei;
254 fldToAdd.boundaryField()[patchi],
267 const mapAddedPolyMesh& meshMap,
269 const fvMesh& meshToAdd,
270 const bool fullyMapped
273 typedef GeometricField<Type, fvPatchField, volMesh> fldType;
275 HashTable<const fldType*>
fields 277 mesh.objectRegistry::lookupClass<fldType>()
280 HashTable<const fldType*> fieldsToAdd
282 meshToAdd.objectRegistry::lookupClass<fldType>()
292 fldType&
fld =
const_cast<fldType&
>(*fieldIter());
295 <<
"MapVolFields : Storing old time for " <<
fld.name() <<
endl;
303 fldType&
fld =
const_cast<fldType&
>(*fieldIter());
305 if (fieldsToAdd.found(
fld.name()))
307 const fldType& fldToAdd = *fieldsToAdd[
fld.name()];
310 <<
"MapVolFields : mapping " <<
fld.name()
311 <<
" and " << fldToAdd.name() <<
endl;
313 MapVolField<Type>(meshMap,
fld, fldToAdd, fullyMapped);
318 <<
"Not mapping field " <<
fld.name()
319 <<
" since not present on mesh to add" <<
endl;
326 void Foam::fvMeshAdder::MapSurfaceField
328 const mapAddedPolyMesh& meshMap,
330 GeometricField<Type, fvsPatchField, surfaceMesh>&
fld,
331 const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd,
332 const bool fullyMapped
335 const fvMesh&
mesh =
fld.mesh();
336 const labelList& oldPatchStarts = meshMap.oldPatchStarts();
338 auto& bfld =
fld.boundaryFieldRef();
345 const Field<Type> oldField(
fld);
348 Field<Type>& intFld =
fld.primitiveFieldRef();
352 intFld.rmap(oldField, meshMap.oldFaceMap());
353 intFld.rmap(fldToAdd, meshMap.addedFaceMap());
361 const fvsPatchField<Type>& pf = bfld[patchi];
363 label start = oldPatchStarts[patchi];
367 label newFacei = meshMap.oldFaceMap()[start + i];
371 intFld[newFacei] = pf[i];
382 const labelList& oldPatchMap = meshMap.oldPatchMap();
383 const labelList& oldPatchSizes = meshMap.oldPatchSizes();
387 label unusedPatchi = 0;
389 forAll(oldPatchMap, patchi)
391 const label newPatchi = oldPatchMap[patchi];
399 label nUsedPatches = unusedPatchi;
404 forAll(oldPatchMap, patchi)
406 const label newPatchi = oldPatchMap[patchi];
410 oldToNew[patchi] = newPatchi;
414 oldToNew[patchi] = unusedPatchi++;
420 bfld.reorder(oldToNew);
426 label newPatchi = nUsedPatches;
427 newPatchi < bfld.size();
431 bfld.set(newPatchi,
nullptr);
438 forAll(oldPatchMap, patchi)
440 const label newPatchi = oldPatchMap[patchi];
448 oldPatchStarts[patchi],
449 oldPatchSizes[patchi],
450 meshMap.oldFaceMap(),
462 patchMapper.hasUnmapped() =
false;
493 const labelList& addedPatchMap = meshMap.addedPatchMap();
496 forAll(addedPatchMap, patchi)
498 const label newPatchi = addedPatchMap[patchi];
503 const polyPatch& oldPatch =
506 if (!bfld.set(newPatchi))
518 meshMap.addedFaceMap(),
530 patchMapper.hasUnmapped() =
false;
538 fldToAdd.boundaryField()[patchi],
550 labelList addedToNew(oldPatch.size(), -1);
553 label addedFacei = oldPatch.start()+i;
554 label newFacei = meshMap.addedFaceMap()[addedFacei];
555 label patchFacei = newFacei-newPatch.start();
556 if (patchFacei >= 0 && patchFacei < newPatch.size())
558 addedToNew[i] = patchFacei;
564 fldToAdd.boundaryField()[patchi],
577 const mapAddedPolyMesh& meshMap,
579 const fvMesh& meshToAdd,
580 const bool fullyMapped
583 typedef GeometricField<Type, fvsPatchField, surfaceMesh> fldType;
585 HashTable<const fldType*>
fields 587 mesh.objectRegistry::lookupClass<fldType>()
590 HashTable<const fldType*> fieldsToAdd
592 meshToAdd.objectRegistry::lookupClass<fldType>()
602 fldType&
fld =
const_cast<fldType&
>(*fieldIter());
605 <<
"MapSurfaceFields : Storing old time for " <<
fld.name() <<
endl;
613 fldType&
fld =
const_cast<fldType&
>(*fieldIter());
615 if (fieldsToAdd.found(
fld.name()))
617 const fldType& fldToAdd = *fieldsToAdd[
fld.name()];
620 <<
"MapSurfaceFields : mapping " <<
fld.name()
621 <<
" and " << fldToAdd.name() <<
endl;
623 MapSurfaceField<Type>(meshMap,
fld, fldToAdd, fullyMapped);
628 <<
"Not mapping field " <<
fld.name()
629 <<
" since not present on mesh to add" <<
endl;
636 void Foam::fvMeshAdder::MapDimField
638 const mapAddedPolyMesh& meshMap,
640 DimensionedField<Type, volMesh>&
fld,
641 const DimensionedField<Type, volMesh>& fldToAdd
644 const fvMesh&
mesh =
fld.mesh();
647 const Field<Type> oldField(
fld);
651 fld.rmap(oldField, meshMap.oldCellMap());
652 fld.rmap(fldToAdd, meshMap.addedCellMap());
670 mesh.objectRegistry::lookupClass<fldType>(
true)
675 meshToAdd.objectRegistry::lookupClass<fldType>(
true)
680 fldType&
fld =
const_cast<fldType&
>(*fieldIter());
684 const fldType& fldToAdd = *fieldsToAdd[
fld.name()];
687 <<
"MapDimFields : mapping " <<
fld.name()
688 <<
" and " << fldToAdd.name() <<
endl;
690 MapDimField<Type>(meshMap,
fld, fldToAdd);
695 <<
"Not mapping field " <<
fld.name()
696 <<
" since not present on mesh to add" <<
endl;
705 void Foam::fvMeshAdder::MapDimField
709 const bool fullyMapped
719 || cellProcAddressing.
size() != flds.size()
740 intFld.
rmap(oldInternalField, cellProcAddressing[0]);
742 for (label meshi = 1; meshi < flds.size(); meshi++)
747 intFld.
rmap(addFld, cellProcAddressing[meshi]);
755 void Foam::fvMeshAdder::MapVolField
763 const bool fullyMapped
769 if (flds.size() == 0 || !flds.set(0))
781 const Field<Type> oldInternalField(flds[0].primitiveField());
784 Field<Type>& intFld = flds[0].primitiveFieldRef();
787 intFld.setSize(flds[0].
mesh().nCells());
789 intFld.rmap(oldInternalField, cellProcAddressing[0]);
791 for (label meshi = 1; meshi < flds.size(); meshi++)
795 const Field<Type>& addFld = flds[meshi].primitiveFieldRef();
796 intFld.rmap(addFld, cellProcAddressing[meshi]);
805 auto& bfld0 = flds[0].boundaryFieldRef();
820 oldPatchStarts0[patchi],
821 oldPatchSizes0[patchi],
822 faceProcAddressing[0],
834 patchMapper.hasUnmapped() =
false;
837 bfld0[patchi].autoMap(patchMapper);
840 for (label meshi = 1; meshi < flds.size(); meshi++)
844 const auto& bfld = flds[meshi].boundaryFieldRef();
846 const labelList& patchMap = patchProcAddressing[meshi];
848 forAll(patchMap, oldPatchi)
850 const auto& fvp = bfld[oldPatchi].patch();
851 const label newPatchi = patchMap[oldPatchi];
856 if (newPatchi >= 0 && newPatchi < bfld0.size())
858 const auto& fvp0 = bfld0[newPatchi].patch();
859 labelList addedToNew(bfld[oldPatchi].size(), -1);
862 const label newFacei =
863 faceProcAddressing[meshi][fvp.start()+i];
864 const label patchFacei = newFacei-fvp0.start();
868 && patchFacei < fvp0.size()
871 addedToNew[i] = patchFacei;
875 bfld0[newPatchi].rmap(bfld[oldPatchi], addedToNew);
880 << bfld[oldPatchi].patch().name() <<
" on field " 881 << flds[meshi].name() <<
endl;
890 void Foam::fvMeshAdder::MapSurfaceField
899 const bool fullyMapped
905 if (flds.size() == 0 || !flds.set(0))
911 const fvMesh& mesh0 = flds[0].mesh();
919 const Field<Type> oldInternalField(flds[0].primitiveField());
922 Field<Type>& intFld = flds[0].primitiveFieldRef();
925 intFld.setSize(mesh0.nInternalFaces());
933 const auto&
fld = flds[meshi];
938 intFld.rmap(oldInternalField,
faceMap);
948 const auto& bfld = flds[meshi].boundaryField();
952 const fvsPatchField<Type>& pf = bfld[oldPatchi];
963 const label oldFacei =
964 oldPatchStarts0[oldPatchi]+patchFacei;
965 newFacei = faceProcAddressing[meshi][oldFacei];
966 const label oldOwn = oldFaceOwner0[oldFacei];
967 newOwn = cellProcAddressing[meshi][oldOwn];
978 const label oldFacei =
979 pf.patch().start()+patchFacei;
980 newFacei = faceProcAddressing[meshi][oldFacei];
982 fld.mesh().faceOwner()[oldFacei];
983 newOwn = cellProcAddressing[meshi][oldOwn];
996 && newFacei < mesh0.nInternalFaces()
997 && (newOwn == mesh0.faceOwner()[newFacei])
1000 intFld[newFacei] = pf[patchFacei];
1021 auto& bfld0 = flds[0].boundaryFieldRef();
1028 oldPatchStarts0[patchi],
1029 oldPatchSizes0[patchi],
1030 faceProcAddressing[0],
1042 patchMapper.hasUnmapped() =
false;
1045 bfld0[patchi].autoMap(patchMapper);
1048 for (label meshi = 1; meshi < flds.size(); meshi++)
1050 if (flds.set(meshi))
1052 const auto& bfld = flds[meshi].boundaryFieldRef();
1054 const labelList& patchMap = patchProcAddressing[meshi];
1056 forAll(patchMap, oldPatchi)
1058 const auto& fvp = bfld[oldPatchi].patch();
1059 const label newPatchi = patchMap[oldPatchi];
1060 if (newPatchi >= 0 && newPatchi < bfld0.size())
1062 const auto& fvp0 = bfld0[newPatchi].patch();
1063 labelList addedToNew(bfld[oldPatchi].size(), -1);
1066 const label newFacei =
1067 faceProcAddressing[meshi][fvp.start()+i];
1068 const label patchFacei = newFacei-fvp0.start();
1072 && patchFacei < fvp0.size()
1075 addedToNew[i] = patchFacei;
1079 bfld0[newPatchi].rmap(bfld[oldPatchi], addedToNew);
1084 << bfld[oldPatchi].patch().name() <<
" on field " 1085 << flds[meshi].name() <<
endl;
1093 template<
class Type>
1103 const bool fullyMapped
1113 const fvMesh& mesh0 =
meshes[0];
1115 HashTable<const fldType*>
fields 1117 mesh0.objectRegistry::lookupClass<fldType>()
1129 <<
"MapVolFields : Storing old time for " <<
fld->name()
1132 const_cast<fldType&
>(*fld).storeOldTimes();
1138 const word& name0 =
fld->name();
1141 <<
"MapVolFields : mapping " << name0 <<
endl;
1143 UPtrList<fldType> meshToField(
meshes.
size());
1148 auto& meshFld =
meshes[meshi].
1149 objectRegistry::lookupObjectRef<fldType>(name0);
1150 meshToField.
set(meshi, &meshFld);
1159 patchProcAddressing,
1168 template<
class Type>
1173 const bool fullyMapped
1184 const fvMesh& mesh0 =
meshes[0];
1186 HashTable<const fldType*>
fields 1188 mesh0.objectRegistry::lookupClass<fldType>()
1194 if (!isA<excludeType>(*
fld))
1196 const word& name0 =
fld->name();
1199 <<
"MapDimFields : mapping " << name0 <<
endl;
1201 UPtrList<fldType> meshToField(
meshes.
size());
1206 auto& meshFld =
meshes[meshi].
1207 objectRegistry::lookupObjectRef<fldType>(name0);
1208 meshToField.
set(meshi, &meshFld);
1212 MapDimField(meshToField, cellProcAddressing, fullyMapped);
1217 <<
"MapDimFields : ignoring " <<
fld->name() <<
endl;
1223 template<
class Type>
1234 const bool fullyMapped
1244 const auto& mesh0 =
meshes[0];
1246 HashTable<const fldType*>
fields 1248 mesh0.objectRegistry::lookupClass<fldType>()
1260 <<
"MapSurfaceFields : Storing old time for " <<
fld->name()
1263 const_cast<fldType&
>(*fld).storeOldTimes();
1269 const word& name0 =
fld->name();
1272 <<
"MapSurfaceFields : Mapping " <<
fld->name() <<
endl;
1274 UPtrList<fldType> meshToField(
meshes.
size());
1279 auto& meshFld =
meshes[meshi].
1280 objectRegistry::lookupObjectRef<fldType>(name0);
1281 meshToField.
set(meshi, &meshFld);
1291 patchProcAddressing,
void size(const label n)
Older name for setAddressableSize.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool found(const Key &key) const
Same as contains()
Ostream & endl(Ostream &os)
Add newline and flush stream.
Class containing mesh-to-mesh mapping information after a mesh addition where we add a mesh ('added m...
Generic GeometricField class.
DirectFieldMapper< fvPatchFieldMapper > directFvPatchFieldMapper
A fvPatchFieldMapper with direct mapping.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
#define forAll(list, i)
Loop across all elements in list.
void setSize(const label n)
Alias for resize()
const polyMesh & mesh() const noexcept
Return the mesh reference.
Generic templated field type.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
label size() const noexcept
The number of entries in the list.
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
#define forAllIters(container, iter)
Iterate across all elements in the container object.
label nInternalFaces() const noexcept
Number of internal faces.
A HashTable similar to std::unordered_map.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static void MapVolFields(const mapAddedPolyMesh &, const fvMesh &mesh, const fvMesh &meshToAdd, const bool fullyMapped=false)
Map all volFields of Type.
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
static void MapSurfaceFields(const mapAddedPolyMesh &, const fvMesh &mesh, const fvMesh &meshToAdd, const bool fullyMapped=false)
Map all surfaceFields of Type.
#define WarningInFunction
Report a warning using Foam::Warning.
label nCells() const noexcept
Number of mesh cells.
Mesh data needed to do the Finite Volume discretisation.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const std::string patch
OpenFOAM patch number as a std::string.
#define DebugPout
Report an information message using Foam::Pout.
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
static void MapDimFields(const mapAddedPolyMesh &, const fvMesh &mesh, const fvMesh &meshToAdd)
Map all DimensionedFields of Type.
List< label > labelList
A List of labels.
static tmp< fvPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, volMesh > &)
Return a pointer to a new patchField created on freestore given.
static tmp< fvsPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Return a pointer to a new patchField created on freestore given.