argList.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-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2020 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 \*---------------------------------------------------------------------------*/
28 
29 #include "argList.H"
30 #include "OSspecific.H"
31 #include "clock.H"
32 #include "dictionary.H"
33 #include "IOobject.H"
34 #include "JobInfo.H"
35 #include "labelList.H"
36 #include "regIOobject.H"
37 #include "dynamicCode.H"
38 #include "simpleObjectRegistry.H"
39 #include "sigFpe.H"
40 #include "sigInt.H"
41 #include "sigQuit.H"
42 #include "sigSegv.H"
43 #include "foamVersion.H"
44 #include "stringOps.H"
45 #include "CStringList.H"
46 #include "stringListOps.H"
47 #include "fileOperation.H"
49 
50 #include <cctype>
51 
52 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
53 
54 bool Foam::argList::argsMandatory_ = true;
55 bool Foam::argList::checkProcessorDirectories_ = true;
56 
68 
71 
72 Foam::argList::initValidTables::initValidTables()
73 {
74  argList::addOption
75  (
76  "case",
77  "dir",
78  "Specify case directory to use (instead of cwd)"
79  );
80  argList::addOption
81  (
82  "lib",
83  "name",
84  "Additional library or library list to load"
85  " (can be used multiple times)",
86  true // advanced option
87  );
88 
89  argList::addOption
90  (
91  "debug-switch",
92  "name=val",
93  "Specify the value of a registered debug switch."
94  " Default is 1 if the value is omitted."
95  " (Can be used multiple times)",
96  true // advanced option
97  );
98 
99  argList::addOption
100  (
101  "info-switch",
102  "name=val",
103  "Specify the value of a registered info switch."
104  " Default is 1 if the value is omitted."
105  " (Can be used multiple times)",
106  true // advanced option
107  );
108 
109  argList::addOption
110  (
111  "opt-switch",
112  "name=val",
113  "Specify the value of a registered optimisation switch (int/bool)."
114  " Default is 1 if the value is omitted."
115  " (Can be used multiple times)",
116  true // advanced option
117  );
118 
119  argList::addBoolOption("parallel", "Run in parallel");
120  validParOptions.set("parallel", "");
121  argList::addOption
122  (
123  "roots",
124  "(dir1 .. dirN)",
125  "Slave root directories for distributed running",
126  true // advanced option
127  );
128  validParOptions.set
129  (
130  "roots",
131  "(dir1 .. dirN)"
132  );
133 
134  argList::addOption
135  (
136  "decomposeParDict",
137  "file",
138  "Use specified file for decomposePar dictionary"
139  );
140  argList::addOption
141  (
142  "hostRoots",
143  "((host1 dir1) .. (hostN dirN))",
144  "Per-host slave root directories for distributed running."
145  " The host specification can be a regex.",
146  true // advanced option
147  );
148  validParOptions.set
149  (
150  "hostRoots",
151  "((host1 dir1) .. (hostN dirN))"
152  );
153 
154  argList::addBoolOption
155  (
156  "noFunctionObjects",
157  "Do not execute function objects",
158  true // advanced option
159  );
160 
161  argList::addOption
162  (
163  "fileHandler",
164  "handler",
165  "Override the file handler type",
166  true // advanced option
167  );
168 
169  argList::addOption
170  (
171  "world",
172  "name",
173  "Name of the local world for parallel communication",
174  true // advanced option
175  );
176  validParOptions.set
177  (
178  "world",
179  "name"
180  );
181 
182 
183  // Some standard option aliases (with or without version warnings)
184 // argList::addOptionCompat
185 // (
186 // "noFunctionObjects", {"no-function-objects", 0}
187 // );
188 
189  Pstream::addValidParOptions(validParOptions);
190 }
191 
192 Foam::argList::initValidTables dummyInitValidTables;
193 
194 
195 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
196 
197 namespace
198 {
199 
200 // Should issue warning if there is +ve versioning (+ve version number)
201 // and the this version number is older than the current OpenFOAM version
202 // as conveyed by the OPENFOAM compiler define.
203 
204 static inline constexpr bool shouldWarnVersion(const int version)
205 {
206  return (version > 0 && version < OPENFOAM);
207 }
208 
209 } // End anonymous namespace
210 
211 
212 namespace Foam
213 {
214 
215 // Counted per machine name
216 // Does not include any sorting since we wish to know the ordering according to
217 // mpi rank.
218 //
219 // Always include the master too.
220 // This provides a better overview of the subscription
221 static void printHostsSubscription(const UList<string>& slaveProcs)
222 {
223  Info<< "Hosts :" << nl << "(" << nl;
224 
225  std::string prev = hostName();
226  int count = 1;
227 
228  for (const auto& str : slaveProcs)
229  {
230  std::string curr(str.substr(0, str.rfind('.')));
231 
232  if (prev != curr)
233  {
234  if (count)
235  {
236  // Finish previous
237  Info<<" (" << prev.c_str() << " " << count << ")" << nl;
238  count = 0;
239  }
240 
241  prev = std::move(curr);
242  }
243  ++count;
244  }
245 
246  if (count)
247  {
248  // Finished last one
249  Info<<" (" << prev.c_str() << " " << count << ")" << nl;
250  }
251 
252  Info<< ")" << nl;
253 }
254 
255 } // End namespace Foam
256 
257 
258 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
259 
260 void Foam::argList::checkITstream(const ITstream& is, const label index)
261 {
262  const label remaining = is.nRemainingTokens();
263 
264  if (remaining)
265  {
266  std::cerr
267  << nl
268  << "--> FOAM WARNING:" << nl
269  << "Argument " << index << " has "
270  << remaining << " excess tokens" << nl << nl;
271  }
272  else if (!is.size())
273  {
274  std::cerr
275  << nl
276  << "--> FOAM WARNING:" << nl
277  << "Argument " << index << " had no tokens" << nl << nl;
278  }
279 }
280 
281 
282 void Foam::argList::checkITstream(const ITstream& is, const word& optName)
283 {
284  const label remaining = is.nRemainingTokens();
285 
286  if (remaining)
287  {
288  std::cerr
289  << nl
290  << "--> FOAM WARNING:" << nl
291  << "Option -" << optName << " has "
292  << remaining << " excess tokens" << nl << nl;
293  }
294  else if (!is.size())
295  {
296  std::cerr
297  << nl
298  << "--> FOAM WARNING:" << nl
299  << "Option -" << optName << " had no tokens" << nl << nl;
300  }
301 }
302 
303 
304 void Foam::argList::raiseBadInput(const word& optName) const
305 {
306  // Can use FatalError
307  // predicate checks are not used at the earliest stages
308  FatalErrorIn(executable())
309  << "Option -" << optName << " with invalid input" << nl
310  << exit(FatalError);
311 }
312 
313 
315 (
316  const string& argName,
317  const string& usage
318 )
319 {
320  validArgs.append(argName);
321 
322  // The first program argument starts at 1 - obtain index after the append
323 
324  const label index = validArgs.size();
325 
326  if (usage.empty())
327  {
328  argUsage.erase(index);
329  }
330  else
331  {
332  argUsage.set(index, usage);
333  }
334 }
335 
336 
338 (
339  const word& optName,
340  const string& usage,
341  bool advanced
342 )
343 {
344  addOption(optName, "", usage, advanced);
345 }
346 
347 
349 (
350  const word& optName,
351  const string& param,
352  const string& usage,
353  bool advanced
354 )
355 {
356  validOptions.set(optName, param);
357  if (!usage.empty())
358  {
359  optionUsage.set(optName, usage);
360  }
361  if (advanced)
362  {
363  advancedOptions.set(optName);
364  }
365 }
366 
367 
368 void Foam::argList::setAdvanced(const word& optName, bool advanced)
369 {
370  if (advanced && validOptions.found(optName))
371  {
372  advancedOptions.set(optName);
373  }
374  else
375  {
376  advancedOptions.erase(optName);
377  }
378 }
379 
380 
382 (
383  const word& optName,
384  std::pair<const char*,int> compat
385 )
386 {
387  validOptionsCompat.insert
388  (
389  compat.first,
390  std::pair<word,int>(optName, compat.second)
391  );
392 }
393 
394 
396 (
397  std::pair<const char*,int> compat,
398  bool expectArg
399 )
400 {
401  ignoreOptionsCompat.insert
402  (
403  compat.first,
404  std::pair<bool,int>(expectArg, compat.second)
405  );
406 }
407 
408 
410 (
411  const word& optName,
412  const string& usage
413 )
414 {
415  if (usage.empty())
416  {
417  optionUsage.erase(optName);
418  }
419  else
420  {
421  optionUsage.set(optName, usage);
422  }
423 }
424 
425 
426 void Foam::argList::addNote(const string& note)
427 {
428  if (!note.empty())
429  {
430  notes.append(note);
431  }
432 }
433 
434 
435 void Foam::argList::removeOption(const word& optName)
436 {
437  validOptions.erase(optName);
438  optionUsage.erase(optName);
439  advancedOptions.erase(optName);
440 }
441 
442 
444 {
445  argsMandatory_ = false;
446 }
447 
448 
450 {
451  return argsMandatory_;
452 }
453 
454 
456 {
458 }
459 
460 
462 {
463  return (::Foam::infoDetailLevel > 0);
464 }
465 
466 
467 void Foam::argList::noFunctionObjects(bool addWithOption)
468 {
469  removeOption("noFunctionObjects");
470 
471  // Ignore this bool option without warning
472  // - cannot tie to any particular version anyhow
473  ignoreOptionCompat({"noFunctionObjects", 0}, false);
474 
475  if (addWithOption)
476  {
477  addBoolOption
478  (
479  "withFunctionObjects",
480  "Execute functionObjects",
481  true // advanced option
482  );
483  }
484 }
485 
486 
488 {
489  JobInfo::writeJobInfo = false;
490 }
491 
492 
494 {
495  addBoolOption
496  (
497  "no-libs",
498  "Disable use of the controlDict libs entry",
499  true // advanced option
500  );
501 }
502 
503 
505 {
506  removeOption("parallel");
507  removeOption("roots");
508  removeOption("decomposeParDict");
509  removeOption("hostRoots");
510  removeOption("world");
511  validParOptions.clear();
512 }
513 
514 
516 {
517  checkProcessorDirectories_ = false;
518 }
519 
520 
521 bool Foam::argList::postProcess(int argc, char *argv[])
522 {
523  for (int i=1; i<argc; ++i)
524  {
525  if (argv[i] == '-' + postProcessOptionName)
526  {
527  return true;
528  }
529  }
530 
531  return false;
532 }
533 
534 
535 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
536 
538 {
539  return Foam::getEnv("FOAM_CASE");
540 }
541 
542 
543 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
544 
545 Foam::word Foam::argList::optionCompat(const word& optName)
546 {
547  // NB: optName includes the leading '-' so that the return value
548  // can be used directly
549 
550  if (!validOptionsCompat.empty())
551  {
552  const auto fnd = validOptionsCompat.cfind(optName.substr(1));
553 
554  if (fnd.found())
555  {
556  const auto& iter = *fnd;
557 
558  if (shouldWarnVersion(iter.second))
559  {
560  std::cerr
561  << "--> FOAM IOWarning :" << nl
562  << " Found [v" << iter.second << "] '"
563  << optName << "' instead of '-"
564  << iter.first << "' option"
565  << nl
566  << std::endl;
567 
568  error::warnAboutAge("option", iter.second);
569  }
570 
571  return "-" + iter.first;
572  }
573  }
574 
575  // Nothing found - pass through the original input
576  return optName;
577 }
578 
579 
580 int Foam::argList::optionIgnore(const word& optName)
581 {
582  // NB: optName is without the leading '-'
583 
584  if (!ignoreOptionsCompat.empty())
585  {
586  const auto fnd = ignoreOptionsCompat.cfind(optName);
587 
588  if (fnd.found())
589  {
590  const auto& iter = *fnd;
591 
592  // Number to skip (including the option itself)
593  // '-option ARG' or '-option'
594  const int nskip = (iter.first ? 2 : 1);
595 
596  if (shouldWarnVersion(iter.second))
597  {
598  std::cerr
599  << "--> FOAM IOWarning :" << nl
600  << " Ignoring [v" << iter.second << "] '-"
601  << optName << (nskip > 1 ? " ARG" : "")
602  << "' option"
603  << nl
604  << std::endl;
605 
606  error::warnAboutAge("option", iter.second);
607  }
608 
609  return nskip;
610  }
611  }
612 
613  return 0; // Do not skip
614 }
615 
616 
617 bool Foam::argList::regroupArgv(int& argc, char**& argv)
618 {
619  int nArgs = 1;
620  int ignore = 0;
621  unsigned depth = 0;
622  string group; // For grouping ( ... ) arguments
623 
624  // Note: we rewrite directly into args_
625  // and use a second pass to sort out args/options
626 
627  args_[0] = fileName(argv[0]);
628  for (int argi = 1; argi < argc; ++argi)
629  {
630  if (strcmp(argv[argi], "(") == 0)
631  {
632  ++depth;
633  group += '(';
634  }
635  else if (strcmp(argv[argi], ")") == 0)
636  {
637  if (depth)
638  {
639  --depth;
640  group += ')';
641  if (!depth)
642  {
643  args_[nArgs++] = group;
644  group.clear();
645  }
646  }
647  else
648  {
649  args_[nArgs++] = argv[argi];
650  }
651  }
652  else if (depth)
653  {
654  // Quote each string element
655  group += '"';
656  group += argv[argi];
657  group += '"';
658  }
659  else if (argv[argi][0] == '-')
660  {
661  // Appears to be an option
662  const char *optName = &argv[argi][1];
663 
664  if (validOptions.found(optName))
665  {
666  // Known option name
667  args_[nArgs++] = argv[argi];
668  }
669  else if ((ignore = optionIgnore(optName)) > 0)
670  {
671  // Option to be ignored (with/without an argument)
672  if (ignore > 1)
673  {
674  ++argi;
675  }
676  }
677  else
678  {
679  // Try alias for the option name
680  args_[nArgs++] = optionCompat(argv[argi]);
681  }
682  }
683  else
684  {
685  args_[nArgs++] = argv[argi];
686  }
687  }
688 
689  if (group.size())
690  {
691  // Group(s) not closed, but flush anything still pending
692  args_[nArgs++] = group;
693  }
694 
695  args_.resize(nArgs);
696 
697  std::string::size_type len = (nArgs-1); // Spaces between args
698  for (const auto& s : args_)
699  {
700  len += s.length();
701  }
702 
703  // Length needed for regrouped command-line
704  commandLine_.reserve(len);
705 
706  return nArgs < argc;
707 }
708 
709 
710 void Foam::argList::setCasePaths()
711 {
712  fileName caseDir;
713 
714  const auto optIter = options_.cfind("case"); // [-case dir] specified?
715 
716  if (optIter.found())
717  {
718  caseDir = fileName::validate(optIter.val());
719  caseDir.clean();
720 
721  if (caseDir.empty() || caseDir == ".")
722  {
723  // Treat "", "." and "./" as if -case was not specified
724  caseDir = cwd();
725  options_.erase("case");
726  }
727  else
728  {
729  caseDir.expand();
730  caseDir.toAbsolute();
731  }
732  }
733  else
734  {
735  // Nothing specified, use the current dir
736  caseDir = cwd();
737  }
738 
739  // The caseDir is a cleaned, absolute path
740 
741  rootPath_ = caseDir.path();
742  globalCase_ = caseDir.name();
743  case_ = globalCase_; // The (processor) local case name
744 
745  // OPENFOAM API
746  setEnv("FOAM_API", std::to_string(foamVersion::api), true);
747 
748  // Global case (directory) and case-name as environment variables
749  setEnv("FOAM_CASE", caseDir, true);
750  setEnv("FOAM_CASENAME", globalCase_, true);
751 
752  // Executable name, unless already present in the environment
753  setEnv("FOAM_EXECUTABLE", executable_, false);
754 }
755 
756 
757 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
758 
760 (
761  int& argc,
762  char**& argv,
763  bool checkArgs,
764  bool checkOpts,
765  bool initialise
766 )
767 :
768  args_(argc),
769  options_(argc),
770  libs_()
771 {
772  // Check for -fileHandler, which requires an argument.
773  word handlerType;
774  for (int argi = argc-2; argi > 0; --argi)
775  {
776  if (argv[argi][0] == '-')
777  {
778  const char *optName = &argv[argi][1];
779 
780  if (strcmp(optName, "fileHandler") == 0)
781  {
782  handlerType = argv[argi+1];
783  break;
784  }
785  }
786  }
787  if (handlerType.empty())
788  {
789  handlerType = Foam::getEnv("FOAM_FILEHANDLER");
790  if (handlerType.empty())
791  {
792  handlerType = fileOperation::defaultFileHandler;
793  }
794  }
795 
796  // Detect any parallel options
798  (
799  handlerType,
800  argc,
801  argv
802  )().needsThreading();
803 
804 
805  // Check if this run is a parallel run by searching for any parallel option
806  // If found call runPar which might filter argv
807  for (int argi = 1; argi < argc; ++argi)
808  {
809  if (argv[argi][0] == '-')
810  {
811  const char *optName = &argv[argi][1];
812 
813  if (validParOptions.found(optName))
814  {
815  parRunControl_.runPar(argc, argv, needsThread);
816  break;
817  }
818  }
819  }
820 
821  // Convert argv -> args_ and capture ( ... ) lists
822  regroupArgv(argc, argv);
823  commandLine_ += args_[0];
824 
825  // Set executable name immediately - useful when emitting errors.
826  executable_ = fileName(args_[0]).name();
827 
828  // Check arguments and options, argv[0] was already handled
829  int nArgs = 1;
830  for (int argi = 1; argi < args_.size(); ++argi)
831  {
832  commandLine_ += ' ';
833  commandLine_ += args_[argi];
834 
835  if (args_[argi][0] == '-')
836  {
837  const char *optName = &args_[argi][1];
838 
839  if (!*optName)
840  {
841  Warning
842  <<"Ignoring lone '-' on the command-line" << endl;
843  }
844  else if
845  (
846  validOptions.lookup(optName, "").size()
847  || validParOptions.lookup(optName, "").size()
848  )
849  {
850  // If the option is known to require an argument,
851  // get it or emit a FatalError.
852 
853  ++argi;
854  if (argi >= args_.size())
855  {
856  foamVersion::printBuildInfo(Info().stdStream(), false);
857 
858  Info<< nl
859  <<"Error: option '-" << optName
860  << "' requires an argument" << nl << nl
861  << "See '" << executable_ << " -help' for usage"
862  << nl << nl;
863 
864  Pstream::exit(1); // works for serial and parallel
865  }
866 
867  commandLine_ += ' ';
868  commandLine_ += args_[argi];
869 
870  if (strcmp(optName, "lib") == 0)
871  {
872  // The '-lib' option:
873  // Append name(s) to libs for later opening
874  libs().append(this->getList<fileName>(argi));
875  }
876  else if (strcmp(optName, "debug-switch") == 0)
877  {
878  // The '-debug-switch' option:
879  // change registered debug switch
880  DetailInfo << "DebugSwitch ";
882  .setNamedInt(args_[argi], 1, true);
883  }
884  else if (strcmp(optName, "info-switch") == 0)
885  {
886  // The '-info-switch' option:
887  // change registered info switch
888  DetailInfo << "InfoSwitch ";
890  .setNamedInt(args_[argi], 1, true);
891  }
892  else if (strcmp(optName, "opt-switch") == 0)
893  {
894  // The '-opt-switch' option:
895  // change registered optimisation switch
896  DetailInfo << "OptimisationSwitch ";
898  .setNamedInt(args_[argi], 1, true);
899  }
900  else
901  {
902  // Regular option:
903  // Duplicates handled by using the last -option specified
904  options_.set(optName, args_[argi]);
905  }
906  }
907  else
908  {
909  // All other options (including unknown ones) are simply
910  // registered as existing.
911 
912  options_.insert(optName, "");
913  }
914  }
915  else
916  {
917  if (nArgs != argi)
918  {
919  args_[nArgs] = args_[argi];
920  }
921  ++nArgs;
922  }
923  }
924 
925  args_.resize(nArgs);
926 
927  parse(checkArgs, checkOpts, initialise);
928 }
929 
930 
932 (
933  const argList& args,
934  const HashTable<string>& options,
935  bool checkArgs,
936  bool checkOpts,
937  bool initialise
938 )
939 :
940  parRunControl_(args.parRunControl_),
941  args_(args.args_),
942  options_(options),
943  libs_(),
944  executable_(args.executable_),
945  rootPath_(args.rootPath_),
946  globalCase_(args.globalCase_),
947  case_(args.case_),
948  commandLine_(args.commandLine_)
949 {
950  parse(checkArgs, checkOpts, initialise);
951 }
952 
953 
955 (
956  bool checkArgs,
957  bool checkOpts,
958  bool initialise
959 )
960 {
961  // Help/documentation options:
962  // -doc Display documentation in browser
963  // -doc-source Display source code in browser
964  // -help Display short help and exit
965  // -help-compat Display compatibility options
966  // -help-full Display full help and exit
967  {
968  bool quickExit = false;
969 
970  // Display either application or source documentation, not both
971  if (options_.found("doc"))
972  {
973  displayDoc(false);
974  quickExit = true;
975  }
976  else if
977  (
978  options_.found("doc-source")
979  || options_.found("srcDoc") // Compat 1706
980  )
981  {
982  displayDoc(true);
983  quickExit = true;
984  }
985 
986  // Display either short or full help, not both
987  if (options_.found("help-full"))
988  {
989  printUsage(true);
990  quickExit = true;
991  }
992  else if (options_.found("help-notes"))
993  {
994  printNotes();
995  Info<< nl;
996  quickExit = true;
997  }
998  else if (options_.found("help"))
999  {
1000  printUsage(false);
1001  quickExit = true;
1002  }
1003  else if (options_.found("help-man"))
1004  {
1005  printMan();
1006  quickExit = true;
1007  }
1008 
1009  // Allow independent display of compatibility information
1010  if (options_.found("help-compat"))
1011  {
1012  printCompat();
1013  quickExit = true;
1014  }
1015 
1016  if (quickExit)
1017  {
1018  std::exit(0);
1019  }
1020  }
1021 
1022  // Print the collected error messages and exit if check fails
1023  if (!check(checkArgs, checkOpts))
1024  {
1025  foamVersion::printBuildInfo(Info().stdStream(), false);
1026  FatalError.write(Info, false);
1027 
1028  Pstream::exit(1); // works for serial and parallel
1029  }
1030 
1031  if (initialise)
1032  {
1033  const string dateString = clock::date();
1034  const string timeString = clock::clockTime();
1035 
1036  // Print the banner once only for parallel runs
1037  if (Pstream::master() && bannerEnabled())
1038  {
1040  << "Build : ";
1041 
1042  if (foamVersion::build.size())
1043  {
1044  Info<< foamVersion::build.c_str() << ' ';
1045  }
1046 
1047  Info<< "OPENFOAM=" << foamVersion::api;
1048 
1049  if (foamVersion::patched())
1050  {
1051  // Patch-level, when defined
1052  Info<< " patch=" << foamVersion::patch.c_str();
1053  }
1054 
1055  Info<< nl
1056  << "Arch : " << foamVersion::buildArch << nl
1057  << "Exec : " << commandLine_.c_str() << nl
1058  << "Date : " << dateString.c_str() << nl
1059  << "Time : " << timeString.c_str() << nl
1060  << "Host : " << hostName().c_str() << nl
1061  << "PID : " << pid() << endl;
1062  }
1063 
1064  jobInfo.add("startDate", dateString);
1065  jobInfo.add("startTime", timeString);
1066  jobInfo.add("userName", userName());
1067  jobInfo.add("foamVersion", word(foamVersion::version));
1068  jobInfo.add("code", executable_);
1069  jobInfo.add("argList", commandLine_);
1070  jobInfo.add("currentDir", cwd());
1071  jobInfo.add("PPID", ppid());
1072  jobInfo.add("PGID", pgid());
1073 
1074  // Add build information - only use the first word
1075  {
1076  std::string build(foamVersion::build);
1077  const auto space = build.find(' ');
1078  if (space != std::string::npos)
1079  {
1080  build.resize(space);
1081  }
1082  jobInfo.add("foamBuild", build);
1083  }
1084 
1085  // Load additional libraries (verbosity according to banner setting)
1086  libs().open(bannerEnabled());
1087  }
1088 
1089 
1090  // Set fileHandler. In increasing order of priority:
1091  // 1. default = uncollated
1092  // 2. env variable "FOAM_FILEHANDLER"
1093  // 3. etc/controlDict optimisationSwitches 'fileHandler'
1094  // 4. system/controlDict 'fileHandler' (not handled here; done in TimeIO.C)
1095  // 5. '-fileHandler' commmand-line option
1096 
1097  {
1098  word handlerType
1099  (
1100  options_.lookup("fileHandler", Foam::getEnv("FOAM_FILEHANDLER"))
1101  );
1102 
1103  if (handlerType.empty())
1104  {
1105  handlerType = fileOperation::defaultFileHandler;
1106  }
1107 
1108  Foam::fileHandler(fileOperation::New(handlerType, bannerEnabled()));
1109  }
1110 
1111 
1112  stringList slaveProcs;
1113  stringList slaveMachine;
1114  const int writeHostsSwitch = debug::infoSwitch("writeHosts", 1);
1115 
1116  // Collect slave machine/pid, and check that the build is identical
1117  if (parRunControl_.parRun())
1118  {
1119  if (Pstream::master())
1120  {
1121  slaveProcs.resize(Pstream::nProcs()-1);
1122  slaveMachine.resize(Pstream::nProcs()-1);
1123  label proci = 0;
1124  for (const int slave : Pstream::subProcs())
1125  {
1126  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
1127 
1128  string slaveBuild;
1129  label slavePid;
1130  fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
1131 
1132  slaveProcs[proci] = slaveMachine[proci] + "." + name(slavePid);
1133  ++proci;
1134 
1135  // Verify that all processors are running the same build
1136  if (slaveBuild != foamVersion::build)
1137  {
1138  FatalErrorIn(executable())
1139  << "Master is running version " << foamVersion::build
1140  << "; slave " << proci << " is running version "
1141  << slaveBuild
1142  << exit(FatalError);
1143  }
1144  }
1145  }
1146  else
1147  {
1148  OPstream toMaster
1149  (
1152  );
1153  toMaster << foamVersion::build << hostName() << pid();
1154  }
1155  }
1156 
1157 
1158  // Case is a single processor run unless it is running parallel
1159  int nProcs = 1;
1160 
1161  // Roots if running distributed
1162  fileNameList roots;
1163 
1164  // If this actually is a parallel run
1165  if (parRunControl_.parRun())
1166  {
1167  // For the master
1168  if (Pstream::master())
1169  {
1170  // Establish rootPath_/globalCase_/case_ for master
1171  setCasePaths();
1172 
1173  // Establish location of decomposeParDict, allow override with
1174  // the -decomposeParDict option.
1175  fileName source = rootPath_/globalCase_/"system"/"decomposeParDict";
1176  if (options_.found("decomposeParDict"))
1177  {
1178  bool adjustOpt = false;
1179 
1180  source = options_["decomposeParDict"];
1181  if (isDir(source))
1182  {
1183  source /= "decomposeParDict";
1184  adjustOpt = true;
1185  }
1186 
1187  // Case-relative if not absolute and not "./" etc
1188  if (!source.isAbsolute() && !source.starts_with('.'))
1189  {
1190  source = rootPath_/globalCase_/source;
1191  adjustOpt = true;
1192  }
1193 
1194  // Could also check for absolute path, but shouldn't be needed
1195  if (adjustOpt)
1196  {
1197  source.clean();
1198  options_.set("decomposeParDict", source);
1199  }
1200  }
1201 
1202  // If running distributed (different roots for different procs)
1203  label dictNProcs = -1;
1204  if (this->readListIfPresent("roots", roots))
1205  {
1206  parRunControl_.distributed(true);
1207  source = "-roots";
1208  if (roots.size() != 1)
1209  {
1210  dictNProcs = roots.size()+1;
1211  }
1212  }
1213  else if (options_.found("hostRoots"))
1214  {
1216 
1217  source = "-hostRoots";
1218  ITstream is(source, options_["hostRoots"]);
1219 
1220  List<Tuple2<wordRe, fileName>> hostRoots(is);
1221  checkITstream(is, "hostRoots");
1222 
1223  for (const auto& hostRoot : hostRoots)
1224  {
1225  labelList matched
1226  (
1227  findStrings(hostRoot.first(), slaveMachine)
1228  );
1229  for (const label slavei : matched)
1230  {
1231  if (!roots[slavei].empty())
1232  {
1234  << "Slave " << slaveMachine[slavei]
1235  << " has multiple matching roots in "
1236  << hostRoots << exit(FatalError);
1237  }
1238 
1239  roots[slavei] = hostRoot.second();
1240  }
1241  }
1242 
1243  // Check
1244  forAll(roots, slavei)
1245  {
1246  if (roots[slavei].empty())
1247  {
1249  << "Slave " << slaveMachine[slavei]
1250  << " has no matching roots in "
1251  << hostRoots << exit(FatalError);
1252  }
1253  }
1254 
1255  if (roots.size() != 1)
1256  {
1257  dictNProcs = roots.size()+1;
1258  }
1259  }
1260  else if (checkProcessorDirectories_ && Pstream::nProcs() > 1)
1261  {
1262  // Use values from decomposeParDict, the location was already
1263  // established above.
1264 
1265  // Disable any parallel comms happening inside the fileHandler
1266  // since we are on master. This can happen e.g. inside
1267  // the masterUncollated/collated handler.
1268  const bool oldParRun = Pstream::parRun(false);
1269 
1270  autoPtr<ISstream> decompDictStream
1271  (
1272  fileHandler().NewIFstream(source)
1273  );
1274 
1275  if (!decompDictStream || !decompDictStream->good())
1276  {
1277  FatalError
1278  << "Cannot read decomposeParDict from "
1279  << source << exit(FatalError);
1280  }
1281 
1282  dictionary decompDict(*decompDictStream);
1283 
1284  Pstream::parRun(oldParRun); // Restore parallel state
1285 
1286  decompDict.readEntry("numberOfSubdomains", dictNProcs);
1287  if (Pstream::nProcs() == 1)
1288  {
1290  << "Running parallel on single processor. This only"
1291  << " makes sense for multi-world simulation" << endl;
1292  dictNProcs = 1;
1293  }
1294 
1295  if (decompDict.getOrDefault("distributed", false))
1296  {
1297  parRunControl_.distributed(true);
1298  decompDict.readEntry("roots", roots);
1299  }
1300  }
1301 
1302  // Convenience:
1303  // when a single root is specified, use it for all processes
1304  if (roots.size() == 1)
1305  {
1306  const fileName rootName(roots[0]);
1307  roots.resize(Pstream::nProcs()-1, rootName);
1308 
1309  // adjust dictNProcs for command-line '-roots' option
1310  if (dictNProcs < 0)
1311  {
1312  dictNProcs = roots.size()+1;
1313  }
1314  }
1315 
1316 
1317  // Check number of processors.
1318  // nProcs => number of actual procs
1319  // dictNProcs => number of procs specified in decompositionDict
1320  // nProcDirs => number of processor directories
1321  // (n/a when running distributed)
1322  //
1323  // - normal running : nProcs = dictNProcs = nProcDirs
1324  // - decomposition to more processors : nProcs = dictNProcs
1325  // - decomposition to fewer processors : nProcs = nProcDirs
1326  if
1327  (
1328  checkProcessorDirectories_
1329  && Pstream::nProcs() > 1
1330  && dictNProcs > Pstream::nProcs()
1331  )
1332  {
1333  FatalError
1334  << source
1335  << " specifies " << dictNProcs
1336  << " processors but job was started with "
1337  << Pstream::nProcs() << " processors."
1338  << exit(FatalError);
1339  }
1340 
1341 
1342  // Distributed data
1343  if (roots.size())
1344  {
1345  if (roots.size() != Pstream::nProcs()-1)
1346  {
1347  FatalError
1348  << "number of entries in roots "
1349  << roots.size()
1350  << " is not equal to the number of slaves "
1351  << Pstream::nProcs()-1
1352  << exit(FatalError);
1353  }
1354 
1355  for (fileName& dir : roots)
1356  {
1357  dir.expand();
1358  }
1359 
1360  // Distribute the master's argument list (with new root)
1361  const bool hadCaseOpt = options_.found("case");
1362  for (const int slave : Pstream::subProcs())
1363  {
1364  options_.set("case", roots[slave-1]/globalCase_);
1365 
1366  OPstream toSlave(Pstream::commsTypes::scheduled, slave);
1367  toSlave << args_ << options_ << roots.size();
1368  }
1369  options_.erase("case");
1370 
1371  // Restore [-case dir]
1372  if (hadCaseOpt)
1373  {
1374  options_.set("case", rootPath_/globalCase_);
1375  }
1376  }
1377  else
1378  {
1379  // Possibly going to fewer processors.
1380  // Check if all procDirs are there.
1381  if
1382  (
1383  checkProcessorDirectories_
1384  && Pstream::nProcs() > 1
1385  && dictNProcs < Pstream::nProcs()
1386  )
1387  {
1388  label nProcDirs = 0;
1389  while
1390  (
1391  isDir
1392  (
1393  rootPath_/globalCase_
1394  / ("processor" + Foam::name(++nProcDirs))
1395  )
1396  )
1397  {}
1398 
1399  if (nProcDirs != Pstream::nProcs())
1400  {
1401  FatalError
1402  << "number of processor directories = "
1403  << nProcDirs
1404  << " is not equal to the number of processors = "
1405  << Pstream::nProcs()
1406  << exit(FatalError);
1407  }
1408  }
1409 
1410  // Distribute the master's argument list (unaltered)
1411  for (const int slave : Pstream::subProcs())
1412  {
1413  OPstream toSlave(Pstream::commsTypes::scheduled, slave);
1414  toSlave << args_ << options_ << roots.size();
1415  }
1416  }
1417  }
1418  else
1419  {
1420  // Collect the master's argument list
1421  label nroots;
1422 
1423  IPstream fromMaster
1424  (
1427  );
1428  fromMaster >> args_ >> options_ >> nroots;
1429 
1430  parRunControl_.distributed(nroots);
1431 
1432  // Establish rootPath_/globalCase_/case_ for slave
1433  setCasePaths();
1434  }
1435 
1436  nProcs = Pstream::nProcs();
1437  if (Pstream::nProcs() > 1)
1438  {
1439  case_ = globalCase_/("processor" + Foam::name(Pstream::myProcNo()));
1440  }
1441  else
1442  {
1443  case_ = globalCase_;
1444  }
1445  }
1446  else
1447  {
1448  // Establish rootPath_/globalCase_/case_
1449  setCasePaths();
1450  case_ = globalCase_; // Redundant, but extra safety?
1451  }
1452 
1453  // If needed, adjust fileHandler for distributed roots
1454  if (parRunControl_.distributed())
1455  {
1457  {
1458  fileOperation::fileHandlerPtr_->distributed(true);
1459  }
1460  }
1461 
1462  // Keep or discard slave and root information for reporting:
1463  if (Pstream::master() && parRunControl_.parRun())
1464  {
1465  if (!writeHostsSwitch)
1466  {
1467  // Clear here to ensures it doesn't show in the jobInfo
1468  slaveProcs.clear();
1469  }
1470  if (!debug::infoSwitch("writeRoots", 1))
1471  {
1472  roots.clear();
1473  }
1474  }
1475 
1476  if (Pstream::master() && bannerEnabled())
1477  {
1478  Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl
1479  << "nProcs : " << nProcs << endl;
1480 
1481  if (parRunControl_.parRun())
1482  {
1483  if (slaveProcs.size())
1484  {
1485  if (writeHostsSwitch == 1)
1486  {
1487  // Compact output (see etc/controlDict)
1488  printHostsSubscription(slaveProcs);
1489  }
1490  else
1491  {
1492  // Full output of "slave.pid"
1493  Info<< "Slaves : " << slaveProcs << nl;
1494  }
1495  }
1496  if (roots.size())
1497  {
1498  Info<< "Roots : " << roots << nl;
1499  }
1500  Info<< "Pstream initialized with:" << nl
1501  << " floatTransfer : " << Pstream::floatTransfer << nl
1502  << " nProcsSimpleSum : " << Pstream::nProcsSimpleSum << nl
1503  << " commsType : "
1505  << " polling iterations : " << Pstream::nPollProcInterfaces
1506  << endl;
1507  if (UPstream::allWorlds().size() > 1)
1508  {
1509  Info<< " worlds : "
1511  << " world : " << UPstream::myWorld()
1512  << endl;
1513  }
1514  }
1515  }
1516 
1517  if (initialise)
1518  {
1519  jobInfo.add("root", rootPath_);
1520  jobInfo.add("case", globalCase_);
1521  jobInfo.add("nProcs", nProcs);
1522  if (slaveProcs.size())
1523  {
1524  jobInfo.add("slaves", slaveProcs);
1525  }
1526  if (roots.size())
1527  {
1528  jobInfo.add("roots", roots);
1529  }
1530  jobInfo.write();
1531 
1532  // Switch on signal trapping. We have to wait until after Pstream::init
1533  // since this sets up its own ones.
1534  sigFpe::set(bannerEnabled());
1535  sigInt::set(bannerEnabled());
1536  sigQuit::set(bannerEnabled());
1537  sigSegv::set(bannerEnabled());
1538 
1539  if (Pstream::master() && bannerEnabled())
1540  {
1541  Info<< "fileModificationChecking : "
1542  << "Monitoring run-time modified files using "
1544  [
1546  ];
1547  if
1548  (
1549  (
1552  )
1553  || (
1556  )
1557  )
1558  {
1560  {
1561  Info<< " (fileModificationSkew "
1563  << ")";
1564  }
1566  {
1567  Info<< " (fileModificationSkew "
1569  << ", maxFileModificationPolls "
1571  << ")";
1572  }
1573  else
1574  {
1576  << "Invalid setting for maxFileModificationPolls "
1578  << exit(FatalError);
1579  }
1580  }
1581  Info<< nl;
1582 
1583  Info<< "allowSystemOperations : ";
1585  {
1586  Info<< "Allowing";
1587  }
1588  else
1589  {
1590  Info<< "Disallowing";
1591  }
1592  Info<< " user-supplied system call operations" << nl
1593  << endl;
1595  }
1596  }
1597 }
1598 
1599 
1600 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
1601 
1603 {
1604  jobInfo.end();
1605 
1606  // Delete file handler to flush any remaining IO
1607  Foam::fileHandler(nullptr);
1608 }
1609 
1610 
1611 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
1612 
1613 Foam::label Foam::argList::count(const UList<word>& optionNames) const
1614 {
1615  label n = 0;
1616  for (const word& optName : optionNames)
1617  {
1618  if (options_.found(optName))
1619  {
1620  ++n;
1621  }
1622  }
1623  return n;
1624 }
1625 
1626 
1627 Foam::label Foam::argList::count
1629  std::initializer_list<word> optionNames
1630 ) const
1631 {
1632  label n = 0;
1633  for (const word& optName : optionNames)
1634  {
1635  if (options_.found(optName))
1636  {
1637  ++n;
1638  }
1639  }
1640  return n;
1641 }
1642 
1643 
1644 bool Foam::argList::setOption(const word& optName, const string& param)
1645 {
1646  // Some options are always protected
1647  if
1648  (
1649  optName == "case"
1650  || optName == "parallel"
1651  || optName == "roots"
1652  )
1653  {
1655  <<"Option: '" << optName << "' is protected" << nl
1656  << exit(FatalError);
1657  return false;
1658  }
1659 
1660  if (options_.found(optName) ? (options_[optName] != param) : true)
1661  {
1662  options_.set(optName, param);
1663  return true;
1664  }
1665 
1666  return false;
1667 }
1668 
1669 
1670 bool Foam::argList::unsetOption(const word& optName)
1671 {
1672  // Some options are always protected
1673  if
1674  (
1675  optName == "case"
1676  || optName == "parallel"
1677  || optName == "roots"
1678  || optName == "hostRoots"
1679  )
1680  {
1682  <<"Option: '" << optName << "' is protected" << nl
1683  << exit(FatalError);
1684  return false;
1685  }
1686 
1687  // Remove the option, return true if state changed
1688  return options_.erase(optName);
1689 }
1690 
1691 
1692 void Foam::argList::displayDoc(bool source) const
1693 {
1694  const dictionary& docDict = debug::controlDict().subDict("Documentation");
1695  fileNameList docDirs(docDict.get<fileNameList>("doxyDocDirs"));
1696  fileName docExt(docDict.get<fileName>("doxySourceFileExt"));
1697 
1698  // For source code: change xxx_8C.html to xxx_8C_source.html
1699  if (source)
1700  {
1701  docExt.replace(".", "_source.");
1702  }
1703 
1704  fileName url;
1705 
1706  for (const fileName& dir : docDirs)
1707  {
1708  // The http protocols are last in the list
1709  if (dir.starts_with("http:") || dir.starts_with("https:"))
1710  {
1711  url = dir/executable_ + docExt;
1712  break;
1713  }
1714 
1715  fileName docFile = stringOps::expand(dir/executable_ + docExt);
1716 
1717  if
1718  (
1719  docFile.starts_with("file://")
1720  ? isFile(docFile.substr(7)) // check part after "file://"
1721  : isFile(docFile)
1722  )
1723  {
1724  url = std::move(docFile);
1725  break;
1726  }
1727  }
1728 
1729  if (url.empty())
1730  {
1731  Info<< nl
1732  << "No documentation found for " << executable_
1733  << ", but you can use -help to display the usage\n" << endl;
1734 
1735  return;
1736  }
1737 
1738  string docBrowser = getEnv("FOAM_DOC_BROWSER");
1739  if (docBrowser.empty())
1740  {
1741  docDict.readEntry("docBrowser", docBrowser);
1742  }
1743 
1744  // Can use FOAM_DOC_BROWSER='application file://%f' if required
1745  if (docBrowser.find("%f") != std::string::npos)
1746  {
1747  docBrowser.replace("%f", url);
1748  }
1749  else
1750  {
1751  docBrowser += " " + url;
1752  }
1753 
1754  // Split on whitespace to use safer version of Foam::system()
1755 
1756  CStringList command(stringOps::splitSpace(docBrowser));
1757 
1758  Info
1759  << "OpenFOAM " << foamVersion::api << " documentation:" << nl
1760  << " " << command << nl << endl;
1761 
1762  Foam::system(command, true);
1763 }
1764 
1765 
1766 bool Foam::argList::check(bool checkArgs, bool checkOpts) const
1767 {
1768  bool ok = true;
1769 
1770  if (Pstream::master())
1771  {
1772  const label nargs = args_.size()-1;
1773  if (checkArgs && nargs != validArgs.size())
1774  {
1775  FatalError
1776  << "Expected " << validArgs.size()
1777  << " arguments but found " << nargs << endl;
1778  ok = false;
1779  }
1780 
1781  if (checkOpts)
1782  {
1783  forAllConstIters(options_, iter)
1784  {
1785  const word& optName = iter.key();
1786  if
1787  (
1788  !validOptions.found(optName)
1789  && !validParOptions.found(optName)
1790  )
1791  {
1792  FatalError
1793  << "Invalid option: -" << optName << endl;
1794  ok = false;
1795  }
1796  }
1797  }
1798 
1799  if (!ok)
1800  {
1801  FatalError
1802  << nl
1803  << "See '" << executable_ << " -help' for usage"
1804  << nl << nl;
1805  }
1806  }
1807 
1808  return ok;
1809 }
1810 
1811 
1813 {
1814  if (!fileHandler().isDir(rootPath()))
1815  {
1816  FatalError
1817  << executable_
1818  << ": cannot open root directory " << rootPath()
1819  << endl;
1820 
1821  return false;
1822  }
1823 
1824  const fileName pathDir(fileHandler().filePath(path()));
1825 
1826  if (checkProcessorDirectories_ && pathDir.empty() && Pstream::master())
1827  {
1828  // Allow slaves on non-existing processor directories, created later
1829  // (e.g. redistributePar)
1830  FatalError
1831  << executable_
1832  << ": cannot open case directory " << path()
1833  << endl;
1834 
1835  return false;
1836  }
1837 
1838  return true;
1839 }
1840 
1841 
1842 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:204
Foam::string::replace
string & replace(const std::string &s1, const std::string &s2, size_type pos=0)
Definition: string.C:121
Foam::argList::count
label count(const UList< word > &optionNames) const
Return how many of the specified options were used.
Definition: argList.C:1613
Foam::sigFpe::set
static void set(bool verbose=false)
Activate SIGFPE signal handler when FOAM_SIGFPE is set.
Definition: sigFpe.C:148
Foam::argList::noBanner
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:455
regIOobject.H
Foam::JobInfo::writeJobInfo
static bool writeJobInfo
Global value for writeJobInfo enabled.
Definition: JobInfo.H:83
Foam::argList::usageMin
static std::string::size_type usageMin
Min indentation when displaying usage (default: 20)
Definition: argList.H:233
Foam::foamVersion::build
const std::string build
OpenFOAM build information as a std::string.
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::UPstream::masterNo
static constexpr int masterNo() noexcept
Process index of the master (always 0)
Definition: UPstream.H:452
Foam::argList::addUsage
static void addUsage(const word &optName, const string &usage)
Add option usage information to optionUsage.
Definition: argList.C:410
Foam::IOobject::timeStamp
Definition: IOobject.H:136
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
dummyInitValidTables
Foam::argList::initValidTables dummyInitValidTables
Definition: argList.C:192
Foam::foamVersion::patched
bool patched()
Foam::IOobject::fileCheckTypesNames
static const Enum< fileCheckTypes > fileCheckTypesNames
Names for the fileCheckTypes.
Definition: IOobject.H:143
Foam::argList::usageMax
static std::string::size_type usageMax
Max screen width when displaying usage (default: 80)
Definition: argList.H:236
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::validOptionsCompat
static HashTable< std::pair< word, int > > validOptionsCompat
A list of aliases for options.
Definition: argList.H:217
Foam::fileName::validate
static fileName validate(const std::string &s, const bool doClean=true)
Definition: fileName.C:58
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
fileOperationInitialise.H
Foam::constant::atomic::group
constexpr const char *const group
Group name for atomic constants.
Definition: atomicConstants.H:52
Foam::argList::envGlobalPath
static fileName envGlobalPath()
Global case (directory) from environment variable.
Definition: argList.C:537
Foam::fileOperation::fileHandlerPtr_
static autoPtr< fileOperation > fileHandlerPtr_
Static fileOperation.
Definition: fileOperation.H:183
Foam::IOobject::writeBanner
static Ostream & writeBanner(Ostream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
Definition: IOobjectWriteHeader.C:45
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::string::starts_with
bool starts_with(const std::string &s) const
True if string starts with the given prefix (cf. C++20)
Definition: string.H:299
Foam::argList::optionUsage
static HashTable< string > optionUsage
Short description for validOptions.
Definition: argList.H:227
Foam::regIOobject::fileModificationSkew
static float fileModificationSkew
Definition: regIOobject.H:133
Foam::fileName::name
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition: fileNameI.H:209
Foam::Warning
messageStream Warning
Foam::system
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: MSwindows.C:1140
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
Foam::IOobject::timeStampMaster
Definition: IOobject.H:137
Foam::IOobject::fileModificationChecking
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Definition: IOobject.H:211
Foam::regIOobject::maxFileModificationPolls
static int maxFileModificationPolls
Definition: regIOobject.H:135
simpleObjectRegistry.H
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:426
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:458
Foam::argList::addOptionCompat
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Definition: argList.C:382
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::isFile
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: MSwindows.C:658
Foam::fileHandler
const fileOperation & fileHandler()
Get current file handler.
Definition: fileOperation.C:1354
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::setEnv
bool setEnv(const word &name, const std::string &value, const bool overwrite)
Set an environment variable, return true on success.
Definition: MSwindows.C:395
Foam::UPstream::defaultCommsType
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:283
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
Foam::stringOps::splitSpace
Foam::SubStrings< StringType > splitSpace(const StringType &str)
Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC)
Definition: stringOpsTemplates.C:180
Foam::HashSet< Foam::string >
Foam::argList::noMandatoryArgs
static void noMandatoryArgs()
Flag command arguments as being optional (non-mandatory)
Definition: argList.C:443
Foam::getEnv
string getEnv(const std::string &envName)
Get environment value for given envName.
Definition: MSwindows.C:371
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::argList::argList
argList(int &argc, char **&argv, bool checkArgs=argList::argsMandatory(), bool checkOpts=true, bool initialise=true)
Definition: argList.C:760
Foam::pgid
pid_t pgid()
Return the group PID of this process.
Definition: MSwindows.C:350
Foam::dynamicCode::allowSystemOperations
static int allowSystemOperations
Flag if system operations are allowed.
Definition: dynamicCode.H:166
Foam::argList::ignoreOptionCompat
static void ignoreOptionCompat(std::pair< const char *, int > compat, bool expectArg)
Specify an option to be ignored.
Definition: argList.C:396
Foam::simpleObjectRegistry::setNamedInt
void setNamedInt(std::string name, int val, bool report=false)
Set named value, but also handle embedded name=value syntax.
Definition: simpleObjectRegistry.C:90
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:315
Foam::stringOps::expand
string expand(const std::string &s, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Definition: stringOps.C:720
Foam::debug::infoSwitch
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Definition: debug.C:231
Foam::printHostsSubscription
static void printHostsSubscription(const UList< string > &slaveProcs)
Definition: argList.C:221
Foam::fileOperation::New
static autoPtr< fileOperation > New(const word &handlerType, bool verbose=false)
Select fileHandler-type.
Definition: fileOperation.C:580
Foam::LList
Template class for non-intrusive linked lists.
Definition: LList.H:54
Foam::argList::validParOptions
static HashTable< string > validParOptions
A list of valid parallel options.
Definition: argList.H:213
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::argList::parse
void parse(bool checkArgs, bool checkOpts, bool initialise)
Definition: argList.C:955
Foam::argList::noLibs
static void noLibs()
Add the '-no-libs' command line option.
Definition: argList.C:493
Foam::argList::noFunctionObjects
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition: argList.C:467
Foam::userName
string userName()
Return the user's login name.
Definition: MSwindows.C:429
Foam::debug::optimisationObjects
simpleObjectRegistry & optimisationObjects()
Access to registered OptimisationSwitch objects.
Definition: debug.C:313
Foam::UPstream::subProcs
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition: UPstream.H:516
Foam::foamVersion::api
const int api
labelList.H
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:55
Foam::argList::setOption
bool setOption(const word &optName, const string &param="")
Set option directly (use with caution)
Definition: argList.C:1644
Foam::argList::noJobInfo
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
Definition: argList.C:487
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::debug::debugObjects
simpleObjectRegistry & debugObjects()
Access to registered DebugSwitch objects.
Definition: debug.C:291
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
clock.H
Foam::UPstream::floatTransfer
static bool floatTransfer
Definition: UPstream.H:276
Foam::pid
pid_t pid()
Return the PID of this process.
Definition: MSwindows.C:330
argList.H
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:528
Foam::ppid
pid_t ppid()
Return the parent PID of this process.
Definition: MSwindows.C:337
Foam::argList::postProcessOptionName
static word postProcessOptionName
Standard name for the post-processing option.
Definition: argList.H:239
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
dynamicCode.H
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:76
Foam::argList::setAdvanced
static void setAdvanced(const word &optName, bool advanced=true)
Set an existing option as being 'advanced' or normal.
Definition: argList.C:368
DetailInfo
#define DetailInfo
Definition: evalEntry.C:36
Foam::UPstream::commsTypeNames
static const Enum< commsTypes > commsTypeNames
Names of the communication types.
Definition: UPstream.H:77
Foam::List::resize
void resize(const label newSize)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::UPstream::commsTypes::scheduled
Foam::UPstream::myWorld
static const word & myWorld()
My world.
Definition: UPstream.H:502
Foam::argList::noCheckProcessorDirectories
static void noCheckProcessorDirectories()
Remove checking of processor directories.
Definition: argList.C:515
IOobject.H
Foam::argList::validOptions
static HashTable< string > validOptions
A list of valid options.
Definition: argList.H:210
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::debug::infoObjects
simpleObjectRegistry & infoObjects()
Access to registered InfoSwitch objects.
Definition: debug.C:302
fileOperation.H
Foam::argList::postProcess
static bool postProcess(int argc, char *argv[])
Return true if the post-processing option is specified.
Definition: argList.C:521
Foam::clock::date
static std::string date()
Definition: clock.C:80
Foam::fileOperation::defaultFileHandler
static word defaultFileHandler
Name of the default fileHandler.
Definition: fileOperation.H:173
Foam::UPstream::allWorlds
static const wordList & allWorlds()
All worlds.
Definition: UPstream.H:484
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:217
Foam::findStrings
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Return list indices for strings matching the regular expression.
Definition: stringListOps.H:76
Foam::infoDetailLevel
int infoDetailLevel
Global for selective suppression of Info output.
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::foamVersion::version
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
Foam::argList::unsetOption
bool unsetOption(const word &optName)
Unset option directly (use with caution)
Definition: argList.C:1670
Foam::UPstream::nProcsSimpleSum
static int nProcsSimpleSum
Definition: UPstream.H:280
Foam::HashTable< Foam::string >
Foam::jobInfo
JobInfo jobInfo
Definition: JobInfo.C:49
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:338
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
CStringList.H
Foam::argList::advancedOptions
static HashSet< string > advancedOptions
The "advanced" options are shown with -help-full (not with –help)
Definition: argList.H:207
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::error::warnAboutAge
static void warnAboutAge(const char *what, const int version)
Emit warning on stderr about something being old.
Definition: error.C:41
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:464
Foam::nl
constexpr char nl
Definition: Ostream.H:385
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::argList::argsMandatory
static bool argsMandatory()
Command arguments type (optional/mandatory).
Definition: argList.C:449
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::sigSegv::set
static void set(bool verbose=false)
Activate SIGSEGV signal handler.
Definition: sigSegv.C:73
Foam::IOobject::writeDivider
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
Definition: IOobjectWriteHeader.C:99
Foam::List< string >
Foam::foamVersion::buildArch
const std::string buildArch
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
dictionary.H
Foam::hostName
string hostName(const bool full=false)
Return the system's host name, as per hostname(1)
Definition: MSwindows.C:410
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:115
path
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Foam::argList::notes
static SLList< string > notes
General usage notes.
Definition: argList.H:230
Foam::argList::checkRootCase
bool checkRootCase() const
Check root path and case path.
Definition: argList.C:1812
Foam::clock::clockTime
static std::string clockTime()
Definition: clock.C:95
JobInfo.H
Foam::fileName::clean
static bool clean(std::string &str)
Cleanup filename.
Definition: fileName.C:298
Foam::cwd
fileName cwd()
The physical or logical current working directory path name.
Definition: MSwindows.C:468
stringListOps.H
Operations on lists of strings.
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:708
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:376
Foam::argList::ignoreOptionsCompat
static HashTable< std::pair< bool, int > > ignoreOptionsCompat
A list of options to ignore.
Definition: argList.H:221
Foam::error::write
void write(Ostream &os, const bool includeTitle=true) const
Print error message.
Definition: error.C:301
Foam::debug::controlDict
dictionary & controlDict()
Definition: debug.C:143
Foam::foamVersion::printBuildInfo
void printBuildInfo(std::ostream &os, const bool full=true)
Print information about version, build, arch to output stream.
Foam::argList::argUsage
static HashTable< string, label, Hash< label > > argUsage
Short description for program arguments.
Definition: argList.H:224
Foam::argList::check
bool check(bool checkArgs=argList::argsMandatory(), bool checkOpts=true) const
Definition: argList.C:1766
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:504
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:224
Foam::sigQuit::set
static void set(bool verbose=false)
Activate SIGQUIT signal handler.
Definition: sigQuit.C:76
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:122
Foam::argList::bannerEnabled
static bool bannerEnabled()
Banner status (enabled/disabled).
Definition: argList.C:461
Foam::argList::addOption
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:349
args
Foam::argList args(argc, argv)
stringOps.H
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
Foam::fileName::isAbsolute
static bool isAbsolute(const std::string &str)
Return true if string starts with a '/'.
Definition: fileNameI.H:136
Foam::argList::~argList
virtual ~argList()
Destructor.
Definition: argList.C:1602
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:446
Foam::argList::displayDoc
void displayDoc(bool source=false) const
Display documentation in browser.
Definition: argList.C:1692
Foam::sigInt::set
static void set(bool verbose=false)
Activate SIGINT signal handler.
Definition: sigInt.C:73
Foam::argList::removeOption
static void removeOption(const word &optName)
Remove option from validOptions and from optionUsage.
Definition: argList.C:435
Foam::UPstream::nPollProcInterfaces
static int nPollProcInterfaces
Number of polling cycles in processor updates.
Definition: UPstream.H:286
Foam::isDir
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:643
Foam::UPstream::exit
static void exit(int errNo=1)
Shutdown (finalize) MPI as required and exit program with errNo.
Definition: UPstream.C:63
Foam::fileOperations::fileOperationInitialise::New
static autoPtr< fileOperationInitialise > New(const word &type, int &argc, char **&argv)
Select type.
Definition: fileOperationInitialise.C:56
foamVersion.H
Foam::CStringList
An adapter for copying a list of C++ strings into a list of C-style strings for passing to C code tha...
Definition: CStringList.H:69