59 "specify alternate case directory, default is the cwd" 65 "roots",
"(dir1 .. dirN)",
66 "slave root directories for distributed running" 72 "hostRoots",
"(((host1 dir1) .. (hostN dirN))",
73 "slave root directories (per host) for distributed running" 80 "do not execute functionObjects" 87 "override the fileHandler" 184 void Foam::argList::printOptionUsage
186 const label location,
215 while (pos != string::npos && pos + textWidth < strLen)
224 next = str.find_first_not_of(
" \t\n", curr);
230 next = str.find_first_not_of(
" \t\n", curr);
238 if (prev != string::npos && prev > pos)
244 if (next == string::npos)
258 Info<< str.substr(pos, (curr - pos)).c_str() <<
nl;
263 if (pos != string::npos)
274 Info<< str.substr(pos).c_str() <<
nl;
286 bool postProcessOption =
false;
288 for (
int i=1; i<argc; i++)
291 if (postProcessOption)
break;
294 return postProcessOption;
302 bool Foam::argList::regroupArgv(
int& argc,
char**& argv)
310 for (
int argi=0; argi<argc; argi++)
312 if (strcmp(argv[argi],
"(") == 0)
317 else if (strcmp(argv[argi],
")") == 0)
325 args_[nArgs++] = tmpString;
331 args_[nArgs++] = argv[argi];
338 tmpString += argv[argi];
343 args_[nArgs++] = argv[argi];
347 if (tmpString.size())
349 args_[nArgs++] = tmpString;
352 args_.setSize(nArgs);
358 void Foam::argList::getRootCase()
365 if (iter != options_.end())
370 if (casePath.empty() || casePath ==
".")
374 options_.erase(
"case");
379 casePath =
cwd()/casePath;
389 rootPath_ = casePath.
path();
390 globalCase_ = casePath.
name();
395 if (rootPath_.isAbsolute())
398 setEnv(
"FOAM_CASE", rootPath_/globalCase_,
true);
399 setEnv(
"FOAM_CASENAME", globalCase_,
true);
404 casePath =
cwd()/rootPath_/globalCase_;
407 setEnv(
"FOAM_CASE", casePath,
true);
408 setEnv(
"FOAM_CASENAME", casePath.
name(),
true);
421 const bool initialise
429 const string libsString(
getEnv(
"FOAM_LIBS"));
430 if (!libsString.empty())
435 for (
int argi=0; argi<argc; argi++)
437 if (argv[argi][0] ==
'-')
439 const char *optionName = &argv[argi][1];
440 if (
string(optionName) ==
"libs")
451 for (
int argi=0; argi<argc; argi++)
453 if (argv[argi][0] ==
'-')
455 const char *optionName = &argv[argi][1];
456 if (
string(optionName) ==
"fileHandler")
458 handlerType = argv[argi+1];
463 if (handlerType.empty())
474 )().needsThreading();
479 for (
int argi=0; argi<argc; argi++)
481 if (argv[argi][0] ==
'-')
483 const char *optionName = &argv[argi][1];
487 parRunControl_.runPar(argc, argv, needsThread);
495 regroupArgv(argc, argv);
503 argListStr_ = args_[0];
505 for (
int argi=1; argi<args_.size(); argi++)
508 argListStr_ += args_[argi];
510 if (args_[argi][0] ==
'-')
512 const char *optionName = &args_[argi][1];
527 if (argi >= args_.size())
530 <<
"Option '-" << optionName
531 <<
"' requires an argument" <<
endl;
537 argListStr_ += args_[argi];
538 options_.insert(optionName, args_[argi]);
542 options_.insert(optionName,
"");
549 args_[nArgs] = args_[argi];
555 args_.setSize(nArgs);
557 parse(checkArgs, checkOpts, initialise);
570 parRunControl_(args.parRunControl_),
573 executable_(args.executable_),
574 rootPath_(args.rootPath_),
575 globalCase_(args.globalCase_),
577 argListStr_(args.argListStr_)
579 parse(checkArgs, checkOpts, initialise);
596 options_.found(
"help")
597 || options_.found(
"doc")
598 || options_.found(
"srcDoc")
601 if (options_.found(
"help"))
607 if (options_.found(
"srcDoc"))
611 else if (options_.found(
"doc"))
620 if (!
check(checkArgs, checkOpts))
636 <<
"Exec : " << argListStr_.c_str() <<
nl 637 <<
"Date : " << dateString.c_str() <<
nl 638 <<
"Time : " << timeString.c_str() <<
nl 657 if (found != std::string::npos)
675 if (iter != options_.end())
677 handlerType = iter();
680 if (handlerType.empty())
701 if (parRunControl_.parRun())
719 fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
721 slaveProcs[proci] = slaveMachine[proci]+
"."+
name(slavePid);
730 <<
"; slave " << proci <<
" is running version " 755 if (parRunControl_.parRun())
764 label dictNProcs = -1;
767 if (options_.found(
"roots"))
771 roots = readList<fileName>(is);
773 if (roots.
size() != 1)
775 dictNProcs = roots.
size()+1;
778 else if (options_.found(
"hostRoots"))
780 source =
"-hostRoots";
790 forAll(matchedRoots, matchi)
792 label slavei = matchedRoots[matchi];
793 if (roots[slavei] !=
wordRe())
796 <<
"Slave " << slaveMachine[slavei]
797 <<
" has multiple matching roots in " 802 roots[slavei] = hostRoot.
second();
810 if (roots[slavei] ==
wordRe())
813 <<
"Slave " << slaveMachine[slavei]
814 <<
" has no matching roots in " 819 if (roots.
size() != 1)
821 dictNProcs = roots.
size()+1;
826 source = rootPath_/globalCase_/
"system/decomposeParDict";
829 if (!decompDictStream.
good())
838 dictNProcs = decompDict.
lookup<
label>(
"numberOfSubdomains");
842 decompDict.
lookup(
"roots") >> roots;
849 if (roots.
size() == 1)
857 dictNProcs = roots.
size()+1;
875 <<
" specifies " << dictNProcs
876 <<
" processors but job was started with " 888 <<
"number of entries in roots " 890 <<
" is not equal to the number of slaves " 901 bool hadCaseOpt = options_.found(
"case");
909 options_.set(
"case", roots[slave-1]/globalCase_);
912 toSlave << args_ << options_;
914 options_.erase(
"case");
919 options_.set(
"case", rootPath_/globalCase_);
933 rootPath_/globalCase_/
"processor" 942 <<
"number of processor directories = " 944 <<
" is not equal to the number of processors = " 959 toSlave << args_ << options_;
971 fromMaster >> args_ >> options_;
989 Info<<
"Case : " << (rootPath_/globalCase_).c_str() <<
nl 990 <<
"nProcs : " << nProcs <<
endl;
992 if (parRunControl_.parRun())
994 Info<<
"Slaves : " << slaveProcs <<
nl;
997 Info<<
"Roots : " << roots <<
nl;
999 Info<<
"Pstream initialized with:" << nl
1014 if (slaveProcs.
size())
1022 jobInfo_.write(executable_, rootPath_/globalCase_);
1033 Info<<
"fileModificationChecking : " 1034 <<
"Monitoring run-time modified files using " 1051 Info<<
" (fileModificationSkew " 1056 Info<<
"allowSystemOperations : ";
1059 Info<<
"Allowing user-supplied system call operations" <<
endl;
1063 Info<<
"Disallowing user-supplied system call operations" 1093 bool changed =
false;
1102 || opt ==
"parallel" 1104 || opt ==
"hostRoots" 1108 <<
"used argList::setOption on a protected option: '" 1109 << opt <<
"'" <<
endl;
1120 <<
"used argList::setOption to change bool to non-bool: '" 1121 << opt <<
"'" <<
endl;
1127 changed = !options_.found(opt);
1137 <<
"used argList::setOption to change non-bool to bool: '" 1138 << opt <<
"'" <<
endl;
1144 changed = options_.found(opt) ? options_[opt] != param :
true;
1151 <<
"used argList::setOption on an invalid option: '" 1152 << opt <<
"'" <<
nl <<
"allowed are the following:" 1160 options_.set(opt, param);
1176 || opt ==
"parallel" 1178 || opt ==
"hostRoots" 1182 <<
"used argList::unsetOption on a protected option: '" 1183 << opt <<
"'" <<
endl;
1188 return options_.erase(opt);
1193 <<
"used argList::unsetOption on an invalid option: '" 1194 << opt <<
"'" <<
nl <<
"allowed are the following:" 1211 Info<< iter().c_str() <<
nl;
1219 Info<<
"\nUsage: " << executable_ <<
" [OPTIONS]";
1223 Info<<
" <" << iter().c_str() <<
'>';
1226 Info<<
"\noptions:\n";
1231 const word& optionName = opts[optI];
1234 Info<<
" -" << optionName;
1235 label len = optionName.size() + 3;
1240 len += iter().size() + 3;
1241 Info<<
" <" << iter().c_str() <<
'>';
1266 "display source code in browser" 1273 "display application documentation in browser" 1288 <<
" (see https://openfoam.org)" <<
nl 1303 docExt.
replace(
".",
"_source.");
1313 if (docDirs[dirI].
component(0) ==
"http:")
1315 httpServer = docDirs[dirI]/executable_ + docExt;
1322 if (docDirs[dirI].
component(0) ==
"file:")
1329 docFile = docDirs[dirI]/executable_ + docExt;
1343 string docBrowser =
getEnv(
"FOAM_DOC_BROWSER");
1344 if (docBrowser.empty())
1346 docDict.
lookup(
"docBrowser") >> docBrowser;
1351 docBrowser +=
" file://" + docFile;
1355 docBrowser +=
" " + httpServer;
1358 Info<<
"Show documentation: " << docBrowser.c_str() <<
endl;
1365 <<
"No documentation found for " << executable_
1366 <<
", but you can use -help to display the usage\n" <<
endl;
1377 if (checkArgs && args_.size() - 1 !=
validArgs.size())
1380 <<
"Wrong number of arguments, expected " <<
validArgs.size()
1381 <<
" found " << args_.size() - 1 <<
endl;
1396 <<
"Invalid option: -" << iter.key() <<
endl;
1418 <<
": cannot open root directory " <<
rootPath()
1432 <<
": cannot open case directory " <<
path()
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
string getEnv(const word &)
Return environment variable of given name.
bool checkRootCase() const
Check root path and case path.
const word & executable() const
Name of executable without the path.
bool setOption(const word &opt, const string ¶m="")
Set option directly (use with caution)
#define forAll(list, i)
Loop across all elements in list.
static void removeOption(const word &opt)
Remove option from validOptions and from optionUsage.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static int masterNo()
Process index of the master.
A class for handling file names.
static Stream & writeBanner(Stream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
An STL-conforming const_iterator.
static word postProcessOptionName
Standard name for the post-processing option.
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool unsetOption(const word &opt)
Unset option directly (use with caution)
static void addUsage(const word &opt, const string &usage)
Add option usage information to optionUsage.
A list of keyword definitions, which are a keyword followed by any number of values (e...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 2-tuple for storing two objects of different types.
bool clean()
Cleanup file name.
argList(int &argc, char **&argv, bool checkArgs=true, bool checkOpts=true, bool initialise=true)
Construct from argc and argv.
const fileName & rootPath() const
Return root path.
static int firstSlave()
Process index of first slave.
const Type1 & first() const
Return first.
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
Template class for non-intrusive linked lists.
pid_t ppid()
Return the parent PID of this process.
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
void size(const label)
Override size to be inconsistent with allocated storage.
static const fileName null
An empty fileName.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
static SLList< string > notes
Additional notes for usage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool master(const label communicator=0)
Am I the master process.
Foam::argList::initValidTables dummyInitValidTables
const dimensionedScalar & re
Classical electron radius: default SI units: [m].
static void noParallel()
Remove the parallel options.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
static bool postProcess(int argc, char *argv[])
Return true if the post-processing option is specified.
Operations on lists of strings.
const char *const FOAMversion
virtual ~argList()
Destructor.
bool good() const
Return true if next operation might succeed.
dlLibraryTable libs
Table of loaded dynamic libraries.
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
static autoPtr< fileOperation > New(const word &type, const bool verbose)
Select type.
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
void parse(bool checkArgs, bool checkOpts, bool initialise)
Parse.
Input inter-processor communications stream.
static autoPtr< fileOperationInitialise > New(const word &type, int &argc, char **&argv)
Select type.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
dimensionedScalar pos(const dimensionedScalar &ds)
void displayDoc(bool source=false) const
Display documentation in browser.
static int nPollProcInterfaces
Number of polling cycles in processor updates.
string hostName(const bool full=false)
Return the system's host name, as per hostname(1)
static HashTable< string > validParOptions
A list of valid parallel options.
void printNotes() const
Print notes (if any)
bool isAbsolute() const
Return true if file name is absolute.
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
A class for handling words, derived from string.
Extract command arguments and options from the supplied argc and argv parameters. ...
static int allowSystemOperations
Flag if system operations are allowed.
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
word name() const
Return file name (part beyond last /)
string userName()
Return the user's login name.
label size() const
Return the number of arguments.
const fileOperation & fileHandler()
Get current file handler.
static HashTable< string > optionUsage
Short usage information for validOptions.
graph_traits< Graph >::vertices_size_type size_type
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
A wordRe is a word, but can also have a regular expression for matching words.
static string clockTime()
Return the current wall-clock time as a string.
static const string null
An empty string.
pid_t pid()
Return the PID of this process.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
static const NamedEnum< commsTypes, 3 > commsTypeNames
Output inter-processor communications stream.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
pid_t pgid()
Return the group PID of this process.
word name(const complex &)
Return a string representation of a complex.
fileName path() const
Return the path to the caseName.
static string date()
Return the current wall-clock date as a string.
static const NamedEnum< fileCheckTypes, 4 > fileCheckTypesNames
static commsTypes defaultCommsType
Default commsType.
void setSize(const label)
Reset size of List.
string & replace(const string &oldStr, const string &newStr, size_type start=0)
Replace first occurrence of sub-string oldStr with newStr.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static word defaultFileHandler
Default fileHandler.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurrences of environment variables.
Input from memory buffer stream.
static void clear()
Clear the options table.
fileName cwd()
Return current working directory path name.
static float fileModificationSkew
bool check(bool checkArgs=true, bool checkOpts=true) const
Check argument list.
const Type2 & second() const
Return second.
fileName path() const
Return directory path name (part before last /)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
static void addNote(const string &)
Add extra notes for the usage information.
static string::size_type usageMin
Min offset for displaying usage (default: 20)
const char *const FOAMbuild
dictionary & controlDict()
The central control dictionary.
List< fileName > fileNameList
A List of fileNames.
void printUsage() const
Print usage.
A class for handling character strings derived from std::string.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
static string::size_type usageMax
Max screen width for displaying usage (default: 80)
static HashTable< string > validOptions
A list of valid options.
bool setEnv(const word &name, const std::string &value, const bool overwrite)
Set an environment variable.
static void addValidParOptions(HashTable< string > &validParOptions)
Add the valid option this type of communications library.
int system(const std::string &command)
Execute the specified command.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
static int lastSlave(const label communicator=0)
Process index of last slave.