45 #include "writePointSet.H" 56 #include <readline/readline.h> 57 #include <readline/history.h> 66 static const char* historyFile =
".setSet";
78 if (isA<faceSet>(currentSet))
88 setFaces[setFacei] = mesh.
faces()[iter.key()];
89 faceValues[setFacei] = iter.key();
105 else if (isA<cellSet>(currentSet))
113 label celli = iter.key();
115 const cell& cFaces = mesh.
cells()[celli];
119 label facei = cFaces[i];
125 if (otherCelli == celli)
130 if (!currentSet.
found(otherCelli))
132 cellFaces.insert(facei, celli);
137 cellFaces.insert(facei, celli);
142 faceList setFaces(cellFaces.size());
148 setFaces[setFacei] = mesh.
faces()[iter.key()];
149 faceValues[setFacei] = iter();
165 else if (isA<pointSet>(currentSet))
178 <<
"Don't know how to handle set of type " << currentSet.type()
186 os <<
"Please type 'help', 'list', 'quit', 'time ddd'" 187 <<
" or a set command after prompt." << endl
188 <<
"'list' will show all current cell/face/point sets." << endl
189 <<
"'time ddd' will change the current time." << endl
191 <<
"A set command should be of the following form" << endl
193 <<
" cellSet|faceSet|pointSet <setName> <action> <source>" 196 <<
"The <action> is one of" << endl
197 <<
" list - prints the contents of the set" << endl
198 <<
" clear - clears the set" << endl
199 <<
" invert - inverts the set" << endl
200 <<
" remove - remove the set" << endl
201 <<
" new <source> - sets to set to the source set" << endl
202 <<
" add <source> - adds all elements from the source set" << endl
203 <<
" delete <source> - deletes ,," << endl
204 <<
" subset <source> - combines current set with the source set" 207 <<
"The sources come in various forms. Type a wrong source" 208 <<
" to see all the types available." << endl
210 <<
"Example: pick up all cells connected by point or face to patch" 211 <<
" movingWall" << endl
213 <<
"Pick up all faces of patch:" << endl
214 <<
" faceSet f0 new patchToFace movingWall" << endl
215 <<
"Add faces 0,1,2:" << endl
216 <<
" faceSet f0 add labelToFace (0 1 2)" << endl
217 <<
"Pick up all points used by faces in faceSet f0:" << endl
218 <<
" pointSet p0 new faceToPoint f0 all" << endl
219 <<
"Pick up cell which has any face in f0:" << endl
220 <<
" cellSet c0 new faceToCell f0 any" << endl
221 <<
"Add cells which have any point in p0:" << endl
222 <<
" cellSet c0 add pointToCell p0 any" << endl
223 <<
"List set:" << endl
224 <<
" cellSet c0 list" << endl
226 <<
"Zones can be set using zoneSets from corresponding sets:" << endl
227 <<
" cellZoneSet c0Zone new setToCellZone c0" << endl
228 <<
" faceZoneSet f0Zone new setToFaceZone f0" << endl
230 <<
"or if orientation is important:" << endl
231 <<
" faceZoneSet f0Zone new setsToFaceZone f0 c0" << endl
233 <<
"ZoneSets can be manipulated using the general actions:" << endl
234 <<
" list - prints the contents of the set" << endl
235 <<
" clear - clears the set" << endl
236 <<
" invert - inverts the set (undefined orientation)" 238 <<
" remove - remove the set" << endl
260 os <<
"cellSets:" <<
endl;
264 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
270 os <<
"faceSets:" <<
endl;
274 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
277 IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
278 if (pointSets.size())
280 os <<
"pointSets:" <<
endl;
284 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
289 if (cellZones.
size())
291 os <<
"cellZones:" <<
endl;
294 const cellZone& zone = cellZones[i];
295 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
299 if (faceZones.
size())
301 os <<
"faceZones:" <<
endl;
304 const faceZone& zone = faceZones[i];
305 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
309 if (pointZones.
size())
311 os <<
"pointZones:" <<
endl;
315 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
323 template<
class ZoneType>
334 Info<<
"Removing zone " << setName <<
" at index " << zoneID <<
endl;
342 oldToNew[i] = newI++;
345 oldToNew[zoneID] = newI;
377 if (objects.found(setName))
380 fileName object = objects[setName]->objectPath();
381 Info<<
"Removing file " <<
object <<
endl;
386 if (setType == cellZoneSet::typeName)
390 const_cast<cellZoneMesh&>(mesh.
cellZones()),
394 else if (setType == faceZoneSet::typeName)
398 const_cast<faceZoneMesh&>(mesh.
faceZones()),
402 else if (setType == pointZoneSet::typeName)
406 const_cast<pointZoneMesh&>(mesh.
pointZones()),
419 const word& actionName,
420 const bool writeVTKFile,
421 const bool writeCurrentTime,
459 removeSet(mesh, setType, setName);
468 currentSetPtr =
topoSet::New(setType, mesh, setName, typSize);
473 currentSetPtr =
topoSet::New(setType, mesh, setName, r);
474 topoSet& currentSet = currentSetPtr();
479 if (currentSetPtr.
valid())
481 topoSet& currentSet = currentSetPtr();
485 <<
" Action:" << actionName
508 if (is >> sourceType)
527 currentSet.
name() +
"_old2",
536 currentSet.
subset(oldSet);
542 if (is >> sourceType)
554 setSource().applyToSet(action, currentSet);
565 if (!noSync) currentSet.
sync(mesh);
574 "VTK"/currentSet.
name()/currentSet.
name()
580 Info<<
" Writing " << currentSet.
name()
586 <<
" and to vtk file " << vtkName << endl <<
endl;
588 writeVTK(mesh, currentSet, vtkName);
592 Info<<
" Writing " << currentSet.
name()
600 if (writeCurrentTime)
614 if (sourceType.size())
625 if (sourceType.size())
645 void printMesh(
const Time& runTime,
const polyMesh& mesh)
664 Info<<
" mesh not changed." <<
endl;
669 Info<<
" points moved; topology unchanged." <<
endl;
674 Info<<
" topology changed; patches unchanged." <<
nl 681 Info<<
" topology changed and patches changed." << nl
690 <<
"Illegal mesh update state " 699 commandStatus parseType
709 Info<<
"Type 'help' for usage information" <<
endl;
713 else if (setType ==
"help")
719 else if (setType ==
"list")
721 printAllSets(mesh,
Info);
725 else if (setType ==
"time")
733 <<
" to " << Times[nearestIndex].name()
737 runTime.
setTime(Times[nearestIndex], nearestIndex);
739 meshReadUpdate(mesh);
743 else if (setType ==
"quit")
752 || setType ==
"faceSet" 753 || setType ==
"pointSet" 760 setType ==
"cellZoneSet" 761 || setType ==
"faceZoneSet" 762 || setType ==
"pointZoneSet" 770 <<
"Illegal command " << setType << endl
771 <<
"Should be one of 'help', 'list', 'time' or a set type :" 772 <<
" 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'" 780 commandStatus parseAction(
const word& actionName)
782 commandStatus stat = INVALID;
784 if (actionName.size())
806 int main(
int argc,
char *argv[])
816 "process in batch mode, using input from specified file" 821 "do not synchronise selection across coupled patches" 836 <<
"Can only loop in batch mode." 844 printMesh(runTime, mesh);
847 printAllSets(mesh,
Info);
851 if (!batch && !read_history((runTime.
path()/historyFile).c_str()))
853 Info<<
"Successfully read history from " << historyFile <<
endl;
864 runTime.
setTime(timeDirs[timeI], timeI);
868 meshReadUpdate(mesh);
880 Info<<
"Reading commands from file " << batchFile <<
endl;
883 if (!
isFile(batchFile,
false))
889 fileStreamPtr.reset(
new IFstream(batchFile));
892 Info<<
"Please type 'help', 'quit' or a set command after prompt." 912 commandStatus stat = INVALID;
914 if (fileStreamPtr.valid())
916 if (!fileStreamPtr().good())
923 fileStreamPtr().getLine(rawLine);
934 char* linePtr = readline(
"readline>");
938 rawLine =
string(linePtr);
942 add_history(linePtr);
943 write_history(historyFile);
955 if (!std::cin.good())
962 std::getline(std::cin, rawLine);
969 if (i != string::npos)
971 rawLine = rawLine(0, i);
984 stat = parseType(runTime, mesh, setType, is);
986 if (stat == VALIDSETCMD || stat == VALIDZONECMD)
990 if (is >> actionName)
992 stat = parseAction(actionName);
1002 else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
label timeIndex() const
Return current time index.
const Time & time() const
Return time.
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
#define forAll(list, i)
Loop across all elements in list.
void clearAddressing()
Clear addressing.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
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 boundBox & bounds() const
Return mesh bounding box.
const fileName & facesInstance() const
Return the current instance directory for faces.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
void reorder(const labelUList &)
Reorders elements. Ordering does not have to be done in.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
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.
void writePointSet(const bool binary, const primitiveMesh &mesh, const topoSet &set, const fileName &fileName)
Write pointSet to vtk polydata file.
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.
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
Ostream & endl(Ostream &os)
Add newline and flush stream.
label size() const
Return number of elements in table.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
readOption
Enumeration defining the read options.
const cellList & cells() const
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
virtual const pointField & points() const
Return raw points.
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Write faceSet to vtk polydata file. Only one data which is original faceID.
const word & name() const
Return name.
A list of faces which address into the list of points.
label findZoneID(const word &zoneName) const
Find zone index given a name.
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".
bool optionFound(const word &opt) const
Return true if the named option is found.
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
A class for handling words, derived from string.
void clear()
Clear all entries from table.
label nTotalFaces() const
Return total number of faces in decomposed mesh. Not.
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.
static const word null
An empty word.
label nTotalPoints() const
Return total number of points in decomposed mesh. Not.
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
const fileName & local() const
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
graph_traits< Graph >::vertices_size_type size_type
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
bool found(const Key &) const
Return true if hashedEntry is found in table.
const globalMeshData & globalData() const
Return parallel info.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
prefixOSstream Pout(cout,"Pout")
virtual const fileName & name() const
Return the name of the stream.
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
const pointZoneMesh & pointZones() const
Return point zone mesh.
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.
void writePatch(const bool binary, const word &setName, const primitiveFacePatch &fp, const word &fieldName, labelList &fieldValues, const fileName &fileName)
Template functions to aid in the implementation of demand driven data.
const cellZoneMesh & cellZones() const
Return cell zone mesh.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Ostream & flush(Ostream &os)
Flush stream.
virtual const labelList & faceNeighbour() const
Return face neighbour.
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.
virtual bool write() const
Write using setting from DB.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
instantList times() const
Search the case for valid time directories.
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
static setAction toAction(const word &actionName)
Convert string to action.
void resize(const label newSize)
Resize the hash table for efficiency.
const faceZoneMesh & faceZones() const
Return face zone mesh.
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.
readUpdateState
Enumeration defining the state of the mesh after a read update.
void writeVTK(OFstream &os, const Type &value)
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.
virtual const labelList & faceOwner() const
Return face owner.
virtual const faceList & faces() const
Return raw faces.
fileName path() const
Return path.
Foam::argList args(argc, argv)
A class for handling character strings derived from std::string.
const fileName & instance() const
label nTotalCells() const
Return total number of cells in decomposed mesh.
const word & name() const
Return name.
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.
label size() const
Return the number of elements in the UPtrList.