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