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-2015 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 
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 
244 {
245  IOobjectList objects
246  (
247  mesh,
249  (
250  polyMesh::meshSubDir/"sets",
251  word::null,
254  ),
255  polyMesh::meshSubDir/"sets"
256  );
257  IOobjectList cellSets(objects.lookupClass(cellSet::typeName));
258  if (cellSets.size())
259  {
260  os << "cellSets:" << endl;
262  {
263  cellSet set(*iter());
264  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
265  }
266  }
267  IOobjectList faceSets(objects.lookupClass(faceSet::typeName));
268  if (faceSets.size())
269  {
270  os << "faceSets:" << endl;
272  {
273  faceSet set(*iter());
274  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
275  }
276  }
277  IOobjectList pointSets(objects.lookupClass(pointSet::typeName));
278  if (pointSets.size())
279  {
280  os << "pointSets:" << endl;
281  forAllConstIter(IOobjectList, pointSets, iter)
282  {
283  pointSet set(*iter());
284  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
285  }
286  }
287 
288  const cellZoneMesh& cellZones = mesh.cellZones();
289  if (cellZones.size())
290  {
291  os << "cellZones:" << endl;
292  forAll(cellZones, i)
293  {
294  const cellZone& zone = cellZones[i];
295  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
296  }
297  }
298  const faceZoneMesh& faceZones = mesh.faceZones();
299  if (faceZones.size())
300  {
301  os << "faceZones:" << endl;
302  forAll(faceZones, i)
303  {
304  const faceZone& zone = faceZones[i];
305  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
306  }
307  }
308  const pointZoneMesh& pointZones = mesh.pointZones();
309  if (pointZones.size())
310  {
311  os << "pointZones:" << endl;
312  forAll(pointZones, i)
313  {
314  const pointZone& zone = pointZones[i];
315  os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
316  }
317  }
318 
319  os << endl;
320 }
321 
322 
323 template<class ZoneType>
324  void removeZone
325 (
327  const word& setName
328  )
329 {
330  label zoneID = zones.findZoneID(setName);
331 
332  if (zoneID != -1)
333  {
334  Info<< "Removing zone " << setName << " at index " << zoneID << endl;
335  // Shuffle to last position
336  labelList oldToNew(zones.size());
337  label newI = 0;
338  forAll(oldToNew, i)
339  {
340  if (i != zoneID)
341  {
342  oldToNew[i] = newI++;
343  }
344  }
345  oldToNew[zoneID] = newI;
346  zones.reorder(oldToNew);
347  // Remove last element
348  zones.setSize(zones.size()-1);
349  zones.clearAddressing();
350  zones.write();
351  }
352 }
353 
354 
355 // Physically remove a set
356  void removeSet
357 (
358  const polyMesh& mesh,
359  const word& setType,
360  const word& setName
361  )
362 {
363  // Remove the file
364  IOobjectList objects
365  (
366  mesh,
368  (
369  polyMesh::meshSubDir/"sets",
370  word::null,
373  ),
374  polyMesh::meshSubDir/"sets"
375  );
376 
377  if (objects.found(setName))
378  {
379  // Remove file
380  fileName object = objects[setName]->objectPath();
381  Info<< "Removing file " << object << endl;
382  rm(object);
383  }
384 
385  // See if zone
386  if (setType == cellZoneSet::typeName)
387  {
388  removeZone
389  (
390  const_cast<cellZoneMesh&>(mesh.cellZones()),
391  setName
392  );
393  }
394  else if (setType == faceZoneSet::typeName)
395  {
396  removeZone
397  (
398  const_cast<faceZoneMesh&>(mesh.faceZones()),
399  setName
400  );
401  }
402  else if (setType == pointZoneSet::typeName)
403  {
404  removeZone
405  (
406  const_cast<pointZoneMesh&>(mesh.pointZones()),
407  setName
408  );
409  }
410 }
411 
412 
413 // Read command and execute. Return true if ok, false otherwise.
414  bool doCommand
415 (
416  const polyMesh& mesh,
417  const word& setType,
418  const word& setName,
419  const word& actionName,
420  const bool writeVTKFile,
421  const bool writeCurrentTime,
422  const bool noSync,
423  Istream& is
424  )
425 {
426  // Get some size estimate for set.
427  const globalMeshData& parData = mesh.globalData();
428 
429  label typSize =
430  max
431  (
432  parData.nTotalCells(),
433  max
434  (
435  parData.nTotalFaces(),
436  parData.nTotalPoints()
437  )
438  )
439  / (10*Pstream::nProcs());
440 
441 
442  bool ok = true;
443 
444  // Set to work on
445  autoPtr<topoSet> currentSetPtr;
446 
447  word sourceType;
448 
449  try
450  {
451  topoSetSource::setAction action =
452  topoSetSource::toAction(actionName);
453 
454 
456 
457  if (action == topoSetSource::REMOVE)
458  {
459  removeSet(mesh, setType, setName);
460  }
461  else if
462  (
463  (action == topoSetSource::NEW)
464  || (action == topoSetSource::CLEAR)
465  )
466  {
467  r = IOobject::NO_READ;
468  currentSetPtr = topoSet::New(setType, mesh, setName, typSize);
469  }
470  else
471  {
473  currentSetPtr = topoSet::New(setType, mesh, setName, r);
474  topoSet& currentSet = currentSetPtr();
475  // Presize it according to current mesh data.
476  currentSet.resize(max(currentSet.size(), typSize));
477  }
478 
479  if (currentSetPtr.valid())
480  {
481  topoSet& currentSet = currentSetPtr();
482 
483  Info<< " Set:" << currentSet.name()
484  << " Size:" << returnReduce(currentSet.size(), sumOp<label>())
485  << " Action:" << actionName
486  << endl;
487 
488  switch (action)
489  {
491  {
492  // Already handled above by not reading
493  break;
494  }
496  {
497  currentSet.invert(currentSet.maxSize(mesh));
498  break;
499  }
500  case topoSetSource::LIST:
501  {
502  currentSet.writeDebug(Pout, mesh, 100);
503  Pout<< endl;
504  break;
505  }
507  {
508  if (is >> sourceType)
509  {
510  autoPtr<topoSetSource> setSource
511  (
513  (
514  sourceType,
515  mesh,
516  is
517  )
518  );
519 
520  // Backup current set.
521  autoPtr<topoSet> oldSet
522  (
524  (
525  setType,
526  mesh,
527  currentSet.name() + "_old2",
528  currentSet
529  )
530  );
531 
532  currentSet.clear();
533  setSource().applyToSet(topoSetSource::NEW, currentSet);
534 
535  // Combine new value of currentSet with old one.
536  currentSet.subset(oldSet);
537  }
538  break;
539  }
540  default:
541  {
542  if (is >> sourceType)
543  {
544  autoPtr<topoSetSource> setSource
545  (
547  (
548  sourceType,
549  mesh,
550  is
551  )
552  );
553 
554  setSource().applyToSet(action, currentSet);
555  }
556  }
557  }
558 
559 
560  if (action != topoSetSource::LIST)
561  {
562  // Set will have been modified.
563 
564  // Synchronize for coupled patches.
565  if (!noSync) currentSet.sync(mesh);
566 
567  // Write
568  if (writeVTKFile)
569  {
570  mkDir(mesh.time().path()/"VTK"/currentSet.name());
571 
572  fileName vtkName
573  (
574  "VTK"/currentSet.name()/currentSet.name()
575  + "_"
576  + name(mesh.time().timeIndex())
577  + ".vtk"
578  );
579 
580  Info<< " Writing " << currentSet.name()
581  << " (size "
582  << returnReduce(currentSet.size(), sumOp<label>())
583  << ") to "
584  << currentSet.instance()/currentSet.local()
585  /currentSet.name()
586  << " and to vtk file " << vtkName << endl << endl;
587 
588  writeVTK(mesh, currentSet, vtkName);
589  }
590  else
591  {
592  Info<< " Writing " << currentSet.name()
593  << " (size "
594  << returnReduce(currentSet.size(), sumOp<label>())
595  << ") to "
596  << currentSet.instance()/currentSet.local()
597  /currentSet.name() << endl << endl;
598  }
599 
600  if (writeCurrentTime)
601  {
602  currentSet.instance() = mesh.time().timeName();
603  }
604  currentSet.write();
605  }
606  }
607  }
608  catch (Foam::IOerror& fIOErr)
609  {
610  ok = false;
611 
612  Pout<< fIOErr.message().c_str() << endl;
613 
614  if (sourceType.size())
615  {
616  Pout<< topoSetSource::usage(sourceType).c_str();
617  }
618  }
619  catch (Foam::error& fErr)
620  {
621  ok = false;
622 
623  Pout<< fErr.message().c_str() << endl;
624 
625  if (sourceType.size())
626  {
627  Pout<< topoSetSource::usage(sourceType).c_str();
628  }
629  }
630 
631  return ok;
632 }
633 
634 
635 // Status returned from parsing the first token of the line
637 {
638  QUIT, // quit program
639  INVALID, // token is not a valid set manipulation command
640  VALIDSETCMD, // ,, is a valid ,,
641  VALIDZONECMD // ,, is a valid zone ,,
642 };
643 
644 
645 void printMesh(const Time& runTime, const polyMesh& mesh)
646 {
647  Info<< "Time:" << runTime.timeName()
648  << " cells:" << mesh.globalData().nTotalCells()
649  << " faces:" << mesh.globalData().nTotalFaces()
650  << " points:" << mesh.globalData().nTotalPoints()
651  << " patches:" << mesh.boundaryMesh().size()
652  << " bb:" << mesh.bounds() << nl;
653 }
654 
655 
657 {
659 
660  switch(stat)
661  {
662  case polyMesh::UNCHANGED:
663  {
664  Info<< " mesh not changed." << endl;
665  break;
666  }
668  {
669  Info<< " points moved; topology unchanged." << endl;
670  break;
671  }
673  {
674  Info<< " topology changed; patches unchanged." << nl
675  << " ";
676  printMesh(mesh.time(), mesh);
677  break;
678  }
680  {
681  Info<< " topology changed and patches changed." << nl
682  << " ";
683  printMesh(mesh.time(), mesh);
684 
685  break;
686  }
687  default:
688  {
690  << "Illegal mesh update state "
691  << stat << abort(FatalError);
692  break;
693  }
694  }
695  return stat;
696 }
697 
698 
700 (
701  Time& runTime,
702  polyMesh& mesh,
703  const word& setType,
704  IStringStream& is
705  )
706 {
707  if (setType.empty())
708  {
709  Info<< "Type 'help' for usage information" << endl;
710 
711  return INVALID;
712  }
713  else if (setType == "help")
714  {
715  printHelp(Info);
716 
717  return INVALID;
718  }
719  else if (setType == "list")
720  {
722 
723  return INVALID;
724  }
725  else if (setType == "time")
726  {
727  scalar requestedTime = readScalar(is);
728  instantList Times = runTime.times();
729 
730  label nearestIndex = Time::findClosestTimeIndex(Times, requestedTime);
731 
732  Info<< "Changing time from " << runTime.timeName()
733  << " to " << Times[nearestIndex].name()
734  << endl;
735 
736  // Set time
737  runTime.setTime(Times[nearestIndex], nearestIndex);
738  // Optionally re-read mesh
740 
741  return INVALID;
742  }
743  else if (setType == "quit")
744  {
745  Info<< "Quitting ..." << endl;
746 
747  return QUIT;
748  }
749  else if
750  (
751  setType == "cellSet"
752  || setType == "faceSet"
753  || setType == "pointSet"
754  )
755  {
756  return VALIDSETCMD;
757  }
758  else if
759  (
760  setType == "cellZoneSet"
761  || setType == "faceZoneSet"
762  || setType == "pointZoneSet"
763  )
764  {
765  return VALIDZONECMD;
766  }
767  else
768  {
770  << "Illegal command " << setType << endl
771  << "Should be one of 'help', 'list', 'time' or a set type :"
772  << " 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'"
773  << endl;
774 
775  return INVALID;
776  }
777 }
778 
779 
780 commandStatus parseAction(const word& actionName)
781 {
782  commandStatus stat = INVALID;
783 
784  if (actionName.size())
785  {
786  try
787  {
788  (void)topoSetSource::toAction(actionName);
789 
790  stat = VALIDSETCMD;
791  }
792  catch (Foam::IOerror& fIOErr)
793  {
794  stat = INVALID;
795  }
796  catch (Foam::error& fErr)
797  {
798  stat = INVALID;
799  }
800  }
801  return stat;
802 }
803 
804 
805 
806 std::string replaceChar(std::string & SourceString, const std::string & strsrc, const std::string & strdst)
807 {
808 
810  std::string::size_type srclen = strsrc.size();
811  std::string::size_type dstlen = strdst.size();
812  std::string stringsource_new = SourceString;
813 
814  while ((pos = stringsource_new.find(strsrc, pos)) != std::string::npos)
815  {
816  stringsource_new.replace(pos, srclen, strdst);
817  pos += dstlen;
818  }
819  return stringsource_new;
820 }
821 
822 
823 
824 int main(int argc, char *argv[])
825 {
826  timeSelector::addOptions(true, false);
827 
828 #include "addRegionOption.H"
829  argList::addBoolOption("noVTK", "do not write VTK files");
830  argList::addBoolOption("loop", "execute batch commands for all timesteps");
832  (
833  "batch",
834  "file",
835  "process in batch mode, using input from specified file"
836  );
838  (
839  "noSync",
840  "do not synchronise selection across coupled patches"
841  );
842 
843 #include "setRootCase.H"
844 #include "createTime.H"
846 
847  const bool writeVTK = !args.optionFound("noVTK");
848  const bool loop = args.optionFound("loop");
849  const bool batch = args.optionFound("batch");
850  const bool noSync = args.optionFound("noSync");
851 
852  if (loop && !batch)
853  {
855  << "Can only loop in batch mode."
856  << exit(FatalError);
857  }
858 
859 
860 #include "createNamedPolyMesh.H"
861 
862  // Print some mesh info
863  printMesh(runTime, mesh);
864 
865  // Print current sets
867 
868  // Read history if interactive
869 # ifdef HAS_READLINE
870  if (!batch && !read_history((runTime.path()/historyFile).c_str()))
871  {
872  Info<< "Successfully read history from " << historyFile << endl;
873  }
874 # endif
875 
876 
877  // Exit status
878  int status = 0;
879 
880 
881  forAll(timeDirs, timeI)
882  {
883  runTime.setTime(timeDirs[timeI], timeI);
884  Info<< "Time = " << runTime.timeName() << endl;
885 
886  // Handle geometry/topology changes
888 
889 
890  // Main command read & execute loop
891  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
892 
893  string inputstring="";
894 
895  if (batch)
896  {
897  Info << "Read command from strings!" << endl;
898  inputstring = args["batch"];
899  inputstring = replaceChar(inputstring,"\\","\"");
900  }
901 
902  Info<< "Please type 'help', 'quit' or a set command after prompt."
903  << endl;
904 
905  // Whether to quit
906  bool quit = false;
907 
910 
911  do
912  {
913  string rawLine;
914 
915  // Type: cellSet, faceSet, pointSet
916  word setType;
917  // Name of destination set.
918  word setName;
919  // Action (new, invert etc.)
920  word actionName;
921 
922  commandStatus stat = INVALID;
923  if (inputstring!="")
924  {
925  Info << "use inputstring" << endl;
926  rawLine=inputstring;
927  }
928 
929  else
930  {
931  Info << "go to else no inputstring ,not fileStreamPtr! danger " <<endl;
932 # ifdef HAS_READLINE
933  {
934  char* linePtr = readline("readline>");
935 
936  if (linePtr)
937  {
938  rawLine = string(linePtr);
939  Info << "readline string is =" << rawLine << endl;
940  if (*linePtr)
941  {
942  add_history(linePtr);
943  write_history(historyFile);
944  }
945 
946  free(linePtr); // readline uses malloc, not new.
947  }
948  else
949  {
950  break;
951  }
952  }
953 # else
954  {
955  if (!std::cin.good())
956  {
957  Info<< "End of cin" << endl;
958  // No error.
959  break;
960  }
961  Info<< "Command>" << flush;
962  std::getline(std::cin, rawLine);
963  }
964 # endif
965  }
966 
967  // Strip off anything after #
968  string::size_type i = rawLine.find_first_of("#");
969  if (i != string::npos)
970  {
971  rawLine = rawLine(0, i);
972  }
973 
974  if (rawLine.empty())
975  {
976  continue;
977  }
978 
979  IStringStream is(rawLine + ' ');
980 
981  // Type: cellSet, faceSet, pointSet, faceZoneSet
982  is >> setType;
983 
984  stat = parseType(runTime, mesh, setType, is);
985 
986  if (stat == VALIDSETCMD || stat == VALIDZONECMD)
987  {
988  if (is >> setName)
989  {
990  if (is >> actionName)
991  {
992  stat = parseAction(actionName);
993  }
994  }
995  }
996 
997  if (stat == QUIT)
998  {
999  // Make sure to quit
1000  quit = true;
1001  }
1002  else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
1003  {
1004  bool ok = doCommand
1005  (
1006  mesh,
1007  setType,
1008  setName,
1009  actionName,
1010  writeVTK,
1011  loop, // if in looping mode dump sets to time directory
1012  noSync,
1013  is
1014  );
1015 
1016  if (!ok && batch)
1017  {
1018  // Exit with error.
1019  quit = true;
1020  status = 1;
1021  }
1022  else
1023  {
1024  quit = true;
1025  }
1026 
1027  }
1028 
1029 
1030  } while (!quit);
1031 
1032  if (quit)
1033  {
1034  break;
1035  }
1036  }
1037 
1038  Info<< "\nEnd\n" << endl;
1039 
1040  return status;
1041 }
1042 
1043 
1044 // ************************************************************************* //
Foam::topoSet::writeDebug
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
removeSet
void removeSet(const polyMesh &mesh, const word &setType, const word &setName)
Definition: setSet.C:357
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::topoSetSource::CLEAR
@ CLEAR
Definition: topoSetSource.H:84
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::HashTable::resize
void resize(const label newSize)
Resize the hash table for efficiency.
Definition: HashTable.C:436
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:86
Foam::polyMesh::POINTS_MOVED
@ POINTS_MOVED
Definition: polyMesh.H:91
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::topoSetSource::toAction
static setAction toAction(const word &actionName)
Convert string to action.
Definition: topoSetSource.H:157
faceZoneSet.H
Foam::rm
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:954
globalMeshData.H
Foam::Time::times
instantList times() const
Search the case for valid time directories.
Definition: Time.C:758
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::pointZone
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list.
Definition: pointZone.H:62
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:387
Foam::topoSetSource::usage
static const string & usage(const word &name)
Definition: topoSetSource.H:216
Foam::globalMeshData::nTotalPoints
label nTotalPoints() const
Return total number of points in decomposed mesh. Not.
Definition: globalMeshData.H:381
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
Foam::globalMeshData::nTotalCells
label nTotalCells() const
Return total number of cells in decomposed mesh.
Definition: globalMeshData.H:394
Foam::zone
Base class for zones.
Definition: zone.H:57
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
main
int main(int argc, char *argv[])
Definition: setSet.C:824
Foam::polyMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:778
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
Foam::Map< label >
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
Foam::faceSet
A list of face labels.
Definition: faceSet.H:48
Foam::topoSet::subset
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: topoSet.C:467
Foam::Time::findClosestTimeIndex
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:841
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::FatalIOError
IOerror FatalIOError
IOobjectList.H
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::globalMeshData::nTotalFaces
label nTotalFaces() const
Return total number of faces in decomposed mesh. Not.
Definition: globalMeshData.H:388
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::topoSet::New
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
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobject.H:350
polyMesh.H
QUIT
@ QUIT
Definition: setSet.C:638
Foam::topoSet::invert
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: topoSet.C:449
createNamedPolyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
IStringStream.H
doCommand
bool doCommand(const polyMesh &mesh, const word &setType, const word &setName, const word &actionName, const bool writeVTKFile, const bool writeCurrentTime, const bool noSync, Istream &is)
Definition: setSet.C:415
Foam::writeVTK
void writeVTK(OFstream &os, const Type &value)
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:61
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
OFstream.H
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
Foam::faceSets
Definition: faceSets.H:44
Foam::fvMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:498
Foam::polyMesh::TOPO_PATCH_CHANGE
@ TOPO_PATCH_CHANGE
Definition: polyMesh.H:93
Foam::flush
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:243
INVALID
@ INVALID
Definition: setSet.C:639
Foam::label
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
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
writePatch.H
Write faceSet to vtk polydata file. Only one data which is original faceID.
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::polyMesh::pointZones
const pointZoneMesh & pointZones() const
Return point zone mesh.
Definition: polyMesh.H:457
argList.H
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1017
faceSet.H
printAllSets
void printAllSets(const polyMesh &mesh, Ostream &os)
Definition: setSet.C:243
SeriousErrorInFunction
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
Definition: messageStream.H:237
addRegionOption.H
commandStatus
commandStatus
Definition: setSet.C:636
Foam::ZoneMesh< cellZone, polyMesh >
Foam::polyMesh::UNCHANGED
@ UNCHANGED
Definition: polyMesh.H:90
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
Foam::polyMesh::TOPO_CHANGE
@ TOPO_CHANGE
Definition: polyMesh.H:92
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Foam::topoSet::maxSize
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
IFstream.H
Foam::cellSets
Definition: cellSets.H:44
replaceChar
std::string replaceChar(std::string &SourceString, const std::string &strsrc, const std::string &strdst)
Definition: setSet.C:806
Foam::topoSetSource::SUBSET
@ SUBSET
Definition: topoSetSource.H:89
Foam::FatalError
error FatalError
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::globalMeshData
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
Definition: globalMeshData.H:106
Foam::Time::setTime
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
Definition: Time.C:964
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam::topoSetSource::New
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Definition: topoSetSource.C:74
Foam::error::message
string message() const
Definition: error.C:159
removeZone
void removeZone(ZoneMesh< ZoneType, polyMesh > &zones, const word &setName)
Definition: setSet.C:325
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::zone::name
const word & name() const
Return name.
Definition: zone.H:150
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:48
Foam::IOobjectList::lookupClass
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:199
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:348
Foam::error::throwExceptions
void throwExceptions()
Definition: error.H:121
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
Foam::Time::findInstance
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Return the location of "dir" containing the file "name".
Definition: findInstance.C:38
printMesh
void printMesh(const Time &runTime, const polyMesh &mesh)
Definition: setSet.C:645
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::polyMesh::bounds
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:427
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
setRootCase.H
timeDirs
static instantList timeDirs
Definition: globalFoam.H:44
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
meshReadUpdate
polyMesh::readUpdateState meshReadUpdate(polyMesh &mesh)
Definition: setSet.C:656
Foam::topoSetSource::LIST
@ LIST
Definition: topoSetSource.H:90
Foam::sumOp
Definition: ops.H:162
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:281
Foam::pointSet
A set of point labels.
Definition: pointSet.H:48
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::HashTable::clear
void clear()
Clear all entries from table.
Definition: HashTable.C:473
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
cellZoneSet.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::primitiveMesh::isInternalFace
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
Definition: primitiveMeshI.H:70
topoSetSource.H
Foam::autoPtr::valid
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::topoSetSource::REMOVE
@ REMOVE
Definition: topoSetSource.H:91
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
timeSelector.H
createTime.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
writePointSet.H
Write pointSet to vtk polydata file. Only one data which is original pointID.
Foam::topoSetSource::INVERT
@ INVERT
Definition: topoSetSource.H:86
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::IOerror
Report an I/O error.
Definition: error.H:195
parseAction
commandStatus parseAction(const word &actionName)
Definition: setSet.C:780
Foam::writePatch
void writePatch(const bool binary, const word &setName, const primitiveFacePatch &fp, const word &fieldName, labelList &fieldValues, const fileName &fileName)
VALIDZONECMD
@ VALIDZONECMD
Definition: setSet.C:641
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
cellSet.H
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
parseType
commandStatus parseType(Time &runTime, polyMesh &mesh, const word &setType, IStringStream &is)
Definition: setSet.C:700
Foam::ZoneMesh::clearAddressing
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:394
Foam::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1143
Foam::TimeState::timeIndex
label timeIndex() const
Return current time index.
Definition: TimeState.C:73
Foam::topoSet::sync
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
Definition: topoSet.C:504
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
args
Foam::argList args(argc, argv)
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: IOobject.H:110
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:66
Foam::IOobject::local
const fileName & local() const
Definition: IOobject.H:360
printHelp
void printHelp(Ostream &os)
Definition: setSet.C:184
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1023
Foam::writePointSet
void writePointSet(const bool binary, const primitiveMesh &mesh, const topoSet &set, const fileName &fileName)
Write pointSet to vtk polydata file.
pointZoneSet.H
VALIDSETCMD
@ VALIDSETCMD
Definition: setSet.C:640
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88
pointSet.H
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:190