Go to the documentation of this file.
58 #ifdef HAVE_LIBREADLINE
59 #include <readline/readline.h>
60 #include <readline/history.h>
62 static const char* historyFile =
".setSet";
92 <<
"Don't know how to handle set of type "
93 << currSet.type() <<
nl;
100 os <<
"Please type 'help', 'list', 'quit', 'time ddd'"
101 <<
" or a set command after prompt." <<
nl
102 <<
"'list' will show all current cell/face/point sets." <<
nl
103 <<
"'time ddd' will change the current time." <<
nl
105 <<
"A set command should be of the following form" <<
nl
107 <<
" cellSet|faceSet|pointSet <setName> <action> <source>"
110 <<
"The <action> is one of" <<
nl
111 <<
" list - prints the contents of the set" <<
nl
112 <<
" clear - clears the set" <<
nl
113 <<
" invert - inverts the set" <<
nl
114 <<
" remove - remove the set" <<
nl
115 <<
" new <source> - use all elements from the source set" <<
nl
116 <<
" add <source> - adds all elements from the source set" <<
nl
117 <<
" subtract <source> - subtract the source set elements" <<
nl
118 <<
" subset <source> - combines current set with the source set"
121 <<
"The sources come in various forms. Type a wrong source"
122 <<
" to see all the types available." <<
nl
124 <<
"Example: pick up all cells connected by point or face to patch"
125 <<
" movingWall" <<
nl
127 <<
"Pick up all faces of patch:" <<
nl
128 <<
" faceSet f0 new patchToFace movingWall" <<
nl
129 <<
"Add faces 0,1,2:" <<
nl
130 <<
" faceSet f0 add labelToFace (0 1 2)" <<
nl
131 <<
"Pick up all points used by faces in faceSet f0:" <<
nl
132 <<
" pointSet p0 new faceToPoint f0 all" <<
nl
133 <<
"Pick up cell which has any face in f0:" <<
nl
134 <<
" cellSet c0 new faceToCell f0 any" <<
nl
135 <<
"Add cells which have any point in p0:" <<
nl
136 <<
" cellSet c0 add pointToCell p0 any" <<
nl
138 <<
" cellSet c0 list" <<
nl
140 <<
"Zones can be set using zoneSets from corresponding sets:" <<
nl
141 <<
" cellZoneSet c0Zone new setToCellZone c0" <<
nl
142 <<
" faceZoneSet f0Zone new setToFaceZone f0" <<
nl
144 <<
"or if orientation is important:" <<
nl
145 <<
" faceZoneSet f0Zone new setsToFaceZone f0 c0" <<
nl
147 <<
"ZoneSets can be manipulated using the general actions:" <<
nl
148 <<
" list - prints the contents of the set" <<
nl
149 <<
" clear - clears the set" <<
nl
150 <<
" invert - inverts the set (undefined orientation)"
152 <<
" remove - remove the set" <<
nl
171 IOobjectList cellSets(objects.lookupClass(cellSet::typeName));
174 os <<
"cellSets:" <<
endl;
178 os <<
'\t' << set.
name() <<
"\tsize:" << set.size() <<
endl;
181 IOobjectList faceSets(objects.lookupClass(faceSet::typeName));
184 os <<
"faceSets:" <<
endl;
188 os <<
'\t' << set.
name() <<
"\tsize:" << set.size() <<
endl;
191 IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
192 if (pointSets.size())
194 os <<
"pointSets:" <<
endl;
198 os <<
'\t' << set.
name() <<
"\tsize:" << set.size() <<
endl;
203 if (cellZones.size())
205 os <<
"cellZones:" <<
endl;
212 if (faceZones.size())
214 os <<
"faceZones:" <<
endl;
221 if (pointZones.size())
223 os <<
"pointZones:" <<
endl;
234 template<
class ZoneType>
245 Info<<
"Removing zone " << setName <<
" at index " <<
zoneID <<
endl;
253 oldToNew[i] = newI++;
257 zones.reorder(oldToNew);
259 zones.setSize(zones.size()-1);
294 if (objects.found(setName))
297 fileName object = objects[setName]->objectPath();
298 Info<<
"Removing file " <<
object <<
endl;
303 if (setType == cellZoneSet::typeName)
311 else if (setType == faceZoneSet::typeName)
319 else if (setType == pointZoneSet::typeName)
336 const word& actionName,
337 const bool writeVTKFile,
338 const bool writeCurrentTime,
376 removeSet(
mesh, setType, setName);
391 topoSet& currentSet = currentSetPtr();
396 if (currentSetPtr.
valid())
398 topoSet& currentSet = currentSetPtr();
402 <<
" Action:" << actionName
425 if (is >> sourceType)
444 currentSet.
name() +
"_old2",
453 currentSet.
subset(oldSet());
459 if (is >> sourceType)
471 setSource().applyToSet(action, currentSet);
485 Info<<
" Writing " << currentSet.
name()
500 / currentSet.
name() +
"_"
505 Info<<
" and to vtk file "
516 if (writeCurrentTime)
520 if (!currentSet.
write())
523 <<
"Failed writing set "
537 if (sourceType.size())
548 if (sourceType.size())
587 Info<<
" mesh not changed." <<
endl;
592 Info<<
" points moved; topology unchanged." <<
endl;
597 Info<<
" topology changed; patches unchanged." <<
nl
604 Info<<
" topology changed and patches changed." <<
nl
613 <<
"Illegal mesh update state "
622 commandStatus parseType
632 Info<<
"Type 'help' for usage information" <<
endl;
636 else if (setType ==
"help")
642 else if (setType ==
"list")
648 else if (setType ==
"time")
650 scalar requestedTime = readScalar(is);
656 <<
" to " << Times[nearestIndex].name()
662 meshReadUpdate(
mesh);
666 else if (setType ==
"quit")
675 || setType ==
"faceSet"
676 || setType ==
"pointSet"
683 setType ==
"cellZoneSet"
684 || setType ==
"faceZoneSet"
685 || setType ==
"pointZoneSet"
693 <<
"Illegal command " << setType <<
endl
694 <<
"Should be one of 'help', 'list', 'time' or a set type :"
695 <<
" 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'"
703 commandStatus parseAction(
const word& actionName)
708 ? VALIDSETCMD : INVALID
714 int main(
int argc,
char *argv[])
718 "Manipulate a cell/face/point Set or Zone interactively."
734 "Process in batch mode, using input from specified file"
739 "Do not synchronise selection across coupled patches"
749 const bool noSync =
args.
found(
"noSync");
754 <<
"Can only loop in batch mode."
768 #ifdef HAVE_LIBREADLINE
769 if (!batch && !read_history((
runTime.
path()/historyFile).c_str()))
771 Info<<
"Successfully read history from " << historyFile <<
endl;
786 meshReadUpdate(
mesh);
798 Info<<
"Reading commands from file " << batchFile <<
endl;
801 if (!
isFile(batchFile,
false))
810 Info<<
"Please type 'help', 'quit' or a set command after prompt."
830 commandStatus stat = INVALID;
832 if (fileStreamPtr.
valid())
834 if (!fileStreamPtr().good())
841 fileStreamPtr().getLine(rawLine);
850 #ifdef HAVE_LIBREADLINE
852 char* linePtr = readline(
"readline>");
856 rawLine =
string(linePtr);
860 add_history(linePtr);
861 write_history(historyFile);
873 if (!std::cin.good())
880 std::getline(std::cin, rawLine);
887 if (i != string::npos)
904 if (stat == VALIDSETCMD || stat == VALIDZONECMD)
908 if (is >> actionName)
910 stat = parseAction(actionName);
920 else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
static label findClosestTimeIndex(const instantList &timeDirs, const scalar t, const word &constantName="constant")
Search instantList for the time index closest to the specified time.
label size() const noexcept
The number of elements in table.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Clear the set, possibly creating it.
const word & name() const
Return name.
A class for handling words, derived from Foam::string.
A class for handling file names.
bool found(const word &enumName) const
Test if there is an enumeration corresponding to the given name.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
static std::string path(const std::string &str)
Return directory path name (part before last /)
Input from file stream, using an ISstream.
Template functions to aid in the implementation of demand driven data.
const fileName & instance() const
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static const string & usage(const word &name)
label nTotalPoints() const
Return total number of points in decomposed mesh. Not.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
static word timeName(const scalar t, const int precision=precision_)
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
label nTotalCells() const
Return total number of cells in decomposed mesh.
Base class for mesh zones.
static void addNote(const string ¬e)
Add extra notes for the usage information.
const fileName & facesInstance() const
Return the current instance directory for faces.
const cellZoneMesh & cellZones() const
Return cell zone mesh.
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
Input/output from string buffers.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
const fileOperation & fileHandler()
Get current file handler.
bool valid() const noexcept
True if the managed pointer is non-null.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Ostream & endl(Ostream &os)
Add newline and flush stream.
setAction
Enumeration defining the valid actions.
label nTotalFaces() const
Return total number of faces in decomposed mesh. Not.
A class for handling character strings derived from std::string.
static autoPtr< topoSet > New(const word &setType, const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Return a pointer to a toposet read from file.
Create a new set and ADD elements to it.
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
fileName relative(const fileName &parent, const bool caseTag=false) const
virtual void invert(const label maxLen)
Invert contents.
Mesh consisting of general polyhedral cells.
#define forAll(list, i)
Loop across all elements in list.
void writeVTK(OFstream &os, const Type &value)
const faceZoneMesh & faceZones() const
Return face zone mesh.
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Ostream & flush(Ostream &os)
Flush stream.
const fileName & local() const
bool writeTopoSet(const polyMesh &mesh, const topoSet &set, const vtk::outputOptions opts, const fileName &file, bool parallel=Pstream::parRun())
Dispatch to vtk::writeCellSetFaces, vtk::writeFaceSet, vtk::writePointSet.
virtual bool write(const bool valid=true) const
Write using setting from DB.
A subset of mesh faces organised as a primitive patch.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
messageStream Info
Information stream (uses stdout - output is on the master only)
const pointZoneMesh & pointZones() const
Return point zone mesh.
word name(const complex &c)
Return string representation of complex.
instantList times() const
Search the case for valid time directories.
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
void resize(const label sz)
Resize the hash table for efficiency.
virtual const fileName & name() const
Return the name of the stream.
graph_traits< Graph >::vertices_size_type size_type
General set of labels of mesh quantity (points, cells, faces).
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Subset with elements in the set.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
XML inline base64, base64Formatter.
const labelIOList & zoneID
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
string message() const
The accumulated error message.
Input from string buffer, using a ISstream.
errorManip< error > abort(error &err)
const word & name() const
Return name.
A collection of cell labels.
label findZoneID(const word &zoneName) const
Find zone index given a name, return -1 if not found.
List of IOobjects with searching and retrieving facilities.
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
errorManipArg< error, int > exit(error &err, const int errNo=1)
readUpdateState
Enumeration defining the state of the mesh after a read update.
const boundBox & bounds() const
Return mesh bounding box.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Print contents of the set.
fileName path() const
Return path.
forAllConstIters(mixture.phases(), phase)
Input/output from file streams.
void clear()
Clear all entries from table.
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Remove the set (from the file system)
static const word null
An empty word.
Invert the elements in the set.
const Time & time() const
Return the top-level database.
Write topoSet in VTK format.
readOption
Enumeration defining the read options.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void clearAddressing()
Clear addressing.
const globalMeshData & globalData() const
Return parallel info.
label timeIndex() const
Return current time index.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
fileName objectPath() const
The complete path + object name.
static instantList select0(Time &runTime, const argList &args)
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Foam::argList args(argc, argv)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
bool throwExceptions(bool doThrow)
Activate/deactivate exception throwing.
#define WarningInFunction
Report a warning using Foam::Warning.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
bool found(const word &optName) const
Return true if the named option is found.
static const Enum< setAction > actionNames
The setActions text representations.