55 #include <readline/readline.h> 56 #include <readline/history.h> 65 static const char* historyFile =
".setSet";
77 if (isA<faceSet>(currentSet))
87 setFaces[setFacei] = mesh.
faces()[iter.key()];
88 faceValues[setFacei] = iter.key();
108 else if (isA<cellSet>(currentSet))
116 label celli = iter.key();
118 const cell& cFaces = mesh.
cells()[celli];
122 label facei = cFaces[i];
128 if (otherCelli == celli)
133 if (!currentSet.
found(otherCelli))
135 cellFaces.insert(facei, celli);
140 cellFaces.insert(facei, celli);
145 faceList setFaces(cellFaces.size());
151 setFaces[setFacei] = mesh.
faces()[iter.key()];
152 faceValues[setFacei] = iter();
172 else if (isA<pointSet>(currentSet))
174 std::ofstream os(mesh.
time().
path()/vtkName);
189 <<
"Don't know how to handle set of type " << currentSet.type()
197 os <<
"Please type 'help', 'list', 'quit', 'time ddd'" 198 <<
" or a set command after prompt." << endl
199 <<
"'list' will show all current cell/face/point sets." << endl
200 <<
"'time ddd' will change the current time." << endl
202 <<
"A set command should be of the following form" << endl
204 <<
" cellSet|faceSet|pointSet <setName> <action> <source>" 207 <<
"The <action> is one of" << endl
208 <<
" list - prints the contents of the set" << endl
209 <<
" clear - clears the set" << endl
210 <<
" invert - inverts the set" << endl
211 <<
" remove - remove the set" << endl
212 <<
" new <source> - sets to set to the source set" << endl
213 <<
" add <source> - adds all elements from the source set" << endl
214 <<
" delete <source> - deletes ,," << endl
215 <<
" subset <source> - combines current set with the source set" 218 <<
"The sources come in various forms. Type a wrong source" 219 <<
" to see all the types available." << endl
221 <<
"Example: pick up all cells connected by point or face to patch" 222 <<
" movingWall" << endl
224 <<
"Pick up all faces of patch:" << endl
225 <<
" faceSet f0 new patchToFace movingWall" << endl
226 <<
"Add faces 0,1,2:" << endl
227 <<
" faceSet f0 add labelToFace (0 1 2)" << endl
228 <<
"Pick up all points used by faces in faceSet f0:" << endl
229 <<
" pointSet p0 new faceToPoint f0 all" << endl
230 <<
"Pick up cell which has any face in f0:" << endl
231 <<
" cellSet c0 new faceToCell f0 any" << endl
232 <<
"Add cells which have any point in p0:" << endl
233 <<
" cellSet c0 add pointToCell p0 any" << endl
234 <<
"List set:" << endl
235 <<
" cellSet c0 list" << endl
237 <<
"Zones can be set using zoneSets from corresponding sets:" << endl
238 <<
" cellZoneSet c0Zone new setToCellZone c0" << endl
239 <<
" faceZoneSet f0Zone new setToFaceZone f0" << endl
241 <<
"or if orientation is important:" << endl
242 <<
" faceZoneSet f0Zone new setsToFaceZone f0 c0" << endl
244 <<
"ZoneSets can be manipulated using the general actions:" << endl
245 <<
" list - prints the contents of the set" << endl
246 <<
" clear - clears the set" << endl
247 <<
" invert - inverts the set (undefined orientation)" 249 <<
" remove - remove the set" << endl
271 os <<
"cellSets:" <<
endl;
275 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
281 os <<
"faceSets:" <<
endl;
285 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
289 if (pointSets.size())
291 os <<
"pointSets:" <<
endl;
295 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
300 if (cellZones.
size())
302 os <<
"cellZones:" <<
endl;
305 const cellZone& zone = cellZones[i];
306 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
310 if (faceZones.
size())
312 os <<
"faceZones:" <<
endl;
315 const faceZone& zone = faceZones[i];
316 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
320 if (pointZones.
size())
322 os <<
"pointZones:" <<
endl;
326 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
334 template<
class ZoneType>
345 Info<<
"Removing zone " << setName <<
" at index " << zoneID <<
endl;
353 oldToNew[i] = newI++;
356 oldToNew[zoneID] = newI;
394 Info<<
"Removing file " <<
object <<
endl;
399 if (setType == cellZoneSet::typeName)
403 const_cast<meshCellZones&>(mesh.
cellZones()),
407 else if (setType == faceZoneSet::typeName)
411 const_cast<meshFaceZones&>(mesh.
faceZones()),
415 else if (setType == pointZoneSet::typeName)
419 const_cast<meshPointZones&>(mesh.
pointZones()),
432 const word& actionName,
433 const bool writeVTKFile,
434 const bool writeCurrentTime,
472 removeSet(mesh, setType, setName);
481 currentSetPtr =
topoSet::New(setType, mesh, setName, typSize);
486 currentSetPtr =
topoSet::New(setType, mesh, setName, r);
487 topoSet& currentSet = currentSetPtr();
492 if (currentSetPtr.
valid())
494 topoSet& currentSet = currentSetPtr();
498 <<
" Action:" << actionName
521 if (is >> sourceType)
540 currentSet.
name() +
"_old2",
549 currentSet.
subset(oldSet);
555 if (is >> sourceType)
567 setSource().applyToSet(action, currentSet);
578 if (!noSync) currentSet.
sync(mesh);
587 "VTK"/currentSet.
name()/currentSet.
name()
593 Info<<
" Writing " << currentSet.
name()
599 <<
" and to vtk file " << vtkName << endl <<
endl;
601 writeVTK(mesh, currentSet, vtkName);
605 Info<<
" Writing " << currentSet.
name()
613 if (writeCurrentTime)
629 if (sourceType.size())
640 if (sourceType.size())
660 void printMesh(
const Time& runTime,
const polyMesh& mesh)
679 Info<<
" mesh not changed." <<
endl;
684 Info<<
" points moved; topology unchanged." <<
endl;
689 Info<<
" topology changed; patches unchanged." <<
nl 696 Info<<
" topology changed and patches changed." << nl
705 <<
"Illegal mesh update state " 714 commandStatus parseType
724 Info<<
"Type 'help' for usage information" <<
endl;
728 else if (setType ==
"help")
734 else if (setType ==
"list")
736 printAllSets(mesh,
Info);
740 else if (setType ==
"time")
748 <<
" to " << Times[nearestIndex].name()
752 runTime.
setTime(Times[nearestIndex], nearestIndex);
754 meshReadUpdate(mesh);
758 else if (setType ==
"quit")
767 || setType ==
"faceSet" 768 || setType ==
"pointSet" 775 setType ==
"cellZoneSet" 776 || setType ==
"faceZoneSet" 777 || setType ==
"pointZoneSet" 785 <<
"Illegal command " << setType << endl
786 <<
"Should be one of 'help', 'list', 'time' or a set type :" 787 <<
" 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'" 795 commandStatus parseAction(
const word& actionName)
797 commandStatus stat = INVALID;
799 if (actionName.size())
821 int main(
int argc,
char *argv[])
834 "process in batch mode, using input from specified file" 839 "do not synchronise selection across coupled patches" 854 <<
"Can only loop in batch mode." 862 printMesh(runTime, mesh);
865 printAllSets(mesh,
Info);
869 if (!batch && !read_history((runTime.
path()/historyFile).c_str()))
871 Info<<
"Successfully read history from " << historyFile <<
endl;
882 runTime.
setTime(timeDirs[timeI], timeI);
886 meshReadUpdate(mesh);
898 Info<<
"Reading commands from file " << batchFile <<
endl;
901 if (!
isFile(batchFile,
false,
false))
907 fileStreamPtr.reset(
new IFstream(batchFile));
910 Info<<
"Please type 'help', 'quit' or a set command after prompt." 930 commandStatus stat = INVALID;
932 if (fileStreamPtr.valid())
934 if (!fileStreamPtr().good())
941 fileStreamPtr().getLine(rawLine);
952 char* linePtr = readline(
"readline>");
956 rawLine =
string(linePtr);
960 add_history(linePtr);
961 write_history(historyFile);
973 if (!std::cin.good())
980 std::getline(std::cin, rawLine);
987 if (i != string::npos)
989 rawLine = rawLine(0, i);
1002 stat = parseType(runTime, mesh, setType, is);
1004 if (stat == VALIDSETCMD || stat == VALIDZONECMD)
1008 if (is >> actionName)
1010 stat = parseAction(actionName);
1020 else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
void reorder(const labelUList &oldToNew)
Reorders elements. Ordering does not have to be done in.
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
label findZoneID(const word &zoneName) const
Find zone index given a name.
#define forAll(list, i)
Loop across all elements in list.
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.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const word & name() const
Return name.
A class for handling file names.
List of IOobjects with searching and retrieving facilities.
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.
const meshCellZones & cellZones() const
Return cell zones.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual const labelList & faceNeighbour() const
Return face neighbour.
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
label nTotalPoints() const
Return total number of points in decomposed mesh. Not.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool optionFound(const word &opt) const
Return true if the named option is found.
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Return the location of "dir" containing the file "name".
label nTotalCells() const
Return total number of cells in decomposed mesh.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
const cellList & cells() const
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
readOption
Enumeration defining the read options.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
label size() const
Return number of elements in table.
const meshPointZones & pointZones() const
Return point zones.
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
virtual const pointField & points() const
Return raw points.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
A list of faces which address into the list of points.
vectorField pointField
pointField is a vectorField.
label nTotalFaces() const
Return total number of faces in decomposed mesh. Not.
bool found(const Key &) const
Return true if hashedEntry is found in table.
A class for handling words, derived from string.
virtual const fileName & name() const
Return the name of the stream.
void clear()
Clear 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.
const fileName & local() const
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
setAction
Enumeration defining the valid actions.
virtual const labelList & faceOwner() const
Return face owner.
static const word null
An empty word.
const globalMeshData & globalData() const
Return parallel info.
List< label > labelList
A List of labels.
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
const word & name() const
Return name.
const fileOperation & fileHandler()
Get current file handler.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
virtual const faceList & faces() const
Return raw faces.
graph_traits< Graph >::vertices_size_type size_type
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
const Time & time() const
Return time.
void write(const fileName &file, const word &title, const bool binary, const PointField &points, const VertexList &vertices, const LineList &lines, const FaceList &faces, const wordList &fieldNames, const boolList &fieldIsPointValues, const UPtrList< const Field< label >> &fieldLabelValues #define FieldTypeValuesConstArg(Type, nullArg))
Write VTK polygonal data to a file. Takes a PtrList of fields of labels and.
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
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.
word name(const complex &)
Return a string representation of a complex.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
label size() const
Return the number of elements in the UPtrList.
Template functions to aid in the implementation of demand driven data.
const boundBox & bounds() const
Return mesh bounding box.
const fileName & instance() const
static label nProcs(const label communicator=0)
Number of processes in parallel run.
label timeIndex() const
Return current time index.
Ostream & flush(Ostream &os)
Flush stream.
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list...
#define WarningInFunction
Report a warning using Foam::Warning.
A cell is defined as a list of faces with extra functionality.
Input from memory buffer stream.
A collection of cell labels.
prefixOSstream Pout(cout, "Pout")
const meshFaceZones & faceZones() const
Return face zones.
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
instantList times() const
Search the case for valid time directories.
static setAction toAction(const word &actionName)
Convert string to action.
void resize(const label newSize)
Resize the hash table for efficiency.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Mesh consisting of general polyhedral cells.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
A subset of mesh faces organised as a primitive patch.
List< Key > toc() const
Return the table of contents.
readUpdateState
Enumeration defining the state of the mesh after a read update.
void writeVTK(OFstream &os, const Type &value)
virtual bool write(const bool write=true) const
Write using setting from DB.
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Foam::argList args(argc, argv)
fileName path() const
Return path.
void clearAddressing()
Clear addressing.
A class for handling character strings derived from std::string.
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.