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" 176 void Foam::argList::printOptionUsage
178 const label location,
207 while (pos != string::npos && pos + textWidth < strLen)
216 next = str.find_first_not_of(
" \t\n", curr);
222 next = str.find_first_not_of(
" \t\n", curr);
230 if (prev != string::npos && prev > pos)
236 if (next == string::npos)
250 Info<< str.substr(pos, (curr - pos)).c_str() <<
nl;
255 if (pos != string::npos)
266 Info<< str.substr(pos).c_str() <<
nl;
278 bool postProcessOption =
false;
280 for (
int i=1; i<argc; i++)
283 if (postProcessOption)
break;
286 return postProcessOption;
294 bool Foam::argList::regroupArgv(
int& argc,
char**& argv)
302 for (
int argI = 0; argI < argc; ++argI)
304 if (strcmp(argv[argI],
"(") == 0)
309 else if (strcmp(argv[argI],
")") == 0)
317 args_[nArgs++] = tmpString;
323 args_[nArgs++] = argv[argI];
330 tmpString += argv[argI];
335 args_[nArgs++] = argv[argI];
339 if (tmpString.size())
341 args_[nArgs++] = tmpString;
344 args_.setSize(nArgs);
350 void Foam::argList::getRootCase()
357 if (iter != options_.end())
362 if (casePath.empty() || casePath ==
".")
366 options_.erase(
"case");
371 casePath =
cwd()/casePath;
381 rootPath_ = casePath.
path();
382 globalCase_ = casePath.
name();
387 if (rootPath_.isAbsolute())
390 setEnv(
"FOAM_CASE", rootPath_/globalCase_,
true);
391 setEnv(
"FOAM_CASENAME", globalCase_,
true);
396 casePath =
cwd()/rootPath_/globalCase_;
399 setEnv(
"FOAM_CASE", casePath,
true);
400 setEnv(
"FOAM_CASENAME", casePath.
name(),
true);
413 const bool initialise
421 for (
int argI = 0; argI < argc; ++argI)
423 if (argv[argI][0] ==
'-')
425 const char *optionName = &argv[argI][1];
426 if (
string(optionName) ==
"fileHandler")
428 handlerType = argv[argI+1];
433 if (handlerType.empty())
444 )().needsThreading();
449 for (
int argI = 0; argI < argc; ++argI)
451 if (argv[argI][0] ==
'-')
453 const char *optionName = &argv[argI][1];
457 parRunControl_.runPar(argc, argv, needsThread);
465 regroupArgv(argc, argv);
473 argListStr_ = args_[0];
475 for (
int argI = 1; argI < args_.size(); ++argI)
478 argListStr_ += args_[argI];
480 if (args_[argI][0] ==
'-')
482 const char *optionName = &args_[argI][1];
497 if (argI >= args_.size())
500 <<
"Option '-" << optionName
501 <<
"' requires an argument" <<
endl;
507 argListStr_ += args_[argI];
508 options_.insert(optionName, args_[argI]);
512 options_.insert(optionName,
"");
519 args_[nArgs] = args_[argI];
525 args_.setSize(nArgs);
527 parse(checkArgs, checkOpts, initialise);
540 parRunControl_(args.parRunControl_),
543 executable_(args.executable_),
544 rootPath_(args.rootPath_),
545 globalCase_(args.globalCase_),
547 argListStr_(args.argListStr_)
549 parse(checkArgs, checkOpts, initialise);
566 options_.found(
"help")
567 || options_.found(
"doc")
568 || options_.found(
"srcDoc")
571 if (options_.found(
"help"))
577 if (options_.found(
"srcDoc"))
581 else if (options_.found(
"doc"))
590 if (!
check(checkArgs, checkOpts))
606 <<
"Exec : " << argListStr_.c_str() <<
nl 607 <<
"Date : " << dateString.c_str() <<
nl 608 <<
"Time : " << timeString.c_str() <<
nl 627 if (found != std::string::npos)
645 if (iter != options_.end())
647 handlerType = iter();
650 if (handlerType.empty())
671 if (parRunControl_.parRun())
689 fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
691 slaveProcs[proci] = slaveMachine[proci]+
"."+
name(slavePid);
700 <<
"; slave " << proci <<
" is running version " 725 if (parRunControl_.parRun())
734 label dictNProcs = -1;
737 if (options_.found(
"roots"))
741 roots = readList<fileName>(is);
743 if (roots.
size() != 1)
745 dictNProcs = roots.
size()+1;
748 else if (options_.found(
"hostRoots"))
750 source =
"-hostRoots";
760 forAll(matchedRoots, matchi)
762 label slavei = matchedRoots[matchi];
763 if (roots[slavei] !=
wordRe())
766 <<
"Slave " << slaveMachine[slavei]
767 <<
" has multiple matching roots in " 772 roots[slavei] = hostRoot.
second();
780 if (roots[slavei] ==
wordRe())
783 <<
"Slave " << slaveMachine[slavei]
784 <<
" has no matching roots in " 789 if (roots.
size() != 1)
791 dictNProcs = roots.
size()+1;
796 source = rootPath_/globalCase_/
"system/decomposeParDict";
799 if (!decompDictStream.
good())
803 << decompDictStream.
name()
811 decompDict.
lookup(
"numberOfSubdomains")
816 decompDict.
lookup(
"roots") >> roots;
822 if (roots.
size() == 1)
830 dictNProcs = roots.
size()+1;
848 <<
" specifies " << dictNProcs
849 <<
" processors but job was started with " 861 <<
"number of entries in roots " 863 <<
" is not equal to the number of slaves " 874 bool hadCaseOpt = options_.found(
"case");
882 options_.set(
"case", roots[slave-1]/globalCase_);
885 toSlave << args_ << options_;
887 options_.erase(
"case");
892 options_.set(
"case", rootPath_/globalCase_);
906 rootPath_/globalCase_/
"processor" 915 <<
"number of processor directories = " 917 <<
" is not equal to the number of processors = " 932 toSlave << args_ << options_;
944 fromMaster >> args_ >> options_;
962 Info<<
"Case : " << (rootPath_/globalCase_).c_str() <<
nl 963 <<
"nProcs : " << nProcs <<
endl;
965 if (parRunControl_.parRun())
967 Info<<
"Slaves : " << slaveProcs <<
nl;
970 Info<<
"Roots : " << roots <<
nl;
972 Info<<
"Pstream initialized with:" << nl
987 if (slaveProcs.
size())
995 jobInfo_.write(executable_, rootPath_/globalCase_);
1006 Info<<
"fileModificationChecking : " 1007 <<
"Monitoring run-time modified files using " 1024 Info<<
" (fileModificationSkew " 1029 Info<<
"allowSystemOperations : ";
1032 Info<<
"Allowing user-supplied system call operations" <<
endl;
1036 Info<<
"Disallowing user-supplied system call operations" 1066 bool changed =
false;
1075 || opt ==
"parallel" 1077 || opt ==
"hostRoots" 1081 <<
"used argList::setOption on a protected option: '" 1082 << opt <<
"'" <<
endl;
1093 <<
"used argList::setOption to change bool to non-bool: '" 1094 << opt <<
"'" <<
endl;
1100 changed = !options_.found(opt);
1110 <<
"used argList::setOption to change non-bool to bool: '" 1111 << opt <<
"'" <<
endl;
1117 changed = options_.found(opt) ? options_[opt] != param :
true;
1124 <<
"used argList::setOption on an invalid option: '" 1125 << opt <<
"'" <<
nl <<
"allowed are the following:" 1133 options_.set(opt, param);
1149 || opt ==
"parallel" 1151 || opt ==
"hostRoots" 1155 <<
"used argList::unsetOption on a protected option: '" 1156 << opt <<
"'" <<
endl;
1161 return options_.erase(opt);
1166 <<
"used argList::unsetOption on an invalid option: '" 1167 << opt <<
"'" <<
nl <<
"allowed are the following:" 1184 Info<< iter().c_str() <<
nl;
1192 Info<<
"\nUsage: " << executable_ <<
" [OPTIONS]";
1196 Info<<
" <" << iter().c_str() <<
'>';
1199 Info<<
"\noptions:\n";
1204 const word& optionName = opts[optI];
1207 Info<<
" -" << optionName;
1208 label len = optionName.size() + 3;
1213 len += iter().size() + 3;
1214 Info<<
" <" << iter().c_str() <<
'>';
1239 "display source code in browser" 1246 "display application documentation in browser" 1261 <<
" (see www.OpenFOAM.org)" <<
nl 1276 docExt.
replace(
".",
"_source.");
1286 if (docDirs[dirI].
component(0) ==
"http:")
1288 httpServer = docDirs[dirI]/executable_ + docExt;
1295 if (docDirs[dirI].
component(0) ==
"file:")
1302 docFile = docDirs[dirI]/executable_ + docExt;
1316 string docBrowser =
getEnv(
"FOAM_DOC_BROWSER");
1317 if (docBrowser.empty())
1319 docDict.
lookup(
"docBrowser") >> docBrowser;
1324 docBrowser +=
" file://" + docFile;
1328 docBrowser +=
" " + httpServer;
1331 Info<<
"Show documentation: " << docBrowser.c_str() <<
endl;
1338 <<
"No documentation found for " << executable_
1339 <<
", but you can use -help to display the usage\n" <<
endl;
1350 if (checkArgs && args_.size() - 1 !=
validArgs.size())
1353 <<
"Wrong number of arguments, expected " <<
validArgs.size()
1354 <<
" found " << args_.size() - 1 <<
endl;
1369 <<
"Invalid option: -" << iter.key() <<
endl;
1391 <<
": cannot open root directory " <<
rootPath()
1405 <<
": 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.
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. ...
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)
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.
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 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 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.