36#include "simpleControl.H"
43#include <Eigen/SparseLU>
55class tutorial06 :
public SteadyNSTurb
58 explicit tutorial06(
int argc,
char* argv[])
60 SteadyNSTurb(argc, argv),
74 Vector<double> inl(0, 0, 0);
75 List<scalar> mu_now(2);
87 Vector<double>
Uinl(0, 0, 0);
90 for (label i =
Ufield.size(); i <
mu.rows(); i++)
102 Vector<double>
Uinl(0, 0, 0);
105 for (label i = 0; i <
mu.rows(); i++)
118 Vector<double> inl(0, 0, 0);
119 List<scalar> mu_now(2);
120 Vector<double>
Uinl(0, 0, 0);
123 for (label i = 0; i < par.rows(); i++)
135 fvMesh& mesh =
_mesh();
136 volScalarField& p =
_p();
137 volVectorField& U =
_U();
138 surfaceScalarField& phi =
_phi();
140 simpleControl& simple =
_simple();
141 IOMRFZoneList& MRF =
_MRF();
143#include "NLsolveSteadyNSTurb.H"
146 volScalarField
_nut(turbulence->nut());
148 Ufield.append((U).clone());
149 Pfield.append((p).clone());
155int main(
int argc,
char* argv[])
160 word par_offline(
"./par_offline");
161 word par_new(
"./par_online");
165 example.inletIndex.resize(2, 2);
166 example.inletIndex(0, 0) = 0;
167 example.inletIndex(0, 1) = 0;
168 example.inletIndex(1, 0) = 0;
169 example.inletIndex(1, 1) = 1;
173 int NmodesU = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesU", 5);
174 int NmodesP = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesP", 5);
175 int NmodesSUP = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesSUP", 5);
176 int NmodesNUT = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesNUT", 5);
177 int NmodesProject = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesProject", 5);
178 word stabilization = para->ITHACAdict->lookupOrDefault<word>(
"Stabilization",
181 example.offlineSolve();
185 example.computeLift(example.Ufield, example.liftfield, example.Uomfield);
192 example.supex, 0, NmodesProject);
195 example.supex, 0, NmodesProject);
198 example.supex, 0, NmodesProject);
201 if (stabilization ==
"supremizer")
203 example.solvesupremizer(
"modes");
208 if (stabilization ==
"supremizer")
210 example.projectSUP(
"./Matrices", NmodesU, NmodesP, NmodesSUP,
213 else if (stabilization ==
"PPE")
215 example.projectPPE(
"./Matrices", NmodesU, NmodesP, NmodesSUP,
224 pod_rbf.tauU.resize(2, 1);
226 Eigen::MatrixXd rbfCoeff;
227 rbfCoeff.resize(NmodesNUT, par_online.rows());
230 for (label k = 0; k < par_online.rows(); k++)
232 Eigen::MatrixXd velNow(2, 1);
233 velNow(0, 0) = par_online(k, 0);
234 velNow(1, 0) = par_online(k, 1);
235 pod_rbf.tauU(0, 0) = 0;
236 pod_rbf.tauU(1, 0) = 0;
238 if (stabilization ==
"supremizer")
240 pod_rbf.solveOnlineSUP(velNow);
242 else if (stabilization ==
"PPE")
244 pod_rbf.solveOnlinePPE(velNow);
247 rbfCoeff.col(k) = pod_rbf.rbfCoeff;
248 Eigen::MatrixXd tmp_sol(pod_rbf.y.rows() + 1, 1);
250 tmp_sol.col(0).tail(pod_rbf.y.rows()) = pod_rbf.y;
251 pod_rbf.online_solution.append(tmp_sol);
256 "./ITHACAoutput/Matrices/");
258 "./ITHACAoutput/Matrices/");
261 "./ITHACAoutput/red_coeff");
263 "./ITHACAoutput/red_coeff");
265 "./ITHACAoutput/red_coeff");
266 pod_rbf.rbfCoeffMat = rbfCoeff;
268 pod_rbf.reconstruct(
true,
"./ITHACAoutput/Reconstruction/");
273 pod_normal.nu = 1e-3;
274 pod_normal.tauU.resize(2, 1);
277 for (label k = 0; k < par_online.rows(); k++)
279 Eigen::MatrixXd vel_now(2, 1);
280 vel_now(0, 0) = par_online(k, 0);
281 vel_now(1, 0) = par_online(k, 1);
282 pod_normal.tauU(0, 0) = 0;
283 pod_normal.tauU(1, 0) = 0;
284 pod_normal.solveOnline_sup(vel_now);
285 Eigen::MatrixXd tmp_sol(pod_normal.y.rows() + 1, 1);
287 tmp_sol.col(0).tail(pod_normal.y.rows()) = pod_normal.y;
288 pod_normal.online_solution.append(tmp_sol);
293 "./ITHACAoutput/red_coeffnew");
295 "./ITHACAoutput/red_coeffnew");
297 "./ITHACAoutput/red_coeffnew");
299 pod_normal.reconstruct(
true,
"./ITHACAoutput/Lam_Rec/");
306 Info <<
"Computing Frobenius errors for velocity fields" << endl;
309 Info <<
"Computing Frobenius errors for pressure fields" << endl;
312 Info <<
"Computing Frobenius errors for eddy viscosity fields" << endl;
314 pod_rbf.nutRecFields);
316 "./ITHACAoutput/ErrorsFrob/");
318 "./ITHACAoutput/ErrorsFrob/");
320 "./ITHACAoutput/ErrorsFrob/");
321 Info <<
"Computing L2 errors for velocity fields" << endl;
324 Info <<
"Computing L2 errors for pressure fields" << endl;
327 Info <<
"Computing L2 errors for eddy viscosity fields" << endl;
329 pod_rbf.nutRecFields);
331 "./ITHACAoutput/ErrorsL2/");
333 "./ITHACAoutput/ErrorsL2/");
335 "./ITHACAoutput/ErrorsL2/");
Header file of the EigenFunctions class.
Header file of the Foam2Eigen class.
Header file of the ITHACAPOD class.
Header file of the ITHACAstream class, it contains the implementation of several methods for input ou...
Header file of the ITHACAutilities namespace.
Header file of the ReducedSteadyNSTurb class.
Header file of the reducedSteadyNS class.
Header file of the SteadyNSTurb class.
Class for the definition of some general parameters, the parameters must be defined from the file ITH...
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
Class where it is implemented a reduced problem for the steady turbulent Navier-stokes problem.
autoPtr< volScalarField > _nut
Eddy viscosity field.
PtrList< volScalarField > nutFields
List of snapshots for the solution for eddy viscosity.
Class where it is implemented a reduced problem for the steady Navier-stokes problem.
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.
bool offline
Boolean variable, it is 1 if the Offline phase has already been computed, else 0.
Eigen::MatrixXd mu
Row matrix of parameters.
void truthSolve()
Perform a TruthSolve.
autoPtr< surfaceScalarField > _phi
Flux.
autoPtr< simpleControl > _simple
simpleControl
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
autoPtr< fv::options > _fvOptions
fvOptions
autoPtr< Time > _runTime
Time.
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
autoPtr< fvMesh > _mesh
Mesh.
autoPtr< singlePhaseTransportModel > _laminarTransport
Laminar transport (used by turbulence model).
autoPtr< IOMRFZoneList > _MRF
MRF variable.
autoPtr< volVectorField > Uinl
Initial dummy field with all Dirichlet boundary conditions.
autoPtr< volVectorField > _U
Velocity field.
autoPtr< volScalarField > _p
Pressure field.
Class where the tutorial number 6 is implemented.
volVectorField & U
[tutorial06]
void offlineSolve()
Perform an Offline solve.
void offlineSolve(Eigen::MatrixXd par, fileName folder)
Perform an Offline solve for a special set of parameter samples called par.
void getModes(PtrList< GeometricField< Type, PatchField, GeoMesh > > &snapshots, PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, word fieldName, bool podex, bool supex, bool sup, label nmodes, bool correctBC)
Computes the bases or reads them for a field.
void exportFields(PtrList< GeometricField< Type, PatchField, GeoMesh > > &field, word folder, word fieldname)
Function to export a scalar of vector field.
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 ...
List< Eigen::MatrixXd > readMatrix(word folder, word mat_name)
Read a three dimensional matrix from a txt file in Eigen format.
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.
double errorL2Rel(GeometricField< T, fvPatchField, volMesh > &field1, GeometricField< T, fvPatchField, volMesh > &field2, List< label > *labels)
Computes the relative error between two geometric Fields in L2 norm.
double errorFrobRel(GeometricField< Type, PatchField, GeoMesh > &field1, GeometricField< Type, PatchField, GeoMesh > &field2, List< label > *labels)
Computes the relative error between two Fields in the Frobenius norm.
Header file of the reductionProblem class.
Header file of the steadyNS class.