Loading...
Searching...
No Matches
CompressibleSteadyNS.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
34
36#include "viscosityModel.H"
37
38
39// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * //
40
41// Constructor
43
45{
46 //#include "postProcess.H"
47 _args = autoPtr<argList>
48 (
49 new argList(argc, argv)
50 );
51
52 if (!_args->checkRootCase())
53 {
54 Foam::FatalError.exit();
55 }
56
57 argList& args = _args();
58#include "createTime.H"
59#include "createMesh.H"
60 _simple = autoPtr<simpleControl>
61 (
62 new simpleControl
63 (
64 mesh
65 )
66 );
67 simpleControl& simple = _simple();
68#include "createFields.H"
69 //#include "createFvOptions.H"
70#include "initContinuityErrs.H"
72 turbulence->validate();
73 ITHACAdict = new IOdictionary
74 (
75 IOobject
76 (
77 "ITHACAdict",
78 runTime.system(),
79 mesh,
80 IOobject::MUST_READ,
81 IOobject::NO_WRITE
82 )
83 );
87 middleExport = para->ITHACAdict->lookupOrDefault<bool>("middleExport", true);
88 middleStep = para->ITHACAdict->lookupOrDefault<label>("middleStep", 20);
89}
90
91
92// * * * * * * * * * * * * * * Full Order Methods * * * * * * * * * * * * * * //
93
94// Method to perform a truthSolve
95
97{
98 Time& runTime = _runTime();
99 volVectorField& U = _U();
100 volScalarField& p = pThermo().p();
101 volScalarField& E = pThermo().he();
102 simpleControl& simple = _simple();
103 volScalarField _nut(turbulence->nut());
104#include "NLsolve.H"
105 // ITHACAstream::exportSolution(U, name(counter), "./ITHACAoutput/Offline/");
106 // ITHACAstream::exportSolution(p, name(counter), "./ITHACAoutput/Offline/");
107 // ITHACAstream::exportSolution(E, name(counter), "./ITHACAoutput/Offline/");
108 // ITHACAstream::exportSolution(_nut, name(counter), "./ITHACAoutput/Offline/");
109 // Ufield.append(U);
110 // Pfield.append(p);
111 // Efield.append(E);
112 // nutFields.append(_nut);
113 counter++;
114}
115
117{
118 const volScalarField& mu = pThermo().mu();
119 volScalarField& mu_field = const_cast<volScalarField&>(mu);
120 this->assignIF(mu_field, mu_new);
121
122 for (int i = 0; i < mu_field.boundaryFieldRef().size(); i++)
123 {
124 this->assignBC(mu_field, i, mu_new);
125 }
126}
127
128fvVectorMatrix CompressibleSteadyNS::getNLTerm(volVectorField& U)
129{
130 surfaceScalarField& phi = _phi();
131 fvVectorMatrix NLTerm = fvm::div(phi, U);
132 return NLTerm;
133}
134
135fvVectorMatrix CompressibleSteadyNS::getViscTerm(volVectorField& U)
136{
137 volScalarField& rho = _rho();
138 volScalarField nuEff = turbulence->nuEff();
139 //fvVectorMatrix viscTerm = turbulence->divDevRhoReff(U);
140 fvVectorMatrix viscTerm = - fvc::div((rho * nuEff) * dev2(T(fvc::grad(
141 U)))) - fvm::laplacian(rho * nuEff, U);
142 return viscTerm;
143}
144
145volVectorField CompressibleSteadyNS::getGradP(volScalarField& p)
146{
147 volVectorField gradP = fvc::grad(p);
148 return gradP;
149}
150
151
152fvVectorMatrix CompressibleSteadyNS::getUmatrix(volVectorField&
153 U)//, Vector<double>& uresidual_v)
154{
155 volScalarField& rho = _rho();
156 fv::options& fvOptions = _fvOptions();
157 Ueqn_global.reset(new fvVectorMatrix(getNLTerm(U)
158 + getViscTerm(U)
159 ==
160 fvOptions(rho, U)
161 ));
162 Ueqn_global().relax();
163 fvOptions.constrain(Ueqn_global());
164 return Ueqn_global();
165}
166
167fvScalarMatrix CompressibleSteadyNS::getFluxTerm()
168{
169 volScalarField& he = pThermo().he();
170 surfaceScalarField& phi = _phi();
171 fvScalarMatrix fluxTerm = fvm::div(phi, he);
172 return fluxTerm;
173}
174
175volScalarField CompressibleSteadyNS::getKinEnTerm(volVectorField& U,
176 volScalarField& p)
177{
178 surfaceScalarField& phi = _phi();
179 volScalarField& rho = _rho();
180 volScalarField kinEn = fvc::div(phi, volScalarField("Ekp",
181 0.5 * magSqr(U) + p / rho));
182 return kinEn;
183}
184
185fvScalarMatrix CompressibleSteadyNS::getDiffTerm()
186{
187 volScalarField& he = pThermo().he();
188 fvScalarMatrix diffTerm = fvm::laplacian(turbulence->alphaEff(), he);
189 return diffTerm;
190}
191
192fvScalarMatrix CompressibleSteadyNS::getEmatrix(volVectorField& U,
193 volScalarField& p)
194{
195 volScalarField& he = pThermo().he();
196 volScalarField& rho = _rho();
197 fv::options& fvOptions = _fvOptions();
198 Eeqn_global.reset(new fvScalarMatrix(
199 getFluxTerm() + getKinEnTerm(U, p) - getDiffTerm()
200 ==
201 fvOptions(rho, he)
202 ));
203 Eeqn_global().relax();
204 fvOptions.constrain(Eeqn_global());
205 return Eeqn_global();
206}
207
208surfaceScalarField CompressibleSteadyNS::getPhiHbyA(fvVectorMatrix& Ueqn,
209 volVectorField& U, volScalarField& p)
210{
211 volScalarField& rho = _rho();
212 volScalarField rAU(1.0 /
213 Ueqn.A()); // Inverse of the diagonal part of the U equation matrix
214 HbyA.reset(new volVectorField(constrainHbyA(rAU * Ueqn.H(), U,
215 p))); // H is the extra diagonal part summed to the r.h.s. of the U equation
216 phiHbyA.reset(new surfaceScalarField("phiHbyA",
217 fvc::interpolate(rho)*fvc::flux(HbyA())));
218 return phiHbyA;
219}
220
221volScalarField CompressibleSteadyNS::getDivPhiHbyA(fvVectorMatrix& Ueqn,
222 volVectorField& U, volScalarField& p)
223{
224 volScalarField divPhiHbyA = fvc::div(getPhiHbyA(Ueqn, U, p));
225 return divPhiHbyA;
226}
227
228surfaceScalarField CompressibleSteadyNS::getRhorAUf(fvVectorMatrix& Ueqn)
229{
230 volScalarField& rho = _rho();
231 volScalarField rAU(1.0 /
232 Ueqn.A()); // Inverse of the diagonal part of the U equation matrix
233 rhorAUf.reset(new surfaceScalarField("rhorAUf", fvc::interpolate(rho * rAU)));
234 return rhorAUf;
235}
236
237fvScalarMatrix CompressibleSteadyNS::getPoissonTerm(fvVectorMatrix& Ueqn,
238 volScalarField& p)
239{
240 fvScalarMatrix poissonTerm = fvm::laplacian(getRhorAUf(Ueqn), p);
241 return poissonTerm;
242}
243
244fvScalarMatrix CompressibleSteadyNS::getPmatrix(fvVectorMatrix& Ueqn,
245 volVectorField& U, volScalarField& p)
246{
247 volScalarField& rho = _rho();
248 fv::options& fvOptions = _fvOptions();
249 volScalarField& psi = _psi();
250 pressureControl& pressureControl = _pressureControl();
251 Peqn_global.reset(new fvScalarMatrix(
252 getDivPhiHbyA(Ueqn, U, p)
253 - getPoissonTerm(Ueqn, p)
254 ==
255 fvOptions(psi, p, rho.name())
256 ));
257 Peqn_global().setReference
258 (
259 pressureControl.refCell(),
260 pressureControl.refValue()
261 );
262 return Peqn_global();
263}
264
266{
267 _runTime().objectRegistry::clear();
268 _mesh().objectRegistry::clear();
269 // _mesh.clear();
270 // _runTime.clear();
271 _simple.clear();
272 pThermo.clear();
273 _p.clear();
274 _rho.clear();
275 _E.clear();
276 _U.clear();
277 _phi.clear();
278 turbulence.clear();
279 _initialMass.clear();
280 _pressureControl.clear();
281 _psi.clear();
282 _fvOptions.clear();
283 argList& args = _args();
284 Info << "ReCreate time\n" << Foam::endl;
285 // _runTime = autoPtr<Foam::Time>( new Foam::Time( Foam::Time::controlDictName,
286 // args ) );
287 // std::cerr << "File: CompressibleSteadyNS.C, Line: 281" << endl;
288 Time& runTime = _runTime();
289 runTime.setTime(0, 1);
290 // _mesh = autoPtr<fvMesh>
291 // (
292 // new fvMesh
293 // (
294 // IOobject
295 // (
296 // fvMesh::defaultRegion,
297 // runTime.timeName(),
298 // runTime,
299 // IOobject::MUST_READ
300 // )
301 // )
302 // );
303 Foam::fvMesh& mesh = _mesh();
304 _simple = autoPtr<simpleControl>
305 (
306 new simpleControl
307 (
308 mesh
309 )
310 );
311 simpleControl& simple = _simple();
312 pThermo = autoPtr<fluidThermo>
313 (
314 fluidThermo::New(mesh)
315 );
316 fluidThermo& thermo = pThermo();
317 thermo.validate(_args().executable(), "h", "e");
318 _p = autoPtr<volScalarField>
319 (
320 new volScalarField(thermo.p())
321 );
322 volScalarField& p = thermo.p();
323 _rho = autoPtr<volScalarField>
324 (
325 new volScalarField
326 (
327 IOobject
328 (
329 "rho",
330 runTime.timeName(),
331 mesh,
332 IOobject::READ_IF_PRESENT,
333 IOobject::AUTO_WRITE
334 ),
335 thermo.rho()
336 )
337 );
338 volScalarField& rho = _rho();
339 _E = autoPtr<volScalarField>
340 (
341 new volScalarField(thermo.he())
342 );
343 Info << "ReReading field U \n" << endl;
344 _U = autoPtr<volVectorField>
345 (
346 new volVectorField
347 (
348 IOobject
349 (
350 "U",
351 runTime.timeName(),
352 mesh,
353 IOobject::MUST_READ,
354 IOobject::AUTO_WRITE
355 ),
356 mesh
357 )
358 );
359 volVectorField& U = _U();
360 Info << "ReReading/calculating face flux field phi\n" << endl;
361 _phi = autoPtr<surfaceScalarField>
362 (
363 new surfaceScalarField
364 (
365 IOobject
366 (
367 "phi",
368 runTime.timeName(),
369 mesh,
370 IOobject::READ_IF_PRESENT,
371 IOobject::AUTO_WRITE
372 ),
373 linearInterpolate(rho * U) & mesh.Sf()
374 )
375 );
376 surfaceScalarField& phi = _phi();
377 _pressureControl = autoPtr<pressureControl>
378 (
379 new pressureControl(p, rho, _simple().dict())
380 );
381 mesh.setFluxRequired(p.name());
382 Info << "ReCreating turbulence model\n" << endl;
383 turbulence = autoPtr<compressible::turbulenceModel>
384 (
385 compressible::turbulenceModel::New
386 (
387 rho,
388 U,
389 phi,
390 thermo
391 )
392 );
393 _initialMass = autoPtr<dimensionedScalar>
394 (
395 new dimensionedScalar(fvc::domainIntegrate(rho))
396 );
397 _psi = autoPtr<volScalarField>
398 (
399 new volScalarField(thermo.psi())
400 );
401 _fvOptions = autoPtr<fv::options>(new fv::options(mesh));
402#include "initContinuityErrs.H"
403 //turbulence->validate();
404}
Header file of the steadyNS class.
CompressibleSteadyNS()
Null constructor.
void changeViscosity(double mu_new)
Function to change the viscosity.
bool middleExport
Export also intermediate fields.
label middleStep
Distancing between intermediate steps (for turbulent case only).
void restart()
set all variables back to the values into the 0 folder
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.
autoPtr< volScalarField > _nut
Eddy viscosity field.
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.
void assignIF(T &s, G &value)
Assign internal field condition.
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
autoPtr< simpleControl > _simple
simpleControl
Definition steadyNS.H:293
autoPtr< fv::options > _fvOptions
fvOptions
Definition steadyNS.H:296
autoPtr< Time > _runTime
Time.
Definition steadyNS.H:299
autoPtr< fvMesh > _mesh
Mesh.
Definition steadyNS.H:290
autoPtr< volVectorField > _U
Velocity field.
Definition steadyNS.H:272
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.