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");
275 for (label k = 0; k < nModes; k++)
283 word bStr =
"b_" + name(nModes);
293 word btStr =
"bt_" + name(nModes);
303 word kStr =
"k_" + name(nModes);
313 word cStr =
"c_" + name(nModes) +
"_t";
323 word ct1Str =
"ct1_" + name(nModes) +
"_t";
333 word ct2Str =
"ct2_" + name(nModes) +
"_t";
367 if (
para->exportPython)
372 "./ITHACAoutput/Matrices/");
374 "./ITHACAoutput/Matrices/");
376 "./ITHACAoutput/Matrices/");
378 "./ITHACAoutput/Matrices/");
381 if (
para->exportMatlab)
386 "./ITHACAoutput/Matrices/");
388 "./ITHACAoutput/Matrices/");
390 "./ITHACAoutput/Matrices/");
392 "./ITHACAoutput/Matrices/");
401 "./ITHACAoutput/Matrices/c");
403 "./ITHACAoutput/Matrices/ct1");
405 "./ITHACAoutput/Matrices/ct2");
421 for (label k = 0; k < nUModes; k++)
429 word bStr =
"b_" + name(nUModes);
439 word btStr =
"bt_" + name(nUModes);
449 word kStr =
"k_" + name(nUModes) +
"_" + name(nPModes);
459 word D_str =
"D_" + name(nPModes);
469 word bc1_str =
"BC1_" + name(nUModes) +
"_" + name(nPModes);
479 word bc2_str =
"BC2_" + name(nUModes) +
"_" + name(nPModes) +
"_t";
489 word bc3_str =
"BC3_" + name(nUModes) +
"_" + name(nPModes);
499 word cStr =
"c_" + name(nUModes) +
"_t";
509 word ct1Str =
"ct1_" + name(nUModes) +
"_t";
519 word ct2Str =
"ct2_" + name(nUModes) +
"_t";
529 word ct1PPEStr =
"ct1PPE_" + name(nUModes) +
"_" + name(nPModes) +
"_t";
540 word ct2PPEStr =
"ct2PPE_" + name(nUModes) +
"_" + name(nPModes) +
"_t";
551 word G_str =
"G_" + name(nUModes) +
"_" + name(nPModes) +
"_t";
592 if (
para->exportPython)
597 "./ITHACAoutput/Matrices/");
600 "./ITHACAoutput/Matrices/");
602 "./ITHACAoutput/Matrices/");
604 "./ITHACAoutput/Matrices/");
606 "./ITHACAoutput/Matrices/");
609 "./ITHACAoutput/Matrices/");
611 "./ITHACAoutput/Matrices/");
613 "./ITHACAoutput/Matrices/");
615 "./ITHACAoutput/Matrices/");
618 if (
para->exportMatlab)
623 "./ITHACAoutput/Matrices/");
626 "./ITHACAoutput/Matrices/");
628 "./ITHACAoutput/Matrices/");
630 "./ITHACAoutput/Matrices/");
632 "./ITHACAoutput/Matrices/");
635 "./ITHACAoutput/Matrices/");
637 "./ITHACAoutput/Matrices/");
639 "./ITHACAoutput/Matrices/");
641 "./ITHACAoutput/Matrices/");
651 "./ITHACAoutput/Matrices/");
653 "./ITHACAoutput/Matrices/");
655 "./ITHACAoutput/Matrices/ct1PPE");
657 "./ITHACAoutput/Matrices/ct2PPE");
659 "./ITHACAoutput/Matrices/G");
661 "./ITHACAoutput/Matrices/BC2");
663 "./ITHACAoutput/Matrices/c");
665 "./ITHACAoutput/Matrices/ct1");
667 "./ITHACAoutput/Matrices/ct2");
680 bMatrix.resize(nModes, nModes);
683 for (label
i = 0;
i < nModes;
i++)
685 for (label j = 0; j < nModes; j++)
688 dimensionedScalar(
"1", dimless, 1),
Umodes[j])).value();
692 if (Pstream::parRun())
694 reduce(
bMatrix, sumOp<Eigen::MatrixXd>());
698 "b_" + name(nModes));
707 for (label
i = 0;
i < nModes;
i++)
709 for (label j = 0; j < nModes; j++)
711 for (label k = 0; k < nModes; k++)
720 if (Pstream::parRun())
722 reduce(
convTensor, sumOp<Eigen::Tensor<double, 3 >> ());
727 "c_" + name(nModes) +
"_t");
733 Eigen::MatrixXd
kMatrix(nModes, nModes);
736 for (label
i = 0;
i < nModes;
i++)
738 for (label j = 0; j < nModes; j++)
745 if (Pstream::parRun())
747 reduce(
kMatrix, sumOp<Eigen::MatrixXd>());
751 "k_" + name(nModes));
758 Eigen::MatrixXd
kMatrix(nUModes, nPModes);
761 for (label
i = 0;
i < nUModes;
i++)
763 for (label j = 0; j < nPModes; j++)
770 if (Pstream::parRun())
772 reduce(
kMatrix, sumOp<Eigen::MatrixXd>());
776 "k_" + name(nUModes) +
"_" + name(nPModes));
782 Eigen::MatrixXd dMatrix(nPModes, nPModes);
785 for (label
i = 0;
i < nPModes;
i++)
787 for (label j = 0; j < nPModes; j++)
789 dMatrix(
i, j) = fvc::domainIntegrate(fvc::grad(
Pmodes[
i]) & fvc::grad(
794 if (Pstream::parRun())
796 reduce(dMatrix, sumOp<Eigen::MatrixXd>());
800 "D_" + name(nPModes));
807 label g1Size = nPModes;
808 label g2Size = nUModes;
809 Eigen::Tensor<double, 3>
gTensor;
810 gTensor.resize(g1Size, g2Size, g2Size);
812 for (label
i = 0;
i < g1Size;
i++)
814 for (label j = 0; j < g2Size; j++)
816 for (label k = 0; k < g2Size; k++)
818 gTensor(
i, j, k) = fvc::domainIntegrate(fvc::grad(
Pmodes[
i]) & (fvc::div(
825 if (Pstream::parRun())
827 reduce(
gTensor, sumOp<Eigen::Tensor<double, 3 >> ());
832 "G_" + name(nUModes) +
"_" + name(
840 label P_BC1size = nPModes;
841 label P_BC2size = nUModes;
842 Eigen::MatrixXd
BC1_matrix(P_BC1size, P_BC2size);
844 for (label
i = 0;
i < P_BC1size;
i++)
846 for (label j = 0; j < P_BC2size; j++)
848 surfaceScalarField lpl((fvc::interpolate(fvc::laplacian(
851 for (label k = 0; k < lpl.boundaryField().size(); k++)
853 s += gSum(lpl.boundaryField()[k]);
860 if (Pstream::parRun())
866 "BC1_" + name(nUModes) +
"_" + name(nPModes));
873 label pressureBC1Size = nPModes;
874 label pressureBC2Size = nUModes;
877 bc2Tensor.resize(pressureBC1Size, pressureBC2Size, pressureBC2Size);
879 for (label
i = 0;
i < pressureBC1Size;
i++)
881 for (label j = 0; j < pressureBC2Size; j++)
883 for (label k = 0; k < pressureBC2Size; k++)
885 surfaceScalarField div_m(fvc::interpolate(fvc::div(fvc::interpolate(
890 for (label k = 0; k < div_m.boundaryField().size(); k++)
892 s += gSum(div_m.boundaryField()[k]);
900 if (Pstream::parRun())
902 reduce(
bc2Tensor, sumOp<Eigen::Tensor<double, 3 >> ());
907 "BC2_" + name(nUModes) +
"_" + name(nPModes) +
"_t");
914 label P3_BC1size = nPModes;
915 label P3_BC2size = nUModes;
916 Eigen::MatrixXd
BC3_matrix(P3_BC1size, P3_BC2size);
918 surfaceVectorField n(
mesh.Sf() /
mesh.magSf());
919 for (label
i = 0;
i < P3_BC1size;
i++)
921 for (label j = 0; j < P3_BC2size; j++)
923 surfaceVectorField BC3 = fvc::interpolate(fvc::curl(
Umodes[j])).ref();
924 surfaceVectorField BC4 = (n^ fvc::interpolate(fvc::grad(
Pmodes[
i]))).ref();
925 surfaceScalarField BC5 = ((BC3& BC4) *
mesh.magSf()).ref();
927 for (label k = 0; k < BC5.boundaryField().size(); k++)
929 s += gSum(BC5.boundaryField()[k]);
936 if (Pstream::parRun())
942 "BC3_" + name(nUModes) +
"_" + name(nPModes));
949 label P4_BC1size = nPModes;
950 label P4_BC2size = nUModes;
951 Eigen::MatrixXd
BC4_matrix(P4_BC1size, P4_BC2size);
953 surfaceVectorField n(
mesh.Sf() /
mesh.magSf());
955 for (label
i = 0;
i < P4_BC1size;
i++)
957 for (label j = 0; j < P4_BC2size; j++)
959 surfaceScalarField BC3 = fvc::interpolate(
Pmodes[
i]).ref();
960 surfaceScalarField BC4 = (n & fvc::interpolate(
Umodes[j])).ref();
961 surfaceScalarField BC5 = ((BC3 * BC4) *
mesh.magSf()).ref();
964 for (label k = 0; k < BC5.boundaryField().size(); k++)
966 s += gSum(BC5.boundaryField()[k]);
973 if (Pstream::parRun())
979 "BC4_" + name(nUModes) +
"_" + name(nPModes));
997 for (label
i = 0;
i < nModes;
i++)
1005 "./ITHACAoutput/Matrices/bcVelVec");
1012 List < Eigen::MatrixXd >
bcVelMat(BCUsize);
1014 for (label j = 0; j <
inletIndex.rows(); j++)
1016 bcVelMat[j].resize(nModes, nModes);
1019 for (label k = 0; k <
inletIndex.rows(); k++)
1024 for (label
i = 0;
i < nModes;
i++)
1026 for (label j = 0; j < nModes; j++)
1030 Umodes[j].boundaryField()[BCind].component(BCcomp));
1036 "./ITHACAoutput/Matrices/bcVelMat");
1041 label nUModes, label nPModes)
1046 for (label
i = 0;
i < nPModes;
i++)
1048 for (label j = 0; j < nUModes; j++)
1050 for (label k = 0; k < nUModes; k++)
1059 if (Pstream::parRun())
1061 reduce(
ct1PPETensor, sumOp<Eigen::Tensor<double, 3 >> ());
1066 "ct1PPE_" + name(nUModes) +
"_" + name(nPModes) +
"_t");
1071 label nUModes, label nPModes)
1076 for (label
i = 0;
i < nPModes;
i++)
1078 for (label j = 0; j < nUModes; j++)
1080 for (label k = 0; k < nUModes; k++)
1088 if (Pstream::parRun())
1090 reduce(
ct2PPETensor, sumOp<Eigen::Tensor<double, 3 >> ());
1095 "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