92 # include <readline/readline.h>
93 # include <readline/history.h>
102 static const char* historyFile =
".setSet";
129 const word& fromName,
136 Info<<
" Backing up " << fromName <<
" into " << toName <<
endl;
148 const word& fromName,
160 backup(setType, mesh, fromName, fromSet(), toName);
172 if (isA<faceSet>(currentSet))
182 setFaces[setFaceI] = mesh.
faces()[iter.key()];
183 faceValues[setFaceI] = iter.key();
199 else if (isA<cellSet>(currentSet))
207 label cellI = iter.key();
209 const cell& cFaces = mesh.
cells()[cellI];
213 label faceI = cFaces[i];
217 label otherCellI = mesh.
faceOwner()[faceI];
219 if (otherCellI == cellI)
224 if (!currentSet.
found(otherCellI))
226 cellFaces.insert(faceI, cellI);
231 cellFaces.insert(faceI, cellI);
236 faceList setFaces(cellFaces.size());
242 setFaces[setFaceI] = mesh.
faces()[iter.key()];
243 faceValues[setFaceI] = iter();
259 else if (isA<pointSet>(currentSet))
274 "(const polyMesh& mesh, const topoSet& currentSet,"
275 "const fileName& vtkName)"
276 ) <<
"Don't know how to handle set of type " << currentSet.type()
284 os <<
"Please type 'help', 'list', 'quit', 'time ddd'"
285 <<
" or a set command after prompt." <<
endl
286 <<
"'list' will show all current cell/face/point sets." <<
endl
287 <<
"'time ddd' will change the current time." <<
endl
289 <<
"A set command should be of the following form" <<
endl
291 <<
" cellSet|faceSet|pointSet <setName> <action> <source>"
294 <<
"The <action> is one of" <<
endl
295 <<
" list - prints the contents of the set" <<
endl
296 <<
" clear - clears the set" <<
endl
297 <<
" invert - inverts the set" <<
endl
298 <<
" remove - remove the set" <<
endl
299 <<
" new <source> - sets to set to the source set" <<
endl
300 <<
" add <source> - adds all elements from the source set" <<
endl
301 <<
" delete <source> - deletes ,," <<
endl
302 <<
" subset <source> - combines current set with the source set"
305 <<
"The sources come in various forms. Type a wrong source"
306 <<
" to see all the types available." <<
endl
308 <<
"Example: pick up all cells connected by point or face to patch"
309 <<
" movingWall" <<
endl
311 <<
"Pick up all faces of patch:" <<
endl
312 <<
" faceSet f0 new patchToFace movingWall" <<
endl
313 <<
"Add faces 0,1,2:" <<
endl
314 <<
" faceSet f0 add labelToFace (0 1 2)" <<
endl
315 <<
"Pick up all points used by faces in faceSet f0:" <<
endl
316 <<
" pointSet p0 new faceToPoint f0 all" <<
endl
317 <<
"Pick up cell which has any face in f0:" <<
endl
318 <<
" cellSet c0 new faceToCell f0 any" <<
endl
319 <<
"Add cells which have any point in p0:" <<
endl
320 <<
" cellSet c0 add pointToCell p0 any" <<
endl
321 <<
"List set:" <<
endl
322 <<
" cellSet c0 list" <<
endl
324 <<
"Zones can be set using zoneSets from corresponding sets:" <<
endl
325 <<
" cellZoneSet c0Zone new setToCellZone c0" <<
endl
326 <<
" faceZoneSet f0Zone new setToFaceZone f0" <<
endl
328 <<
"or if orientation is important:" <<
endl
329 <<
" faceZoneSet f0Zone new setsToFaceZone f0 c0" <<
endl
331 <<
"ZoneSets can be manipulated using the general actions:" <<
endl
332 <<
" list - prints the contents of the set" <<
endl
333 <<
" clear - clears the set" <<
endl
334 <<
" invert - inverts the set (undefined orientation)"
336 <<
" remove - remove the set" <<
endl
352 os <<
"cellSets:" <<
endl;
356 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
362 os <<
"faceSets:" <<
endl;
366 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
369 IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
370 if (pointSets.size())
372 os <<
"pointSets:" <<
endl;
376 os <<
'\t' <<
set.
name() <<
"\tsize:" <<
set.size() <<
endl;
381 if (cellZones.
size())
383 os <<
"cellZones:" <<
endl;
386 const cellZone& zone = cellZones[i];
387 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
391 if (faceZones.
size())
393 os <<
"faceZones:" <<
endl;
396 const faceZone& zone = faceZones[i];
397 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
401 if (pointZones.
size())
403 os <<
"pointZones:" <<
endl;
407 os <<
'\t' << zone.
name() <<
"\tsize:" << zone.
size() <<
endl;
415 template<
class ZoneType>
426 Info<<
"Removing zone " << setName <<
" at index " << zoneID <<
endl;
434 oldToNew[i] = newI++;
437 oldToNew[zoneID] = newI;
463 if (objects.found(setName))
466 fileName object = objects[setName]->objectPath();
467 Info<<
"Removing file " <<
object <<
endl;
472 if (setType == cellZoneSet::typeName)
476 const_cast<cellZoneMesh&>(mesh.
cellZones()),
480 else if (setType == faceZoneSet::typeName)
484 const_cast<faceZoneMesh&>(mesh.
faceZones()),
488 else if (setType == pointZoneSet::typeName)
492 const_cast<pointZoneMesh&>(mesh.
pointZones()),
505 const word& actionName,
506 const bool writeVTKFile,
543 removeSet(mesh, setType, setName);
552 currentSetPtr =
topoSet::New(setType, mesh, setName, typSize);
557 currentSetPtr =
topoSet::New(setType, mesh, setName, r);
558 topoSet& currentSet = currentSetPtr();
563 if (currentSetPtr.
valid())
565 topoSet& currentSet = currentSetPtr();
568 <<
" Size:" << currentSet.
size()
569 <<
" Action:" << actionName
592 if (is >> sourceType)
611 currentSet.
name() +
"_old2",
620 currentSet.
subset(oldSet);
626 if (is >> sourceType)
638 setSource().applyToSet(action, currentSet);
649 currentSet.
sync(mesh);
658 "VTK"/currentSet.
name()/currentSet.
name()
664 Info<<
" Writing " << currentSet.
name()
665 <<
" (size " << currentSet.
size() <<
") to "
668 <<
" and to vtk file " << vtkName << endl <<
endl;
672 writeVTK(mesh, currentSet, vtkName);
676 Info<<
" Writing " << currentSet.
name()
677 <<
" (size " << currentSet.
size() <<
") to "
692 if (sourceType.size())
703 if (sourceType.size())
723 void printMesh(
const Time& runTime,
const polyMesh& mesh)
726 <<
" cells:" << mesh.
nCells()
727 <<
" faces:" << mesh.
nFaces()
728 <<
" points:" << mesh.
nPoints()
735 commandStatus parseType
745 Info<<
"Type 'help' for usage information" <<
endl;
749 else if (setType ==
"help")
755 else if (setType ==
"list")
757 printAllSets(mesh,
Info);
761 else if (setType ==
"time")
769 <<
" to " << Times[nearestIndex].name()
772 runTime.
setTime(Times[nearestIndex], nearestIndex);
779 Info<<
" mesh not changed." <<
endl;
784 Info<<
" points moved; topology unchanged." <<
endl;
789 Info<<
" topology changed; patches unchanged." <<
nl
791 printMesh(runTime, mesh);
796 Info<<
" topology changed and patches changed." <<
nl
798 printMesh(runTime, mesh);
805 <<
"Illegal mesh update state "
813 else if (setType ==
"quit")
822 || setType ==
"faceSet"
823 || setType ==
"pointSet"
830 setType ==
"cellZoneSet"
831 || setType ==
"faceZoneSet"
832 || setType ==
"pointZoneSet"
841 "commandStatus parseType(Time&, polyMesh&, const word&"
843 ) <<
"Illegal command " << setType << endl
844 <<
"Should be one of 'help', 'list', 'time' or a set type :"
845 <<
" 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'"
853 commandStatus parseAction(
const word& actionName)
855 commandStatus stat = INVALID;
857 if (actionName.size())
880 int main(
int argc,
char *argv[])
903 printMesh(runTime, mesh);
906 printAllSets(mesh,
Info);
910 std::ifstream* fileStreamPtr(NULL);
916 Info<<
"Reading commands from file " << batchFile <<
endl;
919 if (!
isFile(batchFile,
false))
925 fileStreamPtr =
new std::ifstream(batchFile.c_str());
928 else if (!read_history(historyFile))
930 Info<<
"Successfully read history from " << historyFile <<
endl;
934 Info<<
"Please type 'help', 'quit' or a set command after prompt." <<
endl;
952 commandStatus stat = INVALID;
956 if (!fileStreamPtr->good())
962 std::getline(*fileStreamPtr, rawLine);
973 char* linePtr = readline(
"readline>");
975 rawLine =
string(linePtr);
979 add_history(linePtr);
980 write_history(historyFile);
988 std::getline(std::cin, rawLine);
993 if (rawLine.empty() || rawLine[0] ==
'#')
1003 stat = parseType(runTime, mesh, setType, is);
1005 if (stat == VALIDSETCMD || stat == VALIDZONECMD)
1009 if (is >> actionName)
1011 stat = parseAction(actionName);
1021 else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
1023 ok = doCommand(mesh, setType, setName, actionName, writeVTK, is);
1031 delete fileStreamPtr;