45 _args = autoPtr<argList>
47 new argList(argc, argv)
50 if (!
_args->checkRootCase())
52 Foam::FatalError.exit();
55 argList& args =
_args();
58 _pimple = autoPtr<pimpleControl>
65#pragma GCC diagnostic push
66#pragma GCC diagnostic ignored "-Wunused-variable"
68#pragma GCC diagnostic pop
84#include "initContinuityErrs.H"
85 volScalarField&
p =
_p();
86 volVectorField&
U =
_U();
88 volScalarField&
T =
_T();
91 volScalarField&
gh =
_gh();
92 surfaceScalarField&
ghf =
_ghf();
93 surfaceScalarField&
phi =
_phi();
96 IOMRFZoneList& MRF =
_MRF();
100 dimensionedScalar&
Pr =
_Pr();
101 dimensionedScalar&
Prt =
_Prt();
102 instantList Times =
runTime.times();
112 std::ofstream of(
"./ITHACAoutput/Offline/" + name(
counter) +
"/" +
124#include "readTimeControls.H"
125#include "CourantNo.H"
126#include "setDeltaT.H"
128 Info <<
"Time = " <<
runTime.timeName() << nl << endl;
149 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
150 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
159 std::ofstream of(
"./ITHACAoutput/Offline/" + name(
counter) +
"/" +
176#include "initContinuityErrs.H"
179 volScalarField&
p =
_p();
180 volVectorField&
U =
_U();
182 volScalarField&
T =
_T();
187 volScalarField&
gh =
_gh();
188 surfaceScalarField&
ghf =
_ghf();
189 surfaceScalarField&
phi =
_phi();
192 IOMRFZoneList& MRF =
_MRF();
199 dimensionedScalar&
Pr =
_Pr();
200 dimensionedScalar&
Prt =
_Prt();
201 instantList Times =
runTime.times();
211 std::ofstream of(folder + name(
counter) +
"/" +
runTime.timeName());
218#include "readTimeControls.H"
219#include "CourantNo.H"
220#include "setDeltaT.H"
222 Info <<
"Time = " <<
runTime.timeName() << nl << endl;
243 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
244 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
253 std::ofstream of(folder + name(
counter) +
"/" +
runTime.timeName());
267 scalar diffnow = mag(
nextWrite - atof(timeObject.timeName().c_str()));
268 scalar diffnext = mag(
nextWrite - atof(timeObject.timeName().c_str()) -
269 timeObject.deltaTValue());
271 if ( diffnow < diffnext)
284 PtrList<volScalarField> P_sup;
290 else if (type ==
"snapshots")
296 std::cout <<
"You must specify the variable type with either snapshots or modes"
303 volVectorField
U =
_U();
315 dimensionedVector(
"zero",
U.dimensions(), vector::zero)
318 if (type ==
"snapshots")
322 else if (type ==
"modes")
332 volVectorField
U =
_U();
344 dimensionedVector(
"zero",
U.dimensions(), vector::zero)
346 dimensionedScalar nu_fake
349 dimensionSet(0, 2, -1, 0, 0, 0, 0),
352 Vector<double>
v(0, 0, 0);
354 for (label
i = 0;
i < Usup.boundaryField().size();
i++)
361 if (type ==
"snapshots")
363 for (label
i = 0;
i < P_sup.size();
i++)
365 fvVectorMatrix u_sup_eqn
367 - fvm::laplacian(nu_fake, Usup)
371 u_sup_eqn == fvc::grad(P_sup[
i])
378 system(
"ln -s ../../constant ./ITHACAoutput/supfield/constant");
379 systemRet += system(
"ln -s ../../0 ./ITHACAoutput/supfield/0");
380 systemRet += system(
"ln -s ../../system ./ITHACAoutput/supfield/system");
384 Info <<
"System Command Failed in steadyNS.C" << endl;
392 fvVectorMatrix u_sup_eqn
394 - fvm::laplacian(nu_fake, Usup)
405 system(
"ln -s ../../constant ./ITHACAoutput/supremizer/constant");
406 systemRet += system(
"ln -s ../../0 ./ITHACAoutput/supremizer/0");
407 systemRet += system(
"ln -s ../../system ./ITHACAoutput/supremizer/system");
411 Info <<
"System Command Failed in steadyNS.C" << endl;
429 volScalarField&
T =
_T();
430 volVectorField&
U =
_U();
431 surfaceScalarField&
phi =
_phi();
432 phi = linearInterpolate(
U) &
mesh.Sf();
439 dimensionedScalar&
Pr =
_Pr();
440 dimensionedScalar&
Prt =
_Prt();
442 volScalarField Tlift(
"Tlift" + name(k),
T);
443 instantList Times =
runTime.times();
445 Info <<
"Solving a lifting Problem" << endl;
449 alphat.correctBoundaryConditions();
452 for (label j = 0; j <
T.boundaryField().size(); j++)
459 else if (
T.boundaryField()[BCind].type() ==
"fixedValue")
469 while (
simple.correctNonOrthogonal())
477 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
478 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
499 word M_str =
"M_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
511 word B_str =
"B_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
523 word C_str =
"C_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
535 word K_str =
"K_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
547 word H_str =
"H_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
582 word P_str =
"P_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
600 for (label k = 0; k <
liftfield.size(); k++)
608 for (label k = 0; k <
NUmodes; k++)
634 for (label k = 0; k <
NTmodes; k++)
663 word M_str =
"M_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
675 word B_str =
"B_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
688 "./ITHACAoutput/Matrices/");
689 word C_str =
"C_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
701 word K_str =
"K_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
713 word H_str =
"H_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
760 word P_str =
"P_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
778 for (label k = 0; k <
liftfield.size(); k++)
786 for (label k = 0; k <
NUmodes; k++)
812 for (label k = 0; k <
NTmodes; k++)
843 Eigen::MatrixXd
K_matrix(K1size, K2size);
844 dimensionedVector
g =
_g();
847 for (label
i = 0;
i < K1size;
i++)
849 for (label j = 0; j < K2size; j++)
852 fvc::reconstruct(fvc::snGrad(
Prghmodes[j]) *
857 if (Pstream::parRun())
859 reduce(
K_matrix, sumOp<Eigen::MatrixXd>());
862 if (Pstream::master())
880 Eigen::MatrixXd
P_matrix(P1size, P2size);
883 for (label
i = 0;
i < P1size;
i++)
885 for (label j = 0; j < P2size; j++)
892 if (Pstream::parRun())
894 reduce(
P_matrix, sumOp<Eigen::MatrixXd>());
897 if (Pstream::master())
913 Eigen::MatrixXd
H_matrix(H1size, H2size);
916 dimensionedVector
g =
_g();
918 surfaceScalarField&
ghf =
_ghf();
921 for (label
i = 0;
i < H1size;
i++)
923 for (label j = 0; j < H2size; j++)
931 if (Pstream::parRun())
933 reduce(
H_matrix, sumOp<Eigen::MatrixXd>());
936 if (Pstream::master())
954 Eigen::MatrixXd
HP_matrix(H1size, H2size);
958 dimensionedVector
g =
_g();
959 volScalarField&
gh =
_gh();
960 surfaceScalarField&
ghf =
_ghf();
963 for (label
i = 0;
i < H1size;
i++)
965 for (label j = 0; j < H2size; j++)
967 HP_matrix(
i, j) = fvc::domainIntegrate(fvc::reconstruct(fvc::snGrad(
975 if (Pstream::parRun())
977 reduce(
HP_matrix, sumOp<Eigen::MatrixXd>());
980 if (Pstream::master())
1001 for (label j = 0; j < Qsizet; j++)
1006 for (label
i = 0;
i < Qsizet;
i++)
1008 for (label j = 0; j < Qsize; j++)
1010 for (label k = 0; k < Qsizet; k++)
1018 if (Pstream::parRun())
1020 reduce(
Q_matrix[
i], sumOp<Eigen::MatrixXd>());
1024 if (Pstream::master())
1041 Eigen::MatrixXd
Y_matrix(Ysize, Ysize);
1043 for (label
i = 0;
i < Ysize;
i++)
1045 for (label j = 0; j < Ysize; j++)
1048 dimensionedScalar(
"1", dimless, 1),
L_T_modes[j])).value();
1052 if (Pstream::parRun())
1054 reduce(
Y_matrix, sumOp<Eigen::MatrixXd>());
1057 if (Pstream::master())
1072 Eigen::MatrixXd
W_matrix(Wsize, Wsize);
1074 for (label
i = 0;
i < Wsize;
i++)
1076 for (label j = 0; j < Wsize; j++)
1082 if (Pstream::parRun())
1084 reduce(
W_matrix, sumOp<Eigen::MatrixXd>());
1087 if (Pstream::master())
1101 for (label k = 0; k <
inletIndex.rows(); k++)
1104 surfaceScalarField&
phi =
_phi();
1107 volVectorField&
U =
_U();
1112 IOMRFZoneList& MRF =
_MRF();
1114 volVectorField Ulift(
"Ulift" + name(k),
U);
1115 instantList Times =
runTime.times();
1117 pisoControl potentialFlow(
mesh,
"potentialFlow");
1118 Info <<
"Solving a lifting Problem" << endl;
1119 Vector<double> v1(0, 0, 0);
1121 Vector<double>
v0(0, 0, 0);
1123 for (label j = 0; j <
U.boundaryField().size(); j++)
1129 else if (
U.boundaryField()[BCind].type() ==
"fixedValue")
1138 phi = linearInterpolate(Ulift) &
mesh.Sf();
1141 Info <<
"Constructing velocity potential field Phi\n" << endl;
1149 IOobject::READ_IF_PRESENT,
1153 dimensionedScalar(
"Phi", dimLength * dimVelocity, 0),
1154 UliftBC.boundaryField().types()
1156 label PhiRefCell = 0;
1157 scalar PhiRefValue = 0.0;
1161 potentialFlow.dict(),
1165 mesh.setFluxRequired(Phi.name());
1166 runTime.functionObjects().start();
1167 MRF.makeRelative(
phi);
1170 while (potentialFlow.correctNonOrthogonal())
1172 fvScalarMatrix PhiEqn
1174 fvm::laplacian(dimensionedScalar(
"1", dimless, 1), Phi)
1178 PhiEqn.setReference(PhiRefCell, PhiRefValue);
1181 if (potentialFlow.finalNonOrthogonalIter())
1183 phi -= PhiEqn.flux();
1187 MRF.makeAbsolute(
phi);
1188 Info <<
"Continuity error = "
1189 << mag(fvc::div(
phi))().weightedAverage(
mesh.V()).value()
1191 Ulift = fvc::reconstruct(
phi);
1192 Ulift.correctBoundaryConditions();
1193 Info <<
"Interpolated velocity error = "
1194 << (sqrt(sum(sqr((fvc::interpolate(
U) &
mesh.Sf()) -
phi)))
1195 / sum(
mesh.magSf())).value()
1205 volScalarField& ciao =
const_cast<volScalarField&
>(
nu);
1208 for (label
i = 0;
i < ciao.boundaryFieldRef().size();
i++)
volScalarField alphaEff("alphaEff", turbulence->nu()/Pr+alphat)
Header file of the UnsteadyBB class.
autoPtr< volScalarField > _p_rgh
Shifted Pressure field.
Eigen::MatrixXd mass_term_temperature(label NUmodes, label NTmodes, label NSUPmodes)
Mass Term Energy Equation.
void liftSolveT()
Perform a lift solve for temperature.
void solvesupremizer(word type="snapshots")
solve the supremizer either with the use of the pressure snaphots or the pressure modes
Eigen::MatrixXd HP_matrix
Buoyancy term - PPE equation.
Eigen::MatrixXd Y_matrix
Diffusive term - energy equation.
autoPtr< volScalarField > _UliftBC
Eigen::MatrixXd diffusive_term_temperature(label NUmodes, label NTmodes, label NSUPmodes)
Diffusive Term Energy Equation.
PtrList< volScalarField > Prghmodes
List of pointers used to form the shifted pressure modes.
autoPtr< volScalarField > _T
Temperature field.
autoPtr< dimensionedScalar > _Prt
dimensionedScalar Prt;
Eigen::MatrixXd W_matrix
Mass Matrix - energy equation.
autoPtr< dimensionedScalar > _Pr
dimensionedScalar Pr;
List< Eigen::MatrixXd > convective_term_temperature(label NUmodes, label NTmodes, label NSUPmodes)
Convective Term Energy Equation.
Eigen::MatrixXd pressure_gradient_term(label NUmodes, label NPrghmodes, label NSUPmodes)
Gradient of pressure.
PtrList< volScalarField > Prghfield
List of pointers used to form the shifted pressure snapshots matrix.
Eigen::MatrixXd divergence_term(label NUmodes, label NPrghmodes, label NSUPmodes)
Divergence Term (supremizer approach)
autoPtr< dimensionedVector > _g
void change_viscosity(double mu)
Function to change the viscosity.
UnsteadyBB()
Null constructor.
void projectSUP(fileName folder, label NUmodes, label NPmodes, label NTmodes, label NSUPmodes)
Project using a supremizer approach.
Eigen::MatrixXd H_matrix
Buoyancy term - momentum equation.
void liftSolve()
Perform a lift solve for velocity field.
autoPtr< volScalarField > _gh
List of pointers used to form the gravitational acceleration.
autoPtr< fvMesh > _mesh
Mesh.
label NPrghmodes
Number of pressure modes used for the projection.
Eigen::MatrixXd buoyant_term_poisson(label NPrghmodes, label NTmodes)
Buoyant Term PPE Equation.
PtrList< volScalarField > L_T_modes
List of pointers containing the lift for temperature and the temperature field.
List< Eigen::MatrixXd > Q_matrix
Non linear convective term - energy equation.
autoPtr< dimensionedScalar > _TRef
dimensionedScalar Tref;
PtrList< volScalarField > Tmodes
List of pointers used to form the temperature modes.
bool checkWrite(Time &timeObject)
Function to check if the solution must be exported.
autoPtr< dimensionedScalar > _beta
dimensionedScalar beta;
autoPtr< volScalarField > _rhok
dimensionedScalar rhok;
autoPtr< volScalarField > _alphat
dimensionedScalar alphat;
PtrList< volScalarField > liftfieldT
List of pointers used to form the list of lifting functions.
Eigen::MatrixXd buoyant_term(label NUmodes, label NTmodes, label NSUPmodes)
Buoyant Term Momentum Equation.
PtrList< volScalarField > Tfield
List of pointers used to form the temperature snapshots matrix.
void projectPPE(fileName folder, label NUmodes, label NPrghmodes, label NTmodes, label NSUPmodes)
Project using a PPE approach.
autoPtr< surfaceScalarField > _ghf
List of pointers used to form the gravitational acceleration.
label NTmodes
Number of temperature modes used for the projection.
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 inletIndexT
void writeMu(List< scalar > mu_now)
Write out a list of scalar corresponding to the parameters used in the truthSolve.
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.
Eigen::MatrixXd mu
Row matrix of parameters.
autoPtr< argList > _args
argList
Eigen::MatrixXi inletIndex
Matrix that contains informations about the inlet boundaries.
bool podex
Boolean variable, it is 1 if the POD has already been computed, else 0.
void truthSolve()
Perform a TruthSolve.
label NPmodes
Number of pressure modes used for the projection.
bool supex
Boolean variable to check the existence of the supremizer modes.
Eigen::MatrixXd BC1_matrix
PPE BC1.
Eigen::MatrixXd diffusive_term(label NUmodes, label NPmodes, label NSUPmodes)
Diffusive Term.
autoPtr< surfaceScalarField > _phi
Flux.
Eigen::MatrixXd BC3_matrix
PPE BC3.
Eigen::Tensor< double, 3 > C_tensor
Diffusion term.
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
volVectorModes supmodes
List of pointers used to form the supremizer modes.
autoPtr< fv::options > _fvOptions
fvOptions
autoPtr< Time > _runTime
Time.
volVectorModes Umodes
List of pointers used to form the velocity modes.
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
Eigen::MatrixXd pressure_BC1(label NPmodes, label NUmodes)
Term N° 1 given by the additional boundary condition using a PPE approach.
List< Eigen::MatrixXd > G_matrix
Divergence of momentum PPE.
Eigen::MatrixXd mass_term(label NUmodes, label NPmodes, label NSUPmodes)
Mass Term.
autoPtr< singlePhaseTransportModel > _laminarTransport
Laminar transport (used by turbulence model)
label NUmodes
Number of velocity modes used for the projection.
PtrList< volVectorField > liftfield
List of pointers used to form the list of lifting functions.
volVectorModes L_U_SUPmodes
List of pointers containing the total number of lift, supremizer and velocity modes.
Eigen::MatrixXd pressure_BC3(label NPmodes, label NUmodes)
Term N° 3 given by the additional boundary condition using a PPE approach.
Eigen::MatrixXd B_matrix
Diffusion term.
Eigen::MatrixXd D_matrix
Laplacian term PPE.
autoPtr< IOMRFZoneList > _MRF
MRF variable.
label NSUPmodes
Number of supremizer modes used for the projection.
Eigen::MatrixXd K_matrix
Gradient of pressure matrix.
Eigen::Tensor< double, 3 > convective_term_tens(label NUmodes, label NPmodes, label NSUPmodes)
Export convective term as a tensor.
List< Eigen::MatrixXd > pressure_BC2(label NPmodes, label NUmodes)
Term N° 2 given by the additional boundary condition using a PPE approach.
PtrList< volVectorField > supfield
List of pointers used to form the supremizer snapshots matrix.
Eigen::MatrixXd P_matrix
Div of velocity.
Eigen::MatrixXd M_matrix
Mass Matrix.
List< Eigen::MatrixXd > BC2_matrix
PPE BC2.
Eigen::MatrixXd laplacian_pressure(label NPmodes)
Laplacian of pressure term (PPE approach)
autoPtr< volVectorField > _U
Velocity field.
List< Eigen::MatrixXd > div_momentum(label NUmodes, label NPmodes)
Divergence of convective term (PPE approach)
autoPtr< volScalarField > _p
Pressure field.
autoPtr< incompressible::turbulenceModel > turbulence
Turbulence model.
autoPtr< pimpleControl > _pimple
pimpleControl
void ReadDenseMatrix(MatrixType &Matrix, word folder, word MatrixName)
Read a dense matrix from a binary format file.
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 ...
void SaveDenseMatrix(MatrixType &Matrix, word folder, word MatrixName)
Save a dense matrix to a binary format file.
void ReadDenseTensor(TensorType &Tensor, word folder, word MatrixName)
Read a dense tensor from file.
void read_fields(PtrList< GeometricField< Type, PatchField, GeoMesh > > &Lfield, word Name, fileName casename, int first_snap, int n_snap)
Function to read a list of fields from the name of the field and casename.
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_folder(word folder)
Checks if a folder exists.
bool check_file(std::string fileName)
Function that returns true if a file exists.
bool check_sup()
Check if the supremizer folder exists.
void changeBCtype(GeometricField< Type, fvPatchField, volMesh > &field, word BCtype, label BC_ind)
Change the boundary condition type for a GeometricField.
simpleControl simple(mesh)
singlePhaseTransportModel & laminarTransport
setRefCell(p, mesh.solutionDict().subDict("SIMPLE"), pRefCell, pRefValue)