80 const regExp matcher(
"processors?[0-9]+(_[0-9]+-[0-9]+)?");
82 bool isProcessorDir(
const string& dir)
84 return (dir.
starts_with(
"processor") && matcher.match(dir));
98 { restoreMethod::MEAN,
"mean" },
99 { restoreMethod::ORIG,
"orig" },
105 { restoreMethod::MEAN,
"Mean" },
106 { restoreMethod::ORIG,
".orig" },
113 return ListOps::create<word>
122 bool dryrun =
false, verbose =
false;
131 const restoreMethod method,
138 const word ending(methodEndings[method]);
145 case restoreMethod::MEAN:
146 bak = methodEndings[restoreMethod::ORIG];
159 for (
word f : existingFiles)
162 if (
f.removeEnd(ending) &&
f.
size())
177 for (
const word& dst : targets)
179 const word src(dst + ending);
181 if (!existingFiles.found(src))
186 if (bak.size() && existingFiles.found(dst))
188 if (dryrun ||
Foam::mv(dirName/dst, dirName/dst + bak))
190 Info<<
" mv " << dst <<
" " <<
word(dst + bak) <<
nl;
195 if (dryrun ||
Foam::mv(dirName/src, dirName/dst))
197 Info<<
" mv " << src <<
" " << dst <<
nl;
208 int main(
int argc,
char *argv[])
212 "Restore field names by removing the ending. Fields are selected" 213 " automatically or can be specified as optional command arguments" 223 "The restore method (mean|orig) [MANDATORY]. " 224 "With <mean> renames files ending with 'Mean' " 225 "(with backup of existing as '.orig'). " 226 "With <orig> renames files ending with '.orig'" 231 "In serial mode use times from processor0/ directory, but operate on " 232 "processor\\d+ directories" 236 "Report action without moving/renaming" 240 "Additional verbosity" 258 const auto&
runTime = *dummyTimePtr;
273 restoreMethod method = restoreMethod::ORIG;
280 && methodNames.found(methodName)
283 method = methodNames[methodName];
287 Info<<
"Unspecified or unknown method name" <<
nl 290 <<
"... stopping" <<
nl <<
nl;
302 for (label argi=1; argi <
args.
size(); ++argi)
306 targetNames[uniq.
size()-1] =
args[argi];
315 <<
"using method=" << methodNames[method] <<
nl 322 <<
"using method=" << methodNames[method] <<
nl 323 <<
"autodetect fields" <<
nl;
341 <<
"No processor* directories found" 364 label leadProcIdx = -1;
366 if (timeDirs.empty())
368 Info<<
"No times selected" <<
nl;
392 leadProcIdx = procDirs.
find(
"processor0");
394 if (!procDirs.
empty())
405 const std::string prefix
412 if (procDirs[idx].starts_with(prefix))
429 for (
const instant& t : timeDirs)
439 if (regionNames0.size() > 1)
449 if (leadProcIdx >= 0)
459 for (
const fileName& procDir : procDirs)
461 count += restoreFields
478 count += restoreFields
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
A class for handling file names.
static void noMandatoryArgs()
Flag command arguments as being optional (non-mandatory)
errorManipArg< error, int > exit(error &err, const int errNo=1)
void resize(const label len)
Adjust allocated size of list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler.
label size() const noexcept
The number of elements in table.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
instantList select(const instantList ×) const
Select a list of Time values that are within the ranges.
void inplaceSubsetList(ListType &input, const UnaryPredicate &pred, const bool invert=false)
Inplace subset of the list when predicate is true.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all processes in communicator.
Extract name (as a word) from an object, typically using its name() method.
static void disable()
Disallow profiling by forcing the InfoSwitch off.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
Foam::word regionName(Foam::polyMesh::defaultRegion)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
A class for handling words, derived from Foam::string.
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a 'dry-run' bool option, with usage information.
int dryRun() const noexcept
Return the dry-run flag.
void sort(UList< T > &list)
Sort the list.
static void addVerboseOption(const string &usage, bool advanced=false)
Enable a 'verbose' bool option, with usage information.
label size() const noexcept
The number of arguments.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
const fileName & rootPath() const noexcept
Return root path.
Encapsulation of natural order sorting for algorithms.
fileName path() const
Return the full path to the (processor local) case.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Wrapper around POSIX extended regular expressions with some additional prefix-handling. The prefix-handling is loosely oriented on PCRE regular expressions and provides a simple means of tuning the expressions.
bool starts_with(char c) const
True if string starts with given character (cf. C++20)
instantList times() const
Search the case for valid time directories.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
static bool master(const label communicator=worldComm)
Am I the master rank.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Foam::argList args(argc, argv)
int verbose() const noexcept
Return the verbose flag.
bool found(const word &optName) const
Return true if the named option is found.
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.