58 "specify alternate case directory, default is the cwd" 64 "roots",
"(dir1 .. dirN)",
65 "slave root directories for distributed running" 71 "hostRoots",
"(((host1 dir1) .. (hostN dirN))",
72 "slave root directories (per host) for distributed running" 79 "do not execute functionObjects" 86 "override the fileHandler" 183 void Foam::argList::printOptionUsage
185 const label location,
214 while (pos != string::npos && pos + textWidth < strLen)
223 next = str.find_first_not_of(
" \t\n", curr);
229 next = str.find_first_not_of(
" \t\n", curr);
237 if (prev != string::npos && prev > pos)
243 if (next == string::npos)
257 Info<< str.substr(pos, (curr - pos)).c_str() <<
nl;
262 if (pos != string::npos)
273 Info<< str.substr(pos).c_str() <<
nl;
285 bool postProcessOption =
false;
287 for (
int i=1; i<argc; i++)
290 if (postProcessOption)
break;
293 return postProcessOption;
301 bool Foam::argList::regroupArgv(
int& argc,
char**& argv)
309 for (
int argI = 0; argI < argc; ++argI)
311 if (strcmp(argv[argI],
"(") == 0)
316 else if (strcmp(argv[argI],
")") == 0)
324 args_[nArgs++] = tmpString;
330 args_[nArgs++] = argv[argI];
337 tmpString += argv[argI];
342 args_[nArgs++] = argv[argI];
346 if (tmpString.size())
348 args_[nArgs++] = tmpString;
351 args_.setSize(nArgs);
357 void Foam::argList::getRootCase()
364 if (iter != options_.end())
369 if (casePath.empty() || casePath ==
".")
373 options_.erase(
"case");
378 casePath =
cwd()/casePath;
388 rootPath_ = casePath.
path();
389 globalCase_ = casePath.
name();
394 if (rootPath_.isAbsolute())
397 setEnv(
"FOAM_CASE", rootPath_/globalCase_,
true);
398 setEnv(
"FOAM_CASENAME", globalCase_,
true);
403 casePath =
cwd()/rootPath_/globalCase_;
406 setEnv(
"FOAM_CASE", casePath,
true);
407 setEnv(
"FOAM_CASENAME", casePath.
name(),
true);
420 const bool initialise
428 const string libsString(
getEnv(
"FOAM_LIBS"));
429 if (!libsString.empty())
439 for (
int argI = 0; argI < argc; ++argI)
441 if (argv[argI][0] ==
'-')
443 const char *optionName = &argv[argI][1];
444 if (
string(optionName) ==
"libs")
446 const string libsString(argv[argI+1]);
462 for (
int argI = 0; argI < argc; ++argI)
464 if (argv[argI][0] ==
'-')
466 const char *optionName = &argv[argI][1];
467 if (
string(optionName) ==
"fileHandler")
469 handlerType = argv[argI+1];
474 if (handlerType.empty())
485 )().needsThreading();
490 for (
int argI = 0; argI < argc; ++argI)
492 if (argv[argI][0] ==
'-')
494 const char *optionName = &argv[argI][1];
498 parRunControl_.runPar(argc, argv, needsThread);
506 regroupArgv(argc, argv);
514 argListStr_ = args_[0];
516 for (
int argI = 1; argI < args_.size(); ++argI)
519 argListStr_ += args_[argI];
521 if (args_[argI][0] ==
'-')
523 const char *optionName = &args_[argI][1];
538 if (argI >= args_.size())
541 <<
"Option '-" << optionName
542 <<
"' requires an argument" <<
endl;
548 argListStr_ += args_[argI];
549 options_.insert(optionName, args_[argI]);
553 options_.insert(optionName,
"");
560 args_[nArgs] = args_[argI];
566 args_.setSize(nArgs);
568 parse(checkArgs, checkOpts, initialise);
581 parRunControl_(args.parRunControl_),
584 executable_(args.executable_),
585 rootPath_(args.rootPath_),
586 globalCase_(args.globalCase_),
588 argListStr_(args.argListStr_)
590 parse(checkArgs, checkOpts, initialise);
607 options_.found(
"help")
608 || options_.found(
"doc")
609 || options_.found(
"srcDoc")
612 if (options_.found(
"help"))
618 if (options_.found(
"srcDoc"))
622 else if (options_.found(
"doc"))
631 if (!
check(checkArgs, checkOpts))
647 <<
"Exec : " << argListStr_.c_str() <<
nl 648 <<
"Date : " << dateString.c_str() <<
nl 649 <<
"Time : " << timeString.c_str() <<
nl 668 if (found != std::string::npos)
686 if (iter != options_.end())
688 handlerType = iter();
691 if (handlerType.empty())
712 if (parRunControl_.parRun())
730 fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
732 slaveProcs[proci] = slaveMachine[proci]+
"."+
name(slavePid);
741 <<
"; slave " << proci <<
" is running version " 766 if (parRunControl_.parRun())
775 label dictNProcs = -1;
778 if (options_.found(
"roots"))
782 roots = readList<fileName>(is);
784 if (roots.
size() != 1)
786 dictNProcs = roots.
size()+1;
789 else if (options_.found(
"hostRoots"))
791 source =
"-hostRoots";
801 forAll(matchedRoots, matchi)
803 label slavei = matchedRoots[matchi];
804 if (roots[slavei] !=
wordRe())
807 <<
"Slave " << slaveMachine[slavei]
808 <<
" has multiple matching roots in " 813 roots[slavei] = hostRoot.
second();
821 if (roots[slavei] ==
wordRe())
824 <<
"Slave " << slaveMachine[slavei]
825 <<
" has no matching roots in " 830 if (roots.
size() != 1)
832 dictNProcs = roots.
size()+1;
837 source = rootPath_/globalCase_/
"system/decomposeParDict";
840 if (!decompDictStream.
good())
851 decompDict.
lookup(
"numberOfSubdomains")
856 decompDict.
lookup(
"roots") >> roots;
863 if (roots.
size() == 1)
871 dictNProcs = roots.
size()+1;
889 <<
" specifies " << dictNProcs
890 <<
" processors but job was started with " 902 <<
"number of entries in roots " 904 <<
" is not equal to the number of slaves " 915 bool hadCaseOpt = options_.found(
"case");
923 options_.set(
"case", roots[slave-1]/globalCase_);
926 toSlave << args_ << options_;
928 options_.erase(
"case");
933 options_.set(
"case", rootPath_/globalCase_);
947 rootPath_/globalCase_/
"processor" 956 <<
"number of processor directories = " 958 <<
" is not equal to the number of processors = " 973 toSlave << args_ << options_;
985 fromMaster >> args_ >> options_;
1003 Info<<
"Case : " << (rootPath_/globalCase_).c_str() <<
nl 1004 <<
"nProcs : " << nProcs <<
endl;
1006 if (parRunControl_.parRun())
1008 Info<<
"Slaves : " << slaveProcs <<
nl;
1011 Info<<
"Roots : " << roots <<
nl;
1013 Info<<
"Pstream initialized with:" << nl
1028 if (slaveProcs.
size())
1036 jobInfo_.write(executable_, rootPath_/globalCase_);
1047 Info<<
"fileModificationChecking : " 1048 <<
"Monitoring run-time modified files using " 1065 Info<<
" (fileModificationSkew " 1070 Info<<
"allowSystemOperations : ";
1073 Info<<
"Allowing user-supplied system call operations" <<
endl;
1077 Info<<
"Disallowing user-supplied system call operations" 1107 bool changed =
false;
1116 || opt ==
"parallel" 1118 || opt ==
"hostRoots" 1122 <<
"used argList::setOption on a protected option: '" 1123 << opt <<
"'" <<
endl;
1134 <<
"used argList::setOption to change bool to non-bool: '" 1135 << opt <<
"'" <<
endl;
1141 changed = !options_.found(opt);
1151 <<
"used argList::setOption to change non-bool to bool: '" 1152 << opt <<
"'" <<
endl;
1158 changed = options_.found(opt) ? options_[opt] != param :
true;
1165 <<
"used argList::setOption on an invalid option: '" 1166 << opt <<
"'" <<
nl <<
"allowed are the following:" 1174 options_.set(opt, param);
1190 || opt ==
"parallel" 1192 || opt ==
"hostRoots" 1196 <<
"used argList::unsetOption on a protected option: '" 1197 << opt <<
"'" <<
endl;
1202 return options_.erase(opt);
1207 <<
"used argList::unsetOption on an invalid option: '" 1208 << opt <<
"'" <<
nl <<
"allowed are the following:" 1225 Info<< iter().c_str() <<
nl;
1233 Info<<
"\nUsage: " << executable_ <<
" [OPTIONS]";
1237 Info<<
" <" << iter().c_str() <<
'>';
1240 Info<<
"\noptions:\n";
1245 const word& optionName = opts[optI];
1248 Info<<
" -" << optionName;
1249 label len = optionName.size() + 3;
1254 len += iter().size() + 3;
1255 Info<<
" <" << iter().c_str() <<
'>';
1280 "display source code in browser" 1287 "display application documentation in browser" 1302 <<
" (see https://openfoam.org)" <<
nl 1317 docExt.
replace(
".",
"_source.");
1327 if (docDirs[dirI].
component(0) ==
"http:")
1329 httpServer = docDirs[dirI]/executable_ + docExt;
1336 if (docDirs[dirI].
component(0) ==
"file:")
1343 docFile = docDirs[dirI]/executable_ + docExt;
1357 string docBrowser =
getEnv(
"FOAM_DOC_BROWSER");
1358 if (docBrowser.empty())
1360 docDict.
lookup(
"docBrowser") >> docBrowser;
1365 docBrowser +=
" file://" + docFile;
1369 docBrowser +=
" " + httpServer;
1372 Info<<
"Show documentation: " << docBrowser.c_str() <<
endl;
1379 <<
"No documentation found for " << executable_
1380 <<
", but you can use -help to display the usage\n" <<
endl;
1391 if (checkArgs && args_.size() - 1 !=
validArgs.size())
1394 <<
"Wrong number of arguments, expected " <<
validArgs.size()
1395 <<
" found " << args_.size() - 1 <<
endl;
1410 <<
"Invalid option: -" << iter.key() <<
endl;
1432 <<
": cannot open root directory " <<
rootPath()
1446 <<
": 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.
const dimensionedScalar re
Classical electron radius: default SI units: [m].
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
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.
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)
label readLabel(Istream &is)
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.
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.
void printUsage() const
Print usage.
A class for handling character strings derived from std::string.
void * dlOpen(const fileName &lib, const bool check=true)
Open a shared library. Return handle to library. Print error message.
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.