DMD.H
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) 2020-2021 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 Class
27  Foam::functionObjects::DMD
28 
29 Group
30  grpFieldFunctionObjects
31 
32 Description
33  Computes a dynamic mode decomposition model on a specified field.
34 
35  Dynamic mode decomposition (i.e. DMD) is a data-driven
36  dimensionality reduction method. DMD is being used as a mathematical
37  processing tool to reveal dominant modes out of a given field (or dataset)
38  each of which is associated with a constant frequency and decay rate,
39  so that dynamic features of a given flow may become interpretable,
40  tractable, and even reproducible without computing simulations.
41  DMD only relies on input data, therefore it is an equation-free approach.
42 
43  References:
44  \verbatim
45  DMD characteristics:
46  Brunton S. L. (2018).
47  Dynamic mode decomposition overview.
48  Seattle, Washington: University of Washington.
49  youtu.be/sQvrK8AGCAo (Retrieved:24-04-20)
50  \endverbatim
51 
52  Operands:
53  \table
54  Operand | Type | Location
55  input | {vol,surface}<Type>Field(s) <!--
56  --> | <time>/<inputField>(s)
57  output file | dat | postProcessing/<FO>/<time>/<file>(s)
58  output field | volVectorField(s) | <time>/<outputField>(s)
59  \endtable
60 
61  where \c <Type>=Scalar/Vector/SphericalTensor/SymmTensor/Tensor.
62 
63  Output fields:
64  \verbatim
65  modeRe_<modeIndex>_<field>_<FO> | Real part of a mode field
66  modeIm_<modeIndex>_<field>_<FO> | Imaginary part of a mode field
67  \endverbatim
68 
69  Output files:
70  \verbatim
71  dynamics_<field>.dat | Dynamics data for each mode
72  filtered_dynamics_<field>.dat | Filtered dynamics data for each mode
73  \endverbatim
74 
75  wherein for each mode, the following quantities are output into files:
76  \vartable
77  freq | Frequency
78  mag | Magnitude
79  ampRe | Amplitude coefficients (real part)
80  ampIm | Amplitude coefficients (imaginary part)
81  evalRe | Eigenvalue (real part)
82  evalIm | Eigenvalue (imaginary part)
83  \endvartable
84 
85 Usage
86  Minimal example by using \c system/controlDict.functions:
87  \verbatim
88  DMD1
89  {
90  // Mandatory entries
91  type DMD;
92  libs (fieldFunctionObjects);
93  DMDModel <DMDModel>;
94  field <word>;
95 
96  // Optional entries
97 
98  // Option-1
99  patch <word>;
100 
101  // Option-2
102  patches (<wordRes>);
103 
104  // Inherited entries
105  ...
106  }
107  \endverbatim
108 
109  where the entries mean:
110  \table
111  Property | Description | Type | Reqd | Deflt
112  type | Type name: DMD | word | yes | -
113  libs | Library name: fieldFunctionObjects | word | yes | -
114  DMDModel | Name of specified DMD model | word | yes | -
115  field | Name of operand field | word | yes | -
116  patch | Name of operand patch | word | no | null
117  patches | Names of operand patches | wordRes | no | null
118  \endtable
119 
120  Options for the \c DMDModel entry:
121  \verbatim
122  STDMD | Streaming total dynamic mode decomposition
123  \endverbatim
124 
125  The inherited entries are elaborated in:
126  - \link functionObject.H \endlink
127  - \link writeFile.H \endlink
128 
129  Minimal example by using the \c postProcess utility:
130  \verbatim
131  <solver> -postProcess -fields '(U p)' -time '10:'
132  \endverbatim
133 
134 Note
135  - Warning: DMD is an active research area at the time of writing;
136  therefore, there could be cases whereat oddities can be seen.
137 
138 See also
139  - Foam::functionObjects::fvMeshFunctionObject
140  - Foam::functionObjects::writeFile
141  - Foam::DMDModel
142  - Foam::DMDModels::STDMD
143 
144 SourceFiles
145  DMD.C
146  DMDTemplates.C
147 
148 \*---------------------------------------------------------------------------*/
149 
150 #ifndef functionObjects_DMD_H
151 #define functionObjects_DMD_H
152 
153 #include "fvMeshFunctionObject.H"
154 #include "RectangularMatrix.H"
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 namespace Foam
159 {
160 
161 // Forward Declarations
162 class DMDModel;
163 
164 namespace functionObjects
165 {
166 
167 /*---------------------------------------------------------------------------*\
168  Class DMD Declaration
169 \*---------------------------------------------------------------------------*/
170 
171 class DMD
172 :
173  public fvMeshFunctionObject
174 {
175  typedef RectangularMatrix<scalar> RMatrix;
176 
177  // Private Data
178 
179  //- Dynamic mode decomposition model
180  autoPtr<DMDModel> DMDModelPtr_;
181 
182  //- Augmented snapshot matrix (effectively a column vector)
183  // Upper half = current-time snapshot slot
184  // Lower half = previous-time snapshot slot
185  // A snapshot is an input dataset to be processed per execution step
186  // A single snapshot is usually referred to as the snapshot of a single
187  // time step, an augmented snapshot is constructed of two snapshots
188  RMatrix z_;
189 
190  //- Names of operand patches
191  const wordRes patches_;
192 
193  //- Name of operand field
194  const word fieldName_;
195 
196  //- Number of elements in a snapshot
197  label nSnap_;
198 
199  //- Current execution-step index of DMD,
200  //- not necessarily that of the simulation
201  label step_;
202 
203 
204  // Private Member Functions
205 
206  // Evaluation
207 
208  //- Initialise snapshot at the first-execution step
209  // Initialisation at the ctor or read level is not possible
210  // since the operand field is not available in the database
211  void initialise();
212 
213  //- Create operand snapshot by using
214  //- current-time and previous-time operand fields
215  void snapshot();
216 
217  //- Get operand field based on its base type
218  template<class Type>
219  bool getSnapshot();
220 
221  //- Store operand field based on its geometric
222  //- field type after few manipulations
223  // Move previous-time field into previous-time slot in snapshot
224  // copy new current-time field into current-time slot in snapshot
225  template<class GeoFieldType>
226  bool storeSnapshot();
227 
228 
229  // Access
230 
231  //- Return number of components of the base type of a given field
232  label nComponents(const word& fieldName) const;
233 
234  //- Get the number of components of the base type of a given field
235  template<class Type>
236  bool nComponents(const word& fieldName, label& nComps) const;
237 
238 
239 public:
240 
241  //- Runtime type information
242  TypeName("DMD");
243 
244 
245  // Constructors
246 
247  //- Construct from Time and dictionary
248  DMD
249  (
250  const word& name,
251  const Time& runTime,
252  const dictionary& dict
253  );
254 
255  //- No copy construct
256  DMD(const DMD&) = delete;
257 
258  //- No copy assignment
259  void operator=(const DMD&) = delete;
260 
261 
262  //- Destructor
263  virtual ~DMD() = default;
264 
265 
266  // Member Functions
267 
268  //- Read DMD settings
269  virtual bool read(const dictionary& dict);
270 
271  //- Execute DMD
272  virtual bool execute();
273 
274  //- Write DMD results
275  virtual bool write();
276 
277  //- Write DMD results
278  virtual bool end();
279 };
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace functionObjects
285 } // End namespace Foam
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 #ifdef NoRepository
290  #include "DMDTemplates.C"
291 #endif
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 #endif
296 
297 // ************************************************************************* //
dictionary dict
void operator=(const DMD &)=delete
No copy assignment.
DMD(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: DMD.C:127
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
engineTime & runTime
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const word & name() const noexcept
Return the name of this functionObject.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool read(const dictionary &dict)
Read DMD settings.
Definition: DMD.C:170
virtual bool end()
Write DMD results.
Definition: DMD.C:219
virtual ~DMD()=default
Destructor.
virtual bool execute()
Execute DMD.
Definition: DMD.C:183
virtual bool write()
Write DMD results.
Definition: DMD.C:208
TypeName("DMD")
Runtime type information.
Computes a dynamic mode decomposition model on a specified field.
Definition: DMD.H:250
Namespace for OpenFOAM.