2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
|
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
|
|
\\ / O peration |
|
|
|
|
\\ / A nd | Copyright held by original author
|
|
|
|
\\/ M anipulation |
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
|
|
|
This file is part of OpenFOAM.
|
|
|
|
|
|
|
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
|
|
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
Description
|
|
|
|
Add pointZones/faceZones/cellZones to the mesh from similar named
|
|
|
|
pointSets/faceSets/cellSets.
|
|
|
|
|
|
|
|
There is one catch: for faceZones you also need to specify a flip
|
2011-02-25 12:10:38 +00:00
|
|
|
condition which basically denotes the side of the face. In this application
|
2010-08-25 21:42:57 +00:00
|
|
|
it reads a cellSet (xxxCells if 'xxx' is the name of the faceSet) which
|
2011-02-25 12:10:38 +00:00
|
|
|
is the masterCells of the zone. Master cell is the one IN FRONT of the
|
2011-03-17 12:50:56 +00:00
|
|
|
face, ie. the one into which the face normal points. If master cells are
|
|
|
|
not found, take faces without a flip
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2011-02-25 12:10:38 +00:00
|
|
|
If one is not interested in sidedness specify the -noFlipMap
|
2010-05-12 13:27:55 +00:00
|
|
|
command line option.
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "argList.H"
|
|
|
|
#include "Time.H"
|
|
|
|
#include "polyMesh.H"
|
|
|
|
#include "IStringStream.H"
|
|
|
|
#include "cellSet.H"
|
|
|
|
#include "faceSet.H"
|
|
|
|
#include "pointSet.H"
|
|
|
|
#include "OFstream.H"
|
|
|
|
#include "IFstream.H"
|
|
|
|
#include "IOobjectList.H"
|
2010-08-25 21:42:57 +00:00
|
|
|
#include "SortableList.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
// Main program:
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
argList::validOptions.insert("noFlipMap", "");
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
# include "addRegionOption.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
# include "addTimeOptions.H"
|
|
|
|
# include "setRootCase.H"
|
|
|
|
# include "createTime.H"
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
bool noFlipMap = args.optionFound("noFlipMap");
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// Get times list
|
|
|
|
instantList Times = runTime.times();
|
|
|
|
|
|
|
|
label startTime = Times.size()-1;
|
|
|
|
label endTime = Times.size();
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
// check -time and -latestTime options
|
2010-05-12 13:27:55 +00:00
|
|
|
# include "checkTimeOption.H"
|
|
|
|
|
|
|
|
runTime.setTime(Times[startTime], startTime);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
# include "createNamedPolyMesh.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// Search for list of objects for the time of the mesh
|
|
|
|
IOobjectList objects
|
|
|
|
(
|
|
|
|
mesh,
|
2011-02-25 12:10:38 +00:00
|
|
|
mesh.facesInstance(),
|
2010-05-12 13:27:55 +00:00
|
|
|
polyMesh::meshSubDir/"sets"
|
|
|
|
);
|
|
|
|
|
2011-02-25 12:10:38 +00:00
|
|
|
Info<< "Searched : " << mesh.facesInstance()/polyMesh::meshSubDir/"sets"
|
2010-05-12 13:27:55 +00:00
|
|
|
<< nl
|
|
|
|
<< "Found : " << objects.names() << nl
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
|
|
IOobjectList pointObjects(objects.lookupClass(pointSet::typeName));
|
|
|
|
|
|
|
|
for
|
|
|
|
(
|
|
|
|
IOobjectList::const_iterator iter = pointObjects.begin();
|
|
|
|
iter != pointObjects.end();
|
|
|
|
++iter
|
|
|
|
)
|
|
|
|
{
|
2011-03-03 11:49:44 +00:00
|
|
|
// Set not in memory. Load it.
|
2010-05-12 13:27:55 +00:00
|
|
|
pointSet set(*iter());
|
2010-08-25 21:42:57 +00:00
|
|
|
SortableList<label> pointLabels(set.toc());
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
label zoneID = mesh.pointZones().findZoneID(set.name());
|
|
|
|
if (zoneID == -1)
|
|
|
|
{
|
|
|
|
Info<< "Adding set " << set.name() << " as a pointZone." << endl;
|
2011-02-25 12:10:38 +00:00
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
label sz = mesh.pointZones().size();
|
|
|
|
mesh.pointZones().setSize(sz+1);
|
|
|
|
mesh.pointZones().set
|
|
|
|
(
|
|
|
|
sz,
|
|
|
|
new pointZone
|
|
|
|
(
|
|
|
|
set.name(), //name
|
2010-08-25 21:42:57 +00:00
|
|
|
pointLabels, //addressing
|
2010-05-12 13:27:55 +00:00
|
|
|
sz, //index
|
|
|
|
mesh.pointZones() //pointZoneMesh
|
|
|
|
)
|
|
|
|
);
|
|
|
|
mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
|
2010-08-25 21:42:57 +00:00
|
|
|
mesh.pointZones().instance() = mesh.facesInstance();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Info<< "Overwriting contents of existing pointZone " << zoneID
|
|
|
|
<< " with that of set " << set.name() << "." << endl;
|
2010-08-25 21:42:57 +00:00
|
|
|
mesh.pointZones()[zoneID] = pointLabels;
|
2010-05-12 13:27:55 +00:00
|
|
|
mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
|
2010-08-25 21:42:57 +00:00
|
|
|
mesh.pointZones().instance() = mesh.facesInstance();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IOobjectList faceObjects(objects.lookupClass(faceSet::typeName));
|
|
|
|
|
2011-02-25 12:10:38 +00:00
|
|
|
HashSet<word> masterCellSets;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
for
|
|
|
|
(
|
|
|
|
IOobjectList::const_iterator iter = faceObjects.begin();
|
|
|
|
iter != faceObjects.end();
|
|
|
|
++iter
|
|
|
|
)
|
|
|
|
{
|
2011-03-03 11:49:44 +00:00
|
|
|
// Set not in memory. Load it.
|
2010-05-12 13:27:55 +00:00
|
|
|
faceSet set(*iter());
|
2010-08-25 21:42:57 +00:00
|
|
|
SortableList<label> faceLabels(set.toc());
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
DynamicList<label> addressing(set.size());
|
|
|
|
DynamicList<bool> flipMap(set.size());
|
|
|
|
|
|
|
|
if (!noFlipMap)
|
|
|
|
{
|
2011-02-25 12:10:38 +00:00
|
|
|
word setName(set.name() + "MasterCells");
|
2010-08-25 21:42:57 +00:00
|
|
|
|
2011-02-25 12:10:38 +00:00
|
|
|
Info<< "Using cellSet " << setName
|
2011-03-17 12:50:56 +00:00
|
|
|
<< " to determine the master side of the zone." << nl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< endl;
|
|
|
|
|
|
|
|
// Load corresponding cells
|
2011-03-17 12:50:56 +00:00
|
|
|
cellSet cells
|
|
|
|
(
|
|
|
|
mesh,
|
|
|
|
setName,
|
|
|
|
IOobject::READ_IF_PRESENT
|
|
|
|
);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
// Store setName to exclude from cellZones further on
|
2011-02-25 12:10:38 +00:00
|
|
|
masterCellSets.insert(setName);
|
2010-08-25 21:42:57 +00:00
|
|
|
|
2011-03-17 12:50:56 +00:00
|
|
|
if (!cells.empty())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2011-03-17 12:50:56 +00:00
|
|
|
forAll(faceLabels, i)
|
|
|
|
{
|
|
|
|
label faceI = faceLabels[i];
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2011-03-17 12:50:56 +00:00
|
|
|
bool flip = false;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2011-03-17 12:50:56 +00:00
|
|
|
if (mesh.isInternalFace(faceI))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2011-03-17 12:50:56 +00:00
|
|
|
if
|
|
|
|
(
|
|
|
|
cells.found(mesh.faceOwner()[faceI])
|
|
|
|
&& !cells.found(mesh.faceNeighbour()[faceI])
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Fixed, using master zone. HJ, 17/Feb/2011
|
|
|
|
flip = true;
|
|
|
|
}
|
|
|
|
else if
|
|
|
|
(
|
|
|
|
!cells.found(mesh.faceOwner()[faceI])
|
|
|
|
&& cells.found(mesh.faceNeighbour()[faceI])
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Fixed, using master zone. HJ, 17/Feb/2011
|
|
|
|
flip = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "Pwner or neighbour of internal face "
|
|
|
|
<< faceI << " should be in cellSet "
|
|
|
|
<< cells.name()
|
|
|
|
<< " to be able to determine orientation."
|
|
|
|
<< nl << "Face:" << faceI
|
|
|
|
<< " own:" << mesh.faceOwner()[faceI]
|
|
|
|
<< " OwnInCellSet:"
|
|
|
|
<< cells.found(mesh.faceOwner()[faceI])
|
|
|
|
<< " nei:" << mesh.faceNeighbour()[faceI]
|
|
|
|
<< " NeiInCellSet:"
|
|
|
|
<< cells.found(mesh.faceNeighbour()[faceI])
|
|
|
|
<< abort(FatalError);
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-17 12:50:56 +00:00
|
|
|
if (cells.found(mesh.faceOwner()[faceI]))
|
|
|
|
{
|
|
|
|
// Fixed, using master zone. HJ, 17/Feb/2011
|
|
|
|
flip = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Fixed, using master zone. HJ, 17/Feb/2011
|
|
|
|
flip = false;
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
2011-03-17 12:50:56 +00:00
|
|
|
|
|
|
|
addressing.append(faceI);
|
|
|
|
flipMap.append(flip);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
2011-03-17 12:50:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Cell set not found or empty. Using faces without flip
|
|
|
|
Info<< "cellSet " << setName
|
|
|
|
<< " not found or empty. Setting flipMap to false" << nl
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
forAll(faceLabels, i)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2011-03-17 12:50:56 +00:00
|
|
|
label faceI = faceLabels[i];
|
|
|
|
addressing.append(faceI);
|
|
|
|
flipMap.append(false);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No flip map.
|
2010-08-25 21:42:57 +00:00
|
|
|
forAll(faceLabels, i)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
label faceI = faceLabels[i];
|
|
|
|
addressing.append(faceI);
|
2010-05-12 13:27:55 +00:00
|
|
|
flipMap.append(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
label zoneID = mesh.faceZones().findZoneID(set.name());
|
|
|
|
if (zoneID == -1)
|
|
|
|
{
|
|
|
|
Info<< "Adding set " << set.name() << " as a faceZone." << endl;
|
|
|
|
label sz = mesh.faceZones().size();
|
|
|
|
mesh.faceZones().setSize(sz+1);
|
|
|
|
mesh.faceZones().set
|
|
|
|
(
|
|
|
|
sz,
|
|
|
|
new faceZone
|
|
|
|
(
|
2011-02-25 12:10:38 +00:00
|
|
|
set.name(), // name
|
|
|
|
addressing.shrink(), // addressing
|
|
|
|
flipMap.shrink(), // flipmap
|
|
|
|
sz, // index
|
|
|
|
mesh.faceZones() // faceZoneMesh
|
2010-05-12 13:27:55 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
|
2010-08-25 21:42:57 +00:00
|
|
|
mesh.faceZones().instance() = mesh.facesInstance();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Info<< "Overwriting contents of existing faceZone " << zoneID
|
|
|
|
<< " with that of set " << set.name() << "." << endl;
|
|
|
|
mesh.faceZones()[zoneID].resetAddressing
|
|
|
|
(
|
|
|
|
addressing.shrink(),
|
|
|
|
flipMap.shrink()
|
|
|
|
);
|
|
|
|
mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
|
2010-08-25 21:42:57 +00:00
|
|
|
mesh.faceZones().instance() = mesh.facesInstance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IOobjectList cellObjects(objects.lookupClass(cellSet::typeName));
|
|
|
|
|
|
|
|
for
|
|
|
|
(
|
|
|
|
IOobjectList::const_iterator iter = cellObjects.begin();
|
|
|
|
iter != cellObjects.end();
|
|
|
|
++iter
|
|
|
|
)
|
|
|
|
{
|
2011-02-25 12:10:38 +00:00
|
|
|
if (!masterCellSets.found(iter.key()))
|
2010-08-25 21:42:57 +00:00
|
|
|
{
|
2011-03-03 11:49:44 +00:00
|
|
|
// Set not in memory. Load it.
|
2010-08-25 21:42:57 +00:00
|
|
|
cellSet set(*iter());
|
|
|
|
SortableList<label> cellLabels(set.toc());
|
|
|
|
|
|
|
|
label zoneID = mesh.cellZones().findZoneID(set.name());
|
|
|
|
if (zoneID == -1)
|
|
|
|
{
|
2011-02-25 12:10:38 +00:00
|
|
|
Info<< "Adding set " << set.name() << " as a cellZone."
|
|
|
|
<< endl;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
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();
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
Info<< "Writing mesh." << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
if (!mesh.write())
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "Failed writing polyMesh."
|
|
|
|
<< exit(FatalError);
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< nl << "End" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|