43 bool Foam::argList::bannerEnabled =
true;
53 Foam::argList::initValidTables::initValidTables()
58 "specify alternate case directory, default is the cwd" 60 argList::addBoolOption(
"parallel",
"run in parallel");
61 validParOptions.set(
"parallel",
"");
64 "roots",
"(dir1 .. dirN)",
65 "slave root directories for distributed running" 67 validParOptions.set(
"roots",
"(dir1 .. dirN)");
69 argList::addBoolOption
72 "do not execute functionObjects" 75 Pstream::addValidParOptions(validParOptions);
90 addOption(opt,
"", usage);
101 validOptions.set(opt, param);
104 optionUsage.set(opt, usage);
117 optionUsage.erase(opt);
121 optionUsage.set(opt, usage);
144 bannerEnabled =
false;
156 void Foam::argList::printOptionUsage
158 const label location,
187 while (pos != string::npos && pos + textWidth < strLen)
196 next = str.find_first_not_of(
" \t\n", curr);
202 next = str.find_first_not_of(
" \t\n", curr);
210 if (prev != string::npos && prev > pos)
216 if (next == string::npos)
230 Info<< str.substr(pos, (curr - pos)).c_str() <<
nl;
235 if (pos != string::npos)
246 Info<< str.substr(pos).c_str() <<
nl;
258 bool postProcessOption =
false;
260 for (
int i=1; i<argc; i++)
263 if (postProcessOption)
break;
266 return postProcessOption;
274 bool Foam::argList::regroupArgv(
int& argc,
char**& argv)
282 for (
int argI = 0; argI < argc; ++argI)
284 if (strcmp(argv[argI],
"(") == 0)
289 else if (strcmp(argv[argI],
")") == 0)
297 args_[nArgs++] = tmpString;
303 args_[nArgs++] = argv[argI];
310 tmpString += argv[argI];
315 args_[nArgs++] = argv[argI];
319 if (tmpString.size())
321 args_[nArgs++] = tmpString;
330 void Foam::argList::getRootCase()
337 if (iter != options_.end())
342 if (casePath.empty() || casePath ==
".")
346 options_.erase(
"case");
351 casePath =
cwd()/casePath;
361 rootPath_ = casePath.
path();
362 globalCase_ = casePath.
name();
370 setEnv(
"FOAM_CASE", rootPath_/globalCase_,
true);
371 setEnv(
"FOAM_CASENAME", globalCase_,
true);
376 casePath =
cwd()/rootPath_/globalCase_;
379 setEnv(
"FOAM_CASE", casePath,
true);
380 setEnv(
"FOAM_CASENAME", casePath.
name(),
true);
393 const bool initialise
401 for (
int argI = 0; argI < argc; ++argI)
403 if (argv[argI][0] ==
'-')
405 const char *optionName = &argv[argI][1];
409 parRunControl_.
runPar(argc, argv);
417 regroupArgv(argc, argv);
425 argListStr_ = args_[0];
427 for (
int argI = 1; argI < args_.
size(); ++argI)
430 argListStr_ += args_[argI];
432 if (args_[argI][0] ==
'-')
434 const char *optionName = &args_[argI][1];
449 if (argI >= args_.
size())
452 <<
"Option '-" << optionName
453 <<
"' requires an argument" <<
endl;
459 argListStr_ += args_[argI];
460 options_.insert(optionName, args_[argI]);
464 options_.insert(optionName,
"");
471 args_[nArgs] = args_[argI];
479 parse(checkArgs, checkOpts, initialise);
492 parRunControl_(args.parRunControl_),
495 executable_(args.executable_),
496 rootPath_(args.rootPath_),
497 globalCase_(args.globalCase_),
499 argListStr_(args.argListStr_)
501 parse(checkArgs, checkOpts, initialise);
518 options_.found(
"help")
519 || options_.found(
"doc")
520 || options_.found(
"srcDoc")
523 if (options_.found(
"help"))
529 if (options_.found(
"srcDoc"))
533 else if (options_.found(
"doc"))
542 if (!
check(checkArgs, checkOpts))
558 <<
"Exec : " << argListStr_.c_str() <<
nl 559 <<
"Date : " << dateString.c_str() <<
nl 560 <<
"Time : " << timeString.c_str() <<
nl 579 if (found != std::string::npos)
597 if (iter != options_.end())
599 handlerType = iter();
602 if (handlerType.empty())
625 if (parRunControl_.
parRun())
634 label dictNProcs = -1;
637 if (options_.found(
"roots"))
641 roots = readList<fileName>(is);
643 if (roots.
size() != 1)
645 dictNProcs = roots.
size()+1;
650 source = rootPath_/globalCase_/
"system/decomposeParDict";
653 if (!decompDictStream.
good())
657 << decompDictStream.
name()
665 decompDict.
lookup(
"numberOfSubdomains")
670 decompDict.
lookup(
"roots") >> roots;
676 if (roots.
size() == 1)
684 dictNProcs = roots.
size()+1;
702 <<
" specifies " << dictNProcs
703 <<
" processors but job was started with " 715 <<
"number of entries in roots " 717 <<
" is not equal to the number of slaves " 728 bool hadCaseOpt = options_.found(
"case");
736 options_.set(
"case", roots[slave-1]/globalCase_);
739 toSlave << args_ << options_;
741 options_.erase(
"case");
746 options_.set(
"case", rootPath_/globalCase_);
760 rootPath_/globalCase_/
"processor" 769 <<
"number of processor directories = " 771 <<
" is not equal to the number of processors = " 786 toSlave << args_ << options_;
798 fromMaster >> args_ >> options_;
818 if (parRunControl_.
parRun())
836 fromSlave >> slaveBuild >> slaveMachine >> slavePid;
838 slaveProcs[proci++] = slaveMachine +
"." +
name(slavePid);
846 <<
"; slave " << proci <<
" is running version " 866 Info<<
"Case : " << (rootPath_/globalCase_).c_str() <<
nl 867 <<
"nProcs : " << nProcs <<
endl;
869 if (parRunControl_.
parRun())
871 Info<<
"Slaves : " << slaveProcs <<
nl;
874 Info<<
"Roots : " << roots <<
nl;
876 Info<<
"Pstream initialized with:" << nl
891 if (slaveProcs.
size())
903 sigFpe_.
set(bannerEnabled);
904 sigInt_.
set(bannerEnabled);
905 sigQuit_.
set(bannerEnabled);
906 sigSegv_.
set(bannerEnabled);
910 Info<<
"fileModificationChecking : " 911 <<
"Monitoring run-time modified files using " 928 Info<<
" (fileModificationSkew " 933 Info<<
"allowSystemOperations : ";
936 Info<<
"Allowing user-supplied system call operations" <<
endl;
940 Info<<
"Disallowing user-supplied system call operations" 970 bool changed =
false;
984 <<
"used argList::setOption on a protected option: '" 985 << opt <<
"'" <<
endl;
996 <<
"used argList::setOption to change bool to non-bool: '" 997 << opt <<
"'" <<
endl;
1003 changed = !options_.found(opt);
1013 <<
"used argList::setOption to change non-bool to bool: '" 1014 << opt <<
"'" <<
endl;
1020 changed = options_.found(opt) ? options_[opt] != param :
true;
1027 <<
"used argList::setOption on an invalid option: '" 1028 << opt <<
"'" <<
nl <<
"allowed are the following:" 1036 options_.set(opt, param);
1052 || opt ==
"parallel" 1057 <<
"used argList::unsetOption on a protected option: '" 1058 << opt <<
"'" <<
endl;
1063 return options_.erase(opt);
1068 <<
"used argList::unsetOption on an invalid option: '" 1069 << opt <<
"'" <<
nl <<
"allowed are the following:" 1086 Info<< iter().c_str() <<
nl;
1094 Info<<
"\nUsage: " << executable_ <<
" [OPTIONS]";
1098 Info<<
" <" << iter().c_str() <<
'>';
1101 Info<<
"\noptions:\n";
1106 const word& optionName = opts[optI];
1109 Info<<
" -" << optionName;
1110 label len = optionName.size() + 3;
1115 len += iter().size() + 3;
1116 Info<<
" <" << iter().c_str() <<
'>';
1141 "display source code in browser" 1148 "display application documentation in browser" 1163 <<
" (see www.OpenFOAM.org)" <<
nl 1178 docExt.
replace(
".",
"_source.");
1188 if (docDirs[dirI].
component(0) ==
"http:")
1190 httpServer = docDirs[dirI]/executable_ + docExt;
1197 if (docDirs[dirI].
component(0) ==
"file:")
1204 docFile = docDirs[dirI]/executable_ + docExt;
1218 string docBrowser =
getEnv(
"FOAM_DOC_BROWSER");
1219 if (docBrowser.empty())
1221 docDict.
lookup(
"docBrowser") >> docBrowser;
1226 docBrowser +=
" file://" + docFile;
1230 docBrowser +=
" " + httpServer;
1233 Info<<
"Show documentation: " << docBrowser.c_str() <<
endl;
1240 <<
"No documentation found for " << executable_
1241 <<
", but you can use -help to display the usage\n" <<
endl;
1255 <<
"Wrong number of arguments, expected " <<
validArgs.size()
1256 <<
" found " << args_.
size() - 1 <<
endl;
1271 <<
"Invalid option: -" << iter.key() <<
endl;
1293 <<
": cannot open root directory " <<
rootPath()
1307 <<
": 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.
void set(const bool verbose)
Activate SIGQUIT signal handler.
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...
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.
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
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.
const char *const FOAMversion
void runPar(int &argc, char **&argv)
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.
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.
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. ...
const fileName & name() const
Return the name of the stream.
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)
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.
bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
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 occurence of sub-string oldStr with newStr.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
void set(const bool verbose)
Activate SIGINT signal handler.
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 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.
static float fileModificationSkew
bool check(bool checkArgs=true, bool checkOpts=true) const
Check argument list.
static void noBanner()
Disable emitting the banner information.
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.
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
dictionary & controlDict()
The central control dictionary.
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.
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.