45 #include "writePointSet.H" 57 #include <readline/readline.h> 58 #include <readline/history.h> 67 static const char* historyFile =
".setSet";
79 if (isA<faceSet>(currentSet))
89 setFaces[setFacei] = mesh.
faces()[iter.key()];
90 faceValues[setFacei] = iter.key();
106 else if (isA<cellSet>(currentSet))
114 label celli = iter.key();
116 const cell& cFaces = mesh.
cells()[celli];
120 label facei = cFaces[i];
126 if (otherCelli == celli)
131 if (!currentSet.
found(otherCelli))
133 cellFaces.insert(facei, celli);
138 cellFaces.insert(facei, celli);
143 faceList setFaces(cellFaces.size());
149 setFaces[setFacei] = mesh.
faces()[iter.key()];
150 faceValues[setFacei] = iter();
166 else if (isA<pointSet>(currentSet))
179 <<
"Don't know how to handle set of type " << currentSet.type()
187 os <<
"Please type 'help', 'list', 'quit', 'time ddd'" 188 <<
" or a set command after prompt." << endl
189 <<
"'list' will show all current cell/face/point sets." << endl
190 <<
"'time ddd' will change the current time." << endl
192 <<
"A set command should be of the following form" << endl
194 <<
" cellSet|faceSet|pointSet <setName> <action> <source>" 197 <<
"The <action> is one of" << endl
198 <<
" list - prints the contents of the set" << endl
199 <<
" clear - clears the set" << endl
200 <<
" invert - inverts the set" << endl
201 <<
" remove - remove the set" << endl
202 <<
" new <source> - sets to set to the source set" << endl
203 <<
" add <source> - adds all elements from the source set" << endl
204 <<
" delete <source> - deletes ,," << endl
205 <<
" subset <source> - combines current set with the source set" 208 <<
"The sources come in various forms. Type a wrong source" 209 <<
" to see all the types available." << endl
211 <<
"Example: pick up all cells connected by point or face to patch" 212 <<
" movingWall" << endl
214 <<
"Pick up all faces of patch:" << endl
215 <<
" faceSet f0 new patchToFace movingWall" << endl
216 <<
"Add faces 0,1,2:" << endl
217 <<
" faceSet f0 add labelToFace (0 1 2)" << endl
218 <<
"Pick up all points used by faces in faceSet f0:" << endl
219 <<
" pointSet p0 new faceToPoint f0 all" << endl
220 <<
"Pick up cell which has any face in f0:" << endl
221 <<
" cellSet c0 new faceToCell f0 any" << endl
222 <<
"Add cells which have any point in p0:" << endl
223 <<
" cellSet c0 add pointToCell p0 any" << endl
224 <<
"List set:" << endl
225 <<
" cellSet c0 list" << endl
227 <<
"Zones can be set using zoneSets from corresponding sets:" << endl
228 <<
" cellZoneSet c0Zone new setToCellZone c0" << endl
229 <<
" faceZoneSet f0Zone new setToFaceZone f0" << endl
231 <<
"or if orientation is important:" << endl
232 <<
" faceZoneSet f0Zone new setsToFaceZone f0 c0" << endl
234 <<
"ZoneSets can be manipulated using the general actions:" << endl
235 <<
" list - prints the contents of the set" << endl
236 <<
" clear - clears the set" << endl
237 <<
" invert - inverts the set (undefined orientation)" 239 <<
" remove - remove the set" << endl
261 os <<
"cellSets:" <<
endl;
265 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
271 os <<
"faceSets:" <<
endl;
275 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
278 IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
279 if (pointSets.size())
281 os <<
"pointSets:" <<
endl;
285 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
290 if (cellZones.
size())
292 os <<
"cellZones:" <<
endl;
295 const cellZone& zone = cellZones[i];
296 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
300 if (faceZones.
size())
302 os <<
"faceZones:" <<
endl;
305 const faceZone& zone = faceZones[i];
306 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
310 if (pointZones.
size())
312 os <<
"pointZones:" <<
endl;
316 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
324 template<
class ZoneType>
335 Info<<
"Removing zone " << setName <<
" at index " << zoneID <<
endl;
343 oldToNew[i] = newI++;
346 oldToNew[zoneID] = newI;
378 if (objects.found(setName))
381 fileName object = objects[setName]->objectPath();
382 Info<<
"Removing file " <<
object <<
endl;
387 if (setType == cellZoneSet::typeName)
391 const_cast<cellZoneMesh&>(mesh.
cellZones()),
395 else if (setType == faceZoneSet::typeName)
399 const_cast<faceZoneMesh&>(mesh.
faceZones()),
403 else if (setType == pointZoneSet::typeName)
407 const_cast<pointZoneMesh&>(mesh.
pointZones()),
420 const word& actionName,
421 const bool writeVTKFile,
422 const bool writeCurrentTime,
460 removeSet(mesh, setType, setName);
469 currentSetPtr =
topoSet::New(setType, mesh, setName, typSize);
474 currentSetPtr =
topoSet::New(setType, mesh, setName, r);
475 topoSet& currentSet = currentSetPtr();
480 if (currentSetPtr.
valid())
482 topoSet& currentSet = currentSetPtr();
486 <<
" Action:" << actionName
509 if (is >> sourceType)
528 currentSet.
name() +
"_old2",
537 currentSet.
subset(oldSet);
543 if (is >> sourceType)
555 setSource().applyToSet(action, currentSet);
566 if (!noSync) currentSet.
sync(mesh);
575 "VTK"/currentSet.
name()/currentSet.
name()
581 Info<<
" Writing " << currentSet.
name()
587 <<
" and to vtk file " << vtkName << endl <<
endl;
589 writeVTK(mesh, currentSet, vtkName);
593 Info<<
" Writing " << currentSet.
name()
601 if (writeCurrentTime)
615 if (sourceType.size())
626 if (sourceType.size())
646 void printMesh(
const Time& runTime,
const polyMesh& mesh)
665 Info<<
" mesh not changed." <<
endl;
670 Info<<
" points moved; topology unchanged." <<
endl;
675 Info<<
" topology changed; patches unchanged." <<
nl 682 Info<<
" topology changed and patches changed." << nl
691 <<
"Illegal mesh update state " 700 commandStatus parseType
710 Info<<
"Type 'help' for usage information" <<
endl;
714 else if (setType ==
"help")
720 else if (setType ==
"list")
722 printAllSets(mesh,
Info);
726 else if (setType ==
"time")
734 <<
" to " << Times[nearestIndex].name()
738 runTime.
setTime(Times[nearestIndex], nearestIndex);
740 meshReadUpdate(mesh);
744 else if (setType ==
"quit")
753 || setType ==
"faceSet" 754 || setType ==
"pointSet" 761 setType ==
"cellZoneSet" 762 || setType ==
"faceZoneSet" 763 || setType ==
"pointZoneSet" 771 <<
"Illegal command " << setType << endl
772 <<
"Should be one of 'help', 'list', 'time' or a set type :" 773 <<
" 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'" 781 commandStatus parseAction(
const word& actionName)
783 commandStatus stat = INVALID;
785 if (actionName.size())
807 int main(
int argc,
char *argv[])
822 "process in batch mode, using input from specified file" 827 "do not synchronise selection across coupled patches" 842 <<
"Can only loop in batch mode." 850 printMesh(runTime, mesh);
853 printAllSets(mesh,
Info);
857 if (!batch && !read_history((runTime.
path()/historyFile).c_str()))
859 Info<<
"Successfully read history from " << historyFile <<
endl;
870 runTime.
setTime(timeDirs[timeI], timeI);
874 meshReadUpdate(mesh);
886 Info<<
"Reading commands from file " << batchFile <<
endl;
889 if (!
isFile(batchFile,
false))
895 fileStreamPtr.reset(
new IFstream(batchFile));
898 Info<<
"Please type 'help', 'quit' or a set command after prompt." 918 commandStatus stat = INVALID;
920 if (fileStreamPtr.valid())
922 if (!fileStreamPtr().good())
929 fileStreamPtr().getLine(rawLine);
940 char* linePtr = readline(
"readline>");
944 rawLine =
string(linePtr);
948 add_history(linePtr);
949 write_history(historyFile);
961 if (!std::cin.good())
968 std::getline(std::cin, rawLine);
975 if (i != string::npos)
977 rawLine = rawLine(0, i);
990 stat = parseType(runTime, mesh, setType, is);
992 if (stat == VALIDSETCMD || stat == VALIDZONECMD)
996 if (is >> actionName)
998 stat = parseAction(actionName);
1008 else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
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.
fileName path() const
Return path.
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.
const faceZoneMesh & faceZones() const
Return face zone mesh.
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.
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.
virtual const labelList & faceNeighbour() const
Return face neighbour.
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.
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.
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.
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.
#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.
Write faceSet to vtk polydata file. Only one data which is original faceID.
A list of faces which address into the list of points.
label nTotalFaces() const
Return total number of faces in decomposed mesh. Not.
label findZoneID(const word &zoneName) const
Find zone index given a name.
bool found(const Key &) const
Return true if hashedEntry is found in table.
const pointZoneMesh & pointZones() const
Return point zone mesh.
A class for handling words, derived from string.
const cellZoneMesh & cellZones() const
Return cell zone mesh.
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.
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
const globalMeshData & globalData() const
Return parallel info.
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
const word & name() const
Return name.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
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.
bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
An Ostream is an abstract base class for all output systems (streams, files, token lists...
const Time & time() const
Return time.
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.
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
void writePatch(const bool binary, const word &setName, const primitiveFacePatch &fp, const word &fieldName, labelList &fieldValues, const fileName &fileName)
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")
instantList times() const
Search the case for valid time directories.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
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.
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 bool write(const bool valid=true) const
Write using setting from DB.
Foam::argList args(argc, argv)
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.