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