Go to the documentation of this file.
55 Foam::argList::initValidTables::initValidTables()
60 "specify alternate case directory, default is the cwd"
62 argList::addBoolOption(
"parallel",
"run in parallel");
63 validParOptions.set(
"parallel",
"");
66 "roots",
"(dir1 .. dirN)",
67 "slave root directories for distributed running"
69 validParOptions.set(
"roots",
"(dir1 .. dirN)");
73 "decomposeParDict",
"file",
74 "read decomposePar dictionary from specified location"
82 argList::addBoolOption
85 "do not execute functionObjects"
88 Pstream::addValidParOptions(validParOptions);
103 addOption(opt,
"", usage);
114 validOptions.set(opt, param);
117 optionUsage.set(opt, usage);
130 optionUsage.erase(opt);
134 optionUsage.set(opt, usage);
150 validOptions.erase(opt);
151 optionUsage.erase(opt);
157 bannerEnabled =
false;
163 removeOption(
"parallel");
164 removeOption(
"roots");
165 removeOption(
"decomposeParDict");
166 validParOptions.clear();
172 const label location,
201 while (
pos != string::npos &&
pos + textWidth < strLen)
210 next = str.find_first_not_of(
" \t\n", curr);
216 next = str.find_first_not_of(
" \t\n", curr);
224 if (prev != string::npos && prev >
pos)
230 if (next == string::npos)
249 if (
pos != string::npos)
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;
324 args_.setSize(nArgs);
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();
367 if (rootPath_.isAbsolute())
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];
407 if (validParOptions.found(optionName))
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];
439 validOptions.found(optionName)
440 && !validOptions[optionName].empty()
443 validParOptions.found(optionName)
444 && !validParOptions[optionName].empty()
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];
477 args_.setSize(nArgs);
479 parse(checkArgs, checkOpts, initialise);
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)
595 if (parRunControl_.parRun())
604 label dictNProcs = -1;
607 if (options_.found(
"roots"))
611 roots = readList<fileName>(is);
613 if (roots.
size() != 1)
615 dictNProcs = roots.
size()+1;
620 source = rootPath_/globalCase_/
"system"/
"decomposeParDict";
622 if (options_.found(
"decomposeParDict"))
624 source = options_[
"decomposeParDict"];
627 source = source/
"decomposeParDict";
633 if (!decompDictStream.
good())
636 <<
"Cannot read decomposeParDict from "
637 << decompDictStream.
name()
645 decompDict.
lookup(
"numberOfSubdomains")
650 decompDict.
lookup(
"roots") >> roots;
656 if (roots.
size() == 1)
664 dictNProcs = roots.
size()+1;
682 <<
" specifies " << dictNProcs
683 <<
" processors but job was started with "
695 <<
"number of entries in roots "
697 <<
" is not equal to the number of slaves "
708 bool hadCaseOpt = options_.found(
"case");
716 options_.set(
"case", roots[slave-1]/globalCase_);
719 toSlave << args_ << options_;
721 options_.erase(
"case");
726 options_.set(
"case", rootPath_/globalCase_);
740 rootPath_/globalCase_/
"processor"
749 <<
"number of processor directories = "
751 <<
" is not equal to the number of processors = "
766 toSlave << args_ << options_;
774 fromMaster >> args_ >> options_;
794 if (parRunControl_.parRun())
812 fromSlave >> slaveBuild >> slaveMachine >> slavePid;
814 slaveProcs[procI++] = slaveMachine +
"." +
name(slavePid);
822 <<
"; slave " << procI <<
" is running version "
838 Info<<
"Case : " << (rootPath_/globalCase_).c_str() <<
nl
839 <<
"nProcs : " << nProcs <<
endl;
841 if (parRunControl_.parRun())
843 Info<<
"Slaves : " << slaveProcs <<
nl;
846 Info<<
"Roots : " << roots <<
nl;
848 Info<<
"Pstream initialized with:" <<
nl
863 if (slaveProcs.
size())
882 Info<<
"fileModificationChecking : "
883 <<
"Monitoring run-time modified files using "
890 Info<<
"allowSystemOperations : ";
893 Info<<
"Allowing user-supplied system call operations" <<
endl;
897 Info<<
"Disallowing user-supplied system call operations"
923 bool changed =
false;
926 if (validOptions.found(opt))
937 <<
"used argList::setOption on a protected option: '"
938 << opt <<
"'" <<
endl;
942 if (validOptions[opt].empty())
949 <<
"used argList::setOption to change bool to non-bool: '"
950 << opt <<
"'" <<
endl;
956 changed = !options_.found(opt);
966 <<
"used argList::setOption to change non-bool to bool: '"
967 << opt <<
"'" <<
endl;
973 changed = options_.found(opt) ? options_[opt] != param :
true;
980 <<
"used argList::setOption on an invalid option: '"
981 << opt <<
"'" <<
nl <<
"allowed are the following:"
982 << validOptions <<
endl;
989 options_.set(opt, param);
999 if (validOptions.found(opt))
1005 || opt ==
"parallel"
1010 <<
"used argList::unsetOption on a protected option: '"
1011 << opt <<
"'" <<
endl;
1016 return options_.erase(opt);
1021 <<
"used argList::unsetOption on an invalid option: '"
1022 << opt <<
"'" <<
nl <<
"allowed are the following:"
1023 << validOptions <<
endl;
1039 Info<< iter().c_str() <<
nl;
1047 Info<<
"\nUsage: " << executable_ <<
" [OPTIONS]";
1051 Info<<
" <" << iter().c_str() <<
'>';
1054 Info<<
"\noptions:\n";
1056 wordList opts = validOptions.sortedToc();
1059 const word& optionName = opts[optI];
1062 Info<<
" -" << optionName;
1063 label len = optionName.size() + 3;
1068 len += iter().size() + 3;
1069 Info<<
" <" << iter().c_str() <<
'>';
1073 optionUsage.find(optionName);
1075 if (usageIter != optionUsage.end())
1096 "display source code in browser"
1103 "display application documentation in browser"
1118 <<
" (see www.OpenFOAM.com)" <<
nl
1135 docExts[extI].replace(
".",
"_source.");
1146 docFile = docDirs[dirI]/executable_ + docExts[extI];
1163 string docBrowser =
getEnv(
"FOAM_DOC_BROWSER");
1164 if (docBrowser.empty())
1166 docDict.
lookup(
"docBrowser") >> docBrowser;
1171 Info<<
"Show documentation: " << docBrowser.c_str() <<
endl;
1178 <<
"No documentation found for " << executable_
1179 <<
", but you can use -help to display the usage\n" <<
endl;
1190 if (checkArgs && args_.size() - 1 != validArgs.size())
1193 <<
"Wrong number of arguments, expected " << validArgs.size()
1194 <<
" found " << args_.size() - 1 <<
endl;
1204 !validOptions.found(iter.key())
1205 && !validParOptions.found(iter.key())
1209 <<
"Invalid option: -" << iter.key() <<
endl;
1227 if (!
isDir(rootPath()))
1231 <<
": cannot open root directory " << rootPath()
1242 <<
": cannot open case directory " <<
path()
static SLList< string > validArgs
A list of valid (mandatory) arguments.
static void noBanner()
Disable emitting the banner information.
static void set(const bool verbose)
Activate SIGFPE signal handler when FOAM_SIGFPE is set.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool write(Ostream &) const
const fileName & name() const
Return the name of the stream.
string & replaceAll(const string &oldStr, const string &newStr, size_type start=0)
Replace all occurences of sub-string oldStr with newStr.
PID_T ppid()
Return the parent PID of this process.
A class for handling words, derived from string.
Foam::argList::initValidTables dummyInitValidTables
A class for handling file names.
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
static void addNote(const string &)
Add extra notes for the usage information.
#define forAll(list, i)
Loop across all elements in list.
static const NamedEnum< fileCheckTypes, 4 > fileCheckTypesNames
bool regroupArgv(int &argc, char **&argv)
Transcribe argv into internal args_.
static string::size_type usageMin
Min offset for displaying usage (default: 20)
Output inter-processor communications stream.
static HashTable< string > optionUsage
Short usage information for validOptions.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
An STL-conforming const_iterator.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
fileName path() const
Return directory path name (part before last /)
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
bool isAbsolute() const
Return true if file name is absolute.
static const NamedEnum< commsTypes, 3 > commsTypeNames
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
static bool bannerEnabled
Extract command arguments and options from the supplied argc and argv parameters.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool setEnv(const word &name, const std::string &value, const bool overwrite)
Set an environment variable.
static commsTypes defaultCommsType
Default commsType.
static string date()
Return the current wall-clock date as a string.
A class for handling character strings derived from std::string.
static void set(const bool verbose)
Activate SIGSEGV signal handler.
static string clockTime()
Return the current wall-clock time as a string.
word name() const
Return file name (part beyond last /)
static int allowSystemOperations
Flag if system operations are allowed.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
static void addUsage(const word &opt, const string &usage)
Add option usage information to optionUsage.
static HashTable< string > validParOptions
A list of valid parallel options.
void printNotes() const
Print notes (if any)
std::string toUnixPath(const std::string &path)
Convert to unix path separators.
void parse(bool checkArgs, bool checkOpts, bool initialise)
Parse.
string userName()
Return the user's login name.
PID_T pid()
Return the PID of this process.
string getEnv(const word &)
Return environment variable of given name.
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 void set(const bool verbose)
Activate SIGINT signal handler.
static void set(const bool verbose)
Activate SIGQUIT signal handler.
static int lastSlave(const label communicator=0)
Process index of last slave.
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
bool setOption(const word &opt, const string ¶m="")
Set option directly (use with caution)
void getRootCase()
Get rootPath_ / globalCase_ from one of the following forms.
void printUsage() const
Print usage.
graph_traits< Graph >::vertices_size_type size_type
static void printOptionUsage(const label location, const string &str)
Helper function for printUsage.
static int masterNo()
Process index of the master.
PID_T pgid()
Return the group PID of this process.
const char *const FOAMbuild
static HashTable< string > validOptions
A list of valid options.
A list of keyword definitions, which are a keyword followed by any number of values (e....
static int firstSlave()
Process index of first slave.
Input from memory buffer stream.
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
static Stream & writeBanner(Stream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static bool master(const label communicator=0)
Am I the master process.
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
static fileCheckTypes fileModificationChecking
void setSize(const label)
Reset size of List.
bool unsetOption(const word &opt)
Unset option directly (use with caution)
ParRunControl parRunControl_
Switch on/off parallel mode. Has to be first to be constructed.
void end(const word &terminationType)
static string::size_type usageMax
Max screen width for displaying usage (default: 80)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
string hostName(const bool full=false)
Return the system's host name, as per hostname(1)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static SLList< string > notes
Additional notes for usage.
bool checkRootCase() const
Check root path and case path.
label readLabel(Istream &is)
static void removeOption(const word &opt)
Remove option from validOptions and from optionUsage.
fileName cwd()
Return current working directory path name.
Input inter-processor communications stream.
bool clean()
Cleanup file name.
dictionary & controlDict()
The central control dictionary.
void size(const label)
Override size to be inconsistent with allocated storage.
static void noParallel()
Remove the parallel options.
bool good() const
Return true if next operation might succeed.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Foam::argList args(argc, argv)
const char *const FOAMversion
int system(const std::string &command)
Execute the specified command.
virtual ~argList()
Destructor.
bool check(bool checkArgs=true, bool checkOpts=true) const
Check argument list.
word name(const complex &)
Return a string representation of a complex.
void displayDoc(bool source=false) const
Display documentation in browser.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
static int nPollProcInterfaces
Number of polling cycles in processor updates.
argList(int &argc, char **&argv, bool checkArgs=true, bool checkOpts=true, bool initialise=true)
Construct from argc and argv.
dimensionedScalar pos(const dimensionedScalar &ds)