2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2018-05-29 07:35:20 +00:00
|
|
|
\\ / O peration | Version: 4.1
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / 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
|
2010-09-23 13:04:10 +00:00
|
|
|
Manipulate a cell/face/point set interactively.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#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 "globalMeshData.H"
|
|
|
|
#include "IStringStream.H"
|
|
|
|
#include "cellSet.H"
|
|
|
|
#include "faceSet.H"
|
2010-08-25 21:42:57 +00:00
|
|
|
#include "pointSet.H"
|
|
|
|
#include "topoSetSource.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
#include "OFstream.H"
|
|
|
|
#include "IFstream.H"
|
|
|
|
#include "demandDrivenData.H"
|
|
|
|
#include "writePatch.H"
|
|
|
|
#include "writePointSet.H"
|
|
|
|
#include "IOobjectList.H"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
2019-04-25 10:05:46 +00:00
|
|
|
#if HAS_READLINE
|
2010-09-23 13:04:10 +00:00
|
|
|
#include <readline/readline.h>
|
|
|
|
#include <readline/history.h>
|
2010-05-12 13:27:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
|
2019-04-25 10:05:46 +00:00
|
|
|
#if HAS_READLINE
|
2010-05-12 13:27:55 +00:00
|
|
|
static const char* historyFile = ".setSet";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Istream& selectStream(Istream* is0Ptr, Istream* is1Ptr)
|
|
|
|
{
|
|
|
|
if (is0Ptr)
|
|
|
|
{
|
|
|
|
return *is0Ptr;
|
|
|
|
}
|
|
|
|
else if (is1Ptr)
|
|
|
|
{
|
|
|
|
return *is1Ptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FatalErrorIn("selectStream(Istream*, Istream*)")
|
|
|
|
<< "No valid stream opened" << abort(FatalError);
|
|
|
|
|
|
|
|
return *is0Ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy set
|
|
|
|
void backup
|
|
|
|
(
|
|
|
|
const polyMesh& mesh,
|
|
|
|
const word& fromName,
|
|
|
|
const topoSet& fromSet,
|
|
|
|
const word& toName
|
|
|
|
)
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
if (fromSet.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< " Backing up " << fromName << " into " << toName << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-09-23 13:04:10 +00:00
|
|
|
topoSet::New(mesh, toName, fromSet)().write();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Read and copy set
|
|
|
|
void backup
|
|
|
|
(
|
2010-08-25 21:42:57 +00:00
|
|
|
const word& setType,
|
2010-05-12 13:27:55 +00:00
|
|
|
const polyMesh& mesh,
|
|
|
|
const word& fromName,
|
|
|
|
const word& toName
|
|
|
|
)
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
autoPtr<topoSet> fromSet = topoSet::New
|
|
|
|
(
|
|
|
|
setType,
|
|
|
|
mesh,
|
|
|
|
fromName,
|
|
|
|
IOobject::READ_IF_PRESENT
|
|
|
|
);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-09-23 13:04:10 +00:00
|
|
|
backup(mesh, fromName, fromSet(), toName);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Write set to VTK readable files
|
|
|
|
void writeVTK
|
|
|
|
(
|
|
|
|
const polyMesh& mesh,
|
|
|
|
const topoSet& currentSet,
|
|
|
|
const fileName& vtkName
|
|
|
|
)
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
if (isA<faceSet>(currentSet))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2013-12-11 16:09:41 +00:00
|
|
|
// Faces of set with FOAM faceID as value
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
faceList setFaces(currentSet.size());
|
|
|
|
labelList faceValues(currentSet.size());
|
|
|
|
label setFaceI = 0;
|
|
|
|
|
|
|
|
forAllConstIter(topoSet, currentSet, iter)
|
|
|
|
{
|
|
|
|
setFaces[setFaceI] = mesh.faces()[iter.key()];
|
|
|
|
faceValues[setFaceI] = iter.key();
|
|
|
|
setFaceI++;
|
|
|
|
}
|
|
|
|
|
|
|
|
primitiveFacePatch fp(setFaces, mesh.points());
|
|
|
|
|
|
|
|
writePatch
|
|
|
|
(
|
|
|
|
true,
|
|
|
|
currentSet.name(),
|
|
|
|
fp,
|
|
|
|
"faceID",
|
|
|
|
faceValues,
|
|
|
|
mesh.time().path()/vtkName
|
|
|
|
);
|
|
|
|
}
|
2010-08-25 21:42:57 +00:00
|
|
|
else if (isA<cellSet>(currentSet))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2013-12-11 16:09:41 +00:00
|
|
|
// External faces of cellset with foam cellID as value
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Map<label> cellFaces(currentSet.size());
|
|
|
|
|
|
|
|
forAllConstIter(cellSet, currentSet, iter)
|
|
|
|
{
|
|
|
|
label cellI = iter.key();
|
|
|
|
|
|
|
|
const cell& cFaces = mesh.cells()[cellI];
|
|
|
|
|
|
|
|
forAll(cFaces, i)
|
|
|
|
{
|
|
|
|
label faceI = cFaces[i];
|
|
|
|
|
|
|
|
if (mesh.isInternalFace(faceI))
|
|
|
|
{
|
|
|
|
label otherCellI = mesh.faceOwner()[faceI];
|
|
|
|
|
|
|
|
if (otherCellI == cellI)
|
|
|
|
{
|
|
|
|
otherCellI = mesh.faceNeighbour()[faceI];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!currentSet.found(otherCellI))
|
|
|
|
{
|
|
|
|
cellFaces.insert(faceI, cellI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cellFaces.insert(faceI, cellI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
faceList setFaces(cellFaces.size());
|
|
|
|
labelList faceValues(cellFaces.size());
|
|
|
|
label setFaceI = 0;
|
|
|
|
|
|
|
|
forAllConstIter(Map<label>, cellFaces, iter)
|
|
|
|
{
|
|
|
|
setFaces[setFaceI] = mesh.faces()[iter.key()];
|
|
|
|
faceValues[setFaceI] = iter(); // Cell ID
|
|
|
|
setFaceI++;
|
|
|
|
}
|
|
|
|
|
|
|
|
primitiveFacePatch fp(setFaces, mesh.points());
|
|
|
|
|
|
|
|
writePatch
|
|
|
|
(
|
|
|
|
true,
|
|
|
|
currentSet.name(),
|
|
|
|
fp,
|
|
|
|
"cellID",
|
|
|
|
faceValues,
|
|
|
|
mesh.time().path()/vtkName
|
|
|
|
);
|
|
|
|
}
|
2010-08-25 21:42:57 +00:00
|
|
|
else if (isA<pointSet>(currentSet))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
writePointSet
|
|
|
|
(
|
|
|
|
true,
|
|
|
|
mesh,
|
|
|
|
currentSet,
|
|
|
|
mesh.time().path()/vtkName
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WarningIn
|
|
|
|
(
|
|
|
|
"void writeVTK"
|
|
|
|
"(const polyMesh& mesh, const topoSet& currentSet,"
|
|
|
|
"const fileName& vtkName)"
|
|
|
|
) << "Don't know how to handle set of type " << currentSet.type()
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void printHelp(Ostream& os)
|
|
|
|
{
|
|
|
|
os << "Please type 'help', 'list', 'quit', 'time ddd'"
|
|
|
|
<< " or a set command after prompt." << endl
|
|
|
|
<< "'list' will show all current cell/face/point sets." << endl
|
|
|
|
<< "'time ddd' will change the current time." << endl
|
|
|
|
<< endl
|
|
|
|
<< "A set command should be of the following form" << endl
|
|
|
|
<< endl
|
|
|
|
<< " cellSet|faceSet|pointSet <setName> <action> <source>"
|
2010-09-23 13:04:10 +00:00
|
|
|
<< endl << endl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< "The <action> is one of" << endl
|
|
|
|
<< " list - prints the contents of the set" << endl
|
|
|
|
<< " clear - clears the set" << endl
|
|
|
|
<< " invert - inverts the set" << endl
|
2010-08-25 21:42:57 +00:00
|
|
|
<< " remove - remove the set" << endl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " new <source> - sets to set to the source set" << endl
|
|
|
|
<< " add <source> - adds all elements from the source set" << endl
|
|
|
|
<< " delete <source> - deletes ,," << endl
|
|
|
|
<< " subset <source> - combines current set with the source set"
|
|
|
|
<< endl
|
|
|
|
<< endl
|
|
|
|
<< "The sources come in various forms. Type a wrong source"
|
|
|
|
<< " to see all the types available." << endl
|
|
|
|
<< endl
|
|
|
|
<< "Example: pick up all cells connected by point or face to patch"
|
|
|
|
<< " movingWall" << endl
|
|
|
|
<< endl
|
|
|
|
<< "Pick up all faces of patch:" << endl
|
|
|
|
<< " faceSet f0 new patchToFace movingWall" << endl
|
|
|
|
<< "Add faces 0,1,2:" << endl
|
|
|
|
<< " faceSet f0 add labelToFace (0 1 2)" << endl
|
|
|
|
<< "Pick up all points used by faces in faceSet f0:" << endl
|
|
|
|
<< " pointSet p0 new faceToPoint f0 all" << endl
|
|
|
|
<< "Pick up cell which has any face in f0:" << endl
|
|
|
|
<< " cellSet c0 new faceToCell f0 any" << endl
|
|
|
|
<< "Add cells which have any point in p0:" << endl
|
|
|
|
<< " cellSet c0 add pointToCell p0 any" << endl
|
|
|
|
<< "List set:" << endl
|
|
|
|
<< " cellSet c0 list" << endl
|
2010-08-25 21:42:57 +00:00
|
|
|
<< endl
|
|
|
|
<< " remove - remove the set" << endl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void printAllSets(const polyMesh& mesh, Ostream& os)
|
|
|
|
{
|
|
|
|
IOobjectList objects
|
|
|
|
(
|
|
|
|
mesh,
|
|
|
|
mesh.pointsInstance(),
|
|
|
|
polyMesh::meshSubDir/"sets"
|
|
|
|
);
|
|
|
|
IOobjectList cellSets(objects.lookupClass(cellSet::typeName));
|
2010-08-25 21:42:57 +00:00
|
|
|
if (cellSets.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
os << "cellSets:" << endl;
|
|
|
|
forAllConstIter(IOobjectList, cellSets, iter)
|
|
|
|
{
|
|
|
|
cellSet set(*iter());
|
|
|
|
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IOobjectList faceSets(objects.lookupClass(faceSet::typeName));
|
2010-08-25 21:42:57 +00:00
|
|
|
if (faceSets.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
os << "faceSets:" << endl;
|
|
|
|
forAllConstIter(IOobjectList, faceSets, iter)
|
|
|
|
{
|
|
|
|
faceSet set(*iter());
|
|
|
|
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
|
2010-08-25 21:42:57 +00:00
|
|
|
if (pointSets.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
os << "pointSets:" << endl;
|
|
|
|
forAllConstIter(IOobjectList, pointSets, iter)
|
|
|
|
{
|
|
|
|
pointSet set(*iter());
|
|
|
|
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
// Physically remove a set
|
2016-02-10 17:50:02 +00:00
|
|
|
bool removeSet
|
2010-08-25 21:42:57 +00:00
|
|
|
(
|
|
|
|
const polyMesh& mesh,
|
|
|
|
const word& setType,
|
|
|
|
const word& setName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Remove the file
|
|
|
|
IOobjectList objects
|
|
|
|
(
|
|
|
|
mesh,
|
|
|
|
mesh.pointsInstance(),
|
|
|
|
polyMesh::meshSubDir/"sets"
|
|
|
|
);
|
|
|
|
|
|
|
|
if (objects.found(setName))
|
|
|
|
{
|
|
|
|
// Remove file
|
|
|
|
fileName object = objects[setName]->objectPath();
|
|
|
|
Info<< "Removing file " << object << endl;
|
|
|
|
rm(object);
|
2016-02-10 17:50:02 +00:00
|
|
|
|
|
|
|
return true;
|
2010-08-25 21:42:57 +00:00
|
|
|
}
|
2016-02-10 17:50:02 +00:00
|
|
|
|
|
|
|
return false;
|
2010-08-25 21:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
// Read command and execute. Return true if ok, false otherwise.
|
|
|
|
bool doCommand
|
|
|
|
(
|
|
|
|
const polyMesh& mesh,
|
|
|
|
const word& setType,
|
|
|
|
const word& setName,
|
|
|
|
const word& actionName,
|
|
|
|
const bool writeVTKFile,
|
|
|
|
Istream& is
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Get some size estimate for set.
|
|
|
|
const globalMeshData& parData = mesh.globalData();
|
|
|
|
|
|
|
|
label typSize =
|
|
|
|
max
|
|
|
|
(
|
|
|
|
parData.nTotalCells(),
|
|
|
|
max
|
|
|
|
(
|
|
|
|
parData.nTotalFaces(),
|
|
|
|
parData.nTotalPoints()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
/ (10*Pstream::nProcs());
|
|
|
|
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
// Set to work on
|
2010-08-25 21:42:57 +00:00
|
|
|
autoPtr<topoSet> currentSetPtr;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
word sourceType;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
topoSetSource::setAction action =
|
|
|
|
topoSetSource::toAction(actionName);
|
|
|
|
|
|
|
|
|
|
|
|
IOobject::readOption r;
|
|
|
|
|
2016-02-10 17:50:02 +00:00
|
|
|
if
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
|
|
|
(action == topoSetSource::NEW)
|
|
|
|
|| (action == topoSetSource::CLEAR)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
r = IOobject::NO_READ;
|
|
|
|
currentSetPtr = topoSet::New(setType, mesh, setName, typSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = IOobject::MUST_READ;
|
|
|
|
currentSetPtr = topoSet::New(setType, mesh, setName, r);
|
|
|
|
topoSet& currentSet = currentSetPtr();
|
|
|
|
// Presize it according to current mesh data.
|
|
|
|
currentSet.resize(max(currentSet.size(), typSize));
|
|
|
|
}
|
|
|
|
|
2016-02-10 17:50:02 +00:00
|
|
|
if (action == topoSetSource::REMOVE)
|
|
|
|
{
|
|
|
|
ok = removeSet(mesh, setType, setName);
|
|
|
|
}
|
|
|
|
else if (!currentSetPtr.valid())
|
2010-09-23 13:04:10 +00:00
|
|
|
{
|
|
|
|
Info<< " Cannot construct/load set "
|
|
|
|
<< topoSet::localPath(mesh, setName) << endl;
|
|
|
|
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
else
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
topoSet& currentSet = currentSetPtr();
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< " Set:" << currentSet.name()
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " Size:" << currentSet.size()
|
|
|
|
<< " Action:" << actionName
|
|
|
|
<< endl;
|
|
|
|
|
2010-09-23 13:04:10 +00:00
|
|
|
if ((r == IOobject::MUST_READ) && (action != topoSetSource::LIST))
|
|
|
|
{
|
|
|
|
// currentSet has been read so can make copy.
|
|
|
|
backup(mesh, setName, currentSet, setName + "_old");
|
|
|
|
}
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case topoSetSource::CLEAR:
|
|
|
|
{
|
|
|
|
// Already handled above by not reading
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case topoSetSource::INVERT:
|
|
|
|
{
|
|
|
|
currentSet.invert(currentSet.maxSize(mesh));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case topoSetSource::LIST:
|
|
|
|
{
|
|
|
|
currentSet.writeDebug(Pout, mesh, 100);
|
|
|
|
Pout<< endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case topoSetSource::SUBSET:
|
|
|
|
{
|
|
|
|
if (is >> sourceType)
|
|
|
|
{
|
|
|
|
autoPtr<topoSetSource> setSource
|
|
|
|
(
|
|
|
|
topoSetSource::New
|
|
|
|
(
|
|
|
|
sourceType,
|
|
|
|
mesh,
|
|
|
|
is
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Backup current set.
|
2010-08-25 21:42:57 +00:00
|
|
|
autoPtr<topoSet> oldSet
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
2010-08-25 21:42:57 +00:00
|
|
|
topoSet::New
|
|
|
|
(
|
|
|
|
mesh,
|
|
|
|
currentSet.name() + "_old2",
|
|
|
|
currentSet
|
|
|
|
)
|
2010-05-12 13:27:55 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
currentSet.clear();
|
|
|
|
setSource().applyToSet(topoSetSource::NEW, currentSet);
|
|
|
|
|
|
|
|
// Combine new value of currentSet with old one.
|
|
|
|
currentSet.subset(oldSet);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if (is >> sourceType)
|
|
|
|
{
|
|
|
|
autoPtr<topoSetSource> setSource
|
|
|
|
(
|
|
|
|
topoSetSource::New
|
|
|
|
(
|
|
|
|
sourceType,
|
|
|
|
mesh,
|
|
|
|
is
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
setSource().applyToSet(action, currentSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (action != topoSetSource::LIST)
|
|
|
|
{
|
|
|
|
// Set will have been modified.
|
|
|
|
|
|
|
|
// Synchronize for coupled patches.
|
|
|
|
currentSet.sync(mesh);
|
|
|
|
|
|
|
|
// Write
|
|
|
|
if (writeVTKFile)
|
|
|
|
{
|
|
|
|
mkDir(mesh.time().path()/"VTK"/currentSet.name());
|
|
|
|
|
|
|
|
fileName vtkName
|
|
|
|
(
|
|
|
|
"VTK"/currentSet.name()/currentSet.name()
|
|
|
|
+ "_"
|
|
|
|
+ name(mesh.time().timeIndex())
|
|
|
|
+ ".vtk"
|
|
|
|
);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< " Writing " << currentSet.name()
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " (size " << currentSet.size() << ") to "
|
|
|
|
<< currentSet.instance()/currentSet.local()
|
|
|
|
/currentSet.name()
|
|
|
|
<< " and to vtk file " << vtkName << endl << endl;
|
|
|
|
|
|
|
|
currentSet.write();
|
|
|
|
|
|
|
|
writeVTK(mesh, currentSet, vtkName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< " Writing " << currentSet.name()
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " (size " << currentSet.size() << ") to "
|
|
|
|
<< currentSet.instance()/currentSet.local()
|
|
|
|
/currentSet.name() << endl << endl;
|
|
|
|
|
|
|
|
currentSet.write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Foam::IOerror& fIOErr)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
|
|
|
|
Pout<< fIOErr.message().c_str() << endl;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (sourceType.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
Pout<< topoSetSource::usage(sourceType).c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Foam::error& fErr)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
|
|
|
|
Pout<< fErr.message().c_str() << endl;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (sourceType.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
Pout<< topoSetSource::usage(sourceType).c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Status returned from parsing the first token of the line
|
|
|
|
enum commandStatus
|
|
|
|
{
|
|
|
|
QUIT, // quit program
|
|
|
|
INVALID, // token is not a valid set manipulation command
|
2010-08-25 21:42:57 +00:00
|
|
|
VALIDSETCMD, // ,, is a valid ,,
|
|
|
|
VALIDZONECMD // ,, is a valid zone ,,
|
2010-05-12 13:27:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void printMesh(const Time& runTime, const polyMesh& mesh)
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Time:" << runTime.timeName()
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " cells:" << mesh.nCells()
|
|
|
|
<< " faces:" << mesh.nFaces()
|
|
|
|
<< " points:" << mesh.nPoints()
|
2010-08-25 21:42:57 +00:00
|
|
|
<< " patches:" << mesh.boundaryMesh().size()
|
|
|
|
<< " bb:" << mesh.bounds() << nl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commandStatus parseType
|
|
|
|
(
|
|
|
|
Time& runTime,
|
|
|
|
polyMesh& mesh,
|
|
|
|
const word& setType,
|
|
|
|
IStringStream& is
|
|
|
|
)
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
if (setType.empty())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Type 'help' for usage information" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
else if (setType == "help")
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
printHelp(Info);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
else if (setType == "list")
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
printAllSets(mesh, Info);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
else if (setType == "time")
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
scalar requestedTime = readScalar(is);
|
2010-05-12 13:27:55 +00:00
|
|
|
instantList Times = runTime.times();
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
label nearestIndex = Time::findClosestTimeIndex(Times, requestedTime);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Changing time from " << runTime.timeName()
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " to " << Times[nearestIndex].name()
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
runTime.setTime(Times[nearestIndex], nearestIndex);
|
|
|
|
polyMesh::readUpdateState stat = mesh.readUpdate();
|
|
|
|
|
|
|
|
switch(stat)
|
|
|
|
{
|
|
|
|
case polyMesh::UNCHANGED:
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< " mesh not changed." << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case polyMesh::POINTS_MOVED:
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< " points moved; topology unchanged." << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case polyMesh::TOPO_CHANGE:
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< " topology changed; patches unchanged." << nl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " ";
|
|
|
|
printMesh(runTime, mesh);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case polyMesh::TOPO_PATCH_CHANGE:
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< " topology changed and patches changed." << nl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " ";
|
|
|
|
printMesh(runTime, mesh);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
FatalErrorIn("parseType")
|
|
|
|
<< "Illegal mesh update state "
|
2010-05-12 13:27:55 +00:00
|
|
|
<< stat << abort(FatalError);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
else if (setType == "quit")
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Quitting ..." << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
return QUIT;
|
|
|
|
}
|
|
|
|
else if
|
|
|
|
(
|
|
|
|
setType == "cellSet"
|
|
|
|
|| setType == "faceSet"
|
|
|
|
|| setType == "pointSet"
|
|
|
|
)
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
return VALIDSETCMD;
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SeriousErrorIn
|
|
|
|
(
|
|
|
|
"commandStatus parseType(Time&, polyMesh&, const word&"
|
|
|
|
", IStringStream&)"
|
|
|
|
) << "Illegal command " << setType << endl
|
|
|
|
<< "Should be one of 'help', 'list', 'time' or a set type :"
|
2010-09-23 13:04:10 +00:00
|
|
|
<< " 'cellSet', 'faceSet', 'pointSet'"
|
2010-05-12 13:27:55 +00:00
|
|
|
<< endl;
|
|
|
|
|
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
commandStatus parseAction(const word& actionName)
|
|
|
|
{
|
|
|
|
commandStatus stat = INVALID;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (actionName.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
(void)topoSetSource::toAction(actionName);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
stat = VALIDSETCMD;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
catch (Foam::IOerror& fIOErr)
|
|
|
|
{
|
|
|
|
stat = INVALID;
|
|
|
|
}
|
|
|
|
catch (Foam::error& fErr)
|
|
|
|
{
|
|
|
|
stat = INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Main program:
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
# include "addRegionOption.H"
|
|
|
|
# include "addTimeOptions.H"
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
argList::validOptions.insert("noVTK", "");
|
|
|
|
argList::validOptions.insert("batch", "file");
|
|
|
|
|
|
|
|
# include "setRootCase.H"
|
|
|
|
# include "createTime.H"
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
bool writeVTK = !args.optionFound("noVTK");
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// Get times list
|
|
|
|
instantList Times = runTime.times();
|
|
|
|
|
|
|
|
# include "checkTimeOptions.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
|
|
|
|
|
|
|
// Print some mesh info
|
|
|
|
printMesh(runTime, mesh);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
// Print current sets
|
|
|
|
printAllSets(mesh, Info);
|
|
|
|
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2019-01-25 16:22:44 +00:00
|
|
|
std::ifstream* fileStreamPtr(nullptr);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (args.optionFound("batch"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
fileName batchFile(args.option("batch"));
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Reading commands from file " << batchFile << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
// we cannot handle .gz files
|
|
|
|
if (!isFile(batchFile, false))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "Cannot open file " << batchFile << exit(FatalError);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileStreamPtr = new std::ifstream(batchFile.c_str());
|
|
|
|
}
|
2019-04-25 10:05:46 +00:00
|
|
|
#if HAS_READLINE
|
2010-05-12 13:27:55 +00:00
|
|
|
else if (!read_history(historyFile))
|
|
|
|
{
|
|
|
|
Info<< "Successfully read history from " << historyFile << endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Please type 'help', 'quit' or a set command after prompt." << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
FatalError.throwExceptions();
|
|
|
|
FatalIOError.throwExceptions();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
string rawLine;
|
|
|
|
|
|
|
|
// Type: cellSet, faceSet, pointSet
|
|
|
|
word setType;
|
|
|
|
// Name of destination set.
|
|
|
|
word setName;
|
|
|
|
// Action (new, invert etc.)
|
|
|
|
word actionName;
|
|
|
|
|
|
|
|
commandStatus stat = INVALID;
|
|
|
|
|
|
|
|
if (fileStreamPtr)
|
|
|
|
{
|
|
|
|
if (!fileStreamPtr->good())
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "End of batch file" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::getline(*fileStreamPtr, rawLine);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (rawLine.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Doing:" << rawLine << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-25 10:05:46 +00:00
|
|
|
# if HAS_READLINE
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
char* linePtr = readline("readline>");
|
|
|
|
|
|
|
|
rawLine = string(linePtr);
|
|
|
|
|
|
|
|
if (*linePtr)
|
|
|
|
{
|
|
|
|
add_history(linePtr);
|
|
|
|
write_history(historyFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(linePtr); // readline uses malloc, not new.
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Command>" << flush;
|
2010-05-12 13:27:55 +00:00
|
|
|
std::getline(std::cin, rawLine);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (rawLine.empty() || rawLine[0] == '#')
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
IStringStream is(rawLine + ' ');
|
|
|
|
|
2010-09-23 13:04:10 +00:00
|
|
|
// Type: cellSet, faceSet, pointSet
|
2010-05-12 13:27:55 +00:00
|
|
|
is >> setType;
|
|
|
|
|
|
|
|
stat = parseType(runTime, mesh, setType, is);
|
|
|
|
|
2010-09-23 13:04:10 +00:00
|
|
|
if (stat == VALIDSETCMD)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
if (is >> setName)
|
|
|
|
{
|
|
|
|
if (is >> actionName)
|
|
|
|
{
|
|
|
|
stat = parseAction(actionName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok = true;
|
|
|
|
|
|
|
|
if (stat == QUIT)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2010-09-23 13:04:10 +00:00
|
|
|
else if (stat == VALIDSETCMD)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
ok = doCommand(mesh, setType, setName, actionName, writeVTK, is);
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (ok);
|
|
|
|
|
|
|
|
|
|
|
|
if (fileStreamPtr)
|
|
|
|
{
|
|
|
|
delete fileStreamPtr;
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "\nEnd\n" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2016-09-05 11:50:12 +00:00
|
|
|
return !ok;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|