57#ifdef HAVE_LIBREADLINE
58 #include <readline/readline.h>
59 #include <readline/history.h>
61 static const char* historyFile =
".setSet";
83 vtk::formatType::INLINE_BASE64,
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
190 polyMesh::meshSubDir/
"sets",
192 IOobject::READ_IF_PRESENT,
195 polyMesh::meshSubDir/
"sets"
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++;
260 mesh.time().findInstance
262 polyMesh::meshSubDir/
"sets",
264 IOobject::READ_IF_PRESENT,
267 polyMesh::meshSubDir/
"sets"
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,
332 / (10*Pstream::nProcs());
345 topoSetSource::actionNames[actionName];
349 case topoSetSource::REMOVE :
351 removeSet(
mesh, setType, setName);
355 case topoSetSource::NEW :
356 case topoSetSource::CLEAR :
358 currentSetPtr = topoSet::New(setType,
mesh, setName, typSize);
362 case topoSetSource::IGNORE :
368 currentSetPtr = topoSet::New
376 topoSet& currentSet = currentSetPtr();
384 topoSet& currentSet = *currentSetPtr;
388 <<
" Action:" << actionName
393 case topoSetSource::CLEAR :
399 case topoSetSource::INVERT :
405 case topoSetSource::LIST :
412 case topoSetSource::SUBSET :
414 if (is >> sourceType)
433 currentSet.
name() +
"_old2",
439 setSource().applyToSet(topoSetSource::NEW, currentSet);
442 currentSet.
subset(oldSet());
449 if (is >> sourceType)
461 setSource().applyToSet(action, currentSet);
466 if (action != topoSetSource::LIST)
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())
528 Pout<< topoSetSource::usage(sourceType).c_str();
537 if (sourceType.size())
539 Pout<< topoSetSource::usage(sourceType).c_str();
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;
574 case polyMesh::UNCHANGED:
576 Info<<
" mesh not changed." <<
endl;
579 case polyMesh::POINTS_MOVED:
581 Info<<
" points moved; topology unchanged." <<
endl;
584 case polyMesh::TOPO_CHANGE:
586 Info<<
" topology changed; patches unchanged." <<
nl
591 case polyMesh::TOPO_PATCH_CHANGE:
593 Info<<
" topology changed and patches changed." <<
nl
602 <<
"Illegal mesh update state "
603 << stat <<
abort(FatalError);
611commandStatus parseType
621 Info<<
"Type 'help' for usage information" <<
endl;
625 else if (setType ==
"help")
631 else if (setType ==
"list")
633 printAllSets(
mesh, Info);
637 else if (setType ==
"time")
639 scalar requestedTime = readScalar(is);
642 label nearestIndex = Time::findClosestTimeIndex(Times, requestedTime);
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)
696 actionName.size() && topoSetSource::actionNames.found(actionName)
697 ? VALIDSETCMD : INVALID
703int main(
int argc,
char *argv[])
707 "Manipulate a cell/face/point Set or Zone interactively."
714 timeSelector::addOptions(
true,
false);
717 argList::addBoolOption(
"noVTK",
"Do not write VTK files");
718 argList::addBoolOption(
"loop",
"Execute batch commands for all timesteps");
723 "Process in batch mode, using input from specified file"
725 argList::addBoolOption
728 "Do not synchronise selection across coupled patches"
738 const bool noSync =
args.
found(
"noSync");
743 <<
"Can only loop in batch mode."
754 printAllSets(
mesh, Info);
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))
793 <<
"Cannot open file " << batchFile <<
exit(FatalError);
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);
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.
label size_type
The type to represent the size of a buffer.
bool found(const Key &key) const
Return true if hashed entry is found in table.
void resize(const label sz)
Resize the hash table for efficiency.
label size() const noexcept
The number of elements in table.
void clear()
Clear all entries from table.
Input from file stream, using an ISstream.
List of IOobjects with searching and retrieving facilities.
UPtrList< const IOobject > sorted() const
The sorted list of IOobjects.
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 newLen)
Same as resize()
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
void reorder(const labelUList &oldToNew, const bool check=false)
label size() const noexcept
The number of elements in the list.
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
void clearAddressing()
Clear addressing.
T get(const label index) const
Get a value from the argument at index.
bool found(const word &optName) const
Return true if the named option is found.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
bool good() const noexcept
True if the managed pointer is non-null.
void reset(autoPtr< T > &&other) 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.
bool throwing() const noexcept
Return the current exception throwing state (on or off)
A class for handling file names.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
label nTotalFaces() const noexcept
Return total number of faces in decomposed mesh. Not.
label nTotalPoints() const noexcept
Return total number of points in decomposed mesh. Not.
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
Mesh consisting of general polyhedral cells.
readUpdateState
Enumeration defining the state of the mesh after a read update.
virtual bool write(const bool valid=true) const
Write using setting from DB.
A class for handling character strings derived from std::string.
setAction
Enumeration defining various actions.
General set of labels of mesh quantity (points, cells, faces).
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
virtual void invert(const label maxLen)
Invert contents.
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 topoSet &set)
Subset contents. Only elements present in both sets remain.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
word outputName("finiteArea-edges.obj")
OBJstream os(runTime.globalPath()/outputName)
Write topoSet in VTK format.
const labelIOList & zoneID
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#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 rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
const fileOperation & fileHandler()
Get current file handler.
void writeVTK(OFstream &os, const Type &value)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
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.