59 "specify alternate case directory, default is the cwd" 65 "roots",
"(dir1 .. dirN)",
66 "slave root directories for distributed running" 72 "hostRoots",
"((host1 dir1) .. (hostN dirN))",
73 "slave root directories (per host) for distributed running" 80 "do not execute functionObjects" 87 "override the fileHandler" 92 "'(\"lib1.so\" ... \"libN.so\")'",
184 void Foam::argList::printOptionUsage
186 const label location,
215 while (pos != string::npos && pos + textWidth < strLen)
224 next = str.find_first_not_of(
" \t\n", curr);
230 next = str.find_first_not_of(
" \t\n", curr);
238 if (prev != string::npos && prev > pos)
244 if (next == string::npos)
258 Info<< str.substr(pos, (curr - pos)).c_str() <<
nl;
263 if (pos != string::npos)
274 Info<< str.substr(pos).c_str() <<
nl;
286 bool postProcessOption =
false;
288 for (
int i=1; i<argc; i++)
291 if (postProcessOption)
break;
294 return postProcessOption;
300 for (
int i=1; i<argc; i++)
302 const string arg(argv[i]);
303 const string argName(
arg(1, arg.size() - 1));
323 bool Foam::argList::regroupArgv(
int& argc,
char**& argv)
331 for (
int argi=0; argi<argc; argi++)
333 if (strcmp(argv[argi],
"(") == 0)
338 else if (strcmp(argv[argi],
")") == 0)
346 args_[nArgs++] = tmpString;
352 args_[nArgs++] = argv[argi];
359 tmpString += argv[argi];
364 args_[nArgs++] = argv[argi];
368 if (tmpString.size())
370 args_[nArgs++] = tmpString;
373 args_.setSize(nArgs);
379 void Foam::argList::getRootCase()
386 if (iter != options_.end())
391 if (casePath.empty() || casePath ==
".")
395 options_.erase(
"case");
400 casePath =
cwd()/casePath;
410 rootPath_ = casePath.
path();
411 globalCase_ = casePath.
name();
416 if (rootPath_.isAbsolute())
419 setEnv(
"FOAM_CASE", rootPath_/globalCase_,
true);
420 setEnv(
"FOAM_CASENAME", globalCase_,
true);
425 casePath =
cwd()/rootPath_/globalCase_;
428 setEnv(
"FOAM_CASE", casePath,
true);
429 setEnv(
"FOAM_CASENAME", casePath.
name(),
true);
442 const bool initialise
450 const string libsString(
getEnv(
"FOAM_LIBS"));
451 if (!libsString.empty())
456 for (
int argi=0; argi<argc; argi++)
458 if (argv[argi][0] ==
'-')
460 const char *optionName = &argv[argi][1];
461 if (
string(optionName) ==
"libs")
472 for (
int argi=0; argi<argc; argi++)
474 if (argv[argi][0] ==
'-')
476 const char *optionName = &argv[argi][1];
477 if (
string(optionName) ==
"fileHandler")
479 handlerType = argv[argi+1];
484 if (handlerType.empty())
495 )().needsThreading();
500 for (
int argi=0; argi<argc; argi++)
502 if (argv[argi][0] ==
'-')
504 const char *optionName = &argv[argi][1];
508 parRunControl_.runPar(argc, argv, needsThread);
516 regroupArgv(argc, argv);
524 argListStr_ = args_[0];
526 for (
int argi=1; argi<args_.size(); argi++)
529 argListStr_ += args_[argi];
531 if (args_[argi][0] ==
'-')
533 const char *optionName = &args_[argi][1];
548 if (argi >= args_.size())
551 <<
"Option '-" << optionName
552 <<
"' requires an argument" <<
endl;
558 argListStr_ += args_[argi];
559 options_.insert(optionName, args_[argi]);
563 options_.insert(optionName,
"");
570 args_[nArgs] = args_[argi];
576 args_.setSize(nArgs);
578 parse(checkArgs, checkOpts, initialise);
591 parRunControl_(args.parRunControl_),
594 executable_(args.executable_),
595 rootPath_(args.rootPath_),
596 globalCase_(args.globalCase_),
598 argListStr_(args.argListStr_)
600 parse(checkArgs, checkOpts, initialise);
617 options_.found(
"help")
618 || options_.found(
"doc")
619 || options_.found(
"srcDoc")
622 if (options_.found(
"help"))
628 if (options_.found(
"srcDoc"))
632 else if (options_.found(
"doc"))
641 if (!
check(checkArgs, checkOpts))
657 <<
"Exec : " << argListStr_.c_str() <<
nl 658 <<
"Date : " << dateString.c_str() <<
nl 659 <<
"Time : " << timeString.c_str() <<
nl 678 if (found != std::string::npos)
696 if (iter != options_.end())
698 handlerType = iter();
701 if (handlerType.empty())
722 if (parRunControl_.parRun())
740 fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
742 slaveProcs[proci] = slaveMachine[proci]+
"."+
name(slavePid);
751 <<
"; slave " << proci <<
" is running version " 776 if (parRunControl_.parRun())
785 label dictNProcs = -1;
788 if (options_.found(
"roots"))
792 roots = readList<fileName>(is);
794 if (roots.
size() != 1)
796 dictNProcs = roots.
size()+1;
799 else if (options_.found(
"hostRoots"))
801 source =
"-hostRoots";
811 forAll(matchedRoots, matchi)
813 label slavei = matchedRoots[matchi];
814 if (roots[slavei] !=
wordRe())
817 <<
"Slave " << slaveMachine[slavei]
818 <<
" has multiple matching roots in " 823 roots[slavei] = hostRoot.
second();
831 if (roots[slavei] ==
wordRe())
834 <<
"Slave " << slaveMachine[slavei]
835 <<
" has no matching roots in " 840 if (roots.
size() != 1)
842 dictNProcs = roots.
size()+1;
847 source = rootPath_/globalCase_/
"system/decomposeParDict";
850 if (!decompDictStream.
good())
859 dictNProcs = decompDict.
lookup<
label>(
"numberOfSubdomains");
863 decompDict.
lookup(
"roots") >> roots;
870 if (roots.
size() == 1)
878 dictNProcs = roots.
size()+1;
896 <<
" specifies " << dictNProcs
897 <<
" processors but job was started with " 909 <<
"number of entries in roots " 911 <<
" is not equal to the number of slaves " 922 bool hadCaseOpt = options_.found(
"case");
930 options_.set(
"case", roots[slave-1]/globalCase_);
933 toSlave << args_ << options_;
935 options_.erase(
"case");
940 options_.set(
"case", rootPath_/globalCase_);
954 rootPath_/globalCase_/
"processor" 963 <<
"number of processor directories = " 965 <<
" is not equal to the number of processors = " 980 toSlave << args_ << options_;
992 fromMaster >> args_ >> options_;
1005 case_ = globalCase_;
1010 Info<<
"Case : " << (rootPath_/globalCase_).c_str() <<
nl 1011 <<
"nProcs : " << nProcs <<
endl;
1013 if (parRunControl_.parRun())
1015 Info<<
"Slaves : " << slaveProcs <<
nl;
1018 Info<<
"Roots : " << roots <<
nl;
1020 Info<<
"Pstream initialised with:" << nl
1035 if (slaveProcs.
size())
1043 jobInfo_.write(executable_, rootPath_/globalCase_);
1054 Info<<
"fileModificationChecking : " 1055 <<
"Monitoring run-time modified files using " 1072 Info<<
" (fileModificationSkew " 1077 Info<<
"allowSystemOperations : ";
1080 Info<<
"Allowing user-supplied system call operations" <<
endl;
1084 Info<<
"Disallowing user-supplied system call operations" 1114 bool changed =
false;
1123 || opt ==
"parallel" 1125 || opt ==
"hostRoots" 1129 <<
"used argList::setOption on a protected option: '" 1130 << opt <<
"'" <<
endl;
1141 <<
"used argList::setOption to change bool to non-bool: '" 1142 << opt <<
"'" <<
endl;
1148 changed = !options_.found(opt);
1158 <<
"used argList::setOption to change non-bool to bool: '" 1159 << opt <<
"'" <<
endl;
1165 changed = options_.found(opt) ? options_[opt] != param :
true;
1172 <<
"used argList::setOption on an invalid option: '" 1173 << opt <<
"'" <<
nl <<
"allowed are the following:" 1181 options_.set(opt, param);
1197 || opt ==
"parallel" 1199 || opt ==
"hostRoots" 1203 <<
"used argList::unsetOption on a protected option: '" 1204 << opt <<
"'" <<
endl;
1209 return options_.erase(opt);
1214 <<
"used argList::unsetOption on an invalid option: '" 1215 << opt <<
"'" <<
nl <<
"allowed are the following:" 1232 Info<< iter().c_str() <<
nl;
1240 Info<<
"\nUsage: " << executable_ <<
" [OPTIONS]";
1244 Info<<
" <" << iter().c_str() <<
'>';
1247 Info<<
"\noptions:\n";
1252 const word& optionName = opts[optI];
1255 Info<<
" -" << optionName;
1256 label len = optionName.size() + 3;
1261 if (iter()[0] ==
'\'')
1263 len += iter().size() + 1;
1264 Info<<
' ' << iter().c_str();
1268 len += iter().size() + 3;
1269 Info<<
" <" << iter().c_str() <<
'>';
1295 "display source code in browser" 1302 "display application documentation in browser" 1317 <<
" (see https://openfoam.org)" <<
nl 1332 docExt.
replace(
".",
"_source.");
1342 if (docDirs[dirI].
component(0) ==
"http:")
1344 httpServer = docDirs[dirI]/executable_ + docExt;
1351 if (docDirs[dirI].
component(0) ==
"file:")
1358 docFile = docDirs[dirI]/executable_ + docExt;
1372 string docBrowser =
getEnv(
"FOAM_DOC_BROWSER");
1373 if (docBrowser.empty())
1375 docDict.
lookup(
"docBrowser") >> docBrowser;
1380 docBrowser +=
" file://" + docFile;
1384 docBrowser +=
" " + httpServer;
1387 Info<<
"Show documentation: " << docBrowser.c_str() <<
endl;
1394 <<
"No documentation found for " << executable_
1395 <<
", but you can use -help to display the usage\n" <<
endl;
1406 if (checkArgs && args_.size() - 1 !=
validArgs.size())
1409 <<
"Wrong number of arguments, expected " <<
validArgs.size()
1410 <<
" found " << args_.size() - 1 <<
endl;
1425 <<
"Invalid option: -" << iter.key() <<
endl;
1447 <<
": cannot open root directory " <<
rootPath()
1461 <<
": 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.
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.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
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?
static bool hasArgs(int argc, char *argv[])
Return true if there are arguments.
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.
Operations on lists of strings.
const char *const FOAMversion
virtual ~argList()
Destructor.
bool good() const
Return true if next operation might succeed.
dlLibraryTable libs
Table of loaded dynamic libraries.
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
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.
const string & arg(const label index) const
Return the argument corresponding to index.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
static const NamedEnum< commsTypes, 3 > commsTypeNames
Output inter-processor communications stream.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
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)
In this string replace first occurrence of sub-string oldStr.
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
const dimensionedScalar re
Classical electron radius: default SI units: [m].
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.
List< fileName > fileNameList
A List of fileNames.
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.