33#include "viscosityModel.H"
38SteadyNSTurb::SteadyNSTurb() {}
40SteadyNSTurb::SteadyNSTurb(
int argc,
char* argv[])
42 _args = autoPtr<argList>
44 new argList(argc, argv)
47 if (!
_args->checkRootCase())
49 Foam::FatalError.exit();
52 argList& args =
_args();
53#include "createTime.H"
54#include "createMesh.H"
55 _simple = autoPtr<simpleControl>
62 simpleControl& simple =
_simple();
63#include "createFields.H"
64#include "createFvOptions.H"
66#pragma GCC diagnostic push
67#pragma GCC diagnostic ignored "-Wunused-variable"
68#include "initContinuityErrs.H"
69#pragma GCC diagnostic pop
87 "The BC method must be set to lift or penalty in ITHACAdict");
102 fvMesh& mesh =
_mesh();
103 volScalarField& p =
_p();
104 volVectorField& U =
_U();
105 surfaceScalarField& phi =
_phi();
107 simpleControl& simple =
_simple();
108 IOMRFZoneList& MRF =
_MRF();
110#include "NLsolveSteadyNSTurb.H"
123 for (label i = 0; i < mu_now.size(); i++)
137 "./ITHACAoutput/Offline");
148 for (label j = 0; j < cSize; j++)
154 for (label i = 0; i < cSize; i++)
156 Info <<
"Filling layer number " << i + 1 <<
" in the matrix ct1Matrix" << endl;
160 for (label k = 0; k < cSize; k++)
170 "./ITHACAoutput/Matrices/");
172 "./ITHACAoutput/Matrices/");
174 "./ITHACAoutput/Matrices/ct1");
182 Eigen::Tensor<double, 3> ct1Tensor;
183 ct1Tensor.resize(cSize,
nNutModes, cSize);
185 for (label i = 0; i < cSize; i++)
189 for (label k = 0; k < cSize; k++)
191 ct1Tensor(i, j, k) = fvc::domainIntegrate(
L_U_SUPmodes[i] & fvc::laplacian(
208 Eigen::Tensor<double, 3> ct1Tensor(cSize,
nNutModes, cSize);
213 List<tmp<volVectorField>> lapRow(cSize);
215 for (label k = 0; k < cSize; ++k)
220 for (label i = 0; i < cSize; ++i)
222 for (label k = 0; k < cSize; ++k)
224 const volVectorField& lapField = lapRow[k]();
225 ct1Tensor(i, j, k) = fvc::domainIntegrate(
L_U_SUPmodes[i] & lapField).value();
231 if (Pstream::master())
248 for (label j = 0; j < cSize; j++)
254 for (label i = 0; i < cSize; i++)
256 Info <<
"Filling layer number " << i + 1 <<
" in the matrix ct2Matrix" << endl;
260 for (label k = 0; k < cSize; k++)
270 "./ITHACAoutput/Matrices/");
272 "./ITHACAoutput/Matrices/");
274 "./ITHACAoutput/Matrices/ct2");
282 Eigen::Tensor<double, 3> ct2Tensor;
283 ct2Tensor.resize(cSize,
nNutModes, cSize);
285 for (label i = 0; i < cSize; i++)
289 for (label k = 0; k < cSize; k++)
291 ct2Tensor(i, j, k) = fvc::domainIntegrate(
L_U_SUPmodes[i] & (fvc::div(
308 Eigen::Tensor<double, 3> ct2Tensor(cSize,
nNutModes, cSize);
313 List<tmp<volVectorField>> divRow(cSize);
315 for (label k = 0; k < cSize; ++k)
320 for (label i = 0; i < cSize; ++i)
322 for (label k = 0; k < cSize; ++k)
324 const volVectorField& divRowField = divRow[k]();
325 ct2Tensor(i, j, k) = fvc::domainIntegrate(
L_U_SUPmodes[i] &
326 divRowField).value();
332 if (Pstream::master())
349 for (label i = 0; i <
NPmodes; i++)
353 for (label k = 0; k < cSize; k++)
379 List<tmp<volVectorField>> PmodesGrad(
NPmodes);
381 for (label i = 0; i <
NPmodes; ++i)
383 PmodesGrad[i] = fvc::grad(
Pmodes[i]);
389 List<tmp<volVectorField>> lapRow(cSize);
391 for (label k = 0; k < cSize; ++k)
396 for (label i = 0; i <
NPmodes; ++i)
398 const volVectorField& gradPi = PmodesGrad[i]();
400 for (label k = 0; k < cSize; ++k)
402 const volVectorField& lapRowField = lapRow[k]();
403 ct1PPETensor(i, j, k) = fvc::domainIntegrate(gradPi & lapRowField).value();
409 if (Pstream::master())
426 for (label i = 0; i <
NPmodes; i++)
430 for (label k = 0; k < cSize; k++)
455 List<tmp<volVectorField>> PmodesGrad(
NPmodes);
457 for (label i = 0; i <
NPmodes; ++i)
459 PmodesGrad[i] = fvc::grad(
Pmodes[i]);
465 List<tmp<volVectorField>> divLow(cSize);
467 for (label k = 0; k < cSize; ++k)
472 for (label i = 0; i <
NPmodes; ++i)
474 const volVectorField& gradPi = PmodesGrad[i]();
476 for (label k = 0; k < cSize; ++k)
478 const volVectorField& divLowField = divLow[k]();
479 ct2PPETensor(i, j, k) = fvc::domainIntegrate(gradPi & divLowField).value();
485 if (Pstream::master())
498 Eigen::MatrixXd
btMatrix(btSize, btSize);
502 for (label i = 0; i < btSize; i++)
504 for (label j = 0; j < btSize; j++)
529 for (label k = 0; k <
liftfield.size(); k++)
537 for (label k = 0; k <
NUmodes; k++)
545 word bStr =
"B_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
557 word btStr =
"bt_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
569 word kStr =
"K_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
581 word pStr =
"P_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
593 word mStr =
"M_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
605 word D_str =
"D_" + name(
NPmodes);
616 word bc3_str =
"BC3_" + name(
liftfield.size()) +
"_" + name(
628 word bc4_str =
"BC4_" + name(
liftfield.size()) +
"_" + name(
640 word C_str =
"C_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
652 word ct1Str =
"ct1_" + name(
liftfield.size()) +
"_" + name(
665 word ct2Str =
"ct2_" + name(
liftfield.size()) +
"_" + name(
678 word G_str =
"G_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
702 for (label k = 0; k <
liftfield.size(); k++)
710 for (label k = 0; k <
NUmodes; k++)
746 if (para->exportPython)
753 "./ITHACAoutput/Matrices/");
755 "./ITHACAoutput/Matrices/");
757 "./ITHACAoutput/Matrices/");
761 "./ITHACAoutput/Matrices/");
763 "./ITHACAoutput/Matrices/");
765 "./ITHACAoutput/Matrices/");
767 "./ITHACAoutput/Matrices/");
770 if (para->exportMatlab)
777 "./ITHACAoutput/Matrices/");
779 "./ITHACAoutput/Matrices/");
781 "./ITHACAoutput/Matrices/");
784 "./ITHACAoutput/Matrices/");
786 "./ITHACAoutput/Matrices/");
788 "./ITHACAoutput/Matrices/");
790 "./ITHACAoutput/Matrices/");
800 "./ITHACAoutput/Matrices/");
802 "./ITHACAoutput/Matrices/");
807 "./ITHACAoutput/Matrices/ct1");
809 "./ITHACAoutput/Matrices/ct2");
811 "./ITHACAoutput/Matrices/ct1PPE");
813 "./ITHACAoutput/Matrices/ct2PPE");
818 cTotalTensor.resize(cSize,
nNutModes, cSize);
819 cTotalTensor = ct1Tensor + ct2Tensor;
826 "./ITHACAoutput/Matrices/");
828 "./ITHACAoutput/Matrices/");
830 "./ITHACAoutput/Matrices/");
843 Eigen::MatrixXd X =
mu.transpose();
844 Eigen::VectorXd y =
coeffL2.row(i).transpose();
848 Info <<
"Constructing ithacaInterpolator for mode " << i + 1 << endl;
851 Info<<
"Info on interpolators for nut coefficients: "<< endl;
866 for (label k = 0; k <
liftfield.size(); k++)
874 for (label k = 0; k <
NUmodes; k++)
890 word bStr =
"B_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
902 word btStr =
"bt_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
914 word kStr =
"K_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
926 word pStr =
"P_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
938 word mStr =
"M_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
950 word C_str =
"C_" + name(
liftfield.size()) +
"_" + name(
NUmodes) +
"_" + name(
962 word ct1Str =
"ct1_" + name(
liftfield.size()) +
"_" + name(
975 word ct2Str =
"ct2_" + name(
liftfield.size()) +
"_" + name(
1000 for (label k = 0; k <
liftfield.size(); k++)
1008 for (label k = 0; k <
NUmodes; k++)
1039 if (para->exportPython)
1046 "./ITHACAoutput/Matrices/");
1049 "./ITHACAoutput/Matrices/");
1051 "./ITHACAoutput/Matrices/");
1054 if (para->exportMatlab)
1061 "./ITHACAoutput/Matrices/");
1064 "./ITHACAoutput/Matrices/");
1066 "./ITHACAoutput/Matrices/");
1069 if (para->exportTxt)
1078 "./ITHACAoutput/Matrices/ct1");
1080 "./ITHACAoutput/Matrices/ct2");
1085 cTotalTensor.resize(cSize,
nNutModes, cSize);
1086 cTotalTensor = ct1Tensor + ct2Tensor;
1091 "./ITHACAoutput/Matrices/");
1093 "./ITHACAoutput/Matrices/");
1095 "./ITHACAoutput/Matrices/");
1108 Eigen::MatrixXd X =
mu.transpose();
1109 Eigen::VectorXd y =
coeffL2.row(i).transpose();
1113 Info <<
"Constructing ithacaInterpolator for mode " << i + 1 << endl;
1115 Info<<
"Info on interpolators for nut coefficients: "<< endl;
Header file of the SteadyNSTurb class.
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
Eigen::MatrixXd coeffL2
The matrix of L2 projection coefficients for the eddy viscosity.
Eigen::MatrixXd btMatrix
Turbulent viscosity matrix.
Eigen::Tensor< double, 3 > cTotalPPETensor
Turbulent total viscosity tensor in the PPE equation.
label nNutModes
Number of viscoisty modes used for the projection.
Eigen::MatrixXd bTotalMatrix
Total B Matrix.
Eigen::Tensor< double, 3 > turbulenceTensor2_cache(label NUmodes, label NSUPmodes, label nNutModes)
Method to compute one of the turbulence eddy viscosity tensors using the cached procedure.
Eigen::MatrixXd btTurbulence(label NUmodes, label NSUPmodes)
bt added matrix for the turbulence treatement
autoPtr< volScalarField > _nut
Eddy viscosity field.
List< Eigen::MatrixXd > turbulenceTerm1(label NUmodes, label NSUPmodes, label nNutModes)
ct1 added matrix for the turbulence treatement
PtrList< volScalarField > nutFields
List of snapshots for the solution for eddy viscosity.
Eigen::Tensor< double, 3 > turbulenceTensor1_cache(label NUmodes, label NSUPmodes, label nNutModes)
ct1 tensor for the turbulence treatement using the cached procedure
List< Eigen::MatrixXd > ct2Matrix
Turbulent viscosity tensor.
Eigen::Tensor< double, 3 > ct1PPETensor
Turbulent viscosity tensor in the PPE equation.
Eigen::Tensor< double, 3 > turbulencePPETensor2_cache(label NUmodes, label NSUPmodes, label NPmodes, label nNutModes)
ct2PPE added tensor for the turbulence treatement in the PPE method using the cached procedure
Eigen::Tensor< double, 3 > turbulencePPETensor1_cache(label NUmodes, label NSUPmodes, label NPmodes, label nNutModes)
ct1PPE added tensor for the turbulence treatement in the PPE method using the cached procedure
List< Eigen::MatrixXd > ct1Matrix
Turbulent viscosity tensor.
List< Eigen::MatrixXd > turbulenceTerm2(label NUmodes, label NSUPmodes, label nNutModes)
Method to compute one of the turbulence eddy viscosity tensors.
void projectSUP(fileName folder, label NUmodes, label NPmodes, label NSUPmodes, label nNutModes)
Project using a supremizer approach.
Eigen::Tensor< double, 3 > ct2PPETensor
Turbulent viscosity tensor in the PPE equation.
Eigen::Tensor< double, 3 > turbulencePPETensor1(label NUmodes, label NSUPmodes, label NPmodes, label nNutModes)
ct1PPE added tensor for the turbulence treatement in the PPE method
Eigen::Tensor< double, 3 > turbulencePPETensor2(label NUmodes, label NSUPmodes, label NPmodes, label nNutModes)
ct2PPE added tensor for the turbulence treatement in the PPE method
Eigen::Tensor< double, 3 > turbulenceTensor1(label NUmodes, label NSUPmodes, label nNutModes)
ct1 tensor for the turbulence treatement
Eigen::Tensor< double, 3 > turbulenceTensor2(label NUmodes, label NSUPmodes, label nNutModes)
Method to compute one of the turbulence eddy viscosity tensors.
std::vector< std::shared_ptr< ithacaInterpolator > > rbfSplines
Interpolators for nut coefficient interpolation.
void projectPPE(fileName folder, label NUmodes, label NPmodes, label NSUPmodes, label nNutModes)
Project using a PPE approach.
volScalarModes nutModes
List of POD modes for eddy viscosity.
dictionary viscDict
The way to compute the eddy viscosity snapshots.
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
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 diffusive_term(label NUmodes, label NPmodes, label NSUPmodes)
Diffusive Term.
autoPtr< surfaceScalarField > _phi
Flux.
Eigen::MatrixXd BC4_matrix
PPE BC4.
Eigen::MatrixXd BC3_matrix
PPE BC3.
Eigen::Tensor< double, 3 > C_tensor
Diffusion term.
autoPtr< simpleControl > _simple
simpleControl
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
volVectorModes supmodes
List of pointers used to form the supremizer modes.
List< Eigen::MatrixXd > bcVelocityVec(label NUmodes, label NSUPmodes)
Boundary integral modes on boundary used by the penaly method.
autoPtr< fv::options > _fvOptions
fvOptions
Eigen::MatrixXd pressure_BC4(label NPmodes, label NUmodes)
Term N° 4 given by the additional boundary condition using a PPE approach for time-dependent BCs.
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 divergence_term(label NUmodes, label NPmodes, label NSUPmodes)
Divergence Term (supremizer approach).
scalar tolerance
Tolerance for the residual of the stationary problems, there is the same tolerance for velocity and p...
Eigen::MatrixXd mass_term(label NUmodes, label NPmodes, label NSUPmodes)
Mass Term.
autoPtr< fvMesh > _mesh
Mesh.
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::Tensor< double, 3 > gTensor
Divergence of momentum PPE.
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.
autoPtr< incompressible::turbulenceModel > turbulence
Turbulence model.
Eigen::Tensor< double, 3 > divMomentum(label NUmodes, label NPmodes)
Divergence of convective term (PPE approach).
Eigen::MatrixXd pressure_gradient_term(label NUmodes, label NPmodes, label NSUPmodes)
Gradient of pressure.
List< Eigen::MatrixXd > bcVelMat
Boundary term for penalty method - matrix.
Eigen::MatrixXd P_matrix
Div of velocity.
Eigen::MatrixXd M_matrix
Mass Matrix.
Eigen::MatrixXd laplacian_pressure(label NPmodes)
Laplacian of pressure term (PPE approach).
List< Eigen::MatrixXd > bcVelocityMat(label NUmodes, label NSUPmodes)
Boundary integral modes on boundary used by the penaly method.
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.
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.
Eigen::VectorXd getCoeffs(GeometricField< Type, PatchField, GeoMesh > &snapshot, PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, label Nmodes, bool consider_volumes)
Projects a snapshot on a basis function and gets the coefficients of the projection.
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.
Header file of the steadyNS class.