44 _args = autoPtr<argList>
46 new argList(argc, argv)
49 if (!
_args->checkRootCase())
51 Foam::FatalError.exit();
54 argList& args =
_args();
57 _pimple = autoPtr<pimpleControl>
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Wunused-variable"
67#pragma GCC diagnostic pop
83#include "initContinuityErrs.H"
84 volScalarField&
p =
_p();
85 volVectorField&
U =
_U();
87 volScalarField&
T =
_T();
90 volScalarField&
gh =
_gh();
91 surfaceScalarField&
ghf =
_ghf();
92 surfaceScalarField&
phi =
_phi();
95 IOMRFZoneList& MRF =
_MRF();
99 dimensionedScalar&
Pr =
_Pr();
100 dimensionedScalar&
Prt =
_Prt();
101 instantList Times =
runTime.times();
111 std::ofstream of(
"./ITHACAoutput/Offline/" + name(
counter) +
"/" +
123#include "readTimeControls.H"
124#include "CourantNo.H"
125#include "setDeltaT.H"
127 Info <<
"Time = " <<
runTime.timeName() << nl << endl;
148 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
149 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
158 std::ofstream of(
"./ITHACAoutput/Offline/" + name(
counter) +
"/" +
175#include "initContinuityErrs.H"
178 volScalarField&
p =
_p();
179 volVectorField&
U =
_U();
181 volScalarField&
T =
_T();
186 volScalarField&
gh =
_gh();
187 surfaceScalarField&
ghf =
_ghf();
188 surfaceScalarField&
phi =
_phi();
191 IOMRFZoneList& MRF =
_MRF();
198 dimensionedScalar&
Pr =
_Pr();
199 dimensionedScalar&
Prt =
_Prt();
200 instantList Times =
runTime.times();
210 std::ofstream of(folder + name(
counter) +
"/" +
runTime.timeName());
217#include "readTimeControls.H"
218#include "CourantNo.H"
219#include "setDeltaT.H"
221 Info <<
"Time = " <<
runTime.timeName() << nl << endl;
242 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
243 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
252 std::ofstream of(folder + name(
counter) +
"/" +
runTime.timeName());
266 scalar diffnow = mag(
nextWrite - atof(timeObject.timeName().c_str()));
267 scalar diffnext = mag(
nextWrite - atof(timeObject.timeName().c_str()) -
268 timeObject.deltaTValue());
270 if ( diffnow < diffnext)
283 PtrList<volScalarField> P_sup;
289 else if (type ==
"snapshots")
295 std::cout <<
"You must specify the variable type with either snapshots or modes"
302 volVectorField
U =
_U();
314 dimensionedVector(
"zero",
U.dimensions(), vector::zero)
317 if (type ==
"snapshots")
321 else if (type ==
"modes")
331 volVectorField
U =
_U();
343 dimensionedVector(
"zero",
U.dimensions(), vector::zero)
345 dimensionedScalar nu_fake
348 dimensionSet(0, 2, -1, 0, 0, 0, 0),
351 Vector<double>
v(0, 0, 0);
353 for (label
i = 0;
i < Usup.boundaryField().size();
i++)
360 if (type ==
"snapshots")
362 for (label
i = 0;
i < P_sup.size();
i++)
364 fvVectorMatrix u_sup_eqn
366 - fvm::laplacian(nu_fake, Usup)
370 u_sup_eqn == fvc::grad(P_sup[
i])
377 system(
"ln -s ../../constant ./ITHACAoutput/supfield/constant");
378 systemRet += system(
"ln -s ../../0 ./ITHACAoutput/supfield/0");
379 systemRet += system(
"ln -s ../../system ./ITHACAoutput/supfield/system");
383 Info <<
"System Command Failed in steadyNS.C" << endl;
391 fvVectorMatrix u_sup_eqn
393 - fvm::laplacian(nu_fake, Usup)
404 system(
"ln -s ../../constant ./ITHACAoutput/supremizer/constant");
405 systemRet += system(
"ln -s ../../0 ./ITHACAoutput/supremizer/0");
406 systemRet += system(
"ln -s ../../system ./ITHACAoutput/supremizer/system");
410 Info <<
"System Command Failed in steadyNS.C" << endl;
428 volScalarField&
T =
_T();
429 volVectorField&
U =
_U();
430 surfaceScalarField&
phi =
_phi();
431 phi = linearInterpolate(
U) &
mesh.Sf();
438 dimensionedScalar&
Pr =
_Pr();
439 dimensionedScalar&
Prt =
_Prt();
441 volScalarField Tlift(
"Tlift" + name(k),
T);
442 instantList Times =
runTime.times();
444 Info <<
"Solving a lifting Problem" << endl;
448 alphat.correctBoundaryConditions();
451 for (label j = 0; j <
T.boundaryField().size(); j++)
458 else if (
T.boundaryField()[BCind].type() ==
"fixedValue")
468 while (
simple.correctNonOrthogonal())
476 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
477 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
498 word M_str =
"M_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
510 word B_str =
"B_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
522 word C_str =
"C_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
534 word K_str =
"K_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
546 word H_str =
"H_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
581 word P_str =
"P_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
599 for (label k = 0; k <
liftfield.size(); k++)
607 for (label k = 0; k <
NUmodes; k++)
633 for (label k = 0; k <
NTmodes; k++)
662 word M_str =
"M_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
674 word B_str =
"B_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
687 "./ITHACAoutput/Matrices/");
688 word C_str =
"C_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
700 word K_str =
"K_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
712 word H_str =
"H_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
759 word P_str =
"P_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
777 for (label k = 0; k <
liftfield.size(); k++)
785 for (label k = 0; k <
NUmodes; k++)
811 for (label k = 0; k <
NTmodes; k++)
841 Eigen::MatrixXd
K_matrix(K1size, K2size);
842 dimensionedVector
g =
_g();
845 for (label
i = 0;
i < K1size;
i++)
847 for (label j = 0; j < K2size; j++)
850 fvc::reconstruct(fvc::snGrad(
Prghmodes[j]) *
855 if (Pstream::parRun())
857 reduce(
K_matrix, sumOp<Eigen::MatrixXd>());
860 if (Pstream::master())
878 Eigen::MatrixXd
P_matrix(P1size, P2size);
881 for (label
i = 0;
i < P1size;
i++)
883 for (label j = 0; j < P2size; j++)
890 if (Pstream::parRun())
892 reduce(
P_matrix, sumOp<Eigen::MatrixXd>());
895 if (Pstream::master())
911 Eigen::MatrixXd
H_matrix(H1size, H2size);
914 dimensionedVector
g =
_g();
916 surfaceScalarField&
ghf =
_ghf();
919 for (label
i = 0;
i < H1size;
i++)
921 for (label j = 0; j < H2size; j++)
929 if (Pstream::parRun())
931 reduce(
H_matrix, sumOp<Eigen::MatrixXd>());
934 if (Pstream::master())
952 Eigen::MatrixXd
HP_matrix(H1size, H2size);
956 dimensionedVector
g =
_g();
957 volScalarField&
gh =
_gh();
958 surfaceScalarField&
ghf =
_ghf();
961 for (label
i = 0;
i < H1size;
i++)
963 for (label j = 0; j < H2size; j++)
965 HP_matrix(
i, j) = fvc::domainIntegrate(fvc::reconstruct(fvc::snGrad(
973 if (Pstream::parRun())
975 reduce(
HP_matrix, sumOp<Eigen::MatrixXd>());
978 if (Pstream::master())
992 label NTmodes, label NSUPmodes)
999 for (label j = 0; j < Qsizet; j++)
1004 for (label
i = 0;
i < Qsizet;
i++)
1006 for (label j = 0; j < Qsize; j++)
1008 for (label k = 0; k < Qsizet; k++)
1016 if (Pstream::parRun())
1018 reduce(
Q_matrix[
i], sumOp<Eigen::MatrixXd>());
1022 if (Pstream::master())
1036 label NTmodes, label NSUPmodes)
1039 Eigen::MatrixXd
Y_matrix(Ysize, Ysize);
1041 for (label
i = 0;
i < Ysize;
i++)
1043 for (label j = 0; j < Ysize; j++)
1046 dimensionedScalar(
"1", dimless, 1),
L_T_modes[j])).value();
1050 if (Pstream::parRun())
1052 reduce(
Y_matrix, sumOp<Eigen::MatrixXd>());
1055 if (Pstream::master())
1070 Eigen::MatrixXd
W_matrix(Wsize, Wsize);
1072 for (label
i = 0;
i < Wsize;
i++)
1074 for (label j = 0; j < Wsize; j++)
1080 if (Pstream::parRun())
1082 reduce(
W_matrix, sumOp<Eigen::MatrixXd>());
1085 if (Pstream::master())
1099 for (label k = 0; k <
inletIndex.rows(); k++)
1102 surfaceScalarField&
phi =
_phi();
1105 volVectorField&
U =
_U();
1110 IOMRFZoneList& MRF =
_MRF();
1112 volVectorField Ulift(
"Ulift" + name(k),
U);
1113 instantList Times =
runTime.times();
1115 pisoControl potentialFlow(
mesh,
"potentialFlow");
1116 Info <<
"Solving a lifting Problem" << endl;
1117 Vector<double> v1(0, 0, 0);
1119 Vector<double>
v0(0, 0, 0);
1121 for (label j = 0; j <
U.boundaryField().size(); j++)
1127 else if (
U.boundaryField()[BCind].type() ==
"fixedValue")
1136 phi = linearInterpolate(Ulift) &
mesh.Sf();
1139 Info <<
"Constructing velocity potential field Phi\n" << endl;
1147 IOobject::READ_IF_PRESENT,
1151 dimensionedScalar(
"Phi", dimLength * dimVelocity, 0),
1152 UliftBC.boundaryField().types()
1154 label PhiRefCell = 0;
1155 scalar PhiRefValue = 0.0;
1159 potentialFlow.dict(),
1163 mesh.setFluxRequired(Phi.name());
1164 runTime.functionObjects().start();
1165 MRF.makeRelative(
phi);
1168 while (potentialFlow.correctNonOrthogonal())
1170 fvScalarMatrix PhiEqn
1172 fvm::laplacian(dimensionedScalar(
"1", dimless, 1), Phi)
1176 PhiEqn.setReference(PhiRefCell, PhiRefValue);
1179 if (potentialFlow.finalNonOrthogonalIter())
1181 phi -= PhiEqn.flux();
1185 MRF.makeAbsolute(
phi);
1186 Info <<
"Continuity error = "
1187 << mag(fvc::div(
phi))().weightedAverage(
mesh.V()).value()
1189 Ulift = fvc::reconstruct(
phi);
1190 Ulift.correctBoundaryConditions();
1191 Info <<
"Interpolated velocity error = "
1192 << (sqrt(sum(sqr((fvc::interpolate(
U) &
mesh.Sf()) -
phi)))
1193 / sum(
mesh.magSf())).value()
1203 volScalarField& ciao =
const_cast<volScalarField&
>(
nu);
1206 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)