DMDImpl.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "volFields.H"
29 #include "surfaceFields.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class GeoType>
35 bool Foam::ROMmodels::DMD::createAndWriteImpl() const
36 {
37  typedef typename GeoType::value_type Type;
38 
39  const wordList modeReNames(modeNames(word("Re")));
40  const wordList modeImNames(modeNames(word("Im")));
41 
42  for (const label i : modes_)
43  {
44  const auto* modeRePtr = mesh_.cfindObject<GeoType>(modeReNames[i]);
45 
46  if (!modeRePtr) return false;
47 
48  const auto* modeImPtr = mesh_.cfindObject<GeoType>(modeImNames[i]);
49 
50  if (!modeImPtr) return false;
51  }
52 
53 
54  forAll(times_, timei)
55  {
56  runTime_.setTime(times_[timei], timei);
57 
58  Info<< "\nTime = " << runTime_.timeName() << endl;
59 
60  // Calculate the eigenvalue exponent corresponding to specified time
61  const scalar k = (times_[timei].value() - startTime_)/deltaT_;
62 
63  GeoType reconstructedFld
64  (
65  IOobject
66  (
67  IOobject::scopedName(fieldName_, "reconstructed"),
69  mesh_,
73  ),
74  mesh_,
75  dimensioned<Type>(dimless, Zero),
77  );
78 
79  forAll(modes_, i)
80  {
81  const label j = modes_[i];
82  const auto& modeRe = mesh_.lookupObject<GeoType>(modeReNames[j]);
83  const auto& modeIm = mesh_.lookupObject<GeoType>(modeImNames[j]);
84 
85  const complex evalk(pow(evals_[i], k));
86 
87  // (K:Eq. 84)
88  reconstructedFld +=
89  (
90  (modeRe*amps_[i].Re() - modeIm*amps_[i].Im())*evalk.Re()
91  - (modeRe*amps_[i].Im() + modeIm*amps_[i].Re())*evalk.Im()
92  );
93  }
94 
95  reconstructedFld.correctBoundaryConditions();
96 
97  reconstructedFld.dimensions().reset(dims_);
98 
99  reconstructedFld.write();
100  }
101 
102  return true;
103 }
104 
105 
106 // ************************************************************************* //
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: fvPatchField.H:221
Foam::surfaceFields.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
Time & runTime_
Reference to the Time.
Definition: ROMmodel.H:74
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
label k
Boltzmann constant.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:40
fvMesh & mesh_
Reference to the fvMesh.
Definition: ROMmodel.H:81
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:902
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
List< word > wordList
List of word.
Definition: fileName.H:59
Nothing to be read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
const instantList & times_
Const reference to field times.
Definition: ROMmodel.H:91
Do not request registration (bool: false)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127