57#ifdef HAVE_LIBREADLINE
58 #include <readline/readline.h>
59 #include <readline/history.h>
61 static const char* historyFile =
".setSet";
91 <<
"Don't know how to handle set of type "
92 << currSet.type() <<
nl;
99 os <<
"Please type 'help', 'list', 'quit', 'time ddd'"
100 <<
" or a set command after prompt." <<
nl
101 <<
"'list' will show all current cell/face/point sets." <<
nl
102 <<
"'time ddd' will change the current time." <<
nl
104 <<
"A set command should be of the following form" <<
nl
106 <<
" cellSet|faceSet|pointSet <setName> <action> <source>"
109 <<
"The <action> is one of" <<
nl
110 <<
" list - prints the contents of the set" <<
nl
111 <<
" clear - clears the set" <<
nl
112 <<
" invert - inverts the set" <<
nl
113 <<
" remove - remove the set" <<
nl
114 <<
" new <source> - use all elements from the source set" <<
nl
115 <<
" add <source> - adds all elements from the source set" <<
nl
116 <<
" subtract <source> - subtract the source set elements" <<
nl
117 <<
" subset <source> - combines current set with the source set"
120 <<
"The sources come in various forms. Type a wrong source"
121 <<
" to see all the types available." <<
nl
123 <<
"Example: pick up all cells connected by point or face to patch"
124 <<
" movingWall" <<
nl
126 <<
"Pick up all faces of patch:" <<
nl
127 <<
" faceSet f0 new patchToFace movingWall" <<
nl
128 <<
"Add faces 0,1,2:" <<
nl
129 <<
" faceSet f0 add labelToFace (0 1 2)" <<
nl
130 <<
"Pick up all points used by faces in faceSet f0:" <<
nl
131 <<
" pointSet p0 new faceToPoint f0 all" <<
nl
132 <<
"Pick up cell which has any face in f0:" <<
nl
133 <<
" cellSet c0 new faceToCell f0 any" <<
nl
134 <<
"Add cells which have any point in p0:" <<
nl
135 <<
" cellSet c0 add pointToCell p0 any" <<
nl
137 <<
" cellSet c0 list" <<
nl
139 <<
"Zones can be set using zoneSets from corresponding sets:" <<
nl
140 <<
" cellZoneSet c0Zone new setToCellZone c0" <<
nl
141 <<
" faceZoneSet f0Zone new setToFaceZone f0" <<
nl
143 <<
"or if orientation is important:" <<
nl
144 <<
" faceZoneSet f0Zone new setsToFaceZone f0 c0" <<
nl
146 <<
"ZoneSets can be manipulated using the general actions:" <<
nl
147 <<
" list - prints the contents of the set" <<
nl
148 <<
" clear - clears the set" <<
nl
149 <<
" invert - inverts the set (undefined orientation)"
151 <<
" remove - remove the set" <<
nl
156template<
class SetType>
164 if (!
n++)
os << SetType::typeName <<
"s:" <<
nl;
165 os <<
'\t' <<
set.name() <<
"\tsize:" <<
set.size() <<
endl;
170template<
class ZoneType>
175 for (
const ZoneType& zn : zones)
177 if (!
n++)
os << ZoneType::typeName <<
"s:" <<
nl;
178 os <<
'\t' << zn.name() <<
"\tsize:" << zn.size() <<
endl;
188 mesh.time().findInstance
198 printSets<cellSet>(
os, objects);
199 printSets<faceSet>(
os, objects);
200 printSets<pointSet>(
os, objects);
202 printZones(
os,
mesh.cellZones());
203 printZones(
os,
mesh.faceZones());
204 printZones(
os,
mesh.pointZones());
210template<
class ZoneType>
221 Info<<
"Removing zone " << setName <<
" at index " << zoneID <<
endl;
229 oldToNew[i] = newI++;
232 oldToNew[zoneID] = newI;
260 mesh.time().findInstance
270 if (objects.
found(setName))
273 fileName object = objects[setName]->objectPath();
274 Info<<
"Removing file " <<
object <<
endl;
279 if (setType == cellZoneSet::typeName)
287 else if (setType == faceZoneSet::typeName)
295 else if (setType == pointZoneSet::typeName)
312 const word& actionName,
313 const bool writeVTKFile,
314 const bool writeCurrentTime,
351 removeSet(
mesh, setType, setName);
376 topoSet& currentSet = currentSetPtr();
384 topoSet& currentSet = *currentSetPtr;
388 <<
" Action:" << actionName
414 if (is >> sourceType)
433 currentSet.
name() +
"_old2",
442 currentSet.
subset(oldSet());
449 if (is >> sourceType)
461 setSource().applyToSet(action, currentSet);
474 Info<<
" Writing " << currentSet.
name()
488 mesh.time().path()/
"VTK"/currentSet.
name()
489 / currentSet.
name() +
"_"
494 Info<<
" and to vtk file "
505 if (writeCurrentTime)
509 if (!currentSet.
write())
512 <<
"Failed writing set "
526 if (sourceType.size())
537 if (sourceType.size())
560 <<
" cells:" <<
mesh.globalData().nTotalCells()
561 <<
" faces:" <<
mesh.globalData().nTotalFaces()
562 <<
" points:" <<
mesh.globalData().nTotalPoints()
563 <<
" patches:" <<
mesh.boundaryMesh().size()
564 <<
" bb:" <<
mesh.bounds() <<
nl;
576 Info<<
" mesh not changed." <<
endl;
581 Info<<
" points moved; topology unchanged." <<
endl;
586 Info<<
" topology changed; patches unchanged." <<
nl
593 Info<<
" topology changed and patches changed." <<
nl
602 <<
"Illegal mesh update state "
611commandStatus parseType
621 Info<<
"Type 'help' for usage information" <<
endl;
625 else if (setType ==
"help")
631 else if (setType ==
"list")
637 else if (setType ==
"time")
639 scalar requestedTime = readScalar(is);
645 <<
" to " << Times[nearestIndex].name()
649 runTime.setTime(Times[nearestIndex], nearestIndex);
651 meshReadUpdate(
mesh);
655 else if (setType ==
"quit")
664 || setType ==
"faceSet"
665 || setType ==
"pointSet"
672 setType ==
"cellZoneSet"
673 || setType ==
"faceZoneSet"
674 || setType ==
"pointZoneSet"
682 <<
"Illegal command " << setType <<
endl
683 <<
"Should be one of 'help', 'list', 'time' or a set type :"
684 <<
" 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'"
692commandStatus parseAction(
const word& actionName)
697 ? VALIDSETCMD : INVALID
703int main(
int argc,
char *argv[])
707 "Manipulate a cell/face/point Set or Zone interactively."
723 "Process in batch mode, using input from specified file"
728 "Do not synchronise selection across coupled patches"
736 const bool loop =
args.found(
"loop");
737 const bool batch =
args.found(
"batch");
738 const bool noSync =
args.found(
"noSync");
743 <<
"Can only loop in batch mode."
757 #ifdef HAVE_LIBREADLINE
758 if (!batch && !read_history((
runTime.path()/historyFile).c_str()))
760 Info<<
"Successfully read history from " << historyFile <<
endl;
771 runTime.setTime(timeDirs[timeI], timeI);
775 meshReadUpdate(
mesh);
787 Info<<
"Reading commands from file " << batchFile <<
endl;
790 if (!
isFile(batchFile,
false))
799 Info<<
"Please type 'help', 'quit' or a set command after prompt."
823 if (!fileStreamPtr->good())
830 fileStreamPtr().getLine(rawLine);
839 #ifdef HAVE_LIBREADLINE
841 char* linePtr = readline(
"readline>");
845 rawLine =
string(linePtr);
849 add_history(linePtr);
850 write_history(historyFile);
862 if (!std::cin.good())
869 std::getline(std::cin, rawLine);
875 string::size_type i = rawLine.find(
'#');
876 if (i != string::npos)
893 if (stat == VALIDSETCMD || stat == VALIDZONECMD)
897 if (is >> actionName)
899 stat = parseAction(actionName);
909 else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
Input/output from string buffers.
bool found(const Key &key) const
Same as contains().
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
label size() const noexcept
The number of elements in table.
void clear()
Remove all entries from table.
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & name() const noexcept
Return the object name.
const fileName & local() const noexcept
Read access to local path component.
const fileName & instance() const noexcept
Read access to instance path component.
fileName objectPath() const
The complete path + object name.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void setSize(const label n)
Same as resize().
static label findClosestTimeIndex(const UList< instant > &timeDirs, const scalar t, const word &constantDirName="constant")
Search instant list for the time index closest to the specified time.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
void reorder(const labelUList &oldToNew, const bool check=false)
Reorder elements. Reordering must be unique (ie, shuffle).
label size() const noexcept
The number of entries in the list.
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
void clearAddressing()
Clear addressing.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
string message() const
The accumulated error message.
A class for handling file names.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
label nTotalFaces() const noexcept
Total global number of mesh faces. Not compensated for duplicate faces!
label nTotalPoints() const noexcept
Total global number of mesh points. Not compensated for duplicate points!
label nTotalCells() const noexcept
Total global number of mesh cells.
Mesh consisting of general polyhedral cells.
readUpdateState
Enumeration defining the state of the mesh after a read update.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
A class for handling character strings derived from std::string.
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options and also set the runTime to the first i...
setAction
Enumeration defining various actions.
@ CLEAR
Clear the set, possibly creating it.
@ SUBSET
Union of elements with current set.
@ LIST
Print contents of the set.
@ REMOVE
Remove the set (from the file system).
@ IGNORE
"ignore" no-op action
@ INVERT
Invert the elements in the current set.
@ NEW
Create a new set and ADD elements to it.
static const string & usage(const word &name)
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
static const Enum< setAction > actionNames
The setActions enum text. Names: "new", add", "subtract", "subset", "invert","clear",...
General set of labels of mesh quantity (points, cells, faces).
virtual void invert(const label maxLen)
Invert contents.
static autoPtr< topoSet > New(const word &setType, const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE)
Return a pointer to a toposet read from file.
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
virtual void subset(const labelUList &elems)
Subset contents. Only elements present in both sets remain.
label writeDebug(Ostream &os, const label maxElem, labelHashSet::const_iterator &iter) const
Write part of contents nicely formatted.
A class for handling words, derived from Foam::string.
static const word null
An empty word.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
word outputName("finiteArea-edges.obj")
OBJstream os(runTime.globalPath()/outputName)
Write topoSet in VTK format.
return returnReduce(nRefine-oldNRefine, sumOp< label >())
#define WarningInFunction
Report a warning using Foam::Warning.
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign 'true').
@ INVALID
Invalid/unknown/error type.
bool writeTopoSet(const polyMesh &mesh, const topoSet &set, const vtk::outputOptions opts, const fileName &file, bool parallel=UPstream::parRun())
Dispatch to vtk::writeCellSetFaces, vtk::writeFaceSet, vtk::writePointSet.
@ INLINE_BASE64
XML inline base64, base64Formatter.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with pointZone content on a polyMesh.
List< label > labelList
A List of labels.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
void writeVTK(OFstream &os, const Type &value)
messageStream Info
Information stream (stdout output on master, null elsewhere).
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with faceZone content on a polyMesh.
List< instant > instantList
List of instants.
Ostream & endl(Ostream &os)
Add newline and flush stream.
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with cellZone content on a polyMesh.
errorManip< error > abort(error &err)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Ostream & flush(Ostream &os)
Flush stream.
constexpr char nl
The newline '\n' character (0x0a).
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.