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" 255 const auto&
runTime = *dummyTimePtr;
270 restoreMethod method = restoreMethod::ORIG;
277 && methodNames.found(methodName)
280 method = methodNames[methodName];
284 Info<<
"Unspecified or unknown method name" <<
nl 287 <<
"... stopping" <<
nl <<
nl;
299 for (label argi=1; argi <
args.
size(); ++argi)
303 targetNames[uniq.
size()-1] =
args[argi];
312 <<
"using method=" << methodNames[method] <<
nl 319 <<
"using method=" << methodNames[method] <<
nl 320 <<
"autodetect fields" <<
nl;
338 <<
"No processor* directories found" 361 label leadProcIdx = -1;
363 if (timeDirs.empty())
365 Info<<
"No times selected" <<
nl;
389 leadProcIdx = procDirs.
find(
"processor0");
391 if (!procDirs.
empty())
402 const std::string prefix
409 if (procDirs[idx].starts_with(prefix))
426 for (
const instant& t : timeDirs)
436 if (regionNames0.size() > 1)
446 if (leadProcIdx >= 0)
456 for (
const fileName& procDir : procDirs)
458 count += restoreFields
475 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.
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 List 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.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
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.
static void disable() noexcept
Disallow profiling - turns the InfoSwitch off.
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 communicator ranks. Does nothing in non-paral...
Extract name (as a word) from an object, typically using its name() method.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
label size() const noexcept
The number of elements in table.
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 expressions::valueTypeCode::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.
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)
label find(const T &val) const
Find index of the first occurrence of the value.
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
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...
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
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.