Loading...
Searching...
No Matches
perform_POD.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2Copyright (C) 2017 by the ITHACA-FV authors
3
4License
5 This file is part of ITHACA-FV
6
7 ITHACA-FV is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ITHACA-FV is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
19
20Class
21 POD
22
23Description
24 Application to perform a POD decomposition of a general field on a given case
25
26SourceFiles
27 perform_POD.C
28
29\*---------------------------------------------------------------------------*/
30
35
38
39
40#include "fvCFD.H"
41#include "IOmanip.H"
42#include "IFstream.H"
43#include "primitiveFields.H"
44#include "FieldFields.H"
45#include "scalarMatrices.H"
46#include "SortableList.H"
47#include "volFieldsFwd.H"
48#include "forces.H"
49#include "forceCoeffs.H"
50#include "volFields.H"
51#include <iostream>
52#include <fstream>
53#include <sstream>
54#include <vector>
55#include <string>
56#include <stdio.h>
57#include "ITHACAPOD.H"
58#include "ITHACAparameters.H"
59// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60
61int main(int argc, char *argv[])
62{
63
64#include "setRootCase.H"
65#include "createTime.H"
66#include "createMesh.H"
67
68 PtrList<volVectorField> Vfield;
69 PtrList<volScalarField> Sfield;
70 PtrList<volVectorField> Vmodes;
71 PtrList<volScalarField> Smodes;
72
74 runTime);
75
76 bool pod_exist;
77 struct stat sb;
78
79 if (stat("./ITHACAoutput/POD", &sb) == 0 && S_ISDIR(sb.st_mode))
80 {
81 pod_exist = true;
82 }
83 else
84 {
85 pod_exist = false;
86 Info << "POD don't exist, performing a POD decomposition" << endl;
87 ITHACAutilities::createSymLink("./ITHACAoutput/POD");
88 }
89 if(pod_exist == 1)
90 {
91 Info << "The POD has already been performed, please delete the ITHACAoutput folder and try again." << endl;
92 return 0;
93 }
94
95 // Initialize Variables
96 label nSnapshots;
97 label startTime;
98 label endTime;
99
100 //Read FORCESdict
101 IOdictionary ITHACAPODdict
102 (
103 IOobject
104 (
105 "ITHACAPODdict",
106 runTime.system(),
107 mesh,
108 IOobject::MUST_READ,
109 IOobject::NO_WRITE
110 )
111 );
112
113 // Get times list from the case folder
114 instantList Times = runTime.times();
115
116 // Read Initial and last time from the POD dictionary
117 const entry* existnsnap = ITHACAPODdict.lookupEntryPtr("Nsnapshots", false, true);
118 const entry* existLT = ITHACAPODdict.lookupEntryPtr("FinalTime", false, true);
119
120 // Initiate variable from PODSolverDict
121 if ((existnsnap) && (existLT))
122 {
123 Info << "Error you cannot define LatestTime and NSnapShots together" << endl;
124 abort();
125 }
126 else if (existnsnap)
127 {
128 scalar InitialTime = ITHACAPODdict.lookupOrDefault<scalar>("InitialTime", 0);
129 nSnapshots = readScalar(ITHACAPODdict.lookup("Nsnapshots"));
130 startTime = Time::findClosestTimeIndex(runTime.times(), InitialTime);
131 nSnapshots = min(nSnapshots , Times.size() - startTime);
132 endTime = startTime + nSnapshots - 1;
133 Info << nSnapshots << endl;
134 }
135 else
136 {
137 scalar InitialTime = ITHACAPODdict.lookupOrDefault<scalar>("InitialTime", 0);
138 scalar FinalTime = ITHACAPODdict.lookupOrDefault<scalar>("FinalTime", 100000000000000);
139 endTime = Time::findClosestTimeIndex(runTime.times(), FinalTime);
140 startTime = Time::findClosestTimeIndex(runTime.times(), InitialTime);
141 nSnapshots = endTime - startTime + 1;
142 if (InitialTime > FinalTime)
143 {
144 Info << "FinalTime cannot be smaller than the InitialTime check your ITHACAPODdict file\n" << endl;
145 abort();
146 }
147 }
148 // Print out some Infos
149 Info << "startTime: " << startTime << "\n" << "endTime: " << endTime << "\n" << "nSnapshots: " << nSnapshots << "\n" << endl;
150
151 // Set the initial time
152 runTime.setTime(Times[startTime], startTime);
153
154 wordList fieldlist
155 (
156 ITHACAPODdict.lookup("fields")
157 );
158
159 //word Name = ITHACAPODdict.lookup("fieldName");
160 //word type = ITHACAPODdict.lookup("type");
161
162 if (startTime == endTime)
163 {
164 Info << "The case has no snapshots to process, exiting the code" << endl;
165 exit(0);
166 }
167
168 for (label k = 0; k < fieldlist.size(); k++)
169 {
170 dictionary& subDict = ITHACAPODdict.subDict(fieldlist[k]);
171 scalar nmodes = readScalar(subDict.lookup("nmodes"));
172 word field_name(subDict.lookup("field_name"));
173 word field_type(subDict.lookup("field_type"));
174
175 for (label i = startTime; i < endTime + 1; i++)
176 {
177 Info << "Reading snapshot " << i << " for field " << field_name << endl;
178 runTime.setTime(Times[i], i);
179 mesh.readUpdate();
180
181 if (field_type == "vector")
182 {
183
184 volVectorField vector_field
185 (
186 IOobject
187 (
188 field_name,
189 runTime.timeName(),
190 mesh,
191 IOobject::MUST_READ
192 ),
193 mesh
194 );
195 Vfield.append(vector_field.clone());
196 }
197
198 if (field_type == "scalar")
199 {
200 volScalarField scalar_field
201 (
202 IOobject
203 (
204 field_name,
205 runTime.timeName(),
206 mesh,
207 IOobject::MUST_READ
208 ),
209 mesh
210 );
211 Sfield.append(scalar_field.clone());
212 }
213 }
214
215 if (field_type == "vector")
216 {
217 ITHACAPOD::getModes(Vfield, Vmodes, field_name, 0, 0, 0, nmodes, para->correctBC);
218 }
219 if (field_type == "scalar")
220 {
221 ITHACAPOD::getModes(Sfield, Smodes, field_name, 0, 0, 0, nmodes, para->correctBC);
222 }
223
224 Vfield.clear();
225 Sfield.clear();
226 }
227 Info << endl;
228 Info << "End\n" << endl;
229 return 0;
230}
231
232
Header file of the ITHACAPOD class.
Class for the definition of some general parameters, the parameters must be defined from the file ITH...
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
T min(Eigen::SparseMatrix< T > &mat, label &ind_row, label &ind_col)
Find the minimum of a sparse Matrix (Useful for DEIM).
void getModes(PtrList< GeometricField< Type, PatchField, GeoMesh > > &snapshots, PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, word fieldName, bool podex, bool supex, bool sup, label nmodes, bool correctBC)
Computes the bases or reads them for a field.
Definition ITHACAPOD.C:93
void createSymLink(word folder)
Creates symbolic links to 0, system and constant.