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.resize(
mesh.boundaryMesh().size());
116 label newPatchi = nUsedPatches;
117 newPatchi < bfld.size();
121 bfld.release(newPatchi);
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 const UPtrList<const fldType>
fields 277 mesh.objectRegistry::csorted<fldType>()
288 <<
"MapVolFields : Storing old time for " 291 const_cast<fldType&
>(
field).storeOldTimes();
297 fldType&
fld =
const_cast<fldType&
>(
field);
300 meshToAdd.objectRegistry::cfindObject<fldType>(
field.name());
305 <<
"MapVolFields : mapping " <<
field.name() <<
endl;
307 MapVolField<Type>(meshMap,
fld, *toAdd, fullyMapped);
312 <<
"Not mapping field " <<
field.name()
313 <<
" - not present on mesh to add" <<
endl;
320 void Foam::fvMeshAdder::MapSurfaceField
322 const mapAddedPolyMesh& meshMap,
324 GeometricField<Type, fvsPatchField, surfaceMesh>&
fld,
325 const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd,
326 const bool fullyMapped
329 const fvMesh&
mesh =
fld.mesh();
330 const labelList& oldPatchStarts = meshMap.oldPatchStarts();
332 auto& bfld =
fld.boundaryFieldRef();
339 const Field<Type> oldField(
fld);
342 Field<Type>& intFld =
fld.primitiveFieldRef();
346 intFld.rmap(oldField, meshMap.oldFaceMap());
347 intFld.rmap(fldToAdd, meshMap.addedFaceMap());
355 const fvsPatchField<Type>& pf = bfld[patchi];
357 label start = oldPatchStarts[patchi];
361 label newFacei = meshMap.oldFaceMap()[start + i];
365 intFld[newFacei] = pf[i];
376 const labelList& oldPatchMap = meshMap.oldPatchMap();
377 const labelList& oldPatchSizes = meshMap.oldPatchSizes();
381 label unusedPatchi = 0;
383 forAll(oldPatchMap, patchi)
385 const label newPatchi = oldPatchMap[patchi];
393 label nUsedPatches = unusedPatchi;
398 forAll(oldPatchMap, patchi)
400 const label newPatchi = oldPatchMap[patchi];
404 oldToNew[patchi] = newPatchi;
408 oldToNew[patchi] = unusedPatchi++;
414 bfld.reorder(oldToNew);
420 label newPatchi = nUsedPatches;
421 newPatchi < bfld.size();
425 bfld.release(newPatchi);
432 forAll(oldPatchMap, patchi)
434 const label newPatchi = oldPatchMap[patchi];
442 oldPatchStarts[patchi],
443 oldPatchSizes[patchi],
444 meshMap.oldFaceMap(),
456 patchMapper.hasUnmapped() =
false;
487 const labelList& addedPatchMap = meshMap.addedPatchMap();
490 forAll(addedPatchMap, patchi)
492 const label newPatchi = addedPatchMap[patchi];
497 const polyPatch& oldPatch =
500 if (!bfld.set(newPatchi))
512 meshMap.addedFaceMap(),
524 patchMapper.hasUnmapped() =
false;
532 fldToAdd.boundaryField()[patchi],
544 labelList addedToNew(oldPatch.size(), -1);
547 label addedFacei = oldPatch.start()+i;
548 label newFacei = meshMap.addedFaceMap()[addedFacei];
549 label patchFacei = newFacei-newPatch.start();
550 if (patchFacei >= 0 && patchFacei < newPatch.size())
552 addedToNew[i] = patchFacei;
558 fldToAdd.boundaryField()[patchi],
571 const mapAddedPolyMesh& meshMap,
573 const fvMesh& meshToAdd,
574 const bool fullyMapped
577 typedef GeometricField<Type, fvsPatchField, surfaceMesh> fldType;
579 const UPtrList<const fldType>
fields 581 mesh.objectRegistry::csorted<fldType>()
592 <<
"MapSurfaceFields : Storing old time for " 595 const_cast<fldType&
>(
field).storeOldTimes();
600 fldType&
fld =
const_cast<fldType&
>(
field);
603 meshToAdd.objectRegistry::cfindObject<fldType>(
field.name());
608 <<
"MapSurfaceFields : mapping " <<
field.name() <<
endl;
610 MapSurfaceField<Type>(meshMap,
fld, *toAdd, fullyMapped);
615 <<
"Not mapping field " <<
field.name()
616 <<
" - not present on mesh to add" <<
endl;
623 void Foam::fvMeshAdder::MapDimField
625 const mapAddedPolyMesh& meshMap,
627 DimensionedField<Type, volMesh>&
fld,
628 const DimensionedField<Type, volMesh>& fldToAdd
631 const fvMesh&
mesh =
fld.mesh();
634 const Field<Type> oldField(
fld);
638 fld.rmap(oldField, meshMap.oldCellMap());
639 fld.rmap(fldToAdd, meshMap.addedCellMap());
656 mesh.objectRegistry::csorted<fldType,
true>()
661 fldType&
fld =
const_cast<fldType&
>(
field);
664 meshToAdd.objectRegistry::cfindObject<fldType>(
field.name());
667 if (toAdd && Foam::isType<fldType>(*toAdd))
670 <<
"MapDimFields : mapping " <<
field.name() <<
endl;
672 MapDimField<Type>(meshMap,
fld, *toAdd);
677 <<
"Not mapping field " <<
field.name()
678 <<
" - not present on mesh to add" <<
endl;
687 void Foam::fvMeshAdder::MapDimField
691 const bool fullyMapped
697 if (!flds.test(0) || cellProcAddressing.
size() != flds.size())
700 <<
"Not valid field at element 0 in list of size " 719 intFld.
rmap(oldInternalField, cellProcAddressing[0]);
721 for (label meshi = 1; meshi < flds.size(); meshi++)
726 intFld.
rmap(addFld, cellProcAddressing[meshi]);
734 void Foam::fvMeshAdder::MapVolField
742 const bool fullyMapped
751 <<
"Not valid field at element 0 in list of size " 762 const Field<Type> oldInternalField(flds[0].primitiveField());
765 Field<Type>& intFld = flds[0].primitiveFieldRef();
768 intFld.setSize(flds[0].
mesh().nCells());
770 intFld.rmap(oldInternalField, cellProcAddressing[0]);
772 for (label meshi = 1; meshi < flds.size(); meshi++)
776 const Field<Type>& addFld = flds[meshi].primitiveFieldRef();
777 intFld.rmap(addFld, cellProcAddressing[meshi]);
786 auto& bfld0 = flds[0].boundaryFieldRef();
801 oldPatchStarts0[patchi],
802 oldPatchSizes0[patchi],
803 faceProcAddressing[0],
815 patchMapper.hasUnmapped() =
false;
818 bfld0[patchi].autoMap(patchMapper);
821 for (label meshi = 1; meshi < flds.size(); meshi++)
825 const auto& bfld = flds[meshi].boundaryFieldRef();
827 const labelList& patchMap = patchProcAddressing[meshi];
829 forAll(patchMap, oldPatchi)
831 const auto& fvp = bfld[oldPatchi].patch();
832 const label newPatchi = patchMap[oldPatchi];
837 if (newPatchi >= 0 && newPatchi < bfld0.size())
839 const auto& fvp0 = bfld0[newPatchi].patch();
840 labelList addedToNew(bfld[oldPatchi].size(), -1);
843 const label newFacei =
844 faceProcAddressing[meshi][fvp.start()+i];
845 const label patchFacei = newFacei-fvp0.start();
849 && patchFacei < fvp0.size()
852 addedToNew[i] = patchFacei;
856 bfld0[newPatchi].rmap(bfld[oldPatchi], addedToNew);
861 << bfld[oldPatchi].patch().name() <<
" on field " 862 << flds[meshi].name() <<
endl;
871 void Foam::fvMeshAdder::MapSurfaceField
880 const bool fullyMapped
889 <<
"Not valid field at element 0 in list of size " 894 const fvMesh& mesh0 = flds[0].mesh();
902 const Field<Type> oldInternalField(flds[0].primitiveField());
905 Field<Type>& intFld = flds[0].primitiveFieldRef();
908 intFld.setSize(mesh0.nInternalFaces());
916 const auto&
fld = flds[meshi];
921 intFld.rmap(oldInternalField,
faceMap);
931 const auto& bfld = flds[meshi].boundaryField();
935 const fvsPatchField<Type>& pf = bfld[oldPatchi];
946 const label oldFacei =
947 oldPatchStarts0[oldPatchi]+patchFacei;
948 newFacei = faceProcAddressing[meshi][oldFacei];
949 const label oldOwn = oldFaceOwner0[oldFacei];
950 newOwn = cellProcAddressing[meshi][oldOwn];
961 const label oldFacei =
962 pf.patch().start()+patchFacei;
963 newFacei = faceProcAddressing[meshi][oldFacei];
965 fld.mesh().faceOwner()[oldFacei];
966 newOwn = cellProcAddressing[meshi][oldOwn];
979 && newFacei < mesh0.nInternalFaces()
980 && (newOwn == mesh0.faceOwner()[newFacei])
983 intFld[newFacei] = pf[patchFacei];
1004 auto& bfld0 = flds[0].boundaryFieldRef();
1011 oldPatchStarts0[patchi],
1012 oldPatchSizes0[patchi],
1013 faceProcAddressing[0],
1025 patchMapper.hasUnmapped() =
false;
1028 bfld0[patchi].autoMap(patchMapper);
1031 for (label meshi = 1; meshi < flds.size(); meshi++)
1033 if (flds.set(meshi))
1035 const auto& bfld = flds[meshi].boundaryFieldRef();
1037 const labelList& patchMap = patchProcAddressing[meshi];
1039 forAll(patchMap, oldPatchi)
1041 const auto& fvp = bfld[oldPatchi].patch();
1042 const label newPatchi = patchMap[oldPatchi];
1043 if (newPatchi >= 0 && newPatchi < bfld0.size())
1045 const auto& fvp0 = bfld0[newPatchi].patch();
1046 labelList addedToNew(bfld[oldPatchi].size(), -1);
1049 const label newFacei =
1050 faceProcAddressing[meshi][fvp.start()+i];
1051 const label patchFacei = newFacei-fvp0.start();
1055 && patchFacei < fvp0.size()
1058 addedToNew[i] = patchFacei;
1062 bfld0[newPatchi].rmap(bfld[oldPatchi], addedToNew);
1067 << bfld[oldPatchi].patch().name() <<
" on field " 1068 << flds[meshi].name() <<
endl;
1076 template<
class Type>
1086 const bool fullyMapped
1094 <<
"Not valid mesh at element 0 in list of size " 1098 const auto& mesh0 =
meshes[0];
1100 const UPtrList<const fldType>
fields 1102 mesh0.objectRegistry::csorted<fldType>()
1114 <<
"MapVolFields : Storing old time for " 1117 const_cast<fldType&
>(
field).storeOldTimes();
1123 const word& name0 =
field.name();
1126 <<
"MapVolFields : mapping " << name0 <<
endl;
1128 UPtrList<fldType> meshToField(
meshes.
size());
1133 auto& meshFld =
meshes[meshi].
1134 objectRegistry::lookupObjectRef<fldType>(name0);
1135 meshToField.
set(meshi, &meshFld);
1144 patchProcAddressing,
1153 template<
class Type>
1158 const bool fullyMapped
1166 <<
"Not valid mesh at element 0 in list of size " 1170 const auto& mesh0 =
meshes[0];
1173 const UPtrList<const fldType>
fields 1175 mesh0.objectRegistry::csorted<fldType,
true>()
1180 const word& name0 =
field.name();
1183 <<
"MapDimFields : mapping " << name0 <<
endl;
1185 UPtrList<fldType> meshToField(
meshes.
size());
1190 auto& meshFld =
meshes[meshi].
1191 objectRegistry::lookupObjectRef<fldType>(name0);
1192 meshToField.
set(meshi, &meshFld);
1196 MapDimField(meshToField, cellProcAddressing, fullyMapped);
1201 template<
class Type>
1212 const bool fullyMapped
1220 <<
"Not valid mesh at element 0 in list of size " 1224 const auto& mesh0 =
meshes[0];
1226 const UPtrList<const fldType>
fields 1228 mesh0.objectRegistry::csorted<fldType>()
1240 <<
"MapSurfaceFields : Storing old time for " 1243 const_cast<fldType&
>(
field).storeOldTimes();
1249 const word& name0 =
field.name();
1252 <<
"MapSurfaceFields : Mapping " <<
field.name() <<
endl;
1254 UPtrList<fldType> meshToField(
meshes.
size());
1259 auto& meshFld =
meshes[meshi].
1260 objectRegistry::lookupObjectRef<fldType>(name0);
1261 meshToField.
set(meshi, &meshFld);
1271 patchProcAddressing,
const T * test(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
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.
constexpr char nl
The newline '\n' character (0x0a)
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())
label nInternalFaces() const noexcept
Number of internal faces.
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.