setSet.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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  // Force flushing so we know it has finished writing
352  fileHandler().flush();
353  }
354 }
355 
356 
357 // Physically remove a set
358 void removeSet
359 (
360  const polyMesh& mesh,
361  const word& setType,
362  const word& setName
363 )
364 {
365  // Remove the file
366  IOobjectList objects
367  (
368  mesh,
369  mesh.time().findInstance
370  (
371  polyMesh::meshSubDir/"sets",
372  word::null,
374  mesh.facesInstance()
375  ),
376  polyMesh::meshSubDir/"sets"
377  );
378 
379  if (objects.found(setName))
380  {
381  // Remove file
382  fileName object = objects[setName]->objectPath();
383  Info<< "Removing file " << object << endl;
384  rm(object);
385  }
386 
387  // See if zone
388  if (setType == cellZoneSet::typeName)
389  {
390  removeZone
391  (
392  const_cast<cellZoneMesh&>(mesh.cellZones()),
393  setName
394  );
395  }
396  else if (setType == faceZoneSet::typeName)
397  {
398  removeZone
399  (
400  const_cast<faceZoneMesh&>(mesh.faceZones()),
401  setName
402  );
403  }
404  else if (setType == pointZoneSet::typeName)
405  {
406  removeZone
407  (
408  const_cast<pointZoneMesh&>(mesh.pointZones()),
409  setName
410  );
411  }
412 }
413 
414 
415 // Read command and execute. Return true if ok, false otherwise.
416 bool doCommand
417 (
418  const polyMesh& mesh,
419  const word& setType,
420  const word& setName,
421  const word& actionName,
422  const bool writeVTKFile,
423  const bool writeCurrentTime,
424  const bool noSync,
425  Istream& is
426 )
427 {
428  // Get some size estimate for set.
429  const globalMeshData& parData = mesh.globalData();
430 
431  label typSize =
432  max
433  (
434  parData.nTotalCells(),
435  max
436  (
437  parData.nTotalFaces(),
438  parData.nTotalPoints()
439  )
440  )
441  / (10*Pstream::nProcs());
442 
443 
444  bool ok = true;
445 
446  // Set to work on
447  autoPtr<topoSet> currentSetPtr;
448 
449  word sourceType;
450 
451  try
452  {
453  topoSetSource::setAction action =
454  topoSetSource::toAction(actionName);
455 
456 
458 
459  if (action == topoSetSource::REMOVE)
460  {
461  removeSet(mesh, setType, setName);
462  }
463  else if
464  (
465  (action == topoSetSource::NEW)
466  || (action == topoSetSource::CLEAR)
467  )
468  {
469  r = IOobject::NO_READ;
470  currentSetPtr = topoSet::New(setType, mesh, setName, typSize);
471  }
472  else
473  {
475  currentSetPtr = topoSet::New(setType, mesh, setName, r);
476  topoSet& currentSet = currentSetPtr();
477  // Presize it according to current mesh data.
478  currentSet.resize(max(currentSet.size(), typSize));
479  }
480 
481  if (currentSetPtr.valid())
482  {
483  topoSet& currentSet = currentSetPtr();
484 
485  Info<< " Set:" << currentSet.name()
486  << " Size:" << returnReduce(currentSet.size(), sumOp<label>())
487  << " Action:" << actionName
488  << endl;
489 
490  switch (action)
491  {
493  {
494  // Already handled above by not reading
495  break;
496  }
498  {
499  currentSet.invert(currentSet.maxSize(mesh));
500  break;
501  }
502  case topoSetSource::LIST:
503  {
504  currentSet.writeDebug(Pout, mesh, 100);
505  Pout<< endl;
506  break;
507  }
509  {
510  if (is >> sourceType)
511  {
512  autoPtr<topoSetSource> setSource
513  (
515  (
516  sourceType,
517  mesh,
518  is
519  )
520  );
521 
522  // Backup current set.
523  autoPtr<topoSet> oldSet
524  (
526  (
527  setType,
528  mesh,
529  currentSet.name() + "_old2",
530  currentSet
531  )
532  );
533 
534  currentSet.clear();
535  setSource().applyToSet(topoSetSource::NEW, currentSet);
536 
537  // Combine new value of currentSet with old one.
538  currentSet.subset(oldSet);
539  }
540  break;
541  }
542  default:
543  {
544  if (is >> sourceType)
545  {
546  autoPtr<topoSetSource> setSource
547  (
549  (
550  sourceType,
551  mesh,
552  is
553  )
554  );
555 
556  setSource().applyToSet(action, currentSet);
557  }
558  }
559  }
560 
561 
562  if (action != topoSetSource::LIST)
563  {
564  // Set will have been modified.
565 
566  // Synchronize for coupled patches.
567  if (!noSync) currentSet.sync(mesh);
568 
569  // Write
570  if (writeVTKFile)
571  {
572  mkDir(mesh.time().path()/"VTK"/currentSet.name());
573 
574  fileName vtkName
575  (
576  "VTK"/currentSet.name()/currentSet.name()
577  + "_"
578  + name(mesh.time().timeIndex())
579  + ".vtk"
580  );
581 
582  Info<< " Writing " << currentSet.name()
583  << " (size "
584  << returnReduce(currentSet.size(), sumOp<label>())
585  << ") to "
586  << currentSet.instance()/currentSet.local()
587  /currentSet.name()
588  << " and to vtk file " << vtkName << endl << endl;
589 
590  writeVTK(mesh, currentSet, vtkName);
591  }
592  else
593  {
594  Info<< " Writing " << currentSet.name()
595  << " (size "
596  << returnReduce(currentSet.size(), sumOp<label>())
597  << ") to "
598  << currentSet.instance()/currentSet.local()
599  /currentSet.name() << endl << endl;
600  }
601 
602  if (writeCurrentTime)
603  {
604  currentSet.instance() = mesh.time().timeName();
605  }
606  currentSet.write();
607  // Make sure writing is finished
608  fileHandler().flush();
609  }
610  }
611  }
612  catch (Foam::IOerror& fIOErr)
613  {
614  ok = false;
615 
616  Pout<< fIOErr.message().c_str() << endl;
617 
618  if (sourceType.size())
619  {
620  Pout<< topoSetSource::usage(sourceType).c_str();
621  }
622  }
623  catch (Foam::error& fErr)
624  {
625  ok = false;
626 
627  Pout<< fErr.message().c_str() << endl;
628 
629  if (sourceType.size())
630  {
631  Pout<< topoSetSource::usage(sourceType).c_str();
632  }
633  }
634 
635  return ok;
636 }
637 
638 
639 // Status returned from parsing the first token of the line
640 enum commandStatus
641 {
642  QUIT, // quit program
643  INVALID, // token is not a valid set manipulation command
644  VALIDSETCMD, // ,, is a valid ,,
645  VALIDZONECMD // ,, is a valid zone ,,
646 };
647 
648 
649 void printMesh(const Time& runTime, const polyMesh& mesh)
650 {
651  Info<< "Time:" << runTime.timeName()
652  << " cells:" << mesh.globalData().nTotalCells()
653  << " faces:" << mesh.globalData().nTotalFaces()
654  << " points:" << mesh.globalData().nTotalPoints()
655  << " patches:" << mesh.boundaryMesh().size()
656  << " bb:" << mesh.bounds() << nl;
657 }
658 
659 
660 polyMesh::readUpdateState meshReadUpdate(polyMesh& mesh)
661 {
663 
664  switch(stat)
665  {
666  case polyMesh::UNCHANGED:
667  {
668  Info<< " mesh not changed." << endl;
669  break;
670  }
672  {
673  Info<< " points moved; topology unchanged." << endl;
674  break;
675  }
677  {
678  Info<< " topology changed; patches unchanged." << nl
679  << " ";
680  printMesh(mesh.time(), mesh);
681  break;
682  }
684  {
685  Info<< " topology changed and patches changed." << nl
686  << " ";
687  printMesh(mesh.time(), mesh);
688 
689  break;
690  }
691  default:
692  {
694  << "Illegal mesh update state "
695  << stat << abort(FatalError);
696  break;
697  }
698  }
699  return stat;
700 }
701 
702 
703 commandStatus parseType
704 (
705  Time& runTime,
706  polyMesh& mesh,
707  const word& setType,
708  IStringStream& is
709 )
710 {
711  if (setType.empty())
712  {
713  Info<< "Type 'help' for usage information" << endl;
714 
715  return INVALID;
716  }
717  else if (setType == "help")
718  {
719  printHelp(Info);
720 
721  return INVALID;
722  }
723  else if (setType == "list")
724  {
725  printAllSets(mesh, Info);
726 
727  return INVALID;
728  }
729  else if (setType == "time")
730  {
731  scalar requestedTime = readScalar(is);
732  instantList Times = runTime.times();
733 
734  label nearestIndex = Time::findClosestTimeIndex(Times, requestedTime);
735 
736  Info<< "Changing time from " << runTime.timeName()
737  << " to " << Times[nearestIndex].name()
738  << endl;
739 
740  // Set time
741  runTime.setTime(Times[nearestIndex], nearestIndex);
742  // Optionally re-read mesh
743  meshReadUpdate(mesh);
744 
745  return INVALID;
746  }
747  else if (setType == "quit")
748  {
749  Info<< "Quitting ..." << endl;
750 
751  return QUIT;
752  }
753  else if
754  (
755  setType == "cellSet"
756  || setType == "faceSet"
757  || setType == "pointSet"
758  )
759  {
760  return VALIDSETCMD;
761  }
762  else if
763  (
764  setType == "cellZoneSet"
765  || setType == "faceZoneSet"
766  || setType == "pointZoneSet"
767  )
768  {
769  return VALIDZONECMD;
770  }
771  else
772  {
774  << "Illegal command " << setType << endl
775  << "Should be one of 'help', 'list', 'time' or a set type :"
776  << " 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'"
777  << endl;
778 
779  return INVALID;
780  }
781 }
782 
783 
784 commandStatus parseAction(const word& actionName)
785 {
786  commandStatus stat = INVALID;
787 
788  if (actionName.size())
789  {
790  try
791  {
792  (void)topoSetSource::toAction(actionName);
793 
794  stat = VALIDSETCMD;
795  }
796  catch (Foam::IOerror& fIOErr)
797  {
798  stat = INVALID;
799  }
800  catch (Foam::error& fErr)
801  {
802  stat = INVALID;
803  }
804  }
805  return stat;
806 }
807 
808 
809 
810 int main(int argc, char *argv[])
811 {
812  // Specific to topoSet/setSet: quite often we want to block upon writing
813  // a set so we can immediately re-read it. So avoid use of threading
814  // for set writing.
815  timeSelector::addOptions(true, false);
816  #include "addRegionOption.H"
817  argList::addBoolOption("noVTK", "do not write VTK files");
818  argList::addBoolOption("loop", "execute batch commands for all timesteps");
820  (
821  "batch",
822  "file",
823  "process in batch mode, using input from specified file"
824  );
826  (
827  "noSync",
828  "do not synchronise selection across coupled patches"
829  );
830 
831  #include "setRootCase.H"
832  #include "createTime.H"
833  instantList timeDirs = timeSelector::select0(runTime, args);
834 
835  const bool writeVTK = !args.optionFound("noVTK");
836  const bool loop = args.optionFound("loop");
837  const bool batch = args.optionFound("batch");
838  const bool noSync = args.optionFound("noSync");
839 
840  if (loop && !batch)
841  {
843  << "Can only loop in batch mode."
844  << exit(FatalError);
845  }
846 
847 
848  #include "createNamedPolyMesh.H"
849 
850  // Print some mesh info
851  printMesh(runTime, mesh);
852 
853  // Print current sets
854  printAllSets(mesh, Info);
855 
856  // Read history if interactive
857  #ifdef HAS_READLINE
858  if (!batch && !read_history((runTime.path()/historyFile).c_str()))
859  {
860  Info<< "Successfully read history from " << historyFile << endl;
861  }
862  #endif
863 
864 
865  // Exit status
866  int status = 0;
867 
868 
869  forAll(timeDirs, timeI)
870  {
871  runTime.setTime(timeDirs[timeI], timeI);
872  Info<< "Time = " << runTime.timeName() << endl;
873 
874  // Handle geometry/topology changes
875  meshReadUpdate(mesh);
876 
877 
878  // Main command read & execute loop
879  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
880 
881  autoPtr<IFstream> fileStreamPtr(nullptr);
882 
883  if (batch)
884  {
885  const fileName batchFile = args["batch"];
886 
887  Info<< "Reading commands from file " << batchFile << endl;
888 
889  // we cannot handle .gz files
890  if (!isFile(batchFile, false))
891  {
893  << "Cannot open file " << batchFile << exit(FatalError);
894  }
895 
896  fileStreamPtr.reset(new IFstream(batchFile));
897  }
898 
899  Info<< "Please type 'help', 'quit' or a set command after prompt."
900  << endl;
901 
902  // Whether to quit
903  bool quit = false;
904 
907 
908  do
909  {
910  string rawLine;
911 
912  // Type: cellSet, faceSet, pointSet
913  word setType;
914  // Name of destination set.
915  word setName;
916  // Action (new, invert etc.)
917  word actionName;
918 
919  commandStatus stat = INVALID;
920 
921  if (fileStreamPtr.valid())
922  {
923  if (!fileStreamPtr().good())
924  {
925  Info<< "End of batch file" << endl;
926  // No error.
927  break;
928  }
929 
930  fileStreamPtr().getLine(rawLine);
931 
932  if (rawLine.size())
933  {
934  Info<< "Doing:" << rawLine << endl;
935  }
936  }
937  else
938  {
939  #ifdef HAS_READLINE
940  {
941  char* linePtr = readline("readline>");
942 
943  if (linePtr)
944  {
945  rawLine = string(linePtr);
946 
947  if (*linePtr)
948  {
949  add_history(linePtr);
950  write_history(historyFile);
951  }
952 
953  free(linePtr); // readline uses malloc, not new.
954  }
955  else
956  {
957  break;
958  }
959  }
960  #else
961  {
962  if (!std::cin.good())
963  {
964  Info<< "End of cin" << endl;
965  // No error.
966  break;
967  }
968  Info<< "Command>" << flush;
969  std::getline(std::cin, rawLine);
970  }
971  #endif
972  }
973 
974  // Strip off anything after #
975  string::size_type i = rawLine.find_first_of("#");
976  if (i != string::npos)
977  {
978  rawLine = rawLine(0, i);
979  }
980 
981  if (rawLine.empty())
982  {
983  continue;
984  }
985 
986  IStringStream is(rawLine + ' ');
987 
988  // Type: cellSet, faceSet, pointSet, faceZoneSet
989  is >> setType;
990 
991  stat = parseType(runTime, mesh, setType, is);
992 
993  if (stat == VALIDSETCMD || stat == VALIDZONECMD)
994  {
995  if (is >> setName)
996  {
997  if (is >> actionName)
998  {
999  stat = parseAction(actionName);
1000  }
1001  }
1002  }
1003 
1004  if (stat == QUIT)
1005  {
1006  // Make sure to quit
1007  quit = true;
1008  }
1009  else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
1010  {
1011  bool ok = doCommand
1012  (
1013  mesh,
1014  setType,
1015  setName,
1016  actionName,
1017  writeVTK,
1018  loop, // if in looping mode dump sets to time directory
1019  noSync,
1020  is
1021  );
1022 
1023  if (!ok && batch)
1024  {
1025  // Exit with error.
1026  quit = true;
1027  status = 1;
1028  }
1029  }
1030 
1031  } while (!quit);
1032 
1033  if (quit)
1034  {
1035  break;
1036  }
1037  }
1038 
1039  Info<< "End\n" << endl;
1040 
1041  return status;
1042 }
1043 
1044 
1045 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:424
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.
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.
Definition: UList.H:428
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.
Definition: ZoneMesh.C:387
fileName path() const
Return path.
Definition: Time.H:266
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
const word & name() const
Return name.
Definition: IOobject.H:297
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
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:466
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const string & usage(const word &name)
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:801
A set of point labels.
Definition: pointSet.H:48
error FatalError
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
void reorder(const labelUList &)
Reorders elements. Ordering does not have to be done in.
Definition: PtrList.C:197
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1047
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")
Definition: polyMesh.H:312
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:163
void writePointSet(const bool binary, const primitiveMesh &mesh, const topoSet &set, const fileName &fileName)
Write pointSet to vtk polydata file.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
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: Time.C:649
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.
Definition: Time.C:626
readOption
Enumeration defining the read options.
Definition: IOobject.H:107
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1003
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.
A list of faces which address into the list of points.
label nTotalFaces() const
Return total number of faces in decomposed mesh. Not.
dynamicFvMesh & mesh
void throwExceptions()
Definition: error.H:122
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:341
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
const pointZoneMesh & pointZones() const
Return point zone mesh.
Definition: polyMesh.H:460
A class for handling words, derived from string.
Definition: word.H:59
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:472
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
void clear()
Clear all entries from table.
Definition: HashTable.C:468
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
string message() const
Definition: error.C:162
const fileName & local() const
Definition: IOobject.H:402
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:120
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1041
static const word null
An empty word.
Definition: word.H:77
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1174
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
Definition: Time.C:873
const word & name() const
Return name.
Definition: zone.H:147
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.
Definition: doubleScalar.H:68
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1028
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Definition: autoPtrI.H:83
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
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
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?
Definition: POSIX.C:543
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:265
const Time & time() const
Return time.
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:257
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:289
A subset of mesh cells.
Definition: cellZone.H:61
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
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
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.
Definition: UPtrListI.H:29
Template functions to aid in the implementation of demand driven data.
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:430
const fileName & instance() const
Definition: IOobject.H:392
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:409
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:248
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
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
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.
Definition: Time.C:642
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:432
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:52
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:110
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:71
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:1008
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.
Definition: string.H:74
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:750
IOerror FatalIOError