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 156 template<
class SetType>
164 if (!
n++)
os << SetType::typeName <<
"s:" <<
nl;
165 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
170 template<
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;
198 printSets<cellSet>(
os, objects);
199 printSets<faceSet>(
os, objects);
200 printSets<pointSet>(
os, objects);
210 template<
class ZoneType>
221 Info<<
"Removing zone " << setName <<
" at index " << zoneID <<
endl;
229 oldToNew[i] = newI++;
232 oldToNew[zoneID] = newI;
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()
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())
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 " 611 commandStatus 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()
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'" 692 commandStatus parseAction(
const word& actionName)
703 int 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" 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;
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);
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)
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
static void addNote(const string ¬e)
Add extra notes for the usage information.
void clearAddressing()
Clear addressing.
fileName path() const
Return path = rootPath/caseName. Same as TimePaths::path()
static const Enum< setAction > actionNames
The setActions enum text. Names: "new", add", "subtract", "subset", "invert", "clear", "remove", "list", "ignore".
A class for handling file names.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static const string & usage(const word &name)
const fileName & facesInstance() const
Return the current instance directory for faces.
word findInstance(const fileName &dir, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null) const
Return time instance (location) of dir that contains the file name (eg, used in reading mesh data)...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Input/output from string buffers.
bool found(const Key &key) const
Same as contains()
bool found(const word &key) const
Same as contains()
virtual const fileName & name() const override
Read/write access to the name of the stream.
const word & name() const noexcept
Return the object name.
Create a new set and ADD elements to it.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
bool throwing() const noexcept
Return the current exception throwing state (on or off)
Clear the set, possibly creating it.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reorder(const labelUList &oldToNew, const bool check=false)
Reorder elements. Reordering must be unique (ie, shuffle).
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
Invert the elements in the current set.
Remove the set (from the file system)
const Time & time() const
Return the top-level database.
Print contents of the set.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
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.
fileName objectPath() const
The complete path + object name.
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
label nTotalPoints() const noexcept
Return total number of points in decomposed mesh. Not compensated for duplicate points! ...
#define forAll(list, i)
Loop across all elements in list.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Invalid/unknown/error type.
label size() const noexcept
The number of elements in table.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
word outputName("finiteArea-edges.obj")
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
A class for handling words, derived from Foam::string.
void clear()
Remove all entries from table.
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
label size() const noexcept
The number of entries in the list.
string message() const
The accumulated error message.
Union of elements with current set.
setAction
Enumeration defining various actions.
Reading is optional [identical to LAZY_READ].
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
Write topoSet in VTK format.
static const word null
An empty word.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
const globalMeshData & globalData() const
Return parallel info (demand-driven)
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
label timeIndex() const noexcept
Return the current time index.
static label findClosestTimeIndex(const instantList &timeDirs, const scalar t, const word &constantDirName="constant")
Search instantList for the time index closest to the specified time.
graph_traits< Graph >::vertices_size_type size_type
errorManip< error > abort(error &err)
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.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
OBJstream os(runTime.globalPath()/outputName)
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Input from file stream, using an ISstream.
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...
void setSize(const label newLen)
Same as resize()
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
General set of labels of mesh quantity (points, cells, faces).
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
const fileName & instance() const noexcept
Read access to instance path component.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
const pointZoneMesh & pointZones() const noexcept
Return point zone mesh.
Ostream & flush(Ostream &os)
Flush stream.
instantList times() const
Search the case for valid time directories.
T get(const label index) const
Get a value from the argument at index.
#define WarningInFunction
Report a warning using Foam::Warning.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
bool good() const noexcept
True if next operation might succeed.
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
virtual void invert(const label maxLen)
Invert contents.
messageStream Info
Information stream (stdout output on master, null elsewhere)
label nTotalFaces() const noexcept
Return total number of faces in decomposed mesh. Not compensated for duplicate faces! ...
const boundBox & bounds() const noexcept
Return mesh bounding box.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
XML inline base64, base64Formatter.
Mesh consisting of general polyhedral cells.
readUpdateState
Enumeration defining the state of the mesh after a read update.
void writeVTK(OFstream &os, const Type &value)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
const fileName & local() const noexcept
Read access to local path component.
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
A class for handling character strings derived from std::string.
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
bool found(const word &optName) const
Return true if the named option is found.
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...