setSet.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  setSet
26 
27 Description
28  Manipulate a cell/face/point/ set or zone interactively.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "Time.H"
34 #include "polyMesh.H"
35 #include "globalMeshData.H"
36 #include "IStringStream.H"
37 #include "cellSet.H"
38 #include "faceSet.H"
39 #include "pointSet.H"
40 #include "topoSetSource.H"
41 #include "OFstream.H"
42 #include "IFstream.H"
43 #include "demandDrivenData.H"
44 #include "writePatch.H"
45 #include "writePointSet.H"
46 #include "IOobjectList.H"
47 #include "cellZoneSet.H"
48 #include "faceZoneSet.H"
49 #include "pointZoneSet.H"
50 #include "timeSelector.H"
51 
52 #include <stdio.h>
53 
54 
55 #ifdef HAS_READLINE
56  #include <readline/readline.h>
57  #include <readline/history.h>
58 #endif
59 
60 using namespace Foam;
61 
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 
64 
65 #ifdef HAS_READLINE
66 static const char* historyFile = ".setSet";
67 #endif
68 
69 
70 // Write set to VTK readable files
71 void writeVTK
72 (
73  const polyMesh& mesh,
74  const topoSet& currentSet,
75  const fileName& vtkName
76 )
77 {
78  if (isA<faceSet>(currentSet))
79  {
80  // Faces of set with OpenFOAM faceID as value
81 
82  faceList setFaces(currentSet.size());
83  labelList faceValues(currentSet.size());
84  label setFacei = 0;
85 
86  forAllConstIter(topoSet, currentSet, iter)
87  {
88  setFaces[setFacei] = mesh.faces()[iter.key()];
89  faceValues[setFacei] = iter.key();
90  setFacei++;
91  }
92 
93  primitiveFacePatch fp(setFaces, mesh.points());
94 
96  (
97  true,
98  currentSet.name(),
99  fp,
100  "faceID",
101  faceValues,
102  mesh.time().path()/vtkName
103  );
104  }
105  else if (isA<cellSet>(currentSet))
106  {
107  // External faces of cellset with OpenFOAM cellID as value
108 
109  Map<label> cellFaces(currentSet.size());
110 
111  forAllConstIter(cellSet, currentSet, iter)
112  {
113  label celli = iter.key();
114 
115  const cell& cFaces = mesh.cells()[celli];
116 
117  forAll(cFaces, i)
118  {
119  label facei = cFaces[i];
120 
121  if (mesh.isInternalFace(facei))
122  {
123  label otherCelli = mesh.faceOwner()[facei];
124 
125  if (otherCelli == celli)
126  {
127  otherCelli = mesh.faceNeighbour()[facei];
128  }
129 
130  if (!currentSet.found(otherCelli))
131  {
132  cellFaces.insert(facei, celli);
133  }
134  }
135  else
136  {
137  cellFaces.insert(facei, celli);
138  }
139  }
140  }
141 
142  faceList setFaces(cellFaces.size());
143  labelList faceValues(cellFaces.size());
144  label setFacei = 0;
145 
146  forAllConstIter(Map<label>, cellFaces, iter)
147  {
148  setFaces[setFacei] = mesh.faces()[iter.key()];
149  faceValues[setFacei] = iter(); // Cell ID
150  setFacei++;
151  }
152 
153  primitiveFacePatch fp(setFaces, mesh.points());
154 
155  writePatch
156  (
157  true,
158  currentSet.name(),
159  fp,
160  "cellID",
161  faceValues,
162  mesh.time().path()/vtkName
163  );
164  }
165  else if (isA<pointSet>(currentSet))
166  {
168  (
169  true,
170  mesh,
171  currentSet,
172  mesh.time().path()/vtkName
173  );
174  }
175  else
176  {
178  << "Don't know how to handle set of type " << currentSet.type()
179  << endl;
180  }
181 }
182 
183 
184 void printHelp(Ostream& os)
185 {
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
190  << endl
191  << "A set command should be of the following form" << endl
192  << endl
193  << " cellSet|faceSet|pointSet <setName> <action> <source>"
194  << endl
195  << endl
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"
205  << endl
206  << endl
207  << "The sources come in various forms. Type a wrong source"
208  << " to see all the types available." << endl
209  << endl
210  << "Example: pick up all cells connected by point or face to patch"
211  << " movingWall" << endl
212  << 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
225  << 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
229  << endl
230  << "or if orientation is important:" << endl
231  << " faceZoneSet f0Zone new setsToFaceZone f0 c0" << endl
232  << 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)"
237  << endl
238  << " remove - remove the set" << endl
239  << endl;
240 }
241 
242 
243 void printAllSets(const polyMesh& mesh, Ostream& os)
244 {
245  IOobjectList objects
246  (
247  mesh,
248  mesh.time().findInstance
249  (
250  polyMesh::meshSubDir/"sets",
251  word::null,
253  mesh.facesInstance()
254  ),
255  polyMesh::meshSubDir/"sets"
256  );
257  IOobjectList cellSets(objects.lookupClass(cellSet::typeName));
258  if (cellSets.size())
259  {
260  os << "cellSets:" << endl;
262  {
263  cellSet set(*iter());
264  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
265  }
266  }
267  IOobjectList faceSets(objects.lookupClass(faceSet::typeName));
268  if (faceSets.size())
269  {
270  os << "faceSets:" << endl;
272  {
273  faceSet set(*iter());
274  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
275  }
276  }
277  IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
278  if (pointSets.size())
279  {
280  os << "pointSets:" << endl;
281  forAllConstIter(IOobjectList, pointSets, iter)
282  {
283  pointSet set(*iter());
284  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
285  }
286  }
287 
288  const cellZoneMesh& cellZones = mesh.cellZones();
289  if (cellZones.size())
290  {
291  os << "cellZones:" << endl;
292  forAll(cellZones, i)
293  {
294  const cellZone& zone = cellZones[i];
295  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
296  }
297  }
298  const faceZoneMesh& faceZones = mesh.faceZones();
299  if (faceZones.size())
300  {
301  os << "faceZones:" << endl;
302  forAll(faceZones, i)
303  {
304  const faceZone& zone = faceZones[i];
305  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
306  }
307  }
308  const pointZoneMesh& pointZones = mesh.pointZones();
309  if (pointZones.size())
310  {
311  os << "pointZones:" << endl;
312  forAll(pointZones, i)
313  {
314  const pointZone& zone = pointZones[i];
315  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
316  }
317  }
318 
319  os << endl;
320 }
321 
322 
323 template<class ZoneType>
324 void removeZone
325 (
327  const word& setName
328 )
329 {
330  label zoneID = zones.findZoneID(setName);
331 
332  if (zoneID != -1)
333  {
334  Info<< "Removing zone " << setName << " at index " << zoneID << endl;
335  // Shuffle to last position
336  labelList oldToNew(zones.size());
337  label newI = 0;
338  forAll(oldToNew, i)
339  {
340  if (i != zoneID)
341  {
342  oldToNew[i] = newI++;
343  }
344  }
345  oldToNew[zoneID] = newI;
346  zones.reorder(oldToNew);
347  // Remove last element
348  zones.setSize(zones.size()-1);
349  zones.clearAddressing();
350  zones.write();
351  }
352 }
353 
354 
355 // Physically remove a set
356 void removeSet
357 (
358  const polyMesh& mesh,
359  const word& setType,
360  const word& setName
361 )
362 {
363  // Remove the file
364  IOobjectList objects
365  (
366  mesh,
367  mesh.time().findInstance
368  (
369  polyMesh::meshSubDir/"sets",
370  word::null,
372  mesh.facesInstance()
373  ),
374  polyMesh::meshSubDir/"sets"
375  );
376 
377  if (objects.found(setName))
378  {
379  // Remove file
380  fileName object = objects[setName]->objectPath();
381  Info<< "Removing file " << object << endl;
382  rm(object);
383  }
384 
385  // See if zone
386  if (setType == cellZoneSet::typeName)
387  {
388  removeZone
389  (
390  const_cast<cellZoneMesh&>(mesh.cellZones()),
391  setName
392  );
393  }
394  else if (setType == faceZoneSet::typeName)
395  {
396  removeZone
397  (
398  const_cast<faceZoneMesh&>(mesh.faceZones()),
399  setName
400  );
401  }
402  else if (setType == pointZoneSet::typeName)
403  {
404  removeZone
405  (
406  const_cast<pointZoneMesh&>(mesh.pointZones()),
407  setName
408  );
409  }
410 }
411 
412 
413 // Read command and execute. Return true if ok, false otherwise.
414 bool doCommand
415 (
416  const polyMesh& mesh,
417  const word& setType,
418  const word& setName,
419  const word& actionName,
420  const bool writeVTKFile,
421  const bool writeCurrentTime,
422  const bool noSync,
423  Istream& is
424 )
425 {
426  // Get some size estimate for set.
427  const globalMeshData& parData = mesh.globalData();
428 
429  label typSize =
430  max
431  (
432  parData.nTotalCells(),
433  max
434  (
435  parData.nTotalFaces(),
436  parData.nTotalPoints()
437  )
438  )
439  / (10*Pstream::nProcs());
440 
441 
442  bool ok = true;
443 
444  // Set to work on
445  autoPtr<topoSet> currentSetPtr;
446 
447  word sourceType;
448 
449  try
450  {
451  topoSetSource::setAction action =
452  topoSetSource::toAction(actionName);
453 
454 
456 
457  if (action == topoSetSource::REMOVE)
458  {
459  removeSet(mesh, setType, setName);
460  }
461  else if
462  (
463  (action == topoSetSource::NEW)
464  || (action == topoSetSource::CLEAR)
465  )
466  {
467  r = IOobject::NO_READ;
468  currentSetPtr = topoSet::New(setType, mesh, setName, typSize);
469  }
470  else
471  {
473  currentSetPtr = topoSet::New(setType, mesh, setName, r);
474  topoSet& currentSet = currentSetPtr();
475  // Presize it according to current mesh data.
476  currentSet.resize(max(currentSet.size(), typSize));
477  }
478 
479  if (currentSetPtr.valid())
480  {
481  topoSet& currentSet = currentSetPtr();
482 
483  Info<< " Set:" << currentSet.name()
484  << " Size:" << returnReduce(currentSet.size(), sumOp<label>())
485  << " Action:" << actionName
486  << endl;
487 
488  switch (action)
489  {
491  {
492  // Already handled above by not reading
493  break;
494  }
496  {
497  currentSet.invert(currentSet.maxSize(mesh));
498  break;
499  }
500  case topoSetSource::LIST:
501  {
502  currentSet.writeDebug(Pout, mesh, 100);
503  Pout<< endl;
504  break;
505  }
507  {
508  if (is >> sourceType)
509  {
510  autoPtr<topoSetSource> setSource
511  (
513  (
514  sourceType,
515  mesh,
516  is
517  )
518  );
519 
520  // Backup current set.
521  autoPtr<topoSet> oldSet
522  (
524  (
525  setType,
526  mesh,
527  currentSet.name() + "_old2",
528  currentSet
529  )
530  );
531 
532  currentSet.clear();
533  setSource().applyToSet(topoSetSource::NEW, currentSet);
534 
535  // Combine new value of currentSet with old one.
536  currentSet.subset(oldSet);
537  }
538  break;
539  }
540  default:
541  {
542  if (is >> sourceType)
543  {
544  autoPtr<topoSetSource> setSource
545  (
547  (
548  sourceType,
549  mesh,
550  is
551  )
552  );
553 
554  setSource().applyToSet(action, currentSet);
555  }
556  }
557  }
558 
559 
560  if (action != topoSetSource::LIST)
561  {
562  // Set will have been modified.
563 
564  // Synchronize for coupled patches.
565  if (!noSync) currentSet.sync(mesh);
566 
567  // Write
568  if (writeVTKFile)
569  {
570  mkDir(mesh.time().path()/"VTK"/currentSet.name());
571 
572  fileName vtkName
573  (
574  "VTK"/currentSet.name()/currentSet.name()
575  + "_"
576  + name(mesh.time().timeIndex())
577  + ".vtk"
578  );
579 
580  Info<< " Writing " << currentSet.name()
581  << " (size "
582  << returnReduce(currentSet.size(), sumOp<label>())
583  << ") to "
584  << currentSet.instance()/currentSet.local()
585  /currentSet.name()
586  << " and to vtk file " << vtkName << endl << endl;
587 
588  writeVTK(mesh, currentSet, vtkName);
589  }
590  else
591  {
592  Info<< " Writing " << currentSet.name()
593  << " (size "
594  << returnReduce(currentSet.size(), sumOp<label>())
595  << ") to "
596  << currentSet.instance()/currentSet.local()
597  /currentSet.name() << endl << endl;
598  }
599 
600  if (writeCurrentTime)
601  {
602  currentSet.instance() = mesh.time().timeName();
603  }
604  currentSet.write();
605  }
606  }
607  }
608  catch (Foam::IOerror& fIOErr)
609  {
610  ok = false;
611 
612  Pout<< fIOErr.message().c_str() << endl;
613 
614  if (sourceType.size())
615  {
616  Pout<< topoSetSource::usage(sourceType).c_str();
617  }
618  }
619  catch (Foam::error& fErr)
620  {
621  ok = false;
622 
623  Pout<< fErr.message().c_str() << endl;
624 
625  if (sourceType.size())
626  {
627  Pout<< topoSetSource::usage(sourceType).c_str();
628  }
629  }
630 
631  return ok;
632 }
633 
634 
635 // Status returned from parsing the first token of the line
636 enum commandStatus
637 {
638  QUIT, // quit program
639  INVALID, // token is not a valid set manipulation command
640  VALIDSETCMD, // ,, is a valid ,,
641  VALIDZONECMD // ,, is a valid zone ,,
642 };
643 
644 
645 void printMesh(const Time& runTime, const polyMesh& mesh)
646 {
647  Info<< "Time:" << runTime.timeName()
648  << " cells:" << mesh.globalData().nTotalCells()
649  << " faces:" << mesh.globalData().nTotalFaces()
650  << " points:" << mesh.globalData().nTotalPoints()
651  << " patches:" << mesh.boundaryMesh().size()
652  << " bb:" << mesh.bounds() << nl;
653 }
654 
655 
656 polyMesh::readUpdateState meshReadUpdate(polyMesh& mesh)
657 {
659 
660  switch(stat)
661  {
662  case polyMesh::UNCHANGED:
663  {
664  Info<< " mesh not changed." << endl;
665  break;
666  }
668  {
669  Info<< " points moved; topology unchanged." << endl;
670  break;
671  }
673  {
674  Info<< " topology changed; patches unchanged." << nl
675  << " ";
676  printMesh(mesh.time(), mesh);
677  break;
678  }
680  {
681  Info<< " topology changed and patches changed." << nl
682  << " ";
683  printMesh(mesh.time(), mesh);
684 
685  break;
686  }
687  default:
688  {
690  << "Illegal mesh update state "
691  << stat << abort(FatalError);
692  break;
693  }
694  }
695  return stat;
696 }
697 
698 
699 commandStatus parseType
700 (
701  Time& runTime,
702  polyMesh& mesh,
703  const word& setType,
704  IStringStream& is
705 )
706 {
707  if (setType.empty())
708  {
709  Info<< "Type 'help' for usage information" << endl;
710 
711  return INVALID;
712  }
713  else if (setType == "help")
714  {
715  printHelp(Info);
716 
717  return INVALID;
718  }
719  else if (setType == "list")
720  {
721  printAllSets(mesh, Info);
722 
723  return INVALID;
724  }
725  else if (setType == "time")
726  {
727  scalar requestedTime = readScalar(is);
728  instantList Times = runTime.times();
729 
730  label nearestIndex = Time::findClosestTimeIndex(Times, requestedTime);
731 
732  Info<< "Changing time from " << runTime.timeName()
733  << " to " << Times[nearestIndex].name()
734  << endl;
735 
736  // Set time
737  runTime.setTime(Times[nearestIndex], nearestIndex);
738  // Optionally re-read mesh
739  meshReadUpdate(mesh);
740 
741  return INVALID;
742  }
743  else if (setType == "quit")
744  {
745  Info<< "Quitting ..." << endl;
746 
747  return QUIT;
748  }
749  else if
750  (
751  setType == "cellSet"
752  || setType == "faceSet"
753  || setType == "pointSet"
754  )
755  {
756  return VALIDSETCMD;
757  }
758  else if
759  (
760  setType == "cellZoneSet"
761  || setType == "faceZoneSet"
762  || setType == "pointZoneSet"
763  )
764  {
765  return VALIDZONECMD;
766  }
767  else
768  {
770  << "Illegal command " << setType << endl
771  << "Should be one of 'help', 'list', 'time' or a set type :"
772  << " 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'"
773  << endl;
774 
775  return INVALID;
776  }
777 }
778 
779 
780 commandStatus parseAction(const word& actionName)
781 {
782  commandStatus stat = INVALID;
783 
784  if (actionName.size())
785  {
786  try
787  {
788  (void)topoSetSource::toAction(actionName);
789 
790  stat = VALIDSETCMD;
791  }
792  catch (Foam::IOerror& fIOErr)
793  {
794  stat = INVALID;
795  }
796  catch (Foam::error& fErr)
797  {
798  stat = INVALID;
799  }
800  }
801  return stat;
802 }
803 
804 
805 
806 int main(int argc, char *argv[])
807 {
808  timeSelector::addOptions(true, false);
809  #include "addRegionOption.H"
810  argList::addBoolOption("noVTK", "do not write VTK files");
811  argList::addBoolOption("loop", "execute batch commands for all timesteps");
813  (
814  "batch",
815  "file",
816  "process in batch mode, using input from specified file"
817  );
819  (
820  "noSync",
821  "do not synchronise selection across coupled patches"
822  );
823 
824  #include "setRootCase.H"
825  #include "createTime.H"
826  instantList timeDirs = timeSelector::select0(runTime, args);
827 
828  const bool writeVTK = !args.optionFound("noVTK");
829  const bool loop = args.optionFound("loop");
830  const bool batch = args.optionFound("batch");
831  const bool noSync = args.optionFound("noSync");
832 
833  if (loop && !batch)
834  {
836  << "Can only loop in batch mode."
837  << exit(FatalError);
838  }
839 
840 
841  #include "createNamedPolyMesh.H"
842 
843  // Print some mesh info
844  printMesh(runTime, mesh);
845 
846  // Print current sets
847  printAllSets(mesh, Info);
848 
849  // Read history if interactive
850  #ifdef HAS_READLINE
851  if (!batch && !read_history((runTime.path()/historyFile).c_str()))
852  {
853  Info<< "Successfully read history from " << historyFile << endl;
854  }
855  #endif
856 
857 
858  // Exit status
859  int status = 0;
860 
861 
862  forAll(timeDirs, timeI)
863  {
864  runTime.setTime(timeDirs[timeI], timeI);
865  Info<< "Time = " << runTime.timeName() << endl;
866 
867  // Handle geometry/topology changes
868  meshReadUpdate(mesh);
869 
870 
871  // Main command read & execute loop
872  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
873 
874  autoPtr<IFstream> fileStreamPtr(NULL);
875 
876  if (batch)
877  {
878  const fileName batchFile = args["batch"];
879 
880  Info<< "Reading commands from file " << batchFile << endl;
881 
882  // we cannot handle .gz files
883  if (!isFile(batchFile, false))
884  {
886  << "Cannot open file " << batchFile << exit(FatalError);
887  }
888 
889  fileStreamPtr.reset(new IFstream(batchFile));
890  }
891 
892  Info<< "Please type 'help', 'quit' or a set command after prompt."
893  << endl;
894 
895  // Whether to quit
896  bool quit = false;
897 
900 
901  do
902  {
903  string rawLine;
904 
905  // Type: cellSet, faceSet, pointSet
906  word setType;
907  // Name of destination set.
908  word setName;
909  // Action (new, invert etc.)
910  word actionName;
911 
912  commandStatus stat = INVALID;
913 
914  if (fileStreamPtr.valid())
915  {
916  if (!fileStreamPtr().good())
917  {
918  Info<< "End of batch file" << endl;
919  // No error.
920  break;
921  }
922 
923  fileStreamPtr().getLine(rawLine);
924 
925  if (rawLine.size())
926  {
927  Info<< "Doing:" << rawLine << endl;
928  }
929  }
930  else
931  {
932  #ifdef HAS_READLINE
933  {
934  char* linePtr = readline("readline>");
935 
936  if (linePtr)
937  {
938  rawLine = string(linePtr);
939 
940  if (*linePtr)
941  {
942  add_history(linePtr);
943  write_history(historyFile);
944  }
945 
946  free(linePtr); // readline uses malloc, not new.
947  }
948  else
949  {
950  break;
951  }
952  }
953  #else
954  {
955  if (!std::cin.good())
956  {
957  Info<< "End of cin" << endl;
958  // No error.
959  break;
960  }
961  Info<< "Command>" << flush;
962  std::getline(std::cin, rawLine);
963  }
964  #endif
965  }
966 
967  // Strip off anything after #
968  string::size_type i = rawLine.find_first_of("#");
969  if (i != string::npos)
970  {
971  rawLine = rawLine(0, i);
972  }
973 
974  if (rawLine.empty())
975  {
976  continue;
977  }
978 
979  IStringStream is(rawLine + ' ');
980 
981  // Type: cellSet, faceSet, pointSet, faceZoneSet
982  is >> setType;
983 
984  stat = parseType(runTime, mesh, setType, is);
985 
986  if (stat == VALIDSETCMD || stat == VALIDZONECMD)
987  {
988  if (is >> setName)
989  {
990  if (is >> actionName)
991  {
992  stat = parseAction(actionName);
993  }
994  }
995  }
996 
997  if (stat == QUIT)
998  {
999  // Make sure to quit
1000  quit = true;
1001  }
1002  else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
1003  {
1004  bool ok = doCommand
1005  (
1006  mesh,
1007  setType,
1008  setName,
1009  actionName,
1010  writeVTK,
1011  loop, // if in looping mode dump sets to time directory
1012  noSync,
1013  is
1014  );
1015 
1016  if (!ok && batch)
1017  {
1018  // Exit with error.
1019  quit = true;
1020  status = 1;
1021  }
1022  }
1023 
1024  } while (!quit);
1025 
1026  if (quit)
1027  {
1028  break;
1029  }
1030  }
1031 
1032  Info<< "End\n" << endl;
1033 
1034  return status;
1035 }
1036 
1037 
1038 // ************************************************************************* //
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
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.
Definition: UList.H:428
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:387
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
A list of face labels.
Definition: faceSet.H:48
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const string & usage(const word &name)
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:427
A set of point labels.
Definition: pointSet.H:48
error FatalError
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:778
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.
Definition: error.H:319
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")
Definition: polyMesh.H:309
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
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.
Definition: topoSet.C:46
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:492
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:715
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
const cellList & cells() const
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:66
Write faceSet to vtk polydata file. Only one data which is original faceID.
const word & name() const
Return name.
Definition: zone.H:150
A list of faces which address into the list of points.
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:341
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".
Definition: findInstance.C:38
dynamicFvMesh & mesh
void throwExceptions()
Definition: error.H:122
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
Definition: topoSet.C:201
A class for handling words, derived from string.
Definition: word.H:59
void clear()
Clear all entries from table.
Definition: HashTable.C:464
label nTotalFaces() const
Return total number of faces in decomposed mesh. Not.
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:93
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
static const word null
An empty word.
Definition: word.H:77
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.
Definition: topoSet.C:467
const fileName & local() const
Definition: IOobject.H:347
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
Definition: Time.C:924
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Report an I/O error.
Definition: error.H:196
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
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.
Definition: HashTable.C:109
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1140
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
static const char nl
Definition: Ostream.H:262
Input from file stream.
Definition: IFstream.H:81
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
const pointZoneMesh & pointZones() const
Return point zone mesh.
Definition: polyMesh.H:457
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:295
A subset of mesh cells.
Definition: cellZone.H:61
string message() const
Definition: error.C:162
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Definition: topoSetSource.C:74
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
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.
Definition: polyMesh.H:469
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:399
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:245
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1023
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list...
Definition: pointZone.H:62
#define WarningInFunction
Report a warning using Foam::Warning.
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Input from memory buffer stream.
Definition: IStringStream.H:49
A collection of cell labels.
Definition: cellSet.H:48
virtual bool write() const
Write using setting from DB.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
Definition: topoSet.C:504
instantList times() const
Search the case for valid time directories.
Definition: Time.C:731
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: topoSet.C:449
messageStream Info
static setAction toAction(const word &actionName)
Convert string to action.
void resize(const label newSize)
Resize the hash table for efficiency.
Definition: HashTable.C:428
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
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...
Definition: PtrList.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
void writeVTK(OFstream &os, const Type &value)
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: polyMeshIO.C:65
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:819
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1017
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
fileName path() const
Return path.
Definition: Time.H:269
Foam::argList args(argc, argv)
A class for handling character strings derived from std::string.
Definition: string.H:74
const fileName & instance() const
Definition: IOobject.H:337
label nTotalCells() const
Return total number of cells in decomposed mesh.
const word & name() const
Return name.
Definition: IOobject.H:260
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Namespace for OpenFOAM.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.
Definition: Time.C:804
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
IOerror FatalIOError