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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2018 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  setSet
29 
30 Group
31  grpMeshManipulationUtilities
32 
33 Description
34  Manipulate a cell/face/point Set or Zone interactively.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "argList.H"
39 #include "Time.H"
40 #include "polyMesh.H"
41 #include "globalMeshData.H"
42 #include "StringStream.H"
43 #include "cellSet.H"
44 #include "faceSet.H"
45 #include "pointSet.H"
46 #include "topoSetSource.H"
47 #include "Fstream.H"
48 #include "foamVtkWriteTopoSet.H"
49 #include "IOobjectList.H"
50 #include "cellZoneSet.H"
51 #include "faceZoneSet.H"
52 #include "pointZoneSet.H"
53 #include "timeSelector.H"
54 
55 #include <stdio.h>
56 
57 #ifdef HAVE_LIBREADLINE
58  #include <readline/readline.h>
59  #include <readline/history.h>
60 
61  static const char* historyFile = ".setSet";
62 #endif
63 
64 using namespace Foam;
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
68 
69 // Write set to VTK readable files
70 void writeVTK
71 (
72  const polyMesh& mesh,
73  const topoSet& currSet,
74  const fileName& outputName
75 )
76 {
77  if
78  (
80  (
81  mesh,
82  currSet,
83  vtk::formatType::INLINE_BASE64, // XML-binary
84  // vtk::formatType::LEGACY_BINARY,
85  outputName,
86  false // Not parallel
87  )
88  )
89  {
91  << "Don't know how to handle set of type "
92  << currSet.type() << nl;
93  }
94 }
95 
96 
97 void printHelp(Ostream& os)
98 {
99  os << "Please type 'help', 'list', 'quit', 'time ddd'"
100  << " or a set command after prompt." << nl
101  << "'list' will show all current cell/face/point sets." << nl
102  << "'time ddd' will change the current time." << nl
103  << nl
104  << "A set command should be of the following form" << nl
105  << nl
106  << " cellSet|faceSet|pointSet <setName> <action> <source>"
107  << nl
108  << nl
109  << "The <action> is one of" << nl
110  << " list - prints the contents of the set" << nl
111  << " clear - clears the set" << nl
112  << " invert - inverts the set" << nl
113  << " remove - remove the set" << nl
114  << " new <source> - use all elements from the source set" << nl
115  << " add <source> - adds all elements from the source set" << nl
116  << " subtract <source> - subtract the source set elements" << nl
117  << " subset <source> - combines current set with the source set"
118  << nl
119  << nl
120  << "The sources come in various forms. Type a wrong source"
121  << " to see all the types available." << nl
122  << nl
123  << "Example: pick up all cells connected by point or face to patch"
124  << " movingWall" << nl
125  << nl
126  << "Pick up all faces of patch:" << nl
127  << " faceSet f0 new patchToFace movingWall" << nl
128  << "Add faces 0,1,2:" << nl
129  << " faceSet f0 add labelToFace (0 1 2)" << nl
130  << "Pick up all points used by faces in faceSet f0:" << nl
131  << " pointSet p0 new faceToPoint f0 all" << nl
132  << "Pick up cell which has any face in f0:" << nl
133  << " cellSet c0 new faceToCell f0 any" << nl
134  << "Add cells which have any point in p0:" << nl
135  << " cellSet c0 add pointToCell p0 any" << nl
136  << "List set:" << nl
137  << " cellSet c0 list" << nl
138  << nl
139  << "Zones can be set using zoneSets from corresponding sets:" << nl
140  << " cellZoneSet c0Zone new setToCellZone c0" << nl
141  << " faceZoneSet f0Zone new setToFaceZone f0" << nl
142  << nl
143  << "or if orientation is important:" << nl
144  << " faceZoneSet f0Zone new setsToFaceZone f0 c0" << nl
145  << nl
146  << "ZoneSets can be manipulated using the general actions:" << nl
147  << " list - prints the contents of the set" << nl
148  << " clear - clears the set" << nl
149  << " invert - inverts the set (undefined orientation)"
150  << nl
151  << " remove - remove the set" << nl
152  << endl;
153 }
154 
155 
156 template<class SetType>
157 void printSets(Ostream& os, const IOobjectList& objects)
158 {
159  label n = 0;
160 
161  for (const IOobject& io : objects.csorted<SetType>())
162  {
163  SetType set(io);
164  if (!n++) os << SetType::typeName << "s:" << nl;
165  os << '\t' << set.name() << "\tsize:" << set.size() << endl;
166  }
167 }
168 
169 
170 template<class ZoneType>
171 void printZones(Ostream& os, const ZoneMesh<ZoneType, polyMesh>& zones)
172 {
173  label n = 0;
174 
175  for (const ZoneType& zn : zones)
176  {
177  if (!n++) os << ZoneType::typeName << "s:" << nl;
178  os << '\t' << zn.name() << "\tsize:" << zn.size() << endl;
179  }
180 }
181 
182 
183 void printAllSets(const polyMesh& mesh, Ostream& os)
184 {
185  IOobjectList objects
186  (
187  mesh,
189  (
190  polyMesh::meshSubDir/"sets",
191  word::null,
194  ),
195  polyMesh::meshSubDir/"sets"
196  );
197 
198  printSets<cellSet>(os, objects);
199  printSets<faceSet>(os, objects);
200  printSets<pointSet>(os, objects);
201 
202  printZones(os, mesh.cellZones());
203  printZones(os, mesh.faceZones());
204  printZones(os, mesh.pointZones());
205 
206  os << endl;
207 }
208 
209 
210 template<class ZoneType>
211 void removeZone
212 (
214  const word& setName
215 )
216 {
217  label zoneID = zones.findZoneID(setName);
218 
219  if (zoneID != -1)
220  {
221  Info<< "Removing zone " << setName << " at index " << zoneID << endl;
222  // Shuffle to last position
223  labelList oldToNew(zones.size());
224  label newI = 0;
225  forAll(oldToNew, i)
226  {
227  if (i != zoneID)
228  {
229  oldToNew[i] = newI++;
230  }
231  }
232  oldToNew[zoneID] = newI;
233  zones.reorder(oldToNew);
234  // Remove last element
235  zones.setSize(zones.size()-1);
236  zones.clearAddressing();
237  if (!zones.write())
238  {
239  WarningInFunction << "Failed writing zone " << setName << endl;
240  }
241  zones.write();
242  // Force flushing so we know it has finished writing
243  fileHandler().flush();
244  }
245 }
246 
247 
248 // Physically remove a set
249 void removeSet
250 (
251  const polyMesh& mesh,
252  const word& setType,
253  const word& setName
254 )
255 {
256  // Remove the file
257  IOobjectList objects
258  (
259  mesh,
261  (
262  polyMesh::meshSubDir/"sets",
263  word::null,
266  ),
267  polyMesh::meshSubDir/"sets"
268  );
269 
270  if (objects.found(setName))
271  {
272  // Remove file
273  fileName object = objects[setName]->objectPath();
274  Info<< "Removing file " << object << endl;
275  rm(object);
276  }
277 
278  // See if zone
279  if (setType == cellZoneSet::typeName)
280  {
281  removeZone
282  (
283  const_cast<cellZoneMesh&>(mesh.cellZones()),
284  setName
285  );
286  }
287  else if (setType == faceZoneSet::typeName)
288  {
289  removeZone
290  (
291  const_cast<faceZoneMesh&>(mesh.faceZones()),
292  setName
293  );
294  }
295  else if (setType == pointZoneSet::typeName)
296  {
297  removeZone
298  (
299  const_cast<pointZoneMesh&>(mesh.pointZones()),
300  setName
301  );
302  }
303 }
304 
305 
306 // Read command and execute. Return true if ok, false otherwise.
307 bool doCommand
308 (
309  const polyMesh& mesh,
310  const word& setType,
311  const word& setName,
312  const word& actionName,
313  const bool writeVTKFile,
314  const bool writeCurrentTime,
315  const bool noSync,
316  Istream& is
317 )
318 {
319  // Get some size estimate for set.
320  const globalMeshData& parData = mesh.globalData();
321 
322  label typSize =
323  max
324  (
325  parData.nTotalCells(),
326  max
327  (
328  parData.nTotalFaces(),
329  parData.nTotalPoints()
330  )
331  )
332  / (10*Pstream::nProcs());
333 
334 
335  bool ok = true;
336 
337  // Set to work on
338  autoPtr<topoSet> currentSetPtr;
339 
340  word sourceType;
341 
342  try
343  {
344  topoSetSource::setAction action =
345  topoSetSource::actionNames[actionName];
346 
347  switch (action)
348  {
349  case topoSetSource::REMOVE :
350  {
351  removeSet(mesh, setType, setName);
352  break;
353  }
354 
355  case topoSetSource::NEW :
356  case topoSetSource::CLEAR :
357  {
358  currentSetPtr = topoSet::New(setType, mesh, setName, typSize);
359  break;
360  }
361 
362  case topoSetSource::IGNORE :
363  // Nothing to do
364  break;
365 
366  default:
367  {
368  currentSetPtr = topoSet::New
369  (
370  setType,
371  mesh,
372  setName,
374  );
375 
376  topoSet& currentSet = currentSetPtr();
377  // Presize it according to current mesh data.
378  currentSet.reserve(max(currentSet.size(), typSize));
379  }
380  }
381 
382  if (currentSetPtr)
383  {
384  topoSet& currentSet = *currentSetPtr;
385 
386  Info<< " Set:" << currentSet.name()
387  << " Size:" << returnReduce(currentSet.size(), sumOp<label>())
388  << " Action:" << actionName
389  << endl;
390 
391  switch (action)
392  {
393  case topoSetSource::CLEAR :
394  {
395  // Already handled above by not reading
396  break;
397  }
398 
399  case topoSetSource::INVERT :
400  {
401  currentSet.invert(currentSet.maxSize(mesh));
402  break;
403  }
404 
405  case topoSetSource::LIST :
406  {
407  currentSet.writeDebug(Pout, mesh, 100);
408  Pout<< endl;
409  break;
410  }
411 
412  case topoSetSource::SUBSET :
413  {
414  if (is >> sourceType)
415  {
416  autoPtr<topoSetSource> setSource
417  (
419  (
420  sourceType,
421  mesh,
422  is
423  )
424  );
425 
426  // Backup current set.
427  autoPtr<topoSet> oldSet
428  (
430  (
431  setType,
432  mesh,
433  currentSet.name() + "_old2",
434  currentSet
435  )
436  );
437 
438  currentSet.clear();
439  setSource().applyToSet(topoSetSource::NEW, currentSet);
440 
441  // Combine new value of currentSet with old one.
442  currentSet.subset(oldSet());
443  }
444  break;
445  }
446 
447  default:
448  {
449  if (is >> sourceType)
450  {
451  autoPtr<topoSetSource> setSource
452  (
454  (
455  sourceType,
456  mesh,
457  is
458  )
459  );
460 
461  setSource().applyToSet(action, currentSet);
462  }
463  }
464  }
465 
466  if (action != topoSetSource::LIST)
467  {
468  // Set will have been modified.
469 
470  // Synchronize for coupled patches.
471  if (!noSync) currentSet.sync(mesh);
472 
473  // Write
474  Info<< " Writing " << currentSet.name()
475  << " (size "
476  << returnReduce(currentSet.size(), sumOp<label>())
477  << ") to "
478  << (
479  currentSet.instance()/currentSet.local()
480  / currentSet.name()
481  );
482 
483 
484  if (writeVTKFile)
485  {
487  (
488  mesh.time().path()/"VTK"/currentSet.name()
489  / currentSet.name() + "_"
491  );
492  mkDir(outputName.path());
493 
494  Info<< " and to vtk file "
495  << outputName.relative(mesh.time().path())
496  << nl << nl;
497 
498  writeVTK(mesh, currentSet, outputName);
499  }
500  else
501  {
502  Info<< nl << nl;
503  }
504 
505  if (writeCurrentTime)
506  {
507  currentSet.instance() = mesh.time().timeName();
508  }
509  if (!currentSet.write())
510  {
512  << "Failed writing set "
513  << currentSet.objectPath() << endl;
514  }
515  // Make sure writing is finished
516  fileHandler().flush();
517  }
518  }
519  }
520  catch (const Foam::IOerror& fIOErr)
521  {
522  ok = false;
523 
524  Pout<< fIOErr.message().c_str() << endl;
525 
526  if (sourceType.size())
527  {
528  Pout<< topoSetSource::usage(sourceType).c_str();
529  }
530  }
531  catch (const Foam::error& fErr)
532  {
533  ok = false;
534 
535  Pout<< fErr.message().c_str() << endl;
536 
537  if (sourceType.size())
538  {
539  Pout<< topoSetSource::usage(sourceType).c_str();
540  }
541  }
542 
543  return ok;
544 }
545 
546 
547 // Status returned from parsing the first token of the line
548 enum commandStatus
549 {
550  QUIT, // quit program
551  INVALID, // token is not a valid set manipulation command
552  VALIDSETCMD, // ,, is a valid ,,
553  VALIDZONECMD // ,, is a valid zone ,,
554 };
555 
556 
557 void printMesh(const Time& runTime, const polyMesh& mesh)
558 {
559  Info<< "Time:" << runTime.timeName()
560  << " cells:" << mesh.globalData().nTotalCells()
561  << " faces:" << mesh.globalData().nTotalFaces()
562  << " points:" << mesh.globalData().nTotalPoints()
563  << " patches:" << mesh.boundaryMesh().size()
564  << " bb:" << mesh.bounds() << nl;
565 }
566 
567 
568 polyMesh::readUpdateState meshReadUpdate(polyMesh& mesh)
569 {
571 
572  switch(stat)
573  {
574  case polyMesh::UNCHANGED:
575  {
576  Info<< " mesh not changed." << endl;
577  break;
578  }
580  {
581  Info<< " points moved; topology unchanged." << endl;
582  break;
583  }
585  {
586  Info<< " topology changed; patches unchanged." << nl
587  << " ";
588  printMesh(mesh.time(), mesh);
589  break;
590  }
592  {
593  Info<< " topology changed and patches changed." << nl
594  << " ";
595  printMesh(mesh.time(), mesh);
596 
597  break;
598  }
599  default:
600  {
602  << "Illegal mesh update state "
603  << stat << abort(FatalError);
604  break;
605  }
606  }
607  return stat;
608 }
609 
610 
611 commandStatus parseType
612 (
613  Time& runTime,
614  polyMesh& mesh,
615  const word& setType,
616  IStringStream& is
617 )
618 {
619  if (setType.empty())
620  {
621  Info<< "Type 'help' for usage information" << endl;
622 
623  return INVALID;
624  }
625  else if (setType == "help")
626  {
627  printHelp(Info);
628 
629  return INVALID;
630  }
631  else if (setType == "list")
632  {
633  printAllSets(mesh, Info);
634 
635  return INVALID;
636  }
637  else if (setType == "time")
638  {
639  scalar requestedTime = readScalar(is);
640  instantList Times = runTime.times();
641 
642  label nearestIndex = Time::findClosestTimeIndex(Times, requestedTime);
643 
644  Info<< "Changing time from " << runTime.timeName()
645  << " to " << Times[nearestIndex].name()
646  << endl;
647 
648  // Set time
649  runTime.setTime(Times[nearestIndex], nearestIndex);
650  // Optionally re-read mesh
651  meshReadUpdate(mesh);
652 
653  return INVALID;
654  }
655  else if (setType == "quit")
656  {
657  Info<< "Quitting ..." << endl;
658 
659  return QUIT;
660  }
661  else if
662  (
663  setType == "cellSet"
664  || setType == "faceSet"
665  || setType == "pointSet"
666  )
667  {
668  return VALIDSETCMD;
669  }
670  else if
671  (
672  setType == "cellZoneSet"
673  || setType == "faceZoneSet"
674  || setType == "pointZoneSet"
675  )
676  {
677  return VALIDZONECMD;
678  }
679  else
680  {
682  << "Illegal command " << setType << endl
683  << "Should be one of 'help', 'list', 'time' or a set type :"
684  << " 'cellSet', 'faceSet', 'pointSet', 'faceZoneSet'"
685  << endl;
686 
687  return INVALID;
688  }
689 }
690 
691 
692 commandStatus parseAction(const word& actionName)
693 {
694  return
695  (
696  actionName.size() && topoSetSource::actionNames.found(actionName)
697  ? VALIDSETCMD : INVALID
698  );
699 }
700 
701 
702 
703 int main(int argc, char *argv[])
704 {
706  (
707  "Manipulate a cell/face/point Set or Zone interactively."
708  );
709 
710  // Specific to topoSet/setSet: quite often we want to block upon writing
711  // a set so we can immediately re-read it. So avoid use of threading
712  // for set writing.
713 
714  timeSelector::addOptions(true, false); // constant(true), zero(false)
715 
716  #include "addRegionOption.H"
717  argList::addBoolOption("noVTK", "Do not write VTK files");
718  argList::addBoolOption("loop", "Execute batch commands for all timesteps");
720  (
721  "batch",
722  "file",
723  "Process in batch mode, using input from specified file"
724  );
726  (
727  "noSync",
728  "Do not synchronise selection across coupled patches"
729  );
730 
731  #include "setRootCase.H"
732  #include "createTime.H"
734 
735  const bool writeVTK = !args.found("noVTK");
736  const bool loop = args.found("loop");
737  const bool batch = args.found("batch");
738  const bool noSync = args.found("noSync");
739 
740  if (loop && !batch)
741  {
743  << "Can only loop in batch mode."
744  << exit(FatalError);
745  }
746 
747 
748  #include "createNamedPolyMesh.H"
749 
750  // Print some mesh info
751  printMesh(runTime, mesh);
752 
753  // Print current sets
754  printAllSets(mesh, Info);
755 
756  // Read history if interactive
757  #ifdef HAVE_LIBREADLINE
758  if (!batch && !read_history((runTime.path()/historyFile).c_str()))
759  {
760  Info<< "Successfully read history from " << historyFile << endl;
761  }
762  #endif
763 
764 
765  // Exit status
766  int status = 0;
767 
768 
769  forAll(timeDirs, timeI)
770  {
771  runTime.setTime(timeDirs[timeI], timeI);
772  Info<< "Time = " << runTime.timeName() << endl;
773 
774  // Handle geometry/topology changes
775  meshReadUpdate(mesh);
776 
777 
778  // Main command read & execute loop
779  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
780 
781  autoPtr<IFstream> fileStreamPtr;
782 
783  if (batch)
784  {
785  const auto batchFile = args.get<fileName>("batch");
786 
787  Info<< "Reading commands from file " << batchFile << endl;
788 
789  // we cannot handle .gz files
790  if (!isFile(batchFile, false))
791  {
793  << "Cannot open file " << batchFile << exit(FatalError);
794  }
795 
796  fileStreamPtr.reset(new IFstream(batchFile));
797  }
798 
799  Info<< "Please type 'help', 'quit' or a set command after prompt."
800  << endl;
801 
802  // Whether to quit
803  bool quit = false;
804 
805  FatalError.throwing(true);
806  FatalIOError.throwing(true);
807 
808  do
809  {
810  string rawLine;
811 
812  // Type: cellSet, faceSet, pointSet
813  word setType;
814  // Name of destination set.
815  word setName;
816  // Action (new, invert etc.)
817  word actionName;
818 
819  commandStatus stat = INVALID;
820 
821  if (fileStreamPtr)
822  {
823  if (!fileStreamPtr->good())
824  {
825  Info<< "End of batch file" << endl;
826  // No error.
827  break;
828  }
829 
830  fileStreamPtr().getLine(rawLine);
831 
832  if (rawLine.size())
833  {
834  Info<< "Doing:" << rawLine << endl;
835  }
836  }
837  else
838  {
839  #ifdef HAVE_LIBREADLINE
840  {
841  char* linePtr = readline("readline>");
842 
843  if (linePtr)
844  {
845  rawLine = string(linePtr);
846 
847  if (*linePtr)
848  {
849  add_history(linePtr);
850  write_history(historyFile);
851  }
852 
853  free(linePtr); // readline uses malloc, not new.
854  }
855  else
856  {
857  break;
858  }
859  }
860  #else
861  {
862  if (!std::cin.good())
863  {
864  Info<< "End of cin" << endl;
865  // No error.
866  break;
867  }
868  Info<< "Command>" << flush;
869  std::getline(std::cin, rawLine);
870  }
871  #endif
872  }
873 
874  // Strip off anything after #
875  string::size_type i = rawLine.find('#');
876  if (i != string::npos)
877  {
878  rawLine.resize(i);
879  }
880 
881  if (rawLine.empty())
882  {
883  continue;
884  }
885 
886  IStringStream is(rawLine + ' ');
887 
888  // Type: cellSet, faceSet, pointSet, faceZoneSet
889  is >> setType;
890 
891  stat = parseType(runTime, mesh, setType, is);
892 
893  if (stat == VALIDSETCMD || stat == VALIDZONECMD)
894  {
895  if (is >> setName)
896  {
897  if (is >> actionName)
898  {
899  stat = parseAction(actionName);
900  }
901  }
902  }
903 
904  if (stat == QUIT)
905  {
906  // Make sure to quit
907  quit = true;
908  }
909  else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
910  {
911  bool ok = doCommand
912  (
913  mesh,
914  setType,
915  setName,
916  actionName,
917  writeVTK,
918  loop, // if in looping mode dump sets to time directory
919  noSync,
920  is
921  );
922 
923  if (!ok && batch)
924  {
925  // Exit with error.
926  quit = true;
927  status = 1;
928  }
929  }
930 
931  } while (!quit);
932 
933  if (quit)
934  {
935  break;
936  }
937  }
938 
939  Info<< "End\n" << endl;
940 
941  return status;
942 }
943 
944 
945 // ************************************************************************* //
virtual void subset(const labelUList &elems)
Subset contents. Only elements present in both sets remain.
Definition: topoSet.C:597
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:905
fileName path() const
Return path = rootPath/caseName. Same as TimePaths::path()
Definition: Time.H:503
static const Enum< setAction > actionNames
The setActions enum text. Names: "new", add", "subtract", "subset", "invert", "clear", "remove", "list", "ignore".
A class for handling file names.
Definition: fileName.H:72
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
static const string & usage(const word &name)
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:859
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
Input/output from string buffers.
bool found(const Key &key) const
Same as contains()
Definition: HashTable.H:1370
bool found(const word &key) const
Same as contains()
Definition: Enum.H:482
virtual const fileName & name() const override
Read/write access to the name of the stream.
Definition: OSstream.H:134
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
Create a new set and ADD elements to it.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
bool throwing() const noexcept
Return the current exception throwing state (on or off)
Definition: error.H:223
Clear the set, possibly creating it.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:411
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A list of mesh zones.
void reorder(const labelUList &oldToNew, const bool check=false)
Reorder elements. Reordering must be unique (ie, shuffle).
Definition: UPtrList.C:79
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:374
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
Invert the elements in the current set.
Required Classes.
static label findClosestTimeIndex(const UList< instant > &timeDirs, const scalar t, const word &constantDirName="constant")
Search instantList for the time index closest to the specified time.
Definition: TimePaths.C:176
Remove the set (from the file system)
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
Print contents of the set.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
bool writeTopoSet(const polyMesh &mesh, const topoSet &set, const vtk::outputOptions opts, const fileName &file, bool parallel=UPstream::parRun())
Dispatch to vtk::writeCellSetFaces, vtk::writeFaceSet, vtk::writePointSet.
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:284
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
label nTotalPoints() const noexcept
Total global number of mesh points. Not compensated for duplicate points!
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:70
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:37
Invalid/unknown/error type.
label size() const noexcept
The number of elements in table.
Definition: HashTable.H:358
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
Definition: UPstream.H:1077
Required Classes.
word outputName("finiteArea-edges.obj")
dynamicFvMesh & mesh
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:614
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:715
word findInstance(const fileName &directory, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null, const bool constant_fallback=true) const
Return time instance (location) of directory containing the file name (eg, used in reading mesh data)...
Definition: Time.C:725
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
Definition: ZoneMesh.C:718
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:609
A class for handling words, derived from Foam::string.
Definition: word.H:63
void clear()
Remove all entries from table.
Definition: HashTable.C:749
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
string message() const
The accumulated error message.
Definition: error.C:339
Union of elements with current set.
setAction
Enumeration defining various actions.
Reading is optional [identical to LAZY_READ].
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
Write topoSet in VTK format.
static const word null
An empty word.
Definition: word.H:84
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition: argList.C:385
const globalMeshData & globalData() const
Return parallel info (demand-driven)
Definition: polyMesh.C:1311
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:902
label timeIndex() const noexcept
Return the current time index.
Definition: TimeStateI.H:43
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:67
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Report an I/O error.
Definition: error.H:375
static autoPtr< topoSet > New(const word &setType, const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE)
Return a pointer to a toposet read from file.
Definition: topoSet.C:48
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
label writeDebug(Ostream &os, const label maxElem, labelHashSet::const_iterator &iter) const
Write part of contents nicely formatted.
Definition: topoSet.C:260
OBJstream os(runTime.globalPath()/outputName)
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:671
Input from file stream as an ISstream, normally using std::ifstream for the actual input...
Definition: IFstream.H:51
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options and also set the runTime to the first i...
Definition: timeSelector.C:260
void setSize(const label newLen)
Same as resize()
Definition: PtrList.H:337
label nTotalCells() const noexcept
Total global number of mesh cells.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:266
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:877
const pointZoneMesh & pointZones() const noexcept
Return point zone mesh.
Definition: polyMesh.H:663
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:521
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:118
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
#define WarningInFunction
Report a warning using Foam::Warning.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:52
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:281
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
Definition: HashTable.C:736
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:679
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
Definition: topoSet.C:646
virtual void invert(const label maxLen)
Invert contents.
Definition: topoSet.C:569
messageStream Info
Information stream (stdout output on master, null elsewhere)
label nTotalFaces() const noexcept
Total global number of mesh faces. Not compensated for duplicate faces!
const boundBox & bounds() const noexcept
Return mesh bounding box.
Definition: polyMesh.H:617
label n
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
XML inline base64, base64Formatter.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
"ignore" no-op action
void writeVTK(OFstream &os, const Type &value)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
const fileName & local() const noexcept
Read access to local path component.
Definition: IOobjectI.H:278
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
A class for handling character strings derived from std::string.
Definition: string.H:72
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Definition: timeSelector.C:101
Namespace for OpenFOAM.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition: POSIX.C:1404
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...