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 method = ITHACAdict->lookupOrDefault<word>("method", "supremizer");
81 M_Assert(method == "supremizer"
82 || method == "PPE",
83 "The method must be set to supremizer or PPE in ITHACAdict");
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 timedepbcMethod = ITHACAdict->lookupOrDefault<word>("timedepbcMethod", "no");
88 M_Assert(timedepbcMethod == "yes" || timedepbcMethod == "no",
89 "The BC method can be set to yes or no");
91 ITHACAdict->lookupOrDefault<word>("timeDerivativeSchemeOrder", "second");
93 || timeDerivativeSchemeOrder == "second",
94 "The time derivative approximation must be set to either first or second order scheme in ITHACAdict");
98}
99
100// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101
102void unsteadyNS::truthSolve(List<scalar> mu_now, fileName folder)
103{
104 Time& runTime = _runTime();
105 surfaceScalarField& phi = _phi();
106 fvMesh& mesh = _mesh();
107#include "initContinuityErrs.H"
108 fv::options& fvOptions = _fvOptions();
109 pimpleControl& pimple = _pimple();
110 volScalarField& p = _p();
111 volVectorField& U = _U();
112 IOMRFZoneList& MRF = _MRF();
113 singlePhaseTransportModel& laminarTransport = _laminarTransport();
114 instantList Times = runTime.times();
115 runTime.setEndTime(finalTime);
116 // Perform a TruthSolve
117 runTime.setTime(Times[1], 1);
118 runTime.setDeltaT(timeStep);
120
121 // Set time-dependent velocity BCs for initial condition
122 if (timedepbcMethod == "yes")
123 {
124 for (label i = 0; i < inletPatch.rows(); i++)
125 {
126 Vector<double> inl(0, 0, 0);
127
128 for (label j = 0; j < inl.size(); j++)
129 {
130 inl[j] = timeBCoff(i * inl.size() + j, 0);
131 }
132
133 assignBC(U, inletPatch(i, 0), inl);
134 }
135 }
136
137 // Export and store the initial conditions for velocity and pressure
138 ITHACAstream::exportSolution(U, name(counter), folder);
139 ITHACAstream::exportSolution(p, name(counter), folder);
140 std::ofstream of(folder + name(counter) + "/" +
141 runTime.timeName());
142 Ufield.append(U.clone());
143 Pfield.append(p.clone());
144 counter++;
146
147 // Start the time loop
148 while (runTime.run())
149 {
150#include "readTimeControls.H"
151#include "CourantNo.H"
152#include "setDeltaT.H"
153 runTime.setEndTime(finalTime);
154 runTime++;
155 Info << "Time = " << runTime.timeName() << nl << endl;
156
157 // Set time-dependent velocity BCs
158 if (timedepbcMethod == "yes")
159 {
160 for (label i = 0; i < inletPatch.rows(); i++)
161 {
162 Vector<double> inl(0, 0, 0);
163
164 for (label j = 0; j < inl.size(); j++)
165 {
166 inl[j] = timeBCoff(i * inl.size() + j, counter2);
167 }
168
169 assignBC(U, inletPatch(i, 0), inl);
170 }
171
172 counter2 ++;
173 }
174
175 // --- Pressure-velocity PIMPLE corrector loop
176 while (pimple.loop())
177 {
178#include "UEqn.H"
179
180 // --- Pressure corrector loop
181 while (pimple.correct())
182 {
183#include "pEqn.H"
184 }
185
186 if (pimple.turbCorr())
187 {
188 laminarTransport.correct();
189 turbulence->correct();
190 }
191 }
192
193 Info << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
194 << " ClockTime = " << runTime.elapsedClockTime() << " s"
195 << nl << endl;
196
197 if (checkWrite(runTime))
198 {
199 ITHACAstream::exportSolution(U, name(counter), folder);
200 ITHACAstream::exportSolution(p, name(counter), folder);
201 Ufield.append(U.clone());
202 Pfield.append(p.clone());
203 counter++;
205 writeMu(mu_now);
206 // --- Fill in the mu_samples with parameters (time, mu) to be used for the PODI sample points
207 mu_samples.conservativeResize(mu_samples.rows() + 1, mu_now.size() + 1);
208 mu_samples(mu_samples.rows() - 1, 0) = atof(runTime.timeName().c_str());
209
210 for (label i = 0; i < mu_now.size(); i++)
211 {
212 mu_samples(mu_samples.rows() - 1, i + 1) = mu_now[i];
213 }
214 }
215 }
216
217 // Resize to Unitary if not initialized by user (i.e. non-parametric problem)
218 if (mu.cols() == 0)
219 {
220 mu.resize(1, 1);
221 }
222
223 if (mu_samples.rows() == counter * mu.cols())
224 {
225 ITHACAstream::exportMatrix(mu_samples, "mu_samples", "eigen",
226 folder);
227 }
228}
Foam::fvMesh & mesh
Definition createMesh.H:47
Foam::Time & runTime
Definition createTime.H:33
#define M_Assert(Expr, Msg)
fv::options & fvOptions
Definition NLsolve.H:25
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:265
autoPtr< surfaceScalarField > _phi
Flux.
Definition steadyNS.H:302
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:296
autoPtr< Time > _runTime
Time.
Definition steadyNS.H:299
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
Definition steadyNS.H:89
autoPtr< fvMesh > _mesh
Mesh.
Definition steadyNS.H:290
autoPtr< singlePhaseTransportModel > _laminarTransport
Laminar transport (used by turbulence model)
Definition steadyNS.H:311
ITHACAparameters * para
Definition steadyNS.H:82
autoPtr< IOMRFZoneList > _MRF
MRF variable.
Definition steadyNS.H:314
autoPtr< volVectorField > _U
Velocity field.
Definition steadyNS.H:272
word bcMethod
Boundary Method.
Definition steadyNS.H:326
autoPtr< volScalarField > _p
Pressure field.
Definition steadyNS.H:269
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
volScalarField & p
pimpleControl & pimple
singlePhaseTransportModel & laminarTransport
label i
Definition pEqn.H:46
Header file of the unsteadyNS class.