mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: DMD: simplify various parts of the class
This commit is contained in:
committed by
Andrew Heather
parent
e3d8b36c63
commit
d2e2533546
@ -114,7 +114,7 @@ void Foam::functionObjects::DMD::initialise()
|
||||
if (nSnapTotal <= 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< " # Zero-size input field = " << fieldName_ << " #"
|
||||
<< "Zero-size input field = " << fieldName_
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ Foam::functionObjects::DMD::DMD
|
||||
if (runTime.isAdjustTimeStep())
|
||||
{
|
||||
WarningInFunction
|
||||
<< " # DMD: Available only for fixed time-step computations. #"
|
||||
<< "DMD is available only for fixed time-step computations."
|
||||
<< endl;
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ Foam::functionObjects::DMD::DMD
|
||||
if (mesh_.topoChanging())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< " # DMD: Available only for non-changing mesh topology. #"
|
||||
<< "DMD is available only for non-changing mesh topology."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
@ -230,11 +230,9 @@ bool Foam::functionObjects::DMD::end()
|
||||
if (step_ < 2)
|
||||
{
|
||||
WarningInFunction
|
||||
<< " # DMD needs at least three snapshots to produce output #"
|
||||
<< nl
|
||||
<< " # Only " << step_ + 1 << " snapshots are available #"
|
||||
<< nl
|
||||
<< " # Skipping DMD output calculation and write #"
|
||||
<< "DMD needs at least three snapshots to produce output" << nl
|
||||
<< " Only " << step_ + 1 << " snapshots are available" << nl
|
||||
<< " Skipping DMD output calculation and write"
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
|
||||
@ -69,7 +69,7 @@ Description
|
||||
Output files:
|
||||
\verbatim
|
||||
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
|
||||
|
||||
wherein for each mode, the following quantities are output into files:
|
||||
@ -173,10 +173,12 @@ class DMD
|
||||
//- Dynamic mode decomposition model
|
||||
autoPtr<DMDModel> DMDModelPtr_;
|
||||
|
||||
//- Snapshot matrix (effectively a column vector)
|
||||
//- Augmented snapshot matrix (effectively a column vector)
|
||||
// Upper half = current-time snapshot slot
|
||||
// Lower half = previous-time snapshot slot
|
||||
// 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_;
|
||||
|
||||
//- Name of operand field
|
||||
@ -195,7 +197,7 @@ class DMD
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
// Process
|
||||
// Evaluation
|
||||
|
||||
//- Initialise snapshot at the first-execution step
|
||||
// Initialisation at the ctor or read level is not possible
|
||||
@ -210,11 +212,12 @@ class DMD
|
||||
template<class Type>
|
||||
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
|
||||
// copy new current-time field into current-time slot in snapshot
|
||||
template<class GeoFieldType>
|
||||
bool getSnapshotField();
|
||||
bool storeSnapshot();
|
||||
|
||||
|
||||
// Access
|
||||
|
||||
@ -149,7 +149,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Process
|
||||
// Evaluation
|
||||
|
||||
//- Initialise model data members with a given snapshot
|
||||
virtual bool initialise(const RMatrix& snapshot) = 0;
|
||||
@ -169,7 +169,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
// IO
|
||||
// I-O
|
||||
|
||||
//- Read model settings
|
||||
virtual bool read(const dictionary& dict) = 0;
|
||||
|
||||
@ -64,7 +64,7 @@ Foam::scalar Foam::DMDModels::STDMD::L2norm(const RMatrix& z) const
|
||||
if (z.n() != 1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< " # Input matrix is not a column vector. #"
|
||||
<< "Input matrix is not a column vector."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
#endif
|
||||
@ -609,7 +609,7 @@ void Foam::DMDModels::STDMD::magnitudes()
|
||||
std::iota(w.begin(), w.end(), 1);
|
||||
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);
|
||||
}
|
||||
@ -622,9 +622,9 @@ void Foam::DMDModels::STDMD::magnitudes()
|
||||
Info<< "weighted amplitude scaling method" << endl;
|
||||
|
||||
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);
|
||||
}
|
||||
@ -664,7 +664,7 @@ Foam::scalar Foam::DMDModels::STDMD::sorter
|
||||
// Omit eigenvalues with very large or very small mags
|
||||
if (!(mag(eigenvalue) < GREAT && mag(eigenvalue) > VSMALL))
|
||||
{
|
||||
Info<< " Returning zero magnitude for mag(eigenvalue) = "
|
||||
Info<< " Returning zero magnitude for mag(eigenvalue) = "
|
||||
<< mag(eigenvalue) << endl;
|
||||
|
||||
return 0;
|
||||
@ -673,7 +673,7 @@ Foam::scalar Foam::DMDModels::STDMD::sorter
|
||||
// Omit eigenvalue-STDMD step combinations that pose a risk of overflow
|
||||
if (mag(eigenvalue)*step_ > sortLimiter_)
|
||||
{
|
||||
Info<< " Returning zero magnitude for"
|
||||
Info<< " Returning zero magnitude for"
|
||||
<< " mag(eigenvalue) = " << mag(eigenvalue)
|
||||
<< " current index = " << step_
|
||||
<< " sortLimiter = " << sortLimiter_
|
||||
@ -784,7 +784,7 @@ void Foam::DMDModels::STDMD::filter()
|
||||
{
|
||||
Info<< tab << "Filtering objects of dynamics" << endl;
|
||||
|
||||
// Filter objects according to iMags
|
||||
// Filter objects according to magsi
|
||||
filterIndexed(evals_, magsi_);
|
||||
filterIndexed(evecs_, magsi_);
|
||||
filterIndexed(freqs_, magsi_);
|
||||
@ -924,17 +924,17 @@ bool Foam::DMDModels::STDMD::read(const dictionary& dict)
|
||||
);
|
||||
|
||||
Info<< tab << "Settings are read for:" << nl
|
||||
<< " field: " << fieldName_ << nl
|
||||
<< " modeSorter: " << modeSorterTypeNames[modeSorter_] << nl
|
||||
<< " nModes: " << nModes_ << nl
|
||||
<< " maxRank: " << maxRank_ << nl
|
||||
<< " nGramSchmidt: " << nGramSchmidt_ << nl
|
||||
<< " fMin: " << fMin_ << nl
|
||||
<< " fMax: " << fMax_ << nl
|
||||
<< " minBasis: " << minBasis_ << nl
|
||||
<< " minEVal: " << minEval_ << nl
|
||||
<< " sortLimiter: " << sortLimiter_ << nl
|
||||
<< " nAgglomerationProcs: " << nAgglomerationProcs_ << nl
|
||||
<< tab << " field: " << fieldName_ << nl
|
||||
<< tab << " modeSorter: " << modeSorterTypeNames[modeSorter_] << nl
|
||||
<< tab << " nModes: " << nModes_ << nl
|
||||
<< tab << " maxRank: " << maxRank_ << nl
|
||||
<< tab << " nGramSchmidt: " << nGramSchmidt_ << nl
|
||||
<< tab << " fMin: " << fMin_ << nl
|
||||
<< tab << " fMax: " << fMax_ << nl
|
||||
<< tab << " minBasis: " << minBasis_ << nl
|
||||
<< tab << " minEVal: " << minEval_ << nl
|
||||
<< tab << " sortLimiter: " << sortLimiter_ << nl
|
||||
<< tab << " nAgglomerationProcs: " << nAgglomerationProcs_ << nl
|
||||
<< endl;
|
||||
|
||||
return true;
|
||||
@ -973,7 +973,12 @@ bool Foam::DMDModels::STDMD::initialise(const RMatrix& z)
|
||||
nSnap
|
||||
);
|
||||
|
||||
std::copy(z.cbegin(), z.cbegin() + nSnap, snapshot0.begin());
|
||||
std::copy
|
||||
(
|
||||
z.cbegin(),
|
||||
z.cbegin() + nSnap,
|
||||
snapshot0.begin()
|
||||
);
|
||||
|
||||
const IOstreamOption streamOpt
|
||||
(
|
||||
@ -1052,7 +1057,7 @@ bool Foam::DMDModels::STDMD::fit()
|
||||
|
||||
filter();
|
||||
|
||||
writeToFile(word("filteredDynamics"));
|
||||
writeToFile(word("filtered_dynamics"));
|
||||
}
|
||||
|
||||
step_ = 0;
|
||||
|
||||
@ -92,13 +92,10 @@ Usage
|
||||
\verbatim
|
||||
DMD1
|
||||
{
|
||||
// Mandatory/Optional entries
|
||||
...
|
||||
|
||||
// Mandatory entries (unmodifiable)
|
||||
// Mandatory entries
|
||||
DMDModel STDMD;
|
||||
|
||||
// Conditional mandatory entries (runtime modifiable)
|
||||
// Conditional mandatory entries
|
||||
|
||||
// Option-1
|
||||
interval 5.5;
|
||||
@ -106,7 +103,7 @@ Usage
|
||||
// Option-2
|
||||
executeInterval 10;
|
||||
|
||||
// Optional entries (runtime modifiable)
|
||||
// Optional entries
|
||||
modeSorter kiewat;
|
||||
nGramSchmidt 5;
|
||||
maxRank 50;
|
||||
@ -115,12 +112,12 @@ Usage
|
||||
fMax 1000000000;
|
||||
nAgglomerationProcs 20;
|
||||
|
||||
// Optional entries (runtime modifiable, yet not recommended)
|
||||
// Optional entries (not recommended to change)
|
||||
minBasis 0.00000001;
|
||||
minEVal 0.00000001;
|
||||
sortLimiter 500.0;
|
||||
|
||||
// Mandatory/Optional (inherited) entries
|
||||
// Inherited entries
|
||||
...
|
||||
}
|
||||
\endverbatim
|
||||
@ -335,7 +332,7 @@ class STDMD
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
// Process
|
||||
// Evaluation
|
||||
|
||||
//- Return (parallel) L2-norm of a given column vector
|
||||
scalar L2norm(const RMatrix& z) const;
|
||||
@ -355,9 +352,6 @@ class STDMD
|
||||
//- Compress orthonormal basis for 'Q' and 'G' if '(Q.n()>maxRank)'
|
||||
void compress();
|
||||
|
||||
|
||||
// Evaluation
|
||||
|
||||
//- Return reduced Koopman operator 'Atilde' (K:Eq. 78)
|
||||
// Also fills 'RxInv'.
|
||||
// The function was not divided into subsections to ensure
|
||||
@ -435,7 +429,7 @@ class STDMD
|
||||
);
|
||||
|
||||
|
||||
// IO
|
||||
// I-O
|
||||
|
||||
//- Write objects of dynamics
|
||||
void writeToFile(const word& fileName) const;
|
||||
|
||||
@ -43,7 +43,7 @@ void Foam::DMDModels::STDMD::filterIndexed
|
||||
|
||||
// Copy if frequency of element is within [a, b]
|
||||
label j = 0;
|
||||
for (const auto& i : indices)
|
||||
for (const label i : indices)
|
||||
{
|
||||
lstWithin[j] = lst[i];
|
||||
++j;
|
||||
@ -64,7 +64,7 @@ void Foam::DMDModels::STDMD::filterIndexed
|
||||
|
||||
// Copy if frequency of element is within [a, b]
|
||||
label j = 0;
|
||||
for (const auto& i : indices)
|
||||
for (const label i : indices)
|
||||
{
|
||||
matWithin.subColumn(j) = mat.subColumn(i);
|
||||
++j;
|
||||
@ -149,19 +149,19 @@ bool Foam::DMDModels::STDMD::calcModes()
|
||||
{
|
||||
if (patch_.empty())
|
||||
{
|
||||
auto& inModeRe = modeRe.primitiveFieldRef();
|
||||
auto& inModeIm = modeIm.primitiveFieldRef();
|
||||
auto& re = modeRe.primitiveFieldRef();
|
||||
auto& im = modeIm.primitiveFieldRef();
|
||||
|
||||
calcMode(inModeRe, inModeIm, primitiveMode, i);
|
||||
calcMode(re, im, primitiveMode, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
const label patchi = mesh_.boundaryMesh().findPatchID(patch_);
|
||||
|
||||
auto& bfModeRe = modeRe.boundaryFieldRef()[patchi];
|
||||
auto& bfModeIm = modeIm.boundaryFieldRef()[patchi];
|
||||
auto& re = modeRe.boundaryFieldRef()[patchi];
|
||||
auto& im = modeIm.boundaryFieldRef()[patchi];
|
||||
|
||||
calcMode(bfModeRe, bfModeIm, primitiveMode, i);
|
||||
calcMode(re, im, primitiveMode, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -38,11 +38,11 @@ bool Foam::functionObjects::DMD::getSnapshot()
|
||||
|
||||
if (foundObject<VolFieldType>(fieldName_))
|
||||
{
|
||||
return getSnapshotField<VolFieldType>();
|
||||
return storeSnapshot<VolFieldType>();
|
||||
}
|
||||
else if (foundObject<SurfaceFieldType>(fieldName_))
|
||||
{
|
||||
return getSnapshotField<SurfaceFieldType>();
|
||||
return storeSnapshot<SurfaceFieldType>();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -50,7 +50,7 @@ bool Foam::functionObjects::DMD::getSnapshot()
|
||||
|
||||
|
||||
template<class GeoFieldType>
|
||||
bool Foam::functionObjects::DMD::getSnapshotField()
|
||||
bool Foam::functionObjects::DMD::storeSnapshot()
|
||||
{
|
||||
if (step_ == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user