STYLE: DMD: simplify various parts of the class

This commit is contained in:
Kutalmis Bercin
2022-02-28 13:25:11 +00:00
committed by Andrew Heather
parent e3d8b36c63
commit d2e2533546
7 changed files with 59 additions and 59 deletions

View File

@ -114,7 +114,7 @@ void Foam::functionObjects::DMD::initialise()
if (nSnapTotal <= 0) if (nSnapTotal <= 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< " # Zero-size input field = " << fieldName_ << " #" << "Zero-size input field = " << fieldName_
<< exit(FatalError); << exit(FatalError);
} }
@ -150,7 +150,7 @@ Foam::functionObjects::DMD::DMD
if (runTime.isAdjustTimeStep()) if (runTime.isAdjustTimeStep())
{ {
WarningInFunction WarningInFunction
<< " # DMD: Available only for fixed time-step computations. #" << "DMD is available only for fixed time-step computations."
<< endl; << endl;
} }
@ -158,7 +158,7 @@ Foam::functionObjects::DMD::DMD
if (mesh_.topoChanging()) if (mesh_.topoChanging())
{ {
FatalErrorInFunction FatalErrorInFunction
<< " # DMD: Available only for non-changing mesh topology. #" << "DMD is available only for non-changing mesh topology."
<< exit(FatalError); << exit(FatalError);
} }
@ -230,11 +230,9 @@ bool Foam::functionObjects::DMD::end()
if (step_ < 2) if (step_ < 2)
{ {
WarningInFunction WarningInFunction
<< " # DMD needs at least three snapshots to produce output #" << "DMD needs at least three snapshots to produce output" << nl
<< nl << " Only " << step_ + 1 << " snapshots are available" << nl
<< " # Only " << step_ + 1 << " snapshots are available #" << " Skipping DMD output calculation and write"
<< nl
<< " # Skipping DMD output calculation and write #"
<< endl; << endl;
return false; return false;

View File

@ -69,7 +69,7 @@ Description
Output files: Output files:
\verbatim \verbatim
dynamics_<field>.dat | Dynamics data for each mode dynamics_<field>.dat | Dynamics data for each mode
filteredDynamics_<field>.dat | Filtered dynamics data for each mode filtered_dynamics_<field>.dat | Filtered dynamics data for each mode
\endverbatim \endverbatim
wherein for each mode, the following quantities are output into files: wherein for each mode, the following quantities are output into files:
@ -173,10 +173,12 @@ class DMD
//- Dynamic mode decomposition model //- Dynamic mode decomposition model
autoPtr<DMDModel> DMDModelPtr_; autoPtr<DMDModel> DMDModelPtr_;
//- Snapshot matrix (effectively a column vector) //- Augmented snapshot matrix (effectively a column vector)
// Upper half = current-time snapshot slot // Upper half = current-time snapshot slot
// Lower half = previous-time snapshot slot // Lower half = previous-time snapshot slot
// A snapshot is an input dataset to be processed per execution step // A snapshot is an input dataset to be processed per execution step
// A single snapshot is usually referred to as the snapshot of a single
// time step, an augmented snapshot is constructed of two snapshots
RMatrix z_; RMatrix z_;
//- Name of operand field //- Name of operand field
@ -195,7 +197,7 @@ class DMD
// Private Member Functions // Private Member Functions
// Process // Evaluation
//- Initialise snapshot at the first-execution step //- Initialise snapshot at the first-execution step
// Initialisation at the ctor or read level is not possible // Initialisation at the ctor or read level is not possible
@ -210,11 +212,12 @@ class DMD
template<class Type> template<class Type>
bool getSnapshot(); bool getSnapshot();
//- Get operand field based on its geometric field type //- Store operand field based on its geometric
//- field type after few manipulations
// Move previous-time field into previous-time slot in snapshot // Move previous-time field into previous-time slot in snapshot
// copy new current-time field into current-time slot in snapshot // copy new current-time field into current-time slot in snapshot
template<class GeoFieldType> template<class GeoFieldType>
bool getSnapshotField(); bool storeSnapshot();
// Access // Access

View File

@ -149,7 +149,7 @@ public:
// Member Functions // Member Functions
// Process // Evaluation
//- Initialise model data members with a given snapshot //- Initialise model data members with a given snapshot
virtual bool initialise(const RMatrix& snapshot) = 0; virtual bool initialise(const RMatrix& snapshot) = 0;
@ -169,7 +169,7 @@ public:
} }
// IO // I-O
//- Read model settings //- Read model settings
virtual bool read(const dictionary& dict) = 0; virtual bool read(const dictionary& dict) = 0;

View File

@ -64,7 +64,7 @@ Foam::scalar Foam::DMDModels::STDMD::L2norm(const RMatrix& z) const
if (z.n() != 1) if (z.n() != 1)
{ {
FatalErrorInFunction FatalErrorInFunction
<< " # Input matrix is not a column vector. #" << "Input matrix is not a column vector."
<< exit(FatalError); << exit(FatalError);
} }
#endif #endif
@ -609,7 +609,7 @@ void Foam::DMDModels::STDMD::magnitudes()
std::iota(w.begin(), w.end(), 1); std::iota(w.begin(), w.end(), 1);
w = sin(twoPi/step_*(w - 1 - 0.25*step_))*pr + pr; w = sin(twoPi/step_*(w - 1 - 0.25*step_))*pr + pr;
forAll(amps_, i) forAll(mags_, i)
{ {
mags_[i] = sorter(w, amps_[i], evals_[i], modeNorm); mags_[i] = sorter(w, amps_[i], evals_[i], modeNorm);
} }
@ -622,9 +622,9 @@ void Foam::DMDModels::STDMD::magnitudes()
Info<< "weighted amplitude scaling method" << endl; Info<< "weighted amplitude scaling method" << endl;
const scalar modeNorm = 1; const scalar modeNorm = 1;
const List<scalar> w(step_, 1.0); const List<scalar> w(step_, 1);
forAll(amps_, i) forAll(mags_, i)
{ {
mags_[i] = sorter(w, amps_[i], evals_[i], modeNorm); mags_[i] = sorter(w, amps_[i], evals_[i], modeNorm);
} }
@ -664,7 +664,7 @@ Foam::scalar Foam::DMDModels::STDMD::sorter
// Omit eigenvalues with very large or very small mags // Omit eigenvalues with very large or very small mags
if (!(mag(eigenvalue) < GREAT && mag(eigenvalue) > VSMALL)) if (!(mag(eigenvalue) < GREAT && mag(eigenvalue) > VSMALL))
{ {
Info<< " Returning zero magnitude for mag(eigenvalue) = " Info<< " Returning zero magnitude for mag(eigenvalue) = "
<< mag(eigenvalue) << endl; << mag(eigenvalue) << endl;
return 0; return 0;
@ -673,7 +673,7 @@ Foam::scalar Foam::DMDModels::STDMD::sorter
// Omit eigenvalue-STDMD step combinations that pose a risk of overflow // Omit eigenvalue-STDMD step combinations that pose a risk of overflow
if (mag(eigenvalue)*step_ > sortLimiter_) if (mag(eigenvalue)*step_ > sortLimiter_)
{ {
Info<< " Returning zero magnitude for" Info<< " Returning zero magnitude for"
<< " mag(eigenvalue) = " << mag(eigenvalue) << " mag(eigenvalue) = " << mag(eigenvalue)
<< " current index = " << step_ << " current index = " << step_
<< " sortLimiter = " << sortLimiter_ << " sortLimiter = " << sortLimiter_
@ -784,7 +784,7 @@ void Foam::DMDModels::STDMD::filter()
{ {
Info<< tab << "Filtering objects of dynamics" << endl; Info<< tab << "Filtering objects of dynamics" << endl;
// Filter objects according to iMags // Filter objects according to magsi
filterIndexed(evals_, magsi_); filterIndexed(evals_, magsi_);
filterIndexed(evecs_, magsi_); filterIndexed(evecs_, magsi_);
filterIndexed(freqs_, magsi_); filterIndexed(freqs_, magsi_);
@ -924,17 +924,17 @@ bool Foam::DMDModels::STDMD::read(const dictionary& dict)
); );
Info<< tab << "Settings are read for:" << nl Info<< tab << "Settings are read for:" << nl
<< " field: " << fieldName_ << nl << tab << " field: " << fieldName_ << nl
<< " modeSorter: " << modeSorterTypeNames[modeSorter_] << nl << tab << " modeSorter: " << modeSorterTypeNames[modeSorter_] << nl
<< " nModes: " << nModes_ << nl << tab << " nModes: " << nModes_ << nl
<< " maxRank: " << maxRank_ << nl << tab << " maxRank: " << maxRank_ << nl
<< " nGramSchmidt: " << nGramSchmidt_ << nl << tab << " nGramSchmidt: " << nGramSchmidt_ << nl
<< " fMin: " << fMin_ << nl << tab << " fMin: " << fMin_ << nl
<< " fMax: " << fMax_ << nl << tab << " fMax: " << fMax_ << nl
<< " minBasis: " << minBasis_ << nl << tab << " minBasis: " << minBasis_ << nl
<< " minEVal: " << minEval_ << nl << tab << " minEVal: " << minEval_ << nl
<< " sortLimiter: " << sortLimiter_ << nl << tab << " sortLimiter: " << sortLimiter_ << nl
<< " nAgglomerationProcs: " << nAgglomerationProcs_ << nl << tab << " nAgglomerationProcs: " << nAgglomerationProcs_ << nl
<< endl; << endl;
return true; return true;
@ -973,7 +973,12 @@ bool Foam::DMDModels::STDMD::initialise(const RMatrix& z)
nSnap nSnap
); );
std::copy(z.cbegin(), z.cbegin() + nSnap, snapshot0.begin()); std::copy
(
z.cbegin(),
z.cbegin() + nSnap,
snapshot0.begin()
);
const IOstreamOption streamOpt const IOstreamOption streamOpt
( (
@ -1052,7 +1057,7 @@ bool Foam::DMDModels::STDMD::fit()
filter(); filter();
writeToFile(word("filteredDynamics")); writeToFile(word("filtered_dynamics"));
} }
step_ = 0; step_ = 0;

View File

@ -92,13 +92,10 @@ Usage
\verbatim \verbatim
DMD1 DMD1
{ {
// Mandatory/Optional entries // Mandatory entries
...
// Mandatory entries (unmodifiable)
DMDModel STDMD; DMDModel STDMD;
// Conditional mandatory entries (runtime modifiable) // Conditional mandatory entries
// Option-1 // Option-1
interval 5.5; interval 5.5;
@ -106,7 +103,7 @@ Usage
// Option-2 // Option-2
executeInterval 10; executeInterval 10;
// Optional entries (runtime modifiable) // Optional entries
modeSorter kiewat; modeSorter kiewat;
nGramSchmidt 5; nGramSchmidt 5;
maxRank 50; maxRank 50;
@ -115,12 +112,12 @@ Usage
fMax 1000000000; fMax 1000000000;
nAgglomerationProcs 20; nAgglomerationProcs 20;
// Optional entries (runtime modifiable, yet not recommended) // Optional entries (not recommended to change)
minBasis 0.00000001; minBasis 0.00000001;
minEVal 0.00000001; minEVal 0.00000001;
sortLimiter 500.0; sortLimiter 500.0;
// Mandatory/Optional (inherited) entries // Inherited entries
... ...
} }
\endverbatim \endverbatim
@ -335,7 +332,7 @@ class STDMD
// Private Member Functions // Private Member Functions
// Process // Evaluation
//- Return (parallel) L2-norm of a given column vector //- Return (parallel) L2-norm of a given column vector
scalar L2norm(const RMatrix& z) const; scalar L2norm(const RMatrix& z) const;
@ -355,9 +352,6 @@ class STDMD
//- Compress orthonormal basis for 'Q' and 'G' if '(Q.n()>maxRank)' //- Compress orthonormal basis for 'Q' and 'G' if '(Q.n()>maxRank)'
void compress(); void compress();
// Evaluation
//- Return reduced Koopman operator 'Atilde' (K:Eq. 78) //- Return reduced Koopman operator 'Atilde' (K:Eq. 78)
// Also fills 'RxInv'. // Also fills 'RxInv'.
// The function was not divided into subsections to ensure // The function was not divided into subsections to ensure
@ -435,7 +429,7 @@ class STDMD
); );
// IO // I-O
//- Write objects of dynamics //- Write objects of dynamics
void writeToFile(const word& fileName) const; void writeToFile(const word& fileName) const;

View File

@ -43,7 +43,7 @@ void Foam::DMDModels::STDMD::filterIndexed
// Copy if frequency of element is within [a, b] // Copy if frequency of element is within [a, b]
label j = 0; label j = 0;
for (const auto& i : indices) for (const label i : indices)
{ {
lstWithin[j] = lst[i]; lstWithin[j] = lst[i];
++j; ++j;
@ -64,7 +64,7 @@ void Foam::DMDModels::STDMD::filterIndexed
// Copy if frequency of element is within [a, b] // Copy if frequency of element is within [a, b]
label j = 0; label j = 0;
for (const auto& i : indices) for (const label i : indices)
{ {
matWithin.subColumn(j) = mat.subColumn(i); matWithin.subColumn(j) = mat.subColumn(i);
++j; ++j;
@ -149,19 +149,19 @@ bool Foam::DMDModels::STDMD::calcModes()
{ {
if (patch_.empty()) if (patch_.empty())
{ {
auto& inModeRe = modeRe.primitiveFieldRef(); auto& re = modeRe.primitiveFieldRef();
auto& inModeIm = modeIm.primitiveFieldRef(); auto& im = modeIm.primitiveFieldRef();
calcMode(inModeRe, inModeIm, primitiveMode, i); calcMode(re, im, primitiveMode, i);
} }
else else
{ {
const label patchi = mesh_.boundaryMesh().findPatchID(patch_); const label patchi = mesh_.boundaryMesh().findPatchID(patch_);
auto& bfModeRe = modeRe.boundaryFieldRef()[patchi]; auto& re = modeRe.boundaryFieldRef()[patchi];
auto& bfModeIm = modeIm.boundaryFieldRef()[patchi]; auto& im = modeIm.boundaryFieldRef()[patchi];
calcMode(bfModeRe, bfModeIm, primitiveMode, i); calcMode(re, im, primitiveMode, i);
} }
} }

View File

@ -38,11 +38,11 @@ bool Foam::functionObjects::DMD::getSnapshot()
if (foundObject<VolFieldType>(fieldName_)) if (foundObject<VolFieldType>(fieldName_))
{ {
return getSnapshotField<VolFieldType>(); return storeSnapshot<VolFieldType>();
} }
else if (foundObject<SurfaceFieldType>(fieldName_)) else if (foundObject<SurfaceFieldType>(fieldName_))
{ {
return getSnapshotField<SurfaceFieldType>(); return storeSnapshot<SurfaceFieldType>();
} }
return false; return false;
@ -50,7 +50,7 @@ bool Foam::functionObjects::DMD::getSnapshot()
template<class GeoFieldType> template<class GeoFieldType>
bool Foam::functionObjects::DMD::getSnapshotField() bool Foam::functionObjects::DMD::storeSnapshot()
{ {
if (step_ == 0) if (step_ == 0)
{ {