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  filteredDynamics_<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 (unmodifiable)
91  type DMD;
92  libs (fieldFunctionObjects);
93  DMDModel <DMDModel>;
94  field <inputField>;
95 
96  // Optional entries (unmodifiable)
97  patch <patchName>;
98 
99  // Mandatory/Optional (inherited) entries
100  ...
101  }
102  \endverbatim
103 
104  where the entries mean:
105  \table
106  Property | Description | Type | Reqd | Deflt
107  type | Type name: DMD | word | yes | -
108  libs | Library name: fieldFunctionObjects | word | yes | -
109  DMDModel | Name of specified DMD model | word | yes | -
110  field | Name of operand field | word | yes | -
111  patch | Name of operand patch | word | no | null
112  \endtable
113 
114  Options for the \c DMDModel entry:
115  \verbatim
116  STDMD | Streaming total dynamic mode decomposition
117  \endverbatim
118 
119  The inherited entries are elaborated in:
120  - \link functionObject.H \endlink
121  - \link writeFile.H \endlink
122 
123  Minimal example by using the \c postProcess utility:
124  \verbatim
125  <solver> -postProcess -fields '(U p)' -time '10:'
126  \endverbatim
127 
128 Note
129  - Warning: DMD is an active research area at the time of writing;
130  therefore, there could be cases whereat oddities can be seen.
131 
132 See also
133  - Foam::functionObjects::fvMeshFunctionObject
134  - Foam::functionObjects::writeFile
135  - Foam::DMDModel
136  - Foam::DMDModels::STDMD
137 
138 SourceFiles
139  DMD.C
140  DMDTemplates.C
141 
142 \*---------------------------------------------------------------------------*/
143 
144 #ifndef functionObjects_DMD_H
145 #define functionObjects_DMD_H
146 
147 #include "fvMeshFunctionObject.H"
148 #include "RectangularMatrix.H"
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 namespace Foam
153 {
154 
155 // Forward Declarations
156 class DMDModel;
157 
158 namespace functionObjects
159 {
160 
161 /*---------------------------------------------------------------------------*\
162  Class DMD Declaration
163 \*---------------------------------------------------------------------------*/
164 
165 class DMD
166 :
167  public fvMeshFunctionObject
168 {
169  typedef RectangularMatrix<scalar> RMatrix;
170 
171  // Private Data
172 
173  //- Dynamic mode decomposition model
174  autoPtr<DMDModel> DMDModelPtr_;
175 
176  //- Snapshot matrix (effectively a column vector)
177  // Upper half = current-time snapshot slot
178  // Lower half = previous-time snapshot slot
179  // A snapshot is an input dataset to be processed per execution step
180  RMatrix z_;
181 
182  //- Name of operand field
183  const word fieldName_;
184 
185  //- Name of operand patch
186  const word patch_;
187 
188  //- Number of elements in a snapshot
189  label nSnap_;
190 
191  //- Current execution-step index of DMD,
192  //- not necessarily that of the simulation
193  label step_;
194 
195 
196  // Private Member Functions
197 
198  // Process
199 
200  //- Initialise snapshot at the first-execution step
201  // Initialisation at the ctor or read level is not possible
202  // since the operand field is not available in the database
203  void initialise();
204 
205  //- Create operand snapshot by using
206  //- current-time and previous-time operand fields
207  void snapshot();
208 
209  //- Get operand field based on its base type
210  template<class Type>
211  bool getSnapshot();
212 
213  //- Get operand field based on its geometric field type
214  // Move previous-time field into previous-time slot in snapshot
215  // copy new current-time field into current-time slot in snapshot
216  template<class GeoFieldType>
217  bool getSnapshotField();
218 
219 
220 public:
221 
222  //- Runtime type information
223  TypeName("DMD");
224 
225 
226  // Constructors
227 
228  //- Construct from Time and dictionary
229  DMD
230  (
231  const word& name,
232  const Time& runTime,
233  const dictionary& dict
234  );
235 
236  //- No copy construct
237  DMD(const DMD&) = delete;
238 
239  //- No copy assignment
240  void operator=(const DMD&) = delete;
241 
242 
243  //- Destructor
244  virtual ~DMD() = default;
245 
246 
247  // Member Functions
248 
249  //- Read DMD settings
250  virtual bool read(const dictionary& dict);
251 
252  //- Execute DMD
253  virtual bool execute();
254 
255  //- Write DMD results
256  virtual bool write();
257 
258  //- Write DMD results
259  virtual bool end();
260 };
261 
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 } // End namespace functionObjects
266 } // End namespace Foam
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 #ifdef NoRepository
271  #include "DMDTemplates.C"
272 #endif
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #endif
277 
278 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
fvMeshFunctionObject.H
DMDTemplates.C
Foam::functionObjects::DMD::TypeName
TypeName("DMD")
Runtime type information.
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::RectangularMatrix< scalar >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::DMD::~DMD
virtual ~DMD()=default
Destructor.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObjects::DMD::execute
virtual bool execute()
Execute DMD.
Definition: DMD.C:162
Foam::functionObjects::DMD::write
virtual bool write()
Write DMD results.
Definition: DMD.C:187
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObjects::DMD
Computes a dynamic mode decomposition model on a specified field.
Definition: DMD.H:242
Foam::functionObjects::DMD::end
virtual bool end()
Write DMD results.
Definition: DMD.C:198
Foam::functionObjects::DMD::DMD
DMD(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: DMD.C:113
Foam::functionObjects::DMD::operator=
void operator=(const DMD &)=delete
No copy assignment.
Foam::functionObjects::DMD::read
virtual bool read(const dictionary &dict)
Read DMD settings.
Definition: DMD.C:149
RectangularMatrix.H