Loading...
Searching...
No Matches
MyIcoSolver.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 "MyIcoSolver.H"
32
35
36// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * //
37
38// Construct Null
40
41// Construct from zero
42MyIcoSolver::MyIcoSolver(int argc, char* argv[])
43 :
44 UnsteadyProblem()
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 _piso = autoPtr<pisoControl>
60 (
61 new pisoControl
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"
79 para = ITHACAparameters::getInstance(mesh, runTime);
82 //supex = ITHACAutilities::check_sup();
83}
84
85// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86
87void MyIcoSolver::truthSolve(List<scalar> mu_now, fileName folder)
88{
89 Time& runTime = _runTime();
90 surfaceScalarField& phi = _phi();
91 fvMesh& mesh = _mesh();
92#include "initContinuityErrs.H"
93 fv::options& fvOptions = _fvOptions();
94 pisoControl& piso = _piso();
95 volScalarField& p = _p();
96 volVectorField& U = _U();
97 IOMRFZoneList& MRF = _MRF();
98 singlePhaseTransportModel& laminarTransport = _laminarTransport();
99 instantList Times = runTime.times();
100 runTime.setEndTime(finalTime);
101 // Perform a TruthSolve
102 runTime.setTime(Times[1], 1);
103 runTime.setDeltaT(timeStep);
105 /*
106 // Set time-dependent velocity BCs for initial condition
107 if (timedepbcMethod == "yes")
108 {
109 for (label i = 0; i < inletPatch.rows(); i++)
110 {
111 Vector<double> inl(0, 0, 0);
112
113 for (label j = 0; j < inl.size(); j++)
114 {
115 inl[j] = timeBCoff(i* inl.size() + j, 0);
116 }
117
118 assignBC(U, inletPatch(i, 0), inl);
119 }
120 }
121
122 // Export and store the initial conditions for velocity and pressure
123 ITHACAstream::exportSolution(U, name(counter), folder);
124 ITHACAstream::exportSolution(p, name(counter), folder);
125 std::ofstream of(folder + name(counter) + "/" +
126 runTime.timeName());
127 Ufield.append(U.clone());
128 Pfield.append(p.clone());
129 counter++;
130 nextWrite += writeEvery;*/
131
132 // Start the time loop
133 while (runTime.run())
134 {
135#include "readTimeControls.H"
136#include "CourantNo.H"
137#include "setDeltaT.H"
138 runTime.setEndTime(finalTime);
139 runTime++;
140 Info << "Time = " << runTime.timeName() << nl << endl;
141 /*
142 // Set time-dependent velocity BCs
143 if (timedepbcMethod == "yes")
144 {
145 for (label i = 0; i < inletPatch.rows(); i++)
146 {
147 Vector<double> inl(0, 0, 0);
148
149 for (label j = 0; j < inl.size(); j++)
150 {
151 inl[j] = timeBCoff(i* inl.size() + j, counter2);
152 }
153
154 assignBC(U, inletPatch(i, 0), inl);
155 }
156
157 counter2 ++;
158 }*/
159
160 // --- Pressure-velocity PIMPLE corrector loop
161 while (piso.loop())
162 {
163#include "UEqn.H"
164
165 // --- Pressure corrector loop
166 while (piso.correct())
167 {
168#include "pEqn.H"
169 }
170
171 if (piso.turbCorr())
172 {
173 laminarTransport.correct();
174 turbulence->correct();
175 }
176 }
177
178 Info << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
179 << " ClockTime = " << runTime.elapsedClockTime() << " s"
180 << nl << endl;
181
182 if (checkWrite(runTime))
183 {
184 ITHACAstream::exportSolution(U, name(counter), folder);
185 ITHACAstream::exportSolution(p, name(counter), folder);
186 Ufield.append(U.clone());
187 Pfield.append(p.clone());
188 counter++;
190 /*
191 writeMu(mu_now);
192 // --- Fill in the mu_samples with parameters (time, mu) to be used for the PODI sample points
193 mu_samples.conservativeResize(mu_samples.rows() + 1, mu_now.size() + 1);
194 mu_samples(mu_samples.rows() - 1, 0) = atof(runTime.timeName().c_str());
195
196 for (label i = 0; i < mu_now.size(); i++)
197 {
198 mu_samples(mu_samples.rows() - 1, i + 1) = mu_now[i];
199 }*/
200 }
201 }
202
203 /*
204 // Resize to Unitary if not initialized by user (i.e. non-parametric problem)
205 if (mu.cols() == 0)
206 {
207 mu.resize(1, 1);
208 }
209
210 if (mu_samples.rows() == counter* mu.cols())
211 {
212 ITHACAstream::exportMatrix(mu_samples, "mu_samples", "eigen",
213 folder);
214 }*/
215}
216
218{
219 //_runTime().objectRegistry::clear();
220 //_mesh().objectRegistry::clear();
221 // _mesh.clear();
222 // _runTime.clear();
223 //_simple.clear();
224 _p.clear();
225 _U.clear();
226 _phi.clear();
227 turbulence.clear();
228 _fvOptions.clear();
229 argList& args = _args();
230 Time& runTime = _runTime();
231 runTime.setTime(0, 1);
232 Foam::fvMesh& mesh = _mesh();
233 pisoControl& piso = _piso();
234 Info << "ReReading field p\n" << endl;
235 _p = autoPtr<volScalarField>
236 (
237 new volScalarField
238 (
239 IOobject
240 (
241 "p",
242 runTime.timeName(),
243 mesh,
244 IOobject::MUST_READ,
245 IOobject::AUTO_WRITE
246 ),
247 mesh
248 )
249 );
250 volScalarField& p = _p();
251 Info << "ReReading field U\n" << endl;
252 _U = autoPtr<volVectorField>
253 (
254 new volVectorField
255 (
256 IOobject
257 (
258 "U",
259 runTime.timeName(),
260 mesh,
261 IOobject::MUST_READ,
262 IOobject::AUTO_WRITE
263 ),
264 mesh
265 )
266 );
267 volVectorField& U = _U();
268 Info << "ReReading/calculating face flux field phi\n" << endl;
269 _phi = autoPtr<surfaceScalarField>
270 (
271 new surfaceScalarField
272 (
273 IOobject
274 (
275 "phi",
276 runTime.timeName(),
277 mesh,
278 IOobject::READ_IF_PRESENT,
279 IOobject::AUTO_WRITE
280 ),
281 linearInterpolate(U) & mesh.Sf()
282 )
283 );
284 surfaceScalarField& phi = _phi();
285 pRefCell = 0;
286 pRefValue = 0.0;
287 setRefCell(p, piso.dict(), pRefCell, pRefValue);
288 _laminarTransport = autoPtr<singlePhaseTransportModel>
289 (
290 new singlePhaseTransportModel( U, phi )
291 );
292 singlePhaseTransportModel& laminarTransport = _laminarTransport();
293 turbulence = autoPtr<incompressible::turbulenceModel>
294 (
295 incompressible::turbulenceModel::New(U, phi, laminarTransport)
296 );
297 _MRF = autoPtr<IOMRFZoneList>
298 (
299 new IOMRFZoneList(mesh)
300 );
301 _fvOptions = autoPtr<fv::options>(new fv::options(mesh));
302 turbulence->validate();
303}
Header file of the unsteadyNS class.
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
autoPtr< pisoControl > _piso
pimpleControl
Definition MyIcoSolver.H:73
void restart()
set U and P back to the values into the 0 folder
autoPtr< incompressible::turbulenceModel > turbulence
Turbulence model.
Definition MyIcoSolver.H:76
MyIcoSolver()
Construct Null.
Definition MyIcoSolver.C:39
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).
label counter
Counter used for the output of the full order solutions.
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
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.
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
scalar pRefValue
Reference pressure value.
Definition steadyNS.H:320
label pRefCell
Reference pressure cell.
Definition steadyNS.H:317
autoPtr< IOMRFZoneList > _MRF
MRF variable.
Definition steadyNS.H:314
autoPtr< volVectorField > _U
Velocity field.
Definition steadyNS.H:272
autoPtr< volScalarField > _p
Pressure field.
Definition steadyNS.H:269
void exportSolution(GeometricField< Type, PatchField, GeoMesh > &s, fileName subfolder, fileName folder, word fieldName)
Export a field to file in a certain folder and subfolder.
bool check_pod()
Check if the POD data folder "./ITHACAoutput/POD" exists.
bool check_off()
Check if the offline data folder "./ITHACAoutput/Offline" exists.