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"
81 "override the fileHandler"
86 "'(\"lib1.so\" ... \"libN.so\")'",
177 void Foam::argList::printOptionUsage
179 const label location,
208 while (
pos != string::npos &&
pos + textWidth < strLen)
217 next = str.find_first_not_of(
" \t\n", curr);
223 next = str.find_first_not_of(
" \t\n", curr);
231 if (prev != string::npos && prev >
pos)
237 if (next == string::npos)
256 if (
pos != string::npos)
279 bool postProcessOption =
false;
281 for (
int i=1; i<argc; i++)
284 if (postProcessOption)
break;
287 return postProcessOption;
295 for (
int i=1; i<argc; i++)
297 const string arg(argv[i]);
298 const string argName(
arg(1,
arg.size() - 1));
318 bool Foam::argList::regroupArgv(
int& argc,
char**& argv)
326 for (
int argi=0; argi<argc; argi++)
328 if (strcmp(argv[argi],
"(") == 0)
333 else if (strcmp(argv[argi],
")") == 0)
341 args_[
nArgs++] = tmpString;
347 args_[
nArgs++] = argv[argi];
354 tmpString += argv[argi];
359 args_[
nArgs++] = argv[argi];
363 if (tmpString.size())
365 args_[
nArgs++] = tmpString;
374 void Foam::argList::getRootCase()
381 if (iter != options_.end())
386 if (casePath.empty() || casePath ==
".")
390 options_.erase(
"case");
392 else if (!casePath.isAbsolute() && casePath.name() ==
"..")
395 casePath =
cwd()/casePath;
405 rootPath_ = casePath.
path();
406 globalCase_ = casePath.
name();
414 setEnv(
"FOAM_CASE", rootPath_/globalCase_,
true);
415 setEnv(
"FOAM_CASENAME", globalCase_,
true);
420 casePath =
cwd()/rootPath_/globalCase_;
423 setEnv(
"FOAM_CASE", casePath,
true);
424 setEnv(
"FOAM_CASENAME", casePath.name(),
true);
437 const bool initialise
445 const string libsString(
getEnv(
"FOAM_LIBS"));
446 if (!libsString.empty())
451 for (
int argi=0; argi<argc; argi++)
453 if (argv[argi][0] ==
'-')
455 const char *optionName = &argv[argi][1];
456 if (
string(optionName) ==
"libs")
467 for (
int argi=0; argi<argc; argi++)
469 if (argv[argi][0] ==
'-')
471 const char *optionName = &argv[argi][1];
472 if (
string(optionName) ==
"fileHandler")
474 handlerType = argv[argi+1];
479 if (handlerType.empty())
490 )().needsThreading();
495 for (
int argi=0; argi<argc; argi++)
497 if (argv[argi][0] ==
'-')
499 const char *optionName = &argv[argi][1];
503 parRunControl_.
runPar(argc, argv, needsThread);
511 regroupArgv(argc, argv);
519 argListStr_ = args_[0];
521 for (
int argi=1; argi<args_.
size(); argi++)
524 argListStr_ += args_[argi];
526 if (args_[argi][0] ==
'-')
528 const char *optionName = &args_[argi][1];
543 if (argi >= args_.
size())
546 <<
"Option '-" << optionName
547 <<
"' requires an argument" <<
endl;
553 argListStr_ += args_[argi];
554 options_.insert(optionName, args_[argi]);
558 options_.insert(optionName,
"");
565 args_[
nArgs] = args_[argi];
573 parse(checkArgs, checkOpts, initialise);
586 parRunControl_(
args.parRunControl_),
589 executable_(
args.executable_),
590 rootPath_(
args.rootPath_),
591 globalCase_(
args.globalCase_),
593 argListStr_(
args.argListStr_)
595 parse(checkArgs, checkOpts, initialise);
612 options_.found(
"help")
613 || options_.found(
"doc")
614 || options_.found(
"srcDoc")
617 if (options_.found(
"help"))
623 if (options_.found(
"srcDoc"))
627 else if (options_.found(
"doc"))
636 if (!check(checkArgs, checkOpts))
652 <<
"Exec : " << argListStr_.c_str() <<
nl
653 <<
"Date : " << dateString.c_str() <<
nl
654 <<
"Time : " << timeString.c_str() <<
nl
673 if (
found != std::string::npos)
691 if (iter != options_.end())
693 handlerType = iter();
696 if (handlerType.empty())
717 if (parRunControl_.parRun())
735 fromSlave >> slaveBuild >> slaveMachine[proci] >> slavePid;
737 slaveProcs[proci] = slaveMachine[proci]+
"."+
name(slavePid);
746 <<
"; slave " << proci <<
" is running version "
771 if (parRunControl_.parRun())
780 label dictNProcs = -1;
783 if (options_.found(
"roots"))
787 roots = readList<fileName>(is);
789 if (roots.
size() != 1)
791 dictNProcs = roots.
size()+1;
794 else if (options_.found(
"hostRoots"))
796 source =
"-hostRoots";
806 forAll(matchedRoots, matchi)
808 label slavei = matchedRoots[matchi];
809 if (roots[slavei] !=
wordRe())
812 <<
"Slave " << slaveMachine[slavei]
813 <<
" has multiple matching roots in "
818 roots[slavei] = hostRoot.
second();
826 if (roots[slavei] ==
wordRe())
829 <<
"Slave " << slaveMachine[slavei]
830 <<
" has no matching roots in "
835 if (roots.
size() != 1)
837 dictNProcs = roots.
size()+1;
842 source = rootPath_/globalCase_/
"system/decomposeParDict";
845 if (!decompDictStream.
good())
854 dictNProcs = decompDict.
lookup<
label>(
"numberOfSubdomains");
858 decompDict.
lookup(
"roots") >> roots;
865 if (roots.
size() == 1)
873 dictNProcs = roots.
size()+1;
891 <<
" specifies " << dictNProcs
892 <<
" processors but job was started with "
904 <<
"number of entries in roots "
906 <<
" is not equal to the number of slaves "
917 bool hadCaseOpt = options_.found(
"case");
925 options_.set(
"case", roots[slave-1]/globalCase_);
928 toSlave << args_ << options_;
930 options_.erase(
"case");
935 options_.set(
"case", rootPath_/globalCase_);
949 rootPath_/globalCase_/
"processor"
958 <<
"number of processor directories = "
960 <<
" is not equal to the number of processors = "
975 toSlave << args_ << options_;
987 fromMaster >> args_ >> options_;
1000 case_ = globalCase_;
1005 Info<<
"Case : " << (rootPath_/globalCase_).c_str() <<
nl
1006 <<
"nProcs : " << nProcs <<
endl;
1008 if (parRunControl_.parRun())
1010 Info<<
"Slaves : " << slaveProcs <<
nl;
1013 Info<<
"Roots : " << roots <<
nl;
1015 Info<<
"Pstream initialised with:" <<
nl
1030 if (slaveProcs.
size())
1038 jobInfo_.write(executable_, rootPath_/globalCase_);
1049 Info<<
"fileModificationChecking : "
1050 <<
"Monitoring run-time modified files using "
1067 Info<<
" (fileModificationSkew "
1072 Info<<
"allowSystemOperations : ";
1075 Info<<
"Allowing user-supplied system call operations" <<
endl;
1079 Info<<
"Disallowing user-supplied system call operations"
1109 bool changed =
false;
1112 if (validOptions.found(opt))
1118 || opt ==
"parallel"
1120 || opt ==
"hostRoots"
1124 <<
"used argList::setOption on a protected option: '"
1125 << opt <<
"'" <<
endl;
1129 if (validOptions[opt].empty())
1136 <<
"used argList::setOption to change bool to non-bool: '"
1137 << opt <<
"'" <<
endl;
1143 changed = !options_.found(opt);
1153 <<
"used argList::setOption to change non-bool to bool: '"
1154 << opt <<
"'" <<
endl;
1160 changed = options_.found(opt) ? options_[opt] != param :
true;
1167 <<
"used argList::setOption on an invalid option: '"
1168 << opt <<
"'" <<
nl <<
"allowed are the following:"
1169 << validOptions <<
endl;
1176 options_.set(opt, param);
1186 if (validOptions.found(opt))
1192 || opt ==
"parallel"
1194 || opt ==
"hostRoots"
1198 <<
"used argList::unsetOption on a protected option: '"
1199 << opt <<
"'" <<
endl;
1204 return options_.erase(opt);
1209 <<
"used argList::unsetOption on an invalid option: '"
1210 << opt <<
"'" <<
nl <<
"allowed are the following:"
1211 << validOptions <<
endl;
1227 Info<< iter().c_str() <<
nl;
1235 Info<<
nl <<
"Usage: " << executable_ <<
" [OPTIONS]";
1239 Info<<
" <" << iter().c_str() <<
'>';
1244 wordList opts = validOptions.sortedToc();
1247 const word& optionName = opts[optI];
1250 Info<<
" -" << optionName;
1251 label len = optionName.size() + 3;
1256 if (iter()[0] ==
'\'')
1258 len += iter().size() + 1;
1259 Info<<
' ' << iter().c_str();
1263 len += iter().size() + 3;
1264 Info<<
" <" << iter().c_str() <<
'>';
1269 optionUsage.find(optionName);
1271 if (usageIter != optionUsage.end())
1290 "display source code in browser"
1297 "display application documentation in browser"
1312 <<
" (see https://openfoam.org)" <<
nl
1323 {
"documentation",
"Documentation"}
1331 docExt.
replace(
".",
"_source.");
1341 if (docDirs[dirI].
component(0) ==
"http:")
1343 httpServer = docDirs[dirI]/executable_ + docExt;
1350 if (docDirs[dirI].
component(0) ==
"file:")
1357 docFile = docDirs[dirI]/executable_ + docExt;
1371 string docBrowser =
getEnv(
"FOAM_DOC_BROWSER");
1372 if (docBrowser.empty())
1374 docDict.
lookup(
"docBrowser") >> docBrowser;
1379 docBrowser +=
" file://" + docFile;
1383 docBrowser +=
" " + httpServer;
1386 Info<<
"Show documentation: " << docBrowser.c_str() <<
endl;
1393 <<
"No documentation found for " << executable_
1394 <<
", but you can use -help to display the usage\n" <<
endl;
1405 if (checkArgs && args_.size() - 1 != validArgs.size())
1408 <<
"Wrong number of arguments, expected " << validArgs.size()
1409 <<
" found " << args_.size() - 1 <<
endl;
1419 !validOptions.found(iter.key())
1420 && !validParOptions.found(iter.key())
1424 <<
"Invalid option: -" << iter.key() <<
endl;
1446 <<
": cannot open root directory " << rootPath()
1460 <<
": cannot open case directory " << path()
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
graph_traits< Graph >::vertices_size_type size_type
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Foam::argList::initValidTables dummyInitValidTables
An STL-conforming const_iterator.
friend class const_iterator
Declare friendship with the const_iterator.
static Stream & writeBanner(Stream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
static const NamedEnum< fileCheckTypes, 4 > fileCheckTypesNames
Input inter-processor communications stream.
Input from memory buffer stream.
bool good() const
Return true if next operation might succeed.
Template class for non-intrusive linked lists.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
Output inter-processor communications stream.
void runPar(int &argc, char **&argv, const bool needsThread)
A 2-tuple for storing two objects of different types.
const Type2 & second() const
Return second.
const Type1 & first() const
Return first.
static int masterNo()
Process index of the master.
static bool master(const label communicator=0)
Am I the master process.
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
static const NamedEnum< commsTypes, 3 > commsTypeNames
static int lastSlave(const label communicator=0)
Process index of last slave.
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
static int nPollProcInterfaces
Number of polling cycles in processor updates.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static void addValidParOptions(HashTable< string > &validParOptions)
Add the valid option this type of communications library.
static int firstSlave()
Process index of first slave.
static commsTypes defaultCommsType
Default commsType.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static void clear()
Clear the options table.
Extract command arguments and options from the supplied argc and argv parameters.
void parse(bool checkArgs, bool checkOpts, bool initialise)
Parse.
static word postProcessOptionName
Standard name for the post-processing option.
static label nArgs(int argc, char *argv[])
Return the number of arguments (not options)
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.
const string & arg(const label index) const
Return the argument corresponding to index.
static void removeOption(const word &opt)
Remove option from validOptions and from optionUsage.
static HashTable< string > validParOptions
A list of valid parallel options.
bool setOption(const word &opt, const string ¶m="")
Set option directly (use with caution)
static bool postProcess(int argc, char *argv[])
Return true if the post-processing option is specified.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
virtual ~argList()
Destructor.
static HashTable< string > optionUsage
Short usage information for validOptions.
static string::size_type usageMin
Min offset for displaying usage (default: 20)
argList(int &argc, char **&argv, bool checkArgs=true, bool checkOpts=true, bool initialise=true)
Construct from argc and argv.
static SLList< string > notes
Additional notes for usage.
bool checkRootCase() const
Check root path and case path.
void displayDoc(bool source=false) const
Display documentation in browser.
static void noParallel()
Remove the parallel options.
static string::size_type usageMax
Max screen width for displaying usage (default: 80)
bool unsetOption(const word &opt)
Unset option directly (use with caution)
void printNotes() const
Print notes (if any)
static HashTable< string > validOptions
A list of valid options.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
static void addUsage(const word &opt, const string &usage)
Add option usage information to optionUsage.
bool check(bool checkArgs=true, bool checkOpts=true) const
Check argument list.
void printUsage() const
Print usage.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
static string clockTime()
Return the current wall-clock time as a string.
static string date()
Return the current wall-clock date as a string.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
T lookupOrDefault(const word &, const T &) const
Find and return a T, if not found return the given default.
const dictionary & subDictBackwardsCompatible(const wordList &) const
Find and return a sub-dictionary, trying a list of keywords in.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
static int allowSystemOperations
Flag if system operations are allowed.
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
A class for handling file names.
bool isAbsolute() const
Return true if file name is absolute.
bool clean()
Cleanup file name.
word name() const
Return file name (part beyond last /)
static const fileName null
An empty fileName.
fileName path() const
Return directory path name (part before last /)
static autoPtr< fileOperation > New(const word &type, const bool verbose)
Select type.
static word defaultFileHandler
Default fileHandler.
static autoPtr< fileOperationInitialise > New(const word &type, int &argc, char **&argv)
Select type.
static float fileModificationSkew
A class for handling character strings derived from std::string.
static const string null
An empty string.
string & replace(const string &oldStr, const string &newStr, size_type start=0)
In this string replace first occurrence of sub-string oldStr.
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurrences of environment variables.
A wordRe is a word, but can also have a regular expression for matching words.
A class for handling words, derived from string.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const dimensionedScalar re
Classical electron radius: default SI units: [m].
dictionary & configDict()
The central control dictionary.
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
const fileOperation & fileHandler()
Get current file handler.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dlLibraryTable libs
Table of loaded dynamic libraries.
fileName cwd()
Return current working directory path name.
int system(const std::string &command)
Execute the specified command.
dimensionedScalar pos(const dimensionedScalar &ds)
bool setEnv(const word &name, const std::string &value, const bool overwrite)
Set an environment variable.
List< fileName > fileNameList
A List of fileNames.
const char *const FOAMbuild
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const char *const FOAMversion
string userName()
Return the user's login name.
pid_t pgid()
Return the group PID of this process.
string hostName(const bool full=false)
Return the system's host name, as per hostname(1)
void component(GeometricField< typename GeometricField< Type, GeoMesh, PrimitiveField1 >::cmptType, GeoMesh, PrimitiveField1 > &gcf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf, const direction d)
pid_t ppid()
Return the parent PID of this process.
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
string getEnv(const word &)
Return environment variable of given name.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
pid_t pid()
Return the PID of this process.
Foam::argList args(argc, argv)
Operations on lists of strings.