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>
81 ITHACAdict->lookupOrDefault<word>(
"timeDerivativeSchemeOrder",
"second");
83 "The BC method must be set to lift or penalty in ITHACAdict");
86 "The time derivative approximation must be set to either first or second order scheme in ITHACAdict");
98 surfaceScalarField&
phi =
_phi();
100#include "initContinuityErrs.H"
103 volScalarField
p =
_p();
104 volVectorField
U =
_U();
106 IOMRFZoneList& MRF =
_MRF();
108 instantList Times =
runTime.times();
115 label nsnapshots = 0;
120#include "readTimeControls.H"
121#include "CourantNo.H"
122#include "setDeltaT.H"
124 Info <<
"Time = " <<
runTime.timeName() << nl << endl;
144 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
145 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
155 std::ofstream of(
"./ITHACAoutput/Offline/" + name(
counter) +
"/" +
167 for (label
i = 0;
i < mu_now.size();
i++)
185 "./ITHACAoutput/Offline");
193 ct1Tensor.resize(nModes, nModes, nModes);
195 for (label
i = 0;
i < nModes;
i++)
197 for (label j = 0; j < nModes; j++)
199 for (label k = 0; k < nModes; k++)
207 if (Pstream::parRun())
209 reduce(
ct1Tensor, sumOp<Eigen::Tensor<double, 3>>());
214 "ct1_" + name(nModes) +
"_t");
222 ct2Tensor.resize(nModes, nModes, nModes);
224 for (label
i = 0;
i < nModes;
i++)
226 for (label j = 0; j < nModes; j++)
228 for (label k = 0; k < nModes; k++)
236 if (Pstream::parRun())
238 reduce(
ct2Tensor, sumOp<Eigen::Tensor<double, 3>>());
243 "ct2_" + name(nModes) +
"_t");
249 Eigen::MatrixXd
btMatrix(nModes, nModes);
253 for (label
i = 0;
i < nModes;
i++)
255 for (label j = 0; j < nModes; j++)
265 "bt_" + name(nModes) +
"_t");
276 for (label k = 0; k < nModes; k++)
284 word bStr =
"b_" + name(nModes);
295 word btStr =
"bt_" + name(nModes);
306 word kStr =
"k_" + name(nModes);
317 word cStr =
"c_" + name(nModes) +
"_t";
328 word ct1Str =
"ct1_" + name(nModes) +
"_t";
339 word ct2Str =
"ct2_" + name(nModes) +
"_t";
378 "./ITHACAoutput/Matrices/");
380 "./ITHACAoutput/Matrices/");
382 "./ITHACAoutput/Matrices/");
384 "./ITHACAoutput/Matrices/");
392 "./ITHACAoutput/Matrices/");
394 "./ITHACAoutput/Matrices/");
396 "./ITHACAoutput/Matrices/");
398 "./ITHACAoutput/Matrices/");
407 "./ITHACAoutput/Matrices/c");
409 "./ITHACAoutput/Matrices/ct1");
411 "./ITHACAoutput/Matrices/ct2");
428 for (label k = 0; k < nUModes; k++)
436 word bStr =
"b_" + name(nUModes);
447 word btStr =
"bt_" + name(nUModes);
458 word kStr =
"k_" + name(nUModes) +
"_" + name(nPModes);
469 word D_str =
"D_" + name(nPModes);
480 word bc1_str =
"BC1_" + name(nUModes) +
"_" + name(nPModes);
491 word bc2_str =
"BC2_" + name(nUModes) +
"_" + name(nPModes) +
"_t";
502 word bc3_str =
"BC3_" + name(nUModes) +
"_" + name(nPModes);
513 word cStr =
"c_" + name(nUModes) +
"_t";
524 word ct1Str =
"ct1_" + name(nUModes) +
"_t";
535 word ct2Str =
"ct2_" + name(nUModes) +
"_t";
546 word ct1PPEStr =
"ct1PPE_" + name(nUModes) +
"_" + name(nPModes) +
"_t";
558 word ct2PPEStr =
"ct2PPE_" + name(nUModes) +
"_" + name(nPModes) +
"_t";
570 word G_str =
"G_" + name(nUModes) +
"_" + name(nPModes) +
"_t";
616 "./ITHACAoutput/Matrices/");
619 "./ITHACAoutput/Matrices/");
621 "./ITHACAoutput/Matrices/");
623 "./ITHACAoutput/Matrices/");
625 "./ITHACAoutput/Matrices/");
628 "./ITHACAoutput/Matrices/");
630 "./ITHACAoutput/Matrices/");
632 "./ITHACAoutput/Matrices/");
634 "./ITHACAoutput/Matrices/");
642 "./ITHACAoutput/Matrices/");
645 "./ITHACAoutput/Matrices/");
647 "./ITHACAoutput/Matrices/");
649 "./ITHACAoutput/Matrices/");
651 "./ITHACAoutput/Matrices/");
654 "./ITHACAoutput/Matrices/");
656 "./ITHACAoutput/Matrices/");
658 "./ITHACAoutput/Matrices/");
660 "./ITHACAoutput/Matrices/");
670 "./ITHACAoutput/Matrices/");
672 "./ITHACAoutput/Matrices/");
674 "./ITHACAoutput/Matrices/ct1PPE");
676 "./ITHACAoutput/Matrices/ct2PPE");
678 "./ITHACAoutput/Matrices/G");
680 "./ITHACAoutput/Matrices/BC2");
682 "./ITHACAoutput/Matrices/c");
684 "./ITHACAoutput/Matrices/ct1");
686 "./ITHACAoutput/Matrices/ct2");
699 bMatrix.resize(nModes, nModes);
702 for (label
i = 0;
i < nModes;
i++)
704 for (label j = 0; j < nModes; j++)
707 dimensionedScalar(
"1", dimless, 1),
Umodes[j])).value();
711 if (Pstream::parRun())
713 reduce(
bMatrix, sumOp<Eigen::MatrixXd>());
717 "b_" + name(nModes));
726 for (label
i = 0;
i < nModes;
i++)
728 for (label j = 0; j < nModes; j++)
730 for (label k = 0; k < nModes; k++)
739 if (Pstream::parRun())
741 reduce(
convTensor, sumOp<Eigen::Tensor<double, 3>>());
746 "c_" + name(nModes) +
"_t");
752 Eigen::MatrixXd
kMatrix(nModes, nModes);
755 for (label
i = 0;
i < nModes;
i++)
757 for (label j = 0; j < nModes; j++)
764 if (Pstream::parRun())
766 reduce(
kMatrix, sumOp<Eigen::MatrixXd>());
770 "k_" + name(nModes));
777 Eigen::MatrixXd
kMatrix(nUModes, nPModes);
780 for (label
i = 0;
i < nUModes;
i++)
782 for (label j = 0; j < nPModes; j++)
789 if (Pstream::parRun())
791 reduce(
kMatrix, sumOp<Eigen::MatrixXd>());
795 "k_" + name(nUModes) +
"_" + name(nPModes));
801 Eigen::MatrixXd dMatrix(nPModes, nPModes);
804 for (label
i = 0;
i < nPModes;
i++)
806 for (label j = 0; j < nPModes; j++)
808 dMatrix(
i, j) = fvc::domainIntegrate(fvc::grad(
Pmodes[
i])&fvc::grad(
813 if (Pstream::parRun())
815 reduce(dMatrix, sumOp<Eigen::MatrixXd>());
819 "D_" + name(nPModes));
826 label g1Size = nPModes;
827 label g2Size = nUModes;
828 Eigen::Tensor<double, 3>
gTensor;
829 gTensor.resize(g1Size, g2Size, g2Size);
831 for (label
i = 0;
i < g1Size;
i++)
833 for (label j = 0; j < g2Size; j++)
835 for (label k = 0; k < g2Size; k++)
837 gTensor(
i, j, k) = fvc::domainIntegrate(fvc::grad(
Pmodes[
i]) & (fvc::div(
844 if (Pstream::parRun())
846 reduce(
gTensor, sumOp<Eigen::Tensor<double, 3>>());
851 "G_" + name(nUModes) +
"_" + name(
859 label P_BC1size = nPModes;
860 label P_BC2size = nUModes;
861 Eigen::MatrixXd
BC1_matrix(P_BC1size, P_BC2size);
864 for (label
i = 0;
i < P_BC1size;
i++)
866 for (label j = 0; j < P_BC2size; j++)
868 surfaceScalarField lpl((fvc::interpolate(fvc::laplacian(
872 for (label k = 0; k < lpl.boundaryField().size(); k++)
874 s += gSum(lpl.boundaryField()[k]);
881 if (Pstream::parRun())
887 "BC1_" + name(nUModes) +
"_" + name(nPModes));
894 label pressureBC1Size = nPModes;
895 label pressureBC2Size = nUModes;
898 bc2Tensor.resize(pressureBC1Size, pressureBC2Size, pressureBC2Size);
900 for (label
i = 0;
i < pressureBC1Size;
i++)
902 for (label j = 0; j < pressureBC2Size; j++)
904 for (label k = 0; k < pressureBC2Size; k++)
906 surfaceScalarField div_m(fvc::interpolate(fvc::div(fvc::interpolate(
911 for (label k = 0; k < div_m.boundaryField().size(); k++)
913 s += gSum(div_m.boundaryField()[k]);
921 if (Pstream::parRun())
923 reduce(
bc2Tensor, sumOp<Eigen::Tensor<double, 3>>());
928 "BC2_" + name(nUModes) +
"_" + name(nPModes) +
"_t");
935 label P3_BC1size = nPModes;
936 label P3_BC2size = nUModes;
937 Eigen::MatrixXd
BC3_matrix(P3_BC1size, P3_BC2size);
939 surfaceVectorField n(
mesh.Sf() /
mesh.magSf());
941 for (label
i = 0;
i < P3_BC1size;
i++)
943 for (label j = 0; j < P3_BC2size; j++)
945 surfaceVectorField BC3 = fvc::interpolate(fvc::curl(
Umodes[j])).ref();
946 surfaceVectorField BC4 = (n ^ fvc::interpolate(fvc::grad(
Pmodes[
i]))).ref();
947 surfaceScalarField BC5 = ((BC3 & BC4) *
mesh.magSf()).ref();
950 for (label k = 0; k < BC5.boundaryField().size(); k++)
952 s += gSum(BC5.boundaryField()[k]);
959 if (Pstream::parRun())
965 "BC3_" + name(nUModes) +
"_" + name(nPModes));
972 label P4_BC1size = nPModes;
973 label P4_BC2size = nUModes;
974 Eigen::MatrixXd
BC4_matrix(P4_BC1size, P4_BC2size);
976 surfaceVectorField n(
mesh.Sf() /
mesh.magSf());
978 for (label
i = 0;
i < P4_BC1size;
i++)
980 for (label j = 0; j < P4_BC2size; j++)
982 surfaceScalarField BC3 = fvc::interpolate(
Pmodes[
i]).ref();
983 surfaceScalarField BC4 = (n & fvc::interpolate(
Umodes[j])).ref();
984 surfaceScalarField BC5 = ((BC3 * BC4) *
mesh.magSf()).ref();
987 for (label k = 0; k < BC5.boundaryField().size(); k++)
989 s += gSum(BC5.boundaryField()[k]);
996 if (Pstream::parRun())
1002 "BC4_" + name(nUModes) +
"_" + name(nPModes));
1010 for (label j = 0; j <
inletIndex.rows(); j++)
1015 for (label k = 0; k <
inletIndex.rows(); k++)
1020 for (label
i = 0;
i < nModes;
i++)
1028 "./ITHACAoutput/Matrices/bcVelVec");
1035 List < Eigen::MatrixXd >
bcVelMat(BCUsize);
1037 for (label j = 0; j <
inletIndex.rows(); j++)
1039 bcVelMat[j].resize(nModes, nModes);
1042 for (label k = 0; k <
inletIndex.rows(); k++)
1047 for (label
i = 0;
i < nModes;
i++)
1049 for (label j = 0; j < nModes; j++)
1053 Umodes[j].boundaryField()[BCind].component(BCcomp));
1059 "./ITHACAoutput/Matrices/bcVelMat");
1064 label nUModes, label nPModes)
1069 for (label
i = 0;
i < nPModes;
i++)
1071 for (label j = 0; j < nUModes; j++)
1073 for (label k = 0; k < nUModes; k++)
1082 if (Pstream::parRun())
1084 reduce(
ct1PPETensor, sumOp<Eigen::Tensor<double, 3>>());
1089 "ct1PPE_" + name(nUModes) +
"_" + name(nPModes) +
"_t");
1094 label nUModes, label nPModes)
1099 for (label
i = 0;
i < nPModes;
i++)
1101 for (label j = 0; j < nUModes; j++)
1103 for (label k = 0; k < nUModes; k++)
1111 if (Pstream::parRun())
1113 reduce(
ct2PPETensor, sumOp<Eigen::Tensor<double, 3>>());
1118 "ct2PPE_" + name(nUModes) +
"_" + name(nPModes) +
"_t");
#define M_Assert(Expr, Msg)
Header file of the UnsteadyNSTurbIntrusive class.
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
Eigen::Tensor< double, 3 > convectiveTerm(label nModes)
The method for computing the convective term tensor.
Eigen::MatrixXd pressureBC4(label nUModes, label nPModes)
Term N° 4 given by the additional boundary condition using a PPE approach.
Eigen::MatrixXd kMatrix
Pressure Gradient matrix.
Eigen::Tensor< double, 3 > cTotalTensor
Total Turbulent tensor.
Eigen::Tensor< double, 3 > turbulencePPETensor1(label nUModes, label nPModes)
Method to compute one of the turbulence eddy viscosity tensors in the PPE approach.
List< Eigen::MatrixXd > bcVelocityMat(label nModes)
Boundary integral modes on boundary used by the penaly method.
Eigen::MatrixXd pressureGradientTerm(label nModes)
The method for computing the pressure gradient term with number of modes of pressure being equal to t...
Eigen::Tensor< double, 3 > ct1PPETensor
Turbulent viscosity tensor PPE approach.
Eigen::Tensor< double, 3 > turbulenceTensor1(label nModes)
Method to compute one of the turbulence tensors.
Eigen::MatrixXd btTurbulence(label nModes)
bt added matrix for the turbulence treatement
Eigen::Tensor< double, 3 > divMomentum(label nUModes, label nPModes)
Divergence of convective term (PPE approach)
Eigen::Tensor< double, 3 > turbulenceTensor2(label nModes)
Method to compute one of the turbulence tensors.
Eigen::Tensor< double, 3 > ct2PPETensor
Turbulent viscosity tensor PPE approach.
Eigen::Tensor< double, 3 > pressureBC2(label nUModes, label nPModes)
Term N° 2 given by the additional boundary condition using a PPE approach.
Eigen::Tensor< double, 3 > turbulencePPETensor2(label nUModes, label nPModes)
Method to compute one of the turbulence eddy viscosity tensors in the PPE approach.
Eigen::MatrixXd pressureBC3(label nUModes, label nPModes)
Term N° 3 given by the additional boundary condition using a PPE approach.
Eigen::Tensor< double, 3 > convTensor
Convective tensor.
void projectPPE(fileName folder, label nUModes, label nPModes)
The projection method for computing the reduced order matrices with the usage of Poisson equation for...
Eigen::Tensor< double, 3 > ct2Tensor
Turbulent viscosity tensor.
Eigen::Tensor< double, 3 > cTotalPPETensor
Total Turbulent tensor PPE approach.
Eigen::MatrixXd btMatrix
Turbulent viscosity matrix.
Eigen::MatrixXd bTotalMatrix
Total B Matrix.
Eigen::MatrixXd laplacianPressure(label nPModes)
Laplacian of pressure term (PPE approach)
Eigen::Tensor< double, 3 > ct1Tensor
Turbulent viscosity tensor.
UnsteadyNSTurbIntrusive()
Construct Null.
autoPtr< volScalarField > _nut
Eddy viscosity field.
Eigen::MatrixXd bMatrix
Diffusive matrix.
PtrList< volScalarField > nutFields
List of snapshots for the solution for eddy viscosity.
label nModesOnline
Number of modes used in the online stage.
volScalarModes nutModes
List of POD modes for eddy viscosity.
Eigen::MatrixXd diffusiveTerm(label nModes)
Diffusive Term.
Eigen::MatrixXd pressureBC1(label nUModes, label nPModes)
Term N° 1 given by the additional boundary condition using a PPE approach.
List< Eigen::MatrixXd > bcVelocityVec(label nModes)
Boundary integral modes on boundary used by the penaly method.
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)
void project()
General projection operation.
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.
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
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.
List< Eigen::MatrixXd > bcVelVec
Boundary term for penalty method - vector.
scalar maxIter
Number of maximum iterations to be done for the computation of the truth solution.
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.
autoPtr< surfaceScalarField > _phi
Flux.
Eigen::MatrixXd BC4_matrix
PPE BC4.
Eigen::MatrixXd BC3_matrix
PPE BC3.
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
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.
scalar tolerance
Tolerance for the residual of the stationary problems, there is the same tolerance for velocity and p...
autoPtr< fvMesh > _mesh
Mesh.
autoPtr< singlePhaseTransportModel > _laminarTransport
Laminar transport (used by turbulence model)
label NUmodes
Number of velocity modes used for the projection.
volVectorModes L_U_SUPmodes
List of pointers containing the total number of lift, supremizer and velocity modes.
Eigen::MatrixXd D_matrix
Laplacian term PPE.
autoPtr< IOMRFZoneList > _MRF
MRF variable.
Eigen::Tensor< double, 3 > gTensor
Divergence of momentum PPE.
List< Eigen::MatrixXd > bcVelMat
Boundary term for penalty method - matrix.
Eigen::Tensor< double, 3 > bc2Tensor
PPE BC2.
autoPtr< volVectorField > _U
Velocity field.
volScalarModes Pmodes
List of pointers used to form the pressure modes.
word bcMethod
Boundary Method.
autoPtr< volScalarField > _p
Pressure field.
autoPtr< incompressible::turbulenceModel > turbulence
Turbulence model.
word timeDerivativeSchemeOrder
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 exportTensor(Eigen::Tensor< T, 3 > tensor, word Name, word type, word folder)
Export the reduced tensor in numpy (tipo=python), matlab (tipo=matlab) and txt (tipo=eigen) format.
void SaveDenseTensor(TensorType &Tensor, word folder, word MatrixName)
Save a dense tensor to file.
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.
singlePhaseTransportModel & laminarTransport