Loading...
Searching...
No Matches
DMD.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-------------------------------------------------------------------------------
10License
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 "DMD.H"
29#include "readFields.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace ROMmodels
37{
40}
41}
42
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46// Implementation
47#include "DMDImpl.C"
48
49
50// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51
52Foam::wordList Foam::ROMmodels::DMD::modeNames(const word& modeType) const
53{
54 wordList modeNames(modes_.size());
55 for (const label modei : modes_)
56 {
57 modeNames[modei] =
58 word
59 (
60 "mode"+modeType+"_"+name(modei)+"_"+fieldName_+"_"+objectName_
61 );
62 }
63 return modeNames;
64}
65
66
67// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68
70(
71 Time& runTime,
72 fvMesh& mesh,
73 const dictionary& dict,
74 const instantList& times
75)
76:
77 ROMmodel(runTime, mesh, dict, times),
78 fieldName_(),
79 objectName_(),
80 deltaT_(),
81 time_(),
82 startTime_(),
83 modes_(),
84 dims_(),
85 amps_(),
86 evals_()
87{
88 read(dict);
89}
90
91
92// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
93
95{
96 dict.readEntry("field", fieldName_);
97 dict.readEntry("object", objectName_);
98 dict.readEntry("deltaT", deltaT_);
99 dict.readEntry("time", time_);
100 dict.readIfPresent("startTime", startTime_);
101
102 if (deltaT_ < SMALL || time_ < SMALL || startTime_ < 0)
103 {
105 << "Out-of-range values for " << nl
106 << tab << "deltaT: " << deltaT_
107 << tab << "time: " << time_ << nl
108 << tab << "startTime: " << startTime_ << nl
109 << exit(FatalIOError);
110 }
111
112 dict.readEntry("modes", modes_);
113
114 if (modes_.empty())
115 {
117 << "Empty list for the mode indices " << nl
118 << tab << "modes: " << modes_ << nl
119 << exit(FatalIOError);
120 }
121
122 dims_.reset(dict.get<dimensionSet>("dimensions"));
123
124 // Load complex amplitudes and eigenvalues
125 dict.readEntry("amplitudes", amps_);
126 dict.readEntry("eigenvalues", evals_);
127
128 if ((amps_.size() != modes_.size()) || (evals_.size() != modes_.size()))
129 {
131 << "Inconsistent input sizes for "
132 << tab << "modes: " << modes_.size() << nl
133 << tab << "amplitudes: " << amps_.size() << nl
134 << tab << "eigenvalues: " << evals_.size() << nl
135 << exit(FatalIOError);
136 }
137
138 // Create mode-field names
139 const wordList modeReNames(modeNames(word("Re")));
140 const wordList modeImNames(modeNames(word("Im")));
141
142 // Load mode fields
143 runTime_.setTime(time_, 0);
144
145 readFieldsHandler(mesh_).execute(modeReNames);
146 readFieldsHandler(mesh_).execute(modeImNames);
147
148 return true;
149}
150
151
153{
154 do
155 {
156 #undef doLocalCode
157 #define doLocalCode(InputType) \
158 { \
159 createAndWriteImpl<VolumeField<InputType>>(); \
160 createAndWriteImpl<SurfaceField<InputType>>(); \
161 }
162
163 doLocalCode(scalar);
168
169 #undef doInnerLocalCode
170 #undef doLocalCode
171 }
172 while (false);
173
174 return true;
175}
176
177
178// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Time & runTime_
Reference to the Time.
Definition ROMmodel.H:74
fvMesh & mesh_
Reference to the fvMesh.
Definition ROMmodel.H:81
Field creation model using the streaming total dynamic mode decomposition method (STDMD).
Definition DMD.H:254
virtual bool read(const dictionary &dict)
Read model settings.
virtual bool createAndWrite()
Create and write fields.
DMD(Time &runTime, fvMesh &mesh, const dictionary &dict, const instantList &times)
Construct from components.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
engineTime & runTime
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
#define doLocalCode(FieldType, Variable)
auto & name
A namespace for various implementations of reduced-order (ROM) field creation models.
Definition DMD.H:246
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< instant > instantList
List of instants.
Definition instantList.H:41
Tensor< scalar > tensor
Definition symmTensor.H:57
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
Vector< scalar > vector
Definition vector.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition symmTensor.H:55
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
constexpr char tab
The tab '\t' character(0x09).
Definition Ostream.H:49
dictionary dict