preserve flipmap

This commit is contained in:
mattijs
2009-06-29 17:30:02 +01:00
parent 4d8c3ffe1f
commit e6416c2604
3 changed files with 123 additions and 99 deletions

View File

@ -87,7 +87,7 @@ int main(int argc, char *argv[])
polyMesh::meshSubDir/"sets" polyMesh::meshSubDir/"sets"
); );
Pout<< "Searched : " << mesh.pointsInstance()/polyMesh::meshSubDir/"sets" Info<< "Searched : " << mesh.pointsInstance()/polyMesh::meshSubDir/"sets"
<< nl << nl
<< "Found : " << objects.names() << nl << "Found : " << objects.names() << nl
<< endl; << endl;
@ -95,7 +95,7 @@ int main(int argc, char *argv[])
IOobjectList pointObjects(objects.lookupClass(pointSet::typeName)); IOobjectList pointObjects(objects.lookupClass(pointSet::typeName));
Pout<< "pointSets:" << pointObjects.names() << endl; //Pout<< "pointSets:" << pointObjects.names() << endl;
for for
( (
@ -126,6 +126,7 @@ int main(int argc, char *argv[])
) )
); );
mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
mesh.pointZones().instance() = mesh.facesInstance();
} }
else else
{ {
@ -133,57 +134,17 @@ int main(int argc, char *argv[])
<< " with that of set " << set.name() << "." << endl; << " with that of set " << set.name() << "." << endl;
mesh.pointZones()[zoneID] = pointLabels; mesh.pointZones()[zoneID] = pointLabels;
mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
mesh.pointZones().instance() = mesh.facesInstance();
} }
} }
IOobjectList cellObjects(objects.lookupClass(cellSet::typeName));
Pout<< "cellSets:" << cellObjects.names() << endl;
for
(
IOobjectList::const_iterator iter = cellObjects.begin();
iter != cellObjects.end();
++iter
)
{
// Not in memory. Load it.
cellSet set(*iter());
SortableList<label> cellLabels(set.toc());
label zoneID = mesh.cellZones().findZoneID(set.name());
if (zoneID == -1)
{
Info<< "Adding set " << set.name() << " as a cellZone." << endl;
label sz = mesh.cellZones().size();
mesh.cellZones().setSize(sz+1);
mesh.cellZones().set
(
sz,
new cellZone
(
set.name(), //name
cellLabels, //addressing
sz, //index
mesh.cellZones() //pointZoneMesh
)
);
mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
}
else
{
Info<< "Overwriting contents of existing cellZone " << zoneID
<< " with that of set " << set.name() << "." << endl;
mesh.cellZones()[zoneID] = cellLabels;
mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
}
}
IOobjectList faceObjects(objects.lookupClass(faceSet::typeName)); IOobjectList faceObjects(objects.lookupClass(faceSet::typeName));
Pout<< "faceSets:" << faceObjects.names() << endl; HashSet<word> slaveCellSets;
//Pout<< "faceSets:" << faceObjects.names() << endl;
for for
( (
@ -203,9 +164,9 @@ int main(int argc, char *argv[])
{ {
word setName(set.name() + "SlaveCells"); word setName(set.name() + "SlaveCells");
Pout<< "Trying to load cellSet " << setName Info<< "Trying to load cellSet " << setName
<< " to find out the slave side of the zone." << nl << " to find out the slave side of the zone." << nl
<< " If you do not care about the flipMap" << "If you do not care about the flipMap"
<< " (i.e. do not use the sideness)" << nl << " (i.e. do not use the sideness)" << nl
<< "use the -noFlipMap command line option." << "use the -noFlipMap command line option."
<< endl; << endl;
@ -213,6 +174,9 @@ int main(int argc, char *argv[])
// Load corresponding cells // Load corresponding cells
cellSet cells(mesh, setName); cellSet cells(mesh, setName);
// Store setName to exclude from cellZones further on
slaveCellSets.insert(setName);
forAll(faceLabels, i) forAll(faceLabels, i)
{ {
label faceI = faceLabels[i]; label faceI = faceLabels[i];
@ -227,7 +191,7 @@ int main(int argc, char *argv[])
&& !cells.found(mesh.faceNeighbour()[faceI]) && !cells.found(mesh.faceNeighbour()[faceI])
) )
{ {
flip = true; flip = false;
} }
else if else if
( (
@ -235,7 +199,7 @@ int main(int argc, char *argv[])
&& cells.found(mesh.faceNeighbour()[faceI]) && cells.found(mesh.faceNeighbour()[faceI])
) )
{ {
flip = false; flip = true;
} }
else else
{ {
@ -257,11 +221,11 @@ int main(int argc, char *argv[])
{ {
if (cells.found(mesh.faceOwner()[faceI])) if (cells.found(mesh.faceOwner()[faceI]))
{ {
flip = true; flip = false;
} }
else else
{ {
flip = false; flip = true;
} }
} }
@ -299,6 +263,7 @@ int main(int argc, char *argv[])
) )
); );
mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE; mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
mesh.faceZones().instance() = mesh.facesInstance();
} }
else else
{ {
@ -310,10 +275,63 @@ int main(int argc, char *argv[])
flipMap.shrink() flipMap.shrink()
); );
mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE; mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
mesh.faceZones().instance() = mesh.facesInstance();
} }
} }
Pout<< "Writing mesh." << endl;
IOobjectList cellObjects(objects.lookupClass(cellSet::typeName));
//Pout<< "cellSets:" << cellObjects.names() << endl;
for
(
IOobjectList::const_iterator iter = cellObjects.begin();
iter != cellObjects.end();
++iter
)
{
if (!slaveCellSets.found(iter.key()))
{
// Not in memory. Load it.
cellSet set(*iter());
SortableList<label> cellLabels(set.toc());
label zoneID = mesh.cellZones().findZoneID(set.name());
if (zoneID == -1)
{
Info<< "Adding set " << set.name() << " as a cellZone." << endl;
label sz = mesh.cellZones().size();
mesh.cellZones().setSize(sz+1);
mesh.cellZones().set
(
sz,
new cellZone
(
set.name(), //name
cellLabels, //addressing
sz, //index
mesh.cellZones() //pointZoneMesh
)
);
mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
mesh.cellZones().instance() = mesh.facesInstance();
}
else
{
Info<< "Overwriting contents of existing cellZone " << zoneID
<< " with that of set " << set.name() << "." << endl;
mesh.cellZones()[zoneID] = cellLabels;
mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
mesh.cellZones().instance() = mesh.facesInstance();
}
}
}
Info<< "Writing mesh." << endl;
if (!mesh.write()) if (!mesh.write())
{ {
@ -322,7 +340,7 @@ int main(int argc, char *argv[])
<< exit(FatalError); << exit(FatalError);
} }
Pout << nl << "End" << endl; Info<< nl << "End" << endl;
return 0; return 0;
} }

View File

@ -58,23 +58,6 @@ const Foam::point Foam::polyTopoChange::greatPoint
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Renumber
void Foam::polyTopoChange::renumber
(
const labelList& map,
DynamicList<label>& elems
)
{
forAll(elems, elemI)
{
if (elems[elemI] >= 0)
{
elems[elemI] = map[elems[elemI]];
}
}
}
// Renumber with special handling for merged items (marked with <-1) // Renumber with special handling for merged items (marked with <-1)
void Foam::polyTopoChange::renumberReverseMap void Foam::polyTopoChange::renumberReverseMap
( (
@ -208,6 +191,20 @@ void Foam::polyTopoChange::countMap
} }
Foam::labelHashSet Foam::polyTopoChange::getSetIndices(const PackedBoolList& lst)
{
labelHashSet values(lst.count());
forAll(lst, i)
{
if (lst[i])
{
values.insert(i);
}
}
return values;
}
void Foam::polyTopoChange::writeMeshStats(const polyMesh& mesh, Ostream& os) void Foam::polyTopoChange::writeMeshStats(const polyMesh& mesh, Ostream& os)
{ {
const polyBoundaryMesh& patches = mesh.boundaryMesh(); const polyBoundaryMesh& patches = mesh.boundaryMesh();
@ -782,9 +779,11 @@ void Foam::polyTopoChange::reorderCompactFaces
renumberKey(oldToNew, faceFromPoint_); renumberKey(oldToNew, faceFromPoint_);
renumberKey(oldToNew, faceFromEdge_); renumberKey(oldToNew, faceFromEdge_);
renumber(oldToNew, flipFaceFlux_); inplaceReorder(oldToNew, flipFaceFlux_);
flipFaceFlux_.setCapacity(newSize);
renumberKey(oldToNew, faceZone_); renumberKey(oldToNew, faceZone_);
renumberKey(oldToNew, faceZoneFlip_); inplaceReorder(oldToNew, faceZoneFlip_);
faceZoneFlip_.setCapacity(newSize);
} }
@ -1097,6 +1096,18 @@ void Foam::polyTopoChange::compact
{ {
faces_[faceI] = faces_[faceI].reverseFace(); faces_[faceI] = faces_[faceI].reverseFace();
Swap(faceOwner_[faceI], faceNeighbour_[faceI]); Swap(faceOwner_[faceI], faceNeighbour_[faceI]);
flipFaceFlux_[faceI] =
(
flipFaceFlux_[faceI]
? 0
: 1
);
faceZoneFlip_[faceI] =
(
faceZoneFlip_[faceI]
? 0
: 1
);
} }
} }
} }
@ -2302,9 +2313,9 @@ void Foam::polyTopoChange::addMesh
faceMap_.setCapacity(faceMap_.size() + nAllFaces); faceMap_.setCapacity(faceMap_.size() + nAllFaces);
faceFromPoint_.resize(faceFromPoint_.size() + nAllFaces/100); faceFromPoint_.resize(faceFromPoint_.size() + nAllFaces/100);
faceFromEdge_.resize(faceFromEdge_.size() + nAllFaces/100); faceFromEdge_.resize(faceFromEdge_.size() + nAllFaces/100);
flipFaceFlux_.resize(flipFaceFlux_.size() + nAllFaces/100); flipFaceFlux_.setCapacity(faces_.size() + nAllFaces);
faceZone_.resize(faceZone_.size() + nAllFaces/100); faceZone_.resize(faceZone_.size() + nAllFaces/100);
faceZoneFlip_.resize(faceZoneFlip_.size() + nAllFaces/100); faceZoneFlip_.setCapacity(faces_.size() + nAllFaces);
// Precalc offset zones // Precalc offset zones
@ -2716,15 +2727,12 @@ Foam::label Foam::polyTopoChange::addFace
} }
reverseFaceMap_.append(faceI); reverseFaceMap_.append(faceI);
if (flipFaceFlux) flipFaceFlux_[faceI] = (flipFaceFlux ? 1 : 0);
{
flipFaceFlux_.insert(faceI);
}
if (zoneID >= 0) if (zoneID >= 0)
{ {
faceZone_.insert(faceI, zoneID); faceZone_.insert(faceI, zoneID);
faceZoneFlip_.insert(faceI, zoneFlip); faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0);
} }
return faceI; return faceI;
@ -2754,34 +2762,27 @@ void Foam::polyTopoChange::modifyFace
faceNeighbour_[faceI] = nei; faceNeighbour_[faceI] = nei;
region_[faceI] = patchID; region_[faceI] = patchID;
if (flipFaceFlux) flipFaceFlux_[faceI] = (flipFaceFlux ? 1 : 0);
{
flipFaceFlux_.insert(faceI);
}
else
{
flipFaceFlux_.erase(faceI);
}
Map<label>::iterator faceFnd = faceZone_.find(faceI); Map<label>::iterator faceFnd = faceZone_.find(faceI);
if (faceFnd != faceZone_.end()) if (faceFnd != faceZone_.end())
{ {
faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0);
if (zoneID >= 0) if (zoneID >= 0)
{ {
faceFnd() = zoneID; faceFnd() = zoneID;
faceZoneFlip_.find(faceI)() = zoneFlip;
} }
else else
{ {
faceZone_.erase(faceFnd); faceZone_.erase(faceFnd);
faceZoneFlip_.erase(faceI);
} }
} }
else if (zoneID >= 0) else if (zoneID >= 0)
{ {
faceZone_.insert(faceI, zoneID); faceZone_.insert(faceI, zoneID);
faceZoneFlip_.insert(faceI, zoneFlip); faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0);
} }
} }
@ -2823,9 +2824,9 @@ void Foam::polyTopoChange::removeFace(const label faceI, const label mergeFaceI)
} }
faceFromEdge_.erase(faceI); faceFromEdge_.erase(faceI);
faceFromPoint_.erase(faceI); faceFromPoint_.erase(faceI);
flipFaceFlux_.erase(faceI); flipFaceFlux_[faceI] = 0;
faceZone_.erase(faceI); faceZone_.erase(faceI);
faceZoneFlip_.erase(faceI); faceZoneFlip_[faceI] = 0;
} }
@ -3119,6 +3120,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::changeMesh
labelListList faceZonePointMap(mesh.faceZones().size()); labelListList faceZonePointMap(mesh.faceZones().size());
calcFaceZonePointMap(mesh, oldFaceZoneMeshPointMaps, faceZonePointMap); calcFaceZonePointMap(mesh, oldFaceZoneMeshPointMaps, faceZonePointMap);
labelHashSet flipFaceFluxSet(getSetIndices(flipFaceFlux_));
return autoPtr<mapPolyMesh> return autoPtr<mapPolyMesh>
( (
@ -3147,7 +3149,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::changeMesh
reverseFaceMap_, reverseFaceMap_,
reverseCellMap_, reverseCellMap_,
flipFaceFlux_, flipFaceFluxSet,
patchPointMap, patchPointMap,
@ -3410,6 +3412,8 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::makeMesh
writeMeshStats(mesh, Pout); writeMeshStats(mesh, Pout);
} }
labelHashSet flipFaceFluxSet(getSetIndices(flipFaceFlux_));
return autoPtr<mapPolyMesh> return autoPtr<mapPolyMesh>
( (
new mapPolyMesh new mapPolyMesh
@ -3437,7 +3441,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::makeMesh
reverseFaceMap_, reverseFaceMap_,
reverseCellMap_, reverseCellMap_,
flipFaceFlux_, flipFaceFluxSet,
patchPointMap, patchPointMap,

View File

@ -171,13 +171,13 @@ class polyTopoChange
Map<label> faceFromEdge_; Map<label> faceFromEdge_;
//- In mapping whether to reverse the flux. //- In mapping whether to reverse the flux.
labelHashSet flipFaceFlux_; PackedBoolList flipFaceFlux_;
//- Zone of face //- Zone of face
Map<label> faceZone_; Map<label> faceZone_;
//- Orientation of face in zone //- Orientation of face in zone
Map<bool> faceZoneFlip_; PackedBoolList faceZoneFlip_;
//- Active faces //- Active faces
label nActiveFaces_; label nActiveFaces_;
@ -216,8 +216,7 @@ class polyTopoChange
template<class T> template<class T>
static void renumberKey(const labelList& map, Map<T>&); static void renumberKey(const labelList& map, Map<T>&);
//- Renumber elements of list according to map //- Renumber elements of container according to map
static void renumber(const labelList&, DynamicList<label>&);
static void renumber(const labelList&, labelHashSet&); static void renumber(const labelList&, labelHashSet&);
//- Special handling of reverse maps which have <-1 in them //- Special handling of reverse maps which have <-1 in them
static void renumberReverseMap(const labelList&, DynamicList<label>&); static void renumberReverseMap(const labelList&, DynamicList<label>&);
@ -225,6 +224,9 @@ class polyTopoChange
//- Renumber & compact elements of list according to map //- Renumber & compact elements of list according to map
static void renumberCompact(const labelList&, labelList&); static void renumberCompact(const labelList&, labelList&);
//- Get all set elements as a labelHashSet
static labelHashSet getSetIndices(const PackedBoolList&);
//- Count number of added and removed quantities from maps. //- Count number of added and removed quantities from maps.
static void countMap static void countMap
( (