From d2edf97b05d6cfdb7da4012f80f54d7007d6559c Mon Sep 17 00:00:00 2001 From: MarkoRamius Date: Thu, 22 Feb 2018 11:57:54 +1100 Subject: [PATCH] standardRecModel: skip zero time Add an optional boolean switch to standardRecModel class to allow ignoring the 0 directory when building the recurrence data base. This is useful when using rStatAnalysis as a post-processing tool on a case where OpenFOAM's purgeWrite feature was used. If purgeWrite is set to 0, then all time steps will be written to disk. If purgeWrite is set to N, then only the last N time steps will be stored. As a new time step is written to disk, the oldest one will be discarded. However, the 0 directory is excluded from removal. If purgeWrite is set to 5, and we run a simulation with deltaT=1 und endTime=10, then the time steps on disk will be: 0, 6, 7, 8, 9, 10. Running rStatAnalysis on this case, will end in fatal error, as the time step within the data base will be found to be non-uniform. The quick and dirty fix, would be to remove or rename the 0 directory, so that it does not get read. However, telling the recurrence model whether to include 0 or not seems the more elegant solution. --- .../standardRecModel/standardRecModel.C | 40 +++++++++++++++++-- .../standardRecModel/standardRecModel.H | 1 + 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/recurrence/recModel/standardRecModel/standardRecModel.C b/src/recurrence/recModel/standardRecModel/standardRecModel.C index 7dfadebd..6fd2c557 100644 --- a/src/recurrence/recModel/standardRecModel/standardRecModel.C +++ b/src/recurrence/recModel/standardRecModel/standardRecModel.C @@ -59,7 +59,8 @@ standardRecModel::standardRecModel dataBaseName_(propsDict_.lookupOrDefault("dataBase", word("dataBase"))), recTime(fileName(dataBaseName_), "", "../system", "../constant", false), timeDirs(recTime.times()), - numRecFields_(label(timeDirs.size())), + skipZero_(propsDict_.lookupOrDefault("skipZero", Switch(false))), + numRecFields_(skipZero_ ? label(timeDirs.size())-1 : label(timeDirs.size())), recurrenceMatrix_(numRecFields_,scalar(0.0)), timeIndexList_(numRecFields_-1), timeValueList_(numRecFields_-1), @@ -79,8 +80,9 @@ standardRecModel::standardRecModel Info << "recTime.caseName() " << recTime.caseName() << endl; Info << "recTime.path() " << recTime.path() << endl; Info << "recTime.timePath() " << recTime.timePath() << endl; - Info << "recTime.timeName() " << recTime.timeName() << endl; - Info << "timeDirs " << timeDirs << endl; + Info << "recTime.timeName() " << recTime.timeName() << endl; + Info << "timeDirs " << timeDirs << endl; + Info << "consider 0 directory: " << skipZero_ << endl; } readTimeSeries(); @@ -129,6 +131,16 @@ scalar standardRecModel::checkTimeStep() forAll(timeValueList_, i) { + // skip zero + if (skipZero_ and timeDirs[i].value() == 0) + { + if (verbose_) + { + Info << " ... skipping 0 in checkTimeStep()" << endl; + } + continue; + } + // compute time step if (timeDirs[i].value() == timeDirs.last().value()) { @@ -197,6 +209,17 @@ void standardRecModel::readFieldSeries() // set time recTime.setTime(*it, it->value()); + // skip zero + if (skipZero_ and recTime.timeName() == "0") + { + if (verbose_) + { + Info << " ... skipping 0 in readFieldSeries()" << endl; + } + + continue; + } + // skip constant if (recTime.timeName() == "constant") { @@ -282,6 +305,17 @@ void standardRecModel::readTimeSeries() continue; } + // skip zero + if (skipZero_ and recTime.timeName() == "0") + { + if (verbose_) + { + Info << " ... skipping 0 in readTimeSeries()" << endl; + } + + continue; + } + if (firsttime) { firsttime = false; diff --git a/src/recurrence/recModel/standardRecModel/standardRecModel.H b/src/recurrence/recModel/standardRecModel/standardRecModel.H index 1e75e4c1..3ec05bfa 100644 --- a/src/recurrence/recModel/standardRecModel/standardRecModel.H +++ b/src/recurrence/recModel/standardRecModel/standardRecModel.H @@ -46,6 +46,7 @@ protected: word dataBaseName_; Foam::Time recTime; instantList timeDirs; + Switch skipZero_; label numRecFields_; // matrix that contains the recurrence ERROR