80const regExp matcher(
"processors?[0-9]+(_[0-9]+-[0-9]+)?");
82bool 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" },
122bool 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;
208int 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;
263 dryrun =
args.dryRun();
264 verbose =
args.verbose();
270 restoreMethod method = restoreMethod::ORIG;
276 args.readIfPresent(
"method", methodName)
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"
346 args.caseName()/
"processor0"
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)
451 args.path()/procDirs[leadProcIdx],
456 for (
const fileName& procDir : procDirs)
458 count += restoreFields
475 count += restoreFields
Various functions to operate on Lists.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
List< word > sortedToc() const
The sorted list of enum names.
bool found(const word &key) const
Same as contains().
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
label size() const noexcept
The number of elements in table.
void resize(const label len)
Adjust allocated size of list.
static void broadcast(Type &value, const int communicator=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
label find(const T &val) const
Find index of the first occurrence of the value.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a 'dry-run' bool option, with usage information.
static void noMandatoryArgs()
Flag command arguments as being optional (non-mandatory).
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
A class for handling file names.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
static const word & regionName(const word ®ion)
The mesh region name or word::null if polyMesh::defaultRegion.
static void disable() noexcept
Disallow profiling - turns the InfoSwitch off.
bool starts_with(char c) const
True if string starts with given character (cf. C++20).
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
instantList select(const instantList ×) const
Select a list of Time values that are within the ranges.
A class for handling words, derived from Foam::string.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
List< T > create(const UList< T2 > &input, const UnaryOperation &op)
Create a List from a List of a dissimilar type, using the entire list.
List< word > wordList
List of word.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
List< fileName > fileNameList
List of fileName.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< instant > instantList
List of instants.
regExpCxx regExp
Selection of preferred regular expression implementation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void inplaceSubsetList(ListType &input, const UnaryPredicate &pred, const bool invert=false)
Inplace subset of the list when predicate is true.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
void sort(UList< T > &list)
Sort the list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
errorManipArg< error, int > exit(error &err, const int errNo=1)
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.
constexpr char nl
The newline '\n' character (0x0a).
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Extract name (as a word) from an object, typically using its name() method.
Encapsulation of natural order sorting for algorithms.