2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / O peration | Version: 3.2
|
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend 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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Description
|
|
|
|
Add pointZones/faceZones/cellZones to the mesh from similar named
|
|
|
|
pointSets/faceSets/cellSets.
|
|
|
|
|
2011-10-12 09:33:31 +00:00
|
|
|
For faceZones the user needs to specify a flip
|
|
|
|
condition which denotes the side of the face. This application
|
|
|
|
reads a cellSet (xxxMasterCells 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
|
2011-03-17 12:50:56 +00:00
|
|
|
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"
|
2013-11-03 20:28:05 +00:00
|
|
|
#include "objectRegistry.H"
|
2015-06-17 13:53:59 +00:00
|
|
|
#include "foamTime.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
#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-05-27 16:17:25 +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-05-27 16:17:25 +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-10-12 09:33:31 +00:00
|
|
|
<< " to determine the master side of the face zone "
|
|
|
|
<< set.name() << 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())
|
2011-10-07 18:21:18 +00:00
|
|
|
<< "Owner or neighbour of internal face "
|
2011-03-17 12:50:56 +00:00
|
|
|
<< 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-05-27 16:17:25 +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
|
|
|
|
(
|
2011-10-12 09:33:31 +00:00
|
|
|
set.name(), // name
|
|
|
|
cellLabels, // addressing
|
|
|
|
sz, // index
|
|
|
|
mesh.cellZones() // pointZoneMesh
|
2010-08-25 21:42:57 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|