37void 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();
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],
270 const bool fullyMapped
277 mesh.objectRegistry::csorted<fldType>()
288 <<
"MapVolFields : Storing old time for "
291 field.storeOldTimes();
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;
320void Foam::fvMeshAdder::MapSurfaceField
326 const bool fullyMapped
330 const labelList& oldPatchStarts = meshMap.oldPatchStarts();
332 auto& bfld =
fld.boundaryFieldRef();
346 intFld.rmap(oldField, meshMap.oldFaceMap());
347 intFld.rmap(fldToAdd, meshMap.addedFaceMap());
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];
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],
574 const bool fullyMapped
581 mesh.objectRegistry::csorted<fldType>()
592 <<
"MapSurfaceFields : Storing old time for "
595 field.storeOldTimes();
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;
623void Foam::fvMeshAdder::MapDimField
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());
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;
687void 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]);
734void Foam::fvMeshAdder::MapVolField
736 UPtrList<GeometricField<Type, fvPatchField, volMesh>>& flds,
742 const bool fullyMapped
751 <<
"Not valid field at element 0 in list of size "
762 const Field<Type> oldInternalField(flds[0].primitiveField());
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;
871void Foam::fvMeshAdder::MapSurfaceField
873 UPtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>& flds,
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());
908 intFld.
setSize(mesh0.nInternalFaces());
916 const auto&
fld = flds[meshi];
921 intFld.rmap(oldInternalField,
faceMap);
931 const auto& bfld = flds[meshi].boundaryField();
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;
1079 const UPtrList<fvMesh>&
meshes,
1086 const bool fullyMapped
1089 typedef GeometricField<Type, fvPatchField, volMesh> fldType;
1094 <<
"Not valid mesh at element 0 in list of size "
1098 const auto& mesh0 =
meshes[0];
1102 mesh0.objectRegistry::csorted<fldType>()
1114 <<
"MapVolFields : Storing old time for "
1117 field.storeOldTimes();
1126 <<
"MapVolFields : mapping " << name0 <<
endl;
1133 auto& meshFld =
meshes[meshi].
1135 meshToField.set(meshi, &meshFld);
1144 patchProcAddressing,
1156 const UPtrList<fvMesh>&
meshes,
1158 const bool fullyMapped
1161 typedef DimensionedField<Type, volMesh> fldType;
1166 <<
"Not valid mesh at element 0 in list of size "
1170 const auto& mesh0 =
meshes[0];
1175 mesh0.objectRegistry::csorted<fldType,
true>()
1183 <<
"MapDimFields : mapping " << name0 <<
endl;
1190 auto& meshFld =
meshes[meshi].
1192 meshToField.set(meshi, &meshFld);
1196 MapDimField(meshToField, cellProcAddressing, fullyMapped);
1204 const UPtrList<fvMesh>&
meshes,
1212 const bool fullyMapped
1215 typedef GeometricField<Type, fvsPatchField, surfaceMesh> fldType;
1220 <<
"Not valid mesh at element 0 in list of size "
1224 const auto& mesh0 =
meshes[0];
1228 mesh0.objectRegistry::csorted<fldType>()
1240 <<
"MapSurfaceFields : Storing old time for "
1243 field.storeOldTimes();
1252 <<
"MapSurfaceFields : Mapping " <<
field.name() <<
endl;
1259 auto& meshFld =
meshes[meshi].
1261 meshToField.set(meshi, &meshFld);
1271 patchProcAddressing,
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Mesh & mesh() const noexcept
Return const reference to mesh.
virtual bool hasUnmapped() const
Any unmapped values?
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Generic GeometricField class.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
void setSize(label n)
Alias for resize().
const T * set(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.
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,...
label size() const noexcept
The number of entries in the list.
static void MapSurfaceFields(const mapAddedPolyMesh &, const fvMesh &mesh, const fvMesh &meshToAdd, const bool fullyMapped=false)
Map all surfaceFields of Type.
static void MapDimFields(const mapAddedPolyMesh &, const fvMesh &mesh, const fvMesh &meshToAdd)
Map all DimensionedFields of Type.
static void MapVolFields(const mapAddedPolyMesh &, const fvMesh &mesh, const fvMesh &meshToAdd, const bool fullyMapped=false)
Map all volFields of Type.
Mesh data needed to do the Finite Volume discretisation.
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
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.
label start() const noexcept
The patch start within the polyMesh face list.
const fvPatch & patch() const noexcept
Return the patch.
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
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.
Class containing mesh-to-mesh mapping information after a mesh addition where we add a mesh ('added m...
const labelList & oldPatchStarts() const
Return list of the old patch start labels.
const labelList & oldCellMap() const
const labelList & addedCellMap() const
const labelList & addedPatchMap() const
From added mesh patch index to new patch index or -1 if.
const labelList & oldPatchMap() const
From old patch index to new patch index or -1 if patch.
const labelList & oldFaceMap() const
const labelList & oldPatchSizes() const
Return list of the old patch sizes.
const labelList & addedFaceMap() const
Type & lookupObjectRef(const word &name, const bool recursive=false) const
Lookup and return non-const reference to the object of the given Type. Fatal if not found or the wron...
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
virtual const labelList & faceOwner() const
Return face owner.
A patch is a list of labels that address the faces in the global face list.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundaryMesh reference.
label nInternalFaces() const noexcept
Number of internal faces.
label nCells() const noexcept
Number of mesh cells.
A class for handling words, derived from Foam::string.
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugPout
Report an information message using Foam::Pout.
const std::string patch
OpenFOAM patch number as a std::string.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
DirectFieldMapper< fvPatchFieldMapper > directFvPatchFieldMapper
A fvPatchFieldMapper with direct mapping.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool isType(const U &obj)
Check if typeid of the object and Type are identical.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
#define forAll(list, i)
Loop across all elements in list.