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