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 -------------------------------------------------------------------------------
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 "DMD.H"
29 #include "readFields.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace ROMmodels
37 {
38  defineTypeNameAndDebug(DMD, 0);
39  addToRunTimeSelectionTable(ROMmodel, DMD, dictionary);
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 // Implementation
47 #include "DMDImpl.C"
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 Foam::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 
94 bool Foam::ROMmodels::DMD::read(const dictionary& dict)
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 // ************************************************************************* //
virtual bool createAndWrite()
Create and write fields.
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
engineTime & runTime
Tensor< scalar > tensor
Definition: symmTensor.H:57
constexpr char tab
The tab &#39;\t&#39; character(0x09)
Definition: Ostream.H:49
#define doLocalCode(FieldType, Variable)
Macros for easy insertion into run-time selection tables.
DMD(Time &runTime, fvMesh &mesh, const dictionary &dict, const instantList &times)
Construct from components.
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:55
virtual bool read(const dictionary &dict)
Read DMD settings.
Definition: DMD.C:170
Vector< scalar > vector
Definition: vector.H:57
defineTypeNameAndDebug(combustionModel, 0)
List< word > wordList
List of word.
Definition: fileName.H:59
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:637
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
List< instant > instantList
List of instants.
Definition: instantList.H:41
virtual bool read(const dictionary &dict)
Read model settings.
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...