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;
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;
383 Info<<
"Removing file " <<
object <<
endl;
388 if (setType == cellZoneSet::typeName)
392 const_cast<cellZoneMesh&>(mesh.
cellZones()),
396 else if (setType == faceZoneSet::typeName)
400 const_cast<faceZoneMesh&>(mesh.
faceZones()),
404 else if (setType == pointZoneSet::typeName)
408 const_cast<pointZoneMesh&>(mesh.
pointZones()),
421 const word& actionName,
422 const bool writeVTKFile,
423 const bool writeCurrentTime,
461 removeSet(mesh, setType, setName);
470 currentSetPtr =
topoSet::New(setType, mesh, setName, typSize);
475 currentSetPtr =
topoSet::New(setType, mesh, setName, r);
476 topoSet& currentSet = currentSetPtr();
481 if (currentSetPtr.
valid())
483 topoSet& currentSet = currentSetPtr();
487 <<
" Action:" << actionName
510 if (is >> sourceType)
529 currentSet.
name() +
"_old2",
538 currentSet.
subset(oldSet);
544 if (is >> sourceType)
556 setSource().applyToSet(action, currentSet);
567 if (!noSync) currentSet.
sync(mesh);
576 "VTK"/currentSet.
name()/currentSet.
name()
582 Info<<
" Writing " << currentSet.
name()
588 <<
" and to vtk file " << vtkName << endl <<
endl;
590 writeVTK(mesh, currentSet, vtkName);
594 Info<<
" Writing " << currentSet.
name()
602 if (writeCurrentTime)
618 if (sourceType.size())
629 if (sourceType.size())
649 void printMesh(
const Time& runTime,
const polyMesh& mesh)
668 Info<<
" mesh not changed." <<
endl;
673 Info<<
" points moved; topology unchanged." <<
endl;
678 Info<<
" topology changed; patches unchanged." <<
nl 685 Info<<
" topology changed and patches changed." << nl
694 <<
"Illegal mesh update state " 703 commandStatus parseType
713 Info<<
"Type 'help' for usage information" <<
endl;
717 else if (setType ==
"help")
723 else if (setType ==
"list")
725 printAllSets(mesh,
Info);
729 else if (setType ==
"time")
737 <<
" to " << Times[nearestIndex].name()
741 runTime.
setTime(Times[nearestIndex], nearestIndex);
743 meshReadUpdate(mesh);
747 else if (setType ==
"quit")
756 || setType ==
"faceSet" 757 || setType ==
"pointSet" 764 setType ==
"cellZoneSet" 765 || setType ==
"faceZoneSet" 766 || setType ==
"pointZoneSet" 774 <<
"Illegal command " << setType << endl
775 <<
"Should be one of 'help', 'list', 'time' or a set type :" 776 <<
" 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'" 784 commandStatus parseAction(
const word& actionName)
786 commandStatus stat = INVALID;
788 if (actionName.size())
810 int main(
int argc,
char *argv[])
823 "process in batch mode, using input from specified file" 828 "do not synchronise selection across coupled patches" 843 <<
"Can only loop in batch mode." 851 printMesh(runTime, mesh);
854 printAllSets(mesh,
Info);
858 if (!batch && !read_history((runTime.
path()/historyFile).c_str()))
860 Info<<
"Successfully read history from " << historyFile <<
endl;
871 runTime.
setTime(timeDirs[timeI], timeI);
875 meshReadUpdate(mesh);
887 Info<<
"Reading commands from file " << batchFile <<
endl;
890 if (!
isFile(batchFile,
false,
false))
896 fileStreamPtr.reset(
new IFstream(batchFile));
899 Info<<
"Please type 'help', 'quit' or a set command after prompt." 919 commandStatus stat = INVALID;
921 if (fileStreamPtr.valid())
923 if (!fileStreamPtr().good())
930 fileStreamPtr().getLine(rawLine);
941 char* linePtr = readline(
"readline>");
945 rawLine =
string(linePtr);
949 add_history(linePtr);
950 write_history(historyFile);
962 if (!std::cin.good())
969 std::getline(std::cin, rawLine);
976 if (i != string::npos)
978 rawLine = rawLine(0, i);
991 stat = parseType(runTime, mesh, setType, is);
993 if (stat == VALIDSETCMD || stat == VALIDZONECMD)
997 if (is >> actionName)
999 stat = parseAction(actionName);
1009 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.
#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.
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 > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual const labelList & faceNeighbour() const
Return face neighbour.
void writePatch(const bool binary, const word &setName, const primitiveFacePatch &fp, const word &fieldName, labelList &fieldValues, const fileName &fileName)
Write patch.
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.
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.
void writePointSet(const bool binary, const primitiveMesh &mesh, const topoSet &set, const fileName &fileName)
Write pointSet to vtk polydata file.
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.
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.
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.
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")
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.
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)
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.