Loading...
Searching...
No Matches
unsteadyNS.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ██╗████████╗██╗ ██╗ █████╗ ██████╗ █████╗ ███████╗██╗ ██╗
3 ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝██╔══██╗ ██╔════╝██║ ██║
4 ██║ ██║ ███████║███████║██║ ███████║█████╗█████╗ ██║ ██║
5 ██║ ██║ ██╔══██║██╔══██║██║ ██╔══██║╚════╝██╔══╝ ╚██╗ ██╔╝
6 ██║ ██║ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ╚████╔╝
7 ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═══╝
8
9 * In real Time Highly Advanced Computational Applications for Finite Volumes
10 * Copyright (C) 2017 by the ITHACA-FV authors
11-------------------------------------------------------------------------------
12
13 License
14 This file is part of ITHACA-FV
15
16 ITHACA-FV is free software: you can redistribute it and/or modify
17 it under the terms of the GNU Lesser General Public License as published by
18 the Free Software Foundation, either version 3 of the License, or
19 (at your option) any later version.
20
21 ITHACA-FV is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU Lesser General Public License for more details.
25
26 You should have received a copy of the GNU Lesser General Public License
27 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
28
29\*---------------------------------------------------------------------------*/
30
31#include "unsteadyNS.H"
32
35
36// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * //
37
38// Construct Null
40
41// Construct from zero
42unsteadyNS::unsteadyNS(int argc, char* argv[])
43 :
45{
46 _args = autoPtr<argList>
47 (
48 new argList(argc, argv)
49 );
50
51 if (!_args->checkRootCase())
52 {
53 Foam::FatalError.exit();
54 }
55
56 argList& args = _args();
57#include "createTime.H"
58#include "createMesh.H"
59 _pimple = autoPtr<pimpleControl>
60 (
61 new pimpleControl
62 (
63 mesh
64 )
65 );
66 ITHACAdict = new IOdictionary
67 (
68 IOobject
69 (
70 "ITHACAdict",
71 runTime.system(),
72 mesh,
73 IOobject::MUST_READ,
74 IOobject::NO_WRITE
75 )
76 );
77#include "createFields.H"
78#include "createFvOptions.H"
80
81 method = ITHACAdict->lookupOrDefault<word>("method", "supremizer");
82 M_Assert(method == "supremizer" || method == "PPE", "The method must be set to supremizer or PPE in ITHACAdict");
83
84 bcMethod = ITHACAdict->lookupOrDefault<word>("bcMethod", "lift");
85 M_Assert(bcMethod == "lift" || bcMethod == "penalty",
86 "The BC method must be set to lift or penalty in ITHACAdict");
87
88 timedepbcMethod = ITHACAdict->lookupOrDefault<word>("timedepbcMethod", "no");
89 M_Assert(timedepbcMethod == "yes" || timedepbcMethod == "no",
90 "The BC method can be set to yes or no");
92 ITHACAdict->lookupOrDefault<word>("timeDerivativeSchemeOrder", "second");
94 || timeDerivativeSchemeOrder == "second",
95 "The time derivative approximation must be set to either first or second order scheme in ITHACAdict");
99}
100
101// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102
103void unsteadyNS::truthSolve(List<scalar> mu_now, fileName folder)
104{
105 Time& runTime = _runTime();
106 surfaceScalarField& phi = _phi();
107 fvMesh& mesh = _mesh();
108#include "initContinuityErrs.H"
109 fv::options& fvOptions = _fvOptions();
110 pimpleControl& pimple = _pimple();
111 volScalarField& p = _p();
112 volVectorField& U = _U();
113 IOMRFZoneList& MRF = _MRF();
114 singlePhaseTransportModel& laminarTransport = _laminarTransport();
115 instantList Times = runTime.times();
116 runTime.setEndTime(finalTime);
117 // Perform a TruthSolve
118 runTime.setTime(Times[1], 1);
119 runTime.setDeltaT(timeStep);
121
122 // Set time-dependent velocity BCs for initial condition
123 if (timedepbcMethod == "yes")
124 {
125 for (label i = 0; i < inletPatch.rows(); i++)
126 {
127 Vector<double> inl(0, 0, 0);
128
129 for (label j = 0; j < inl.size(); j++)
130 {
131 inl[j] = timeBCoff(i * inl.size() + j, 0);
132 }
133
134 assignBC(U, inletPatch(i, 0), inl);
135 }
136 }
137
138 // Export and store the initial conditions for velocity and pressure
139 ITHACAstream::exportSolution(U, name(counter), folder);
140 ITHACAstream::exportSolution(p, name(counter), folder);
141 std::ofstream of(folder + name(counter) + "/" +
142 runTime.timeName());
143 Ufield.append(U.clone());
144 Pfield.append(p.clone());
145 counter++;
147
148 // Start the time loop
149 while (runTime.run())
150 {
151#include "readTimeControls.H"
152#include "CourantNo.H"
153#include "setDeltaT.H"
154 runTime.setEndTime(finalTime);
155 runTime++;
156 Info << "Time = " << runTime.timeName() << nl << endl;
157
158 // Set time-dependent velocity BCs
159 if (timedepbcMethod == "yes")
160 {
161 for (label i = 0; i < inletPatch.rows(); i++)
162 {
163 Vector<double> inl(0, 0, 0);
164
165 for (label j = 0; j < inl.size(); j++)
166 {
167 inl[j] = timeBCoff(i * inl.size() + j, counter2);
168 }
169
170 assignBC(U, inletPatch(i, 0), inl);
171 }
172
173 counter2 ++;
174 }
175
176 // --- Pressure-velocity PIMPLE corrector loop
177 while (pimple.loop())
178 {
179#include "UEqn.H"
180
181 // --- Pressure corrector loop
182 while (pimple.correct())
183 {
184#include "pEqn.H"
185 }
186
187 if (pimple.turbCorr())
188 {
189 laminarTransport.correct();
190 turbulence->correct();
191 }
192 }
193
194 Info << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
195 << " ClockTime = " << runTime.elapsedClockTime() << " s"
196 << nl << endl;
197
198 if (checkWrite(runTime))
199 {
200 ITHACAstream::exportSolution(U, name(counter), folder);
201 ITHACAstream::exportSolution(p, name(counter), folder);
202 Ufield.append(U.clone());
203 Pfield.append(p.clone());
204 counter++;
206 writeMu(mu_now);
207 // --- Fill in the mu_samples with parameters (time, mu) to be used for the PODI sample points
208 mu_samples.conservativeResize(mu_samples.rows() + 1, mu_now.size() + 1);
209 mu_samples(mu_samples.rows() - 1, 0) = atof(runTime.timeName().c_str());
210
211 for (label i = 0; i < mu_now.size(); i++)
212 {
213 mu_samples(mu_samples.rows() - 1, i + 1) = mu_now[i];
214 }
215 }
216 }
217
218 // Resize to Unitary if not initialized by user (i.e. non-parametric problem)
219 if (mu.cols() == 0)
220 {
221 mu.resize(1, 1);
222 }
223
224 if (mu_samples.rows() == counter * mu.cols())
225 {
226 ITHACAstream::exportMatrix(mu_samples, "mu_samples", "eigen",
227 folder);
228 }
229}
Foam::fvMesh & mesh
Definition createMesh.H:47
Foam::Time & runTime
Definition createTime.H:33
#define M_Assert(Expr, Msg)
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
bool checkWrite(Time &timeObject)
Function to check if the solution must be exported.
scalar startTime
Start Time (initial time to start storing the snapshots)
scalar writeEvery
Time step of the writing procedure.
scalar timeStep
Time step of the simulation.
scalar nextWrite
Auxiliary variable to store the next writing instant.
scalar finalTime
Final time (final time of the simulation and consequently of the acquisition of the snapshots)
Eigen::MatrixXi inletPatch
Matrix that contains informations about the inlet boundaries without specifing the direction Rows = N...
void writeMu(List< scalar > mu_now)
Write out a list of scalar corresponding to the parameters used in the truthSolve.
Eigen::MatrixXd mu_samples
Matrix of parameters to be used for PODI, where each row corresponds to a sample point....
label counter
Counter used for the output of the full order solutions.
void assignBC(volVectorField &s, label BC_ind, Vector< double > &value)
Assign Boundary Condition to a volVectorField.
bool offline
Boolean variable, it is 1 if the Offline phase has already been computed, else 0.
IOdictionary * ITHACAdict
dictionary to store input output infos
Eigen::MatrixXd mu
Row matrix of parameters.
autoPtr< argList > _args
argList
bool podex
Boolean variable, it is 1 if the POD has already been computed, else 0.
void truthSolve()
Perform a TruthSolve.
bool supex
Boolean variable to check the existence of the supremizer modes.
Definition steadyNS.H:256
autoPtr< surfaceScalarField > _phi
Flux.
Definition steadyNS.H:293
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
Definition steadyNS.H:86
autoPtr< fv::options > _fvOptions
fvOptions
Definition steadyNS.H:287
autoPtr< Time > _runTime
Time.
Definition steadyNS.H:290
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
Definition steadyNS.H:89
autoPtr< fvMesh > _mesh
Mesh.
Definition steadyNS.H:281
autoPtr< singlePhaseTransportModel > _laminarTransport
Laminar transport (used by turbulence model)
Definition steadyNS.H:302
ITHACAparameters * para
Definition steadyNS.H:82
autoPtr< IOMRFZoneList > _MRF
MRF variable.
Definition steadyNS.H:305
autoPtr< volVectorField > _U
Velocity field.
Definition steadyNS.H:263
word bcMethod
Boundary Method.
Definition steadyNS.H:317
autoPtr< volScalarField > _p
Pressure field.
Definition steadyNS.H:260
word method
Definition unsteadyNS.H:90
label counter2
Definition unsteadyNS.H:88
autoPtr< incompressible::turbulenceModel > turbulence
Turbulence model.
Definition unsteadyNS.H:76
Eigen::MatrixXd timeBCoff
Definition unsteadyNS.H:96
word timeDerivativeSchemeOrder
Definition unsteadyNS.H:99
autoPtr< pimpleControl > _pimple
pimpleControl
Definition unsteadyNS.H:73
unsteadyNS()
Construct Null.
Definition unsteadyNS.C:39
word timedepbcMethod
Time-dependent Boundary Method.
Definition unsteadyNS.H:93
void exportSolution(GeometricField< Type, PatchField, GeoMesh > &s, fileName subfolder, fileName folder, word fieldName)
Export a field to file in a certain folder and subfolder.
void exportMatrix(Eigen::Matrix< T, -1, dim > &matrix, word Name, word type, word folder)
Export the reduced matrices in numpy (type=python), matlab (type=matlab) and txt (type=eigen) format ...
bool check_pod()
Check if the POD data folder "./ITHACAoutput/POD" exists.
bool check_off()
Check if the offline data folder "./ITHACAoutput/Offline" exists.
bool check_sup()
Check if the supremizer folder exists.
surfaceScalarField & phi
volVectorField & U
pimpleControl & pimple
volScalarField & p
singlePhaseTransportModel & laminarTransport
label i
Definition pEqn.H:46
Header file of the unsteadyNS class.