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-2017 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 #include "collatedFileOperation.H"
52 
53 #include <stdio.h>
54 
55 
56 #ifdef HAS_READLINE
57  #include <readline/readline.h>
58  #include <readline/history.h>
59 #endif
60 
61 using namespace Foam;
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 
66 #ifdef HAS_READLINE
67 static const char* historyFile = ".setSet";
68 #endif
69 
70 
71 // Write set to VTK readable files
72 void writeVTK
73 (
74  const polyMesh& mesh,
75  const topoSet& currentSet,
76  const fileName& vtkName
77 )
78 {
79  if (isA<faceSet>(currentSet))
80  {
81  // Faces of set with OpenFOAM faceID as value
82 
83  faceList setFaces(currentSet.size());
84  labelList faceValues(currentSet.size());
85  label setFacei = 0;
86 
87  forAllConstIter(topoSet, currentSet, iter)
88  {
89  setFaces[setFacei] = mesh.faces()[iter.key()];
90  faceValues[setFacei] = iter.key();
91  setFacei++;
92  }
93 
94  primitiveFacePatch fp(setFaces, mesh.points());
95 
97  (
98  true,
99  currentSet.name(),
100  fp,
101  "faceID",
102  faceValues,
103  mesh.time().path()/vtkName
104  );
105  }
106  else if (isA<cellSet>(currentSet))
107  {
108  // External faces of cellset with OpenFOAM cellID as value
109 
110  Map<label> cellFaces(currentSet.size());
111 
112  forAllConstIter(cellSet, currentSet, iter)
113  {
114  label celli = iter.key();
115 
116  const cell& cFaces = mesh.cells()[celli];
117 
118  forAll(cFaces, i)
119  {
120  label facei = cFaces[i];
121 
122  if (mesh.isInternalFace(facei))
123  {
124  label otherCelli = mesh.faceOwner()[facei];
125 
126  if (otherCelli == celli)
127  {
128  otherCelli = mesh.faceNeighbour()[facei];
129  }
130 
131  if (!currentSet.found(otherCelli))
132  {
133  cellFaces.insert(facei, celli);
134  }
135  }
136  else
137  {
138  cellFaces.insert(facei, celli);
139  }
140  }
141  }
142 
143  faceList setFaces(cellFaces.size());
144  labelList faceValues(cellFaces.size());
145  label setFacei = 0;
146 
147  forAllConstIter(Map<label>, cellFaces, iter)
148  {
149  setFaces[setFacei] = mesh.faces()[iter.key()];
150  faceValues[setFacei] = iter(); // Cell ID
151  setFacei++;
152  }
153 
154  primitiveFacePatch fp(setFaces, mesh.points());
155 
156  writePatch
157  (
158  true,
159  currentSet.name(),
160  fp,
161  "cellID",
162  faceValues,
163  mesh.time().path()/vtkName
164  );
165  }
166  else if (isA<pointSet>(currentSet))
167  {
169  (
170  true,
171  mesh,
172  currentSet,
173  mesh.time().path()/vtkName
174  );
175  }
176  else
177  {
179  << "Don't know how to handle set of type " << currentSet.type()
180  << endl;
181  }
182 }
183 
184 
185 void printHelp(Ostream& os)
186 {
187  os << "Please type 'help', 'list', 'quit', 'time ddd'"
188  << " or a set command after prompt." << endl
189  << "'list' will show all current cell/face/point sets." << endl
190  << "'time ddd' will change the current time." << endl
191  << endl
192  << "A set command should be of the following form" << endl
193  << endl
194  << " cellSet|faceSet|pointSet <setName> <action> <source>"
195  << endl
196  << endl
197  << "The <action> is one of" << endl
198  << " list - prints the contents of the set" << endl
199  << " clear - clears the set" << endl
200  << " invert - inverts the set" << endl
201  << " remove - remove the set" << endl
202  << " new <source> - sets to set to the source set" << endl
203  << " add <source> - adds all elements from the source set" << endl
204  << " delete <source> - deletes ,," << endl
205  << " subset <source> - combines current set with the source set"
206  << endl
207  << endl
208  << "The sources come in various forms. Type a wrong source"
209  << " to see all the types available." << endl
210  << endl
211  << "Example: pick up all cells connected by point or face to patch"
212  << " movingWall" << endl
213  << endl
214  << "Pick up all faces of patch:" << endl
215  << " faceSet f0 new patchToFace movingWall" << endl
216  << "Add faces 0,1,2:" << endl
217  << " faceSet f0 add labelToFace (0 1 2)" << endl
218  << "Pick up all points used by faces in faceSet f0:" << endl
219  << " pointSet p0 new faceToPoint f0 all" << endl
220  << "Pick up cell which has any face in f0:" << endl
221  << " cellSet c0 new faceToCell f0 any" << endl
222  << "Add cells which have any point in p0:" << endl
223  << " cellSet c0 add pointToCell p0 any" << endl
224  << "List set:" << endl
225  << " cellSet c0 list" << endl
226  << endl
227  << "Zones can be set using zoneSets from corresponding sets:" << endl
228  << " cellZoneSet c0Zone new setToCellZone c0" << endl
229  << " faceZoneSet f0Zone new setToFaceZone f0" << endl
230  << endl
231  << "or if orientation is important:" << endl
232  << " faceZoneSet f0Zone new setsToFaceZone f0 c0" << endl
233  << endl
234  << "ZoneSets can be manipulated using the general actions:" << endl
235  << " list - prints the contents of the set" << endl
236  << " clear - clears the set" << endl
237  << " invert - inverts the set (undefined orientation)"
238  << endl
239  << " remove - remove the set" << endl
240  << endl;
241 }
242 
243 
244 void printAllSets(const polyMesh& mesh, Ostream& os)
245 {
246  IOobjectList objects
247  (
248  mesh,
249  mesh.time().findInstance
250  (
251  polyMesh::meshSubDir/"sets",
252  word::null,
254  mesh.facesInstance()
255  ),
256  polyMesh::meshSubDir/"sets"
257  );
258  IOobjectList cellSets(objects.lookupClass(cellSet::typeName));
259  if (cellSets.size())
260  {
261  os << "cellSets:" << endl;
263  {
264  cellSet set(*iter());
265  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
266  }
267  }
268  IOobjectList faceSets(objects.lookupClass(faceSet::typeName));
269  if (faceSets.size())
270  {
271  os << "faceSets:" << endl;
273  {
274  faceSet set(*iter());
275  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
276  }
277  }
278  IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
279  if (pointSets.size())
280  {
281  os << "pointSets:" << endl;
282  forAllConstIter(IOobjectList, pointSets, iter)
283  {
284  pointSet set(*iter());
285  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
286  }
287  }
288 
289  const cellZoneMesh& cellZones = mesh.cellZones();
290  if (cellZones.size())
291  {
292  os << "cellZones:" << endl;
293  forAll(cellZones, i)
294  {
295  const cellZone& zone = cellZones[i];
296  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
297  }
298  }
299  const faceZoneMesh& faceZones = mesh.faceZones();
300  if (faceZones.size())
301  {
302  os << "faceZones:" << endl;
303  forAll(faceZones, i)
304  {
305  const faceZone& zone = faceZones[i];
306  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
307  }
308  }
309  const pointZoneMesh& pointZones = mesh.pointZones();
310  if (pointZones.size())
311  {
312  os << "pointZones:" << endl;
313  forAll(pointZones, i)
314  {
315  const pointZone& zone = pointZones[i];
316  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
317  }
318  }
319 
320  os << endl;
321 }
322 
323 
324 template<class ZoneType>
325 void removeZone
326 (
328  const word& setName
329 )
330 {
331  label zoneID = zones.findZoneID(setName);
332 
333  if (zoneID != -1)
334  {
335  Info<< "Removing zone " << setName << " at index " << zoneID << endl;
336  // Shuffle to last position
337  labelList oldToNew(zones.size());
338  label newI = 0;
339  forAll(oldToNew, i)
340  {
341  if (i != zoneID)
342  {
343  oldToNew[i] = newI++;
344  }
345  }
346  oldToNew[zoneID] = newI;
347  zones.reorder(oldToNew);
348  // Remove last element
349  zones.setSize(zones.size()-1);
350  zones.clearAddressing();
351  zones.write();
352  }
353 }
354 
355 
356 // Physically remove a set
357 void removeSet
358 (
359  const polyMesh& mesh,
360  const word& setType,
361  const word& setName
362 )
363 {
364  // Remove the file
365  IOobjectList objects
366  (
367  mesh,
368  mesh.time().findInstance
369  (
370  polyMesh::meshSubDir/"sets",
371  word::null,
373  mesh.facesInstance()
374  ),
375  polyMesh::meshSubDir/"sets"
376  );
377 
378  if (objects.found(setName))
379  {
380  // Remove file
381  fileName object = objects[setName]->objectPath();
382  Info<< "Removing file " << object << endl;
383  rm(object);
384  }
385 
386  // See if zone
387  if (setType == cellZoneSet::typeName)
388  {
389  removeZone
390  (
391  const_cast<cellZoneMesh&>(mesh.cellZones()),
392  setName
393  );
394  }
395  else if (setType == faceZoneSet::typeName)
396  {
397  removeZone
398  (
399  const_cast<faceZoneMesh&>(mesh.faceZones()),
400  setName
401  );
402  }
403  else if (setType == pointZoneSet::typeName)
404  {
405  removeZone
406  (
407  const_cast<pointZoneMesh&>(mesh.pointZones()),
408  setName
409  );
410  }
411 }
412 
413 
414 // Read command and execute. Return true if ok, false otherwise.
415 bool doCommand
416 (
417  const polyMesh& mesh,
418  const word& setType,
419  const word& setName,
420  const word& actionName,
421  const bool writeVTKFile,
422  const bool writeCurrentTime,
423  const bool noSync,
424  Istream& is
425 )
426 {
427  // Get some size estimate for set.
428  const globalMeshData& parData = mesh.globalData();
429 
430  label typSize =
431  max
432  (
433  parData.nTotalCells(),
434  max
435  (
436  parData.nTotalFaces(),
437  parData.nTotalPoints()
438  )
439  )
440  / (10*Pstream::nProcs());
441 
442 
443  bool ok = true;
444 
445  // Set to work on
446  autoPtr<topoSet> currentSetPtr;
447 
448  word sourceType;
449 
450  try
451  {
452  topoSetSource::setAction action =
453  topoSetSource::toAction(actionName);
454 
455 
457 
458  if (action == topoSetSource::REMOVE)
459  {
460  removeSet(mesh, setType, setName);
461  }
462  else if
463  (
464  (action == topoSetSource::NEW)
465  || (action == topoSetSource::CLEAR)
466  )
467  {
468  r = IOobject::NO_READ;
469  currentSetPtr = topoSet::New(setType, mesh, setName, typSize);
470  }
471  else
472  {
474  currentSetPtr = topoSet::New(setType, mesh, setName, r);
475  topoSet& currentSet = currentSetPtr();
476  // Presize it according to current mesh data.
477  currentSet.resize(max(currentSet.size(), typSize));
478  }
479 
480  if (currentSetPtr.valid())
481  {
482  topoSet& currentSet = currentSetPtr();
483 
484  Info<< " Set:" << currentSet.name()
485  << " Size:" << returnReduce(currentSet.size(), sumOp<label>())
486  << " Action:" << actionName
487  << endl;
488 
489  switch (action)
490  {
492  {
493  // Already handled above by not reading
494  break;
495  }
497  {
498  currentSet.invert(currentSet.maxSize(mesh));
499  break;
500  }
501  case topoSetSource::LIST:
502  {
503  currentSet.writeDebug(Pout, mesh, 100);
504  Pout<< endl;
505  break;
506  }
508  {
509  if (is >> sourceType)
510  {
511  autoPtr<topoSetSource> setSource
512  (
514  (
515  sourceType,
516  mesh,
517  is
518  )
519  );
520 
521  // Backup current set.
522  autoPtr<topoSet> oldSet
523  (
525  (
526  setType,
527  mesh,
528  currentSet.name() + "_old2",
529  currentSet
530  )
531  );
532 
533  currentSet.clear();
534  setSource().applyToSet(topoSetSource::NEW, currentSet);
535 
536  // Combine new value of currentSet with old one.
537  currentSet.subset(oldSet);
538  }
539  break;
540  }
541  default:
542  {
543  if (is >> sourceType)
544  {
545  autoPtr<topoSetSource> setSource
546  (
548  (
549  sourceType,
550  mesh,
551  is
552  )
553  );
554 
555  setSource().applyToSet(action, currentSet);
556  }
557  }
558  }
559 
560 
561  if (action != topoSetSource::LIST)
562  {
563  // Set will have been modified.
564 
565  // Synchronize for coupled patches.
566  if (!noSync) currentSet.sync(mesh);
567 
568  // Write
569  if (writeVTKFile)
570  {
571  mkDir(mesh.time().path()/"VTK"/currentSet.name());
572 
573  fileName vtkName
574  (
575  "VTK"/currentSet.name()/currentSet.name()
576  + "_"
577  + name(mesh.time().timeIndex())
578  + ".vtk"
579  );
580 
581  Info<< " Writing " << currentSet.name()
582  << " (size "
583  << returnReduce(currentSet.size(), sumOp<label>())
584  << ") to "
585  << currentSet.instance()/currentSet.local()
586  /currentSet.name()
587  << " and to vtk file " << vtkName << endl << endl;
588 
589  writeVTK(mesh, currentSet, vtkName);
590  }
591  else
592  {
593  Info<< " Writing " << currentSet.name()
594  << " (size "
595  << returnReduce(currentSet.size(), sumOp<label>())
596  << ") to "
597  << currentSet.instance()/currentSet.local()
598  /currentSet.name() << endl << endl;
599  }
600 
601  if (writeCurrentTime)
602  {
603  currentSet.instance() = mesh.time().timeName();
604  }
605  currentSet.write();
606  }
607  }
608  }
609  catch (Foam::IOerror& fIOErr)
610  {
611  ok = false;
612 
613  Pout<< fIOErr.message().c_str() << endl;
614 
615  if (sourceType.size())
616  {
617  Pout<< topoSetSource::usage(sourceType).c_str();
618  }
619  }
620  catch (Foam::error& fErr)
621  {
622  ok = false;
623 
624  Pout<< fErr.message().c_str() << endl;
625 
626  if (sourceType.size())
627  {
628  Pout<< topoSetSource::usage(sourceType).c_str();
629  }
630  }
631 
632  return ok;
633 }
634 
635 
636 // Status returned from parsing the first token of the line
637 enum commandStatus
638 {
639  QUIT, // quit program
640  INVALID, // token is not a valid set manipulation command
641  VALIDSETCMD, // ,, is a valid ,,
642  VALIDZONECMD // ,, is a valid zone ,,
643 };
644 
645 
646 void printMesh(const Time& runTime, const polyMesh& mesh)
647 {
648  Info<< "Time:" << runTime.timeName()
649  << " cells:" << mesh.globalData().nTotalCells()
650  << " faces:" << mesh.globalData().nTotalFaces()
651  << " points:" << mesh.globalData().nTotalPoints()
652  << " patches:" << mesh.boundaryMesh().size()
653  << " bb:" << mesh.bounds() << nl;
654 }
655 
656 
657 polyMesh::readUpdateState meshReadUpdate(polyMesh& mesh)
658 {
660 
661  switch(stat)
662  {
663  case polyMesh::UNCHANGED:
664  {
665  Info<< " mesh not changed." << endl;
666  break;
667  }
669  {
670  Info<< " points moved; topology unchanged." << endl;
671  break;
672  }
674  {
675  Info<< " topology changed; patches unchanged." << nl
676  << " ";
677  printMesh(mesh.time(), mesh);
678  break;
679  }
681  {
682  Info<< " topology changed and patches changed." << nl
683  << " ";
684  printMesh(mesh.time(), mesh);
685 
686  break;
687  }
688  default:
689  {
691  << "Illegal mesh update state "
692  << stat << abort(FatalError);
693  break;
694  }
695  }
696  return stat;
697 }
698 
699 
700 commandStatus parseType
701 (
702  Time& runTime,
703  polyMesh& mesh,
704  const word& setType,
705  IStringStream& is
706 )
707 {
708  if (setType.empty())
709  {
710  Info<< "Type 'help' for usage information" << endl;
711 
712  return INVALID;
713  }
714  else if (setType == "help")
715  {
716  printHelp(Info);
717 
718  return INVALID;
719  }
720  else if (setType == "list")
721  {
722  printAllSets(mesh, Info);
723 
724  return INVALID;
725  }
726  else if (setType == "time")
727  {
728  scalar requestedTime = readScalar(is);
729  instantList Times = runTime.times();
730 
731  label nearestIndex = Time::findClosestTimeIndex(Times, requestedTime);
732 
733  Info<< "Changing time from " << runTime.timeName()
734  << " to " << Times[nearestIndex].name()
735  << endl;
736 
737  // Set time
738  runTime.setTime(Times[nearestIndex], nearestIndex);
739  // Optionally re-read mesh
740  meshReadUpdate(mesh);
741 
742  return INVALID;
743  }
744  else if (setType == "quit")
745  {
746  Info<< "Quitting ..." << endl;
747 
748  return QUIT;
749  }
750  else if
751  (
752  setType == "cellSet"
753  || setType == "faceSet"
754  || setType == "pointSet"
755  )
756  {
757  return VALIDSETCMD;
758  }
759  else if
760  (
761  setType == "cellZoneSet"
762  || setType == "faceZoneSet"
763  || setType == "pointZoneSet"
764  )
765  {
766  return VALIDZONECMD;
767  }
768  else
769  {
771  << "Illegal command " << setType << endl
772  << "Should be one of 'help', 'list', 'time' or a set type :"
773  << " 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'"
774  << endl;
775 
776  return INVALID;
777  }
778 }
779 
780 
781 commandStatus parseAction(const word& actionName)
782 {
783  commandStatus stat = INVALID;
784 
785  if (actionName.size())
786  {
787  try
788  {
789  (void)topoSetSource::toAction(actionName);
790 
791  stat = VALIDSETCMD;
792  }
793  catch (Foam::IOerror& fIOErr)
794  {
795  stat = INVALID;
796  }
797  catch (Foam::error& fErr)
798  {
799  stat = INVALID;
800  }
801  }
802  return stat;
803 }
804 
805 
806 
807 int main(int argc, char *argv[])
808 {
809  // Specific to topoSet/setSet: quite often we want to block upon writing
810  // a set so we can immediately re-read it. So avoid use of threading
811  // for set writing.
813 
814  timeSelector::addOptions(true, false);
815  #include "addRegionOption.H"
816  argList::addBoolOption("noVTK", "do not write VTK files");
817  argList::addBoolOption("loop", "execute batch commands for all timesteps");
819  (
820  "batch",
821  "file",
822  "process in batch mode, using input from specified file"
823  );
825  (
826  "noSync",
827  "do not synchronise selection across coupled patches"
828  );
829 
830  #include "setRootCase.H"
831  #include "createTime.H"
832  instantList timeDirs = timeSelector::select0(runTime, args);
833 
834  const bool writeVTK = !args.optionFound("noVTK");
835  const bool loop = args.optionFound("loop");
836  const bool batch = args.optionFound("batch");
837  const bool noSync = args.optionFound("noSync");
838 
839  if (loop && !batch)
840  {
842  << "Can only loop in batch mode."
843  << exit(FatalError);
844  }
845 
846 
847  #include "createNamedPolyMesh.H"
848 
849  // Print some mesh info
850  printMesh(runTime, mesh);
851 
852  // Print current sets
853  printAllSets(mesh, Info);
854 
855  // Read history if interactive
856  #ifdef HAS_READLINE
857  if (!batch && !read_history((runTime.path()/historyFile).c_str()))
858  {
859  Info<< "Successfully read history from " << historyFile << endl;
860  }
861  #endif
862 
863 
864  // Exit status
865  int status = 0;
866 
867 
868  forAll(timeDirs, timeI)
869  {
870  runTime.setTime(timeDirs[timeI], timeI);
871  Info<< "Time = " << runTime.timeName() << endl;
872 
873  // Handle geometry/topology changes
874  meshReadUpdate(mesh);
875 
876 
877  // Main command read & execute loop
878  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
879 
880  autoPtr<IFstream> fileStreamPtr(nullptr);
881 
882  if (batch)
883  {
884  const fileName batchFile = args["batch"];
885 
886  Info<< "Reading commands from file " << batchFile << endl;
887 
888  // we cannot handle .gz files
889  if (!isFile(batchFile, false))
890  {
892  << "Cannot open file " << batchFile << exit(FatalError);
893  }
894 
895  fileStreamPtr.reset(new IFstream(batchFile));
896  }
897 
898  Info<< "Please type 'help', 'quit' or a set command after prompt."
899  << endl;
900 
901  // Whether to quit
902  bool quit = false;
903 
906 
907  do
908  {
909  string rawLine;
910 
911  // Type: cellSet, faceSet, pointSet
912  word setType;
913  // Name of destination set.
914  word setName;
915  // Action (new, invert etc.)
916  word actionName;
917 
918  commandStatus stat = INVALID;
919 
920  if (fileStreamPtr.valid())
921  {
922  if (!fileStreamPtr().good())
923  {
924  Info<< "End of batch file" << endl;
925  // No error.
926  break;
927  }
928 
929  fileStreamPtr().getLine(rawLine);
930 
931  if (rawLine.size())
932  {
933  Info<< "Doing:" << rawLine << endl;
934  }
935  }
936  else
937  {
938  #ifdef HAS_READLINE
939  {
940  char* linePtr = readline("readline>");
941 
942  if (linePtr)
943  {
944  rawLine = string(linePtr);
945 
946  if (*linePtr)
947  {
948  add_history(linePtr);
949  write_history(historyFile);
950  }
951 
952  free(linePtr); // readline uses malloc, not new.
953  }
954  else
955  {
956  break;
957  }
958  }
959  #else
960  {
961  if (!std::cin.good())
962  {
963  Info<< "End of cin" << endl;
964  // No error.
965  break;
966  }
967  Info<< "Command>" << flush;
968  std::getline(std::cin, rawLine);
969  }
970  #endif
971  }
972 
973  // Strip off anything after #
974  string::size_type i = rawLine.find_first_of("#");
975  if (i != string::npos)
976  {
977  rawLine = rawLine(0, i);
978  }
979 
980  if (rawLine.empty())
981  {
982  continue;
983  }
984 
985  IStringStream is(rawLine + ' ');
986 
987  // Type: cellSet, faceSet, pointSet, faceZoneSet
988  is >> setType;
989 
990  stat = parseType(runTime, mesh, setType, is);
991 
992  if (stat == VALIDSETCMD || stat == VALIDZONECMD)
993  {
994  if (is >> setName)
995  {
996  if (is >> actionName)
997  {
998  stat = parseAction(actionName);
999  }
1000  }
1001  }
1002 
1003  if (stat == QUIT)
1004  {
1005  // Make sure to quit
1006  quit = true;
1007  }
1008  else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
1009  {
1010  bool ok = doCommand
1011  (
1012  mesh,
1013  setType,
1014  setName,
1015  actionName,
1016  writeVTK,
1017  loop, // if in looping mode dump sets to time directory
1018  noSync,
1019  is
1020  );
1021 
1022  if (!ok && batch)
1023  {
1024  // Exit with error.
1025  quit = true;
1026  status = 1;
1027  }
1028  }
1029 
1030  } while (!quit);
1031 
1032  if (quit)
1033  {
1034  break;
1035  }
1036  }
1037 
1038  Info<< "End\n" << endl;
1039 
1040  return status;
1041 }
1042 
1043 
1044 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:424
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
fileName path() const
Return path.
Definition: Time.H:269
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:291
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:1055
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.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
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: findInstance.C:82
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:644
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:1011
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.
Definition: topoSet.C:201
string message() const
Definition: error.C:162
const fileName & local() const
Definition: IOobject.H:396
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:95
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1049
static const word null
An empty word.
Definition: word.H:77
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: topoSet.C:467
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1182
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
Definition: Time.C:856
const word & name() const
Return name.
Definition: zone.H:147
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1036
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:551
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:262
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:297
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
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
void writePatch(const bool binary, const word &setName, const primitiveFacePatch &fp, const word &fieldName, labelList &fieldValues, const fileName &fileName)
label size() const
Return the number of elements in the UPtrList.
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:386
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:400
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:245
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
instantList times() const
Search the case for valid time directories.
Definition: Time.C:660
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
Definition: topoSet.C:504
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: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:85
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:984
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:738
IOerror FatalIOError