41 bool Foam::argList::bannerEnabled =
true;
51 Foam::argList::initValidTables::initValidTables()
56 "specify alternate case directory, default is the cwd" 58 argList::addBoolOption(
"parallel",
"run in parallel");
59 validParOptions.set(
"parallel",
"");
62 "roots",
"(dir1 .. dirN)",
63 "slave root directories for distributed running" 65 validParOptions.set(
"roots",
"(dir1 .. dirN)");
67 argList::addBoolOption
70 "do not execute functionObjects" 73 Pstream::addValidParOptions(validParOptions);
88 addOption(opt,
"", usage);
99 validOptions.set(opt, param);
102 optionUsage.set(opt, usage);
115 optionUsage.erase(opt);
119 optionUsage.set(opt, usage);
142 bannerEnabled =
false;
154 void Foam::argList::printOptionUsage
156 const label location,
185 while (pos != string::npos && pos + textWidth < strLen)
194 next = str.find_first_not_of(
" \t\n", curr);
200 next = str.find_first_not_of(
" \t\n", curr);
208 if (prev != string::npos && prev > pos)
214 if (next == string::npos)
228 Info<< str.substr(pos, (curr - pos)).c_str() <<
nl;
233 if (pos != string::npos)
244 Info<< str.substr(pos).c_str() <<
nl;
256 bool postProcessOption =
false;
258 for (
int i=1; i<argc; i++)
261 if (postProcessOption)
break;
264 return postProcessOption;
272 bool Foam::argList::regroupArgv(
int& argc,
char**& argv)
280 for (
int argI = 0; argI < argc; ++argI)
282 if (strcmp(argv[argI],
"(") == 0)
287 else if (strcmp(argv[argI],
")") == 0)
295 args_[nArgs++] = tmpString;
301 args_[nArgs++] = argv[argI];
308 tmpString += argv[argI];
313 args_[nArgs++] = argv[argI];
317 if (tmpString.size())
319 args_[nArgs++] = tmpString;
328 void Foam::argList::getRootCase()
335 if (iter != options_.end())
340 if (casePath.empty() || casePath ==
".")
344 options_.erase(
"case");
349 casePath =
cwd()/casePath;
359 rootPath_ = casePath.
path();
360 globalCase_ = casePath.
name();
368 setEnv(
"FOAM_CASE", rootPath_/globalCase_,
true);
369 setEnv(
"FOAM_CASENAME", globalCase_,
true);
374 casePath =
cwd()/rootPath_/globalCase_;
377 setEnv(
"FOAM_CASE", casePath,
true);
378 setEnv(
"FOAM_CASENAME", casePath.
name(),
true);
391 const bool initialise
399 for (
int argI = 0; argI < argc; ++argI)
401 if (argv[argI][0] ==
'-')
403 const char *optionName = &argv[argI][1];
407 parRunControl_.
runPar(argc, argv);
415 regroupArgv(argc, argv);
423 argListStr_ = args_[0];
425 for (
int argI = 1; argI < args_.
size(); ++argI)
428 argListStr_ += args_[argI];
430 if (args_[argI][0] ==
'-')
432 const char *optionName = &args_[argI][1];
447 if (argI >= args_.
size())
450 <<
"Option '-" << optionName
451 <<
"' requires an argument" <<
endl;
457 argListStr_ += args_[argI];
458 options_.insert(optionName, args_[argI]);
462 options_.insert(optionName,
"");
469 args_[nArgs] = args_[argI];
477 parse(checkArgs, checkOpts, initialise);
490 parRunControl_(args.parRunControl_),
493 executable_(args.executable_),
494 rootPath_(args.rootPath_),
495 globalCase_(args.globalCase_),
497 argListStr_(args.argListStr_)
499 parse(checkArgs, checkOpts, initialise);
516 options_.found(
"help")
517 || options_.found(
"doc")
518 || options_.found(
"srcDoc")
521 if (options_.found(
"help"))
527 if (options_.found(
"srcDoc"))
531 else if (options_.found(
"doc"))
540 if (!
check(checkArgs, checkOpts))
556 <<
"Exec : " << argListStr_.c_str() <<
nl 557 <<
"Date : " << dateString.c_str() <<
nl 558 <<
"Time : " << timeString.c_str() <<
nl 577 if (found != std::string::npos)
593 if (parRunControl_.
parRun())
602 label dictNProcs = -1;
605 if (options_.found(
"roots"))
609 roots = readList<fileName>(is);
611 if (roots.
size() != 1)
613 dictNProcs = roots.
size()+1;
618 source = rootPath_/globalCase_/
"system/decomposeParDict";
621 if (!decompDictStream.
good())
625 << decompDictStream.
name()
633 decompDict.
lookup(
"numberOfSubdomains")
638 decompDict.
lookup(
"roots") >> roots;
644 if (roots.
size() == 1)
652 dictNProcs = roots.
size()+1;
670 <<
" specifies " << dictNProcs
671 <<
" processors but job was started with " 683 <<
"number of entries in roots " 685 <<
" is not equal to the number of slaves " 696 bool hadCaseOpt = options_.found(
"case");
704 options_.set(
"case", roots[slave-1]/globalCase_);
707 toSlave << args_ << options_;
709 options_.erase(
"case");
714 options_.set(
"case", rootPath_/globalCase_);
728 rootPath_/globalCase_/
"processor" 737 <<
"number of processor directories = " 739 <<
" is not equal to the number of processors = " 754 toSlave << args_ << options_;
762 fromMaster >> args_ >> options_;
782 if (parRunControl_.
parRun())
800 fromSlave >> slaveBuild >> slaveMachine >> slavePid;
802 slaveProcs[proci++] = slaveMachine +
"." +
name(slavePid);
810 <<
"; slave " << proci <<
" is running version " 826 Info<<
"Case : " << (rootPath_/globalCase_).c_str() <<
nl 827 <<
"nProcs : " << nProcs <<
endl;
829 if (parRunControl_.
parRun())
831 Info<<
"Slaves : " << slaveProcs <<
nl;
834 Info<<
"Roots : " << roots <<
nl;
836 Info<<
"Pstream initialized with:" << nl
851 if (slaveProcs.
size())
863 sigFpe_.
set(bannerEnabled);
864 sigInt_.
set(bannerEnabled);
865 sigQuit_.
set(bannerEnabled);
866 sigSegv_.
set(bannerEnabled);
870 Info<<
"fileModificationChecking : " 871 <<
"Monitoring run-time modified files using " 878 Info<<
"allowSystemOperations : ";
881 Info<<
"Allowing user-supplied system call operations" <<
endl;
885 Info<<
"Disallowing user-supplied system call operations" 911 bool changed =
false;
925 <<
"used argList::setOption on a protected option: '" 926 << opt <<
"'" <<
endl;
937 <<
"used argList::setOption to change bool to non-bool: '" 938 << opt <<
"'" <<
endl;
944 changed = !options_.found(opt);
954 <<
"used argList::setOption to change non-bool to bool: '" 955 << opt <<
"'" <<
endl;
961 changed = options_.found(opt) ? options_[opt] != param :
true;
968 <<
"used argList::setOption on an invalid option: '" 969 << opt <<
"'" <<
nl <<
"allowed are the following:" 977 options_.set(opt, param);
998 <<
"used argList::unsetOption on a protected option: '" 999 << opt <<
"'" <<
endl;
1004 return options_.erase(opt);
1009 <<
"used argList::unsetOption on an invalid option: '" 1010 << opt <<
"'" <<
nl <<
"allowed are the following:" 1027 Info<< iter().c_str() <<
nl;
1035 Info<<
"\nUsage: " << executable_ <<
" [OPTIONS]";
1039 Info<<
" <" << iter().c_str() <<
'>';
1042 Info<<
"\noptions:\n";
1047 const word& optionName = opts[optI];
1050 Info<<
" -" << optionName;
1051 label len = optionName.size() + 3;
1056 len += iter().size() + 3;
1057 Info<<
" <" << iter().c_str() <<
'>';
1082 "display source code in browser" 1089 "display application documentation in browser" 1104 <<
" (see www.OpenFOAM.org)" <<
nl 1121 docExts[extI].replace(
".",
"_source.");
1132 docFile = docDirs[dirI]/executable_ + docExts[extI];
1149 string docBrowser =
getEnv(
"FOAM_DOC_BROWSER");
1150 if (docBrowser.empty())
1152 docDict.
lookup(
"docBrowser") >> docBrowser;
1157 Info<<
"Show documentation: " << docBrowser.c_str() <<
endl;
1164 <<
"No documentation found for " << executable_
1165 <<
", but you can use -help to display the usage\n" <<
endl;
1179 <<
"Wrong number of arguments, expected " <<
validArgs.size()
1180 <<
" found " << args_.
size() - 1 <<
endl;
1195 <<
"Invalid option: -" << iter.key() <<
endl;
1217 <<
": cannot open root directory " <<
rootPath()
1228 <<
": 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.
string & replaceAll(const string &oldStr, const string &newStr, size_type start=0)
Replace all occurences of sub-string oldStr with newStr.
void set(const bool verbose)
Activate SIGQUIT signal handler.
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...
bool clean()
Cleanup file name.
argList(int &argc, char **&argv, bool checkArgs=true, bool checkOpts=true, bool initialise=true)
Construct from argc and argv.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
static int firstSlave()
Process index of first slave.
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.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
bool good() const
Return true if next operation might succeed.
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
static SLList< string > notes
Additional notes for usage.
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
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.
const fileName & name() const
Return the name of the stream.
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
static bool postProcess(int argc, char *argv[])
Return true if the post-processing option is specified.
const char *const FOAMversion
const fileName & rootPath() const
Return root path.
void runPar(int &argc, char **&argv)
virtual ~argList()
Destructor.
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.
const word & executable() const
Name of executable without the path.
void parse(bool checkArgs, bool checkOpts, bool initialise)
Parse.
Input inter-processor communications stream.
fileName path() const
Return the path to the caseName.
static fileCheckTypes fileModificationChecking
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
dimensionedScalar pos(const dimensionedScalar &ds)
word name() const
Return file name (part beyond last /)
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.
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.
bool check(bool checkArgs=true, bool checkOpts=true) const
Check argument list.
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
bool checkRootCase() const
Check root path and case path.
string userName()
Return the user's login name.
static HashTable< string > optionUsage
Short usage information for validOptions.
graph_traits< Graph >::vertices_size_type size_type
void printNotes() const
Print notes (if any)
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
label readLabel(Istream &is)
static string clockTime()
Return the current wall-clock time as a string.
bool isAbsolute() const
Return true if file name is absolute.
pid_t pid()
Return the PID of this process.
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.
static string date()
Return the current wall-clock date as a string.
static commsTypes defaultCommsType
Default commsType.
void setSize(const label)
Reset size of List.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
void set(const bool verbose)
Activate SIGINT signal handler.
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
Input from memory buffer stream.
fileName cwd()
Return current working directory path name.
void set(const bool verbose)
Activate SIGFPE signal handler when FOAM_SIGFPE is set.
label size() const
Return the number of arguments.
static void noBanner()
Disable emitting the banner information.
static const NamedEnum< fileCheckTypes, 4 > fileCheckTypesNames
void displayDoc(bool source=false) const
Display documentation in browser.
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.
void set(const bool verbose)
Activate SIGSEGV signal handler.
static string::size_type usageMin
Min offset for displaying usage (default: 20)
const char *const FOAMbuild
void printUsage() const
Print usage.
dictionary & controlDict()
The central control dictionary.
fileName path() const
Return directory path name (part before last /)
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
A class for handling character strings derived from std::string.
#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.
int system(const std::string &command)
Execute the specified command.
static int lastSlave(const label communicator=0)
Process index of last slave.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.