40#define _USE_MATH_DEFINES
46class tutorialIPOD:
public laplacianProblem
49 explicit tutorialIPOD(
int argc,
char* argv[])
51 laplacianProblem(argc, argv),
76 List<scalar> mu_now(9);
79 for (label i = 0; i <
mu.rows(); i++)
81 for (label j = 0; j <
mu.cols() ; j++)
97 volScalarField yPos =
T.mesh().C().component(vector::Y).ref();
98 volScalarField xPos =
T.mesh().C().component(vector::X).ref();
110 volScalarField nu1(
nu);
111 volScalarField nu2(
nu);
112 volScalarField nu3(
nu);
113 volScalarField nu4(
nu);
114 volScalarField nu5(
nu);
115 volScalarField nu6(
nu);
116 volScalarField nu7(
nu);
117 volScalarField nu8(
nu);
118 volScalarField nu9(
nu);
119 Eigen::MatrixXd Box1(2, 3);
120 Box1 << 0, 0, 0, 0.3, 0.3, 0.1;
121 Eigen::MatrixXd Box2(2, 3);
122 Box2 << 0.3, 0, 0, 0.6, 0.3, 0.1;
123 Eigen::MatrixXd Box3(2, 3);
124 Box3 << 0.6, 0, 0, 0.91, 0.3, 0.1;
125 Eigen::MatrixXd Box4(2, 3);
126 Box4 << 0, 0.3, 0, 0.3, 0.6, 0.1;
127 Eigen::MatrixXd Box5(2, 3);
128 Box5 << 0.3, 0.3, 0, 0.6, 0.6, 0.1;
129 Eigen::MatrixXd Box6(2, 3);
130 Box6 << 0.6, 0.3, 0, 0.91, 0.6, 0.1;
131 Eigen::MatrixXd Box7(2, 3);
132 Box7 << 0, 0.6, 0, 0.3, 0.91, 0.1;
133 Eigen::MatrixXd Box8(2, 3);
134 Box8 << 0.3, 0.61, 0, 0.6, 0.91, 0.1;
135 Eigen::MatrixXd Box9(2, 3);
136 Box9 << 0.6, 0.6, 0, 0.9, 0.91, 0.1;
160 for (
int i = 0; i <
nu_list.size(); i++)
169 word folder =
"./ITHACAoutput/test/";
171 List<scalar> mu_now(9);
172 volScalarField&
T =
_T();
174 for (label j = 0; j <
mu.cols() ; j++)
188int main(
int argc,
char* argv[])
195 int NmodesTout = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesTout", 15);
196 int NmodesTproj = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesTproj", 10);
197 double tolleranceSVD =
198 para->ITHACAdict->lookupOrDefault<
double>(
"tolleranceSVD", 1);
201 example.Tnumber = NmodesTout;
203 example.setParameters();
206 example.mu_range.col(0) = Eigen::MatrixXd::Ones(9, 1) * 0.001;
207 example.mu_range.col(1) = Eigen::MatrixXd::Ones(9, 1) * 0.1;
209 example.genRandPar(example.Tnumber);
211 example.theta.resize(9);
215 example.compute_nu();
217 example.assemble_operator();
219 example.offlineSolve();
225 scalarIncrementalPOD IPOD(example.Tfield[0], tolleranceSVD,
"L2");
228 for (
int fieldI = 1; fieldI < example.Tfield.size(); fieldI++)
230 IPOD.addSnapshot(example.Tfield[fieldI]);
235 word folder =
"./ITHACAoutput/testReconstruction";
237 volScalarField Tfull(example.solveFull(0.05));
238 PtrList<volScalarField> TfullList;
239 TfullList.append(Tfull.clone());
240 PtrList<volScalarField> Tproj;
242 example.Tmodes.projectSnapshots(TfullList, Tproj, NmodesTproj);
247 volScalarField relativeErrorField(Tproj[0]);
249 for (label i = 0; i < relativeErrorField.internalField().size(); i++)
251 if (std::abs(Tfull.ref()[i]) < EPS)
253 relativeErrorField.ref()[i] = (std::abs(Tfull.ref()[i] - Tproj[0].ref()[i])) /
258 relativeErrorField.ref()[i] = (std::abs(Tfull.ref()[i] - Tproj[0].ref()[i])) /
265 "relativeErrorField_POD");
267 relativeErrorField) << endl;
269 IPOD.projectSnapshots(TfullList, Tproj);
271 volScalarField Tipod = Tproj[0];
274 for (label i = 0; i < relativeErrorField.internalField().size(); i++)
276 if (std::abs(Tfull.ref()[i]) < EPS)
278 relativeErrorField.ref()[i] = (std::abs(Tfull.ref()[i] - Tipod.ref()[i])) / EPS;
282 relativeErrorField.ref()[i] = (std::abs(Tfull.ref()[i] - Tipod.ref()[i])) /
289 "relativeErrorField_IPOD");
290 Info <<
"\n\nRelative error L2 norm incrementalPOD = " <<
Header file of the ITHACAPOD class.
Header file of the ITHACAutilities namespace.
Header file of the reducedLaplacian 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.
PtrList< volScalarField > nu_list
Nu (diffusivity).
List< scalar > theta
Theta (coefficients of the affine expansion).
PtrList< fvScalarMatrix > operator_list
List of operators.
autoPtr< volScalarField > _T
Temperature field.
autoPtr< volScalarField > _nu
Diffusivity.
autoPtr< volScalarField > _S
Source Term.
PtrList< volScalarField > Tfield
List of snapshots for the solution.
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.
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.
void truthSolve()
Perform a TruthSolve.
Class where the tutorial number 20 is implemented.
void compute_nu()
Compute the diffusivity in each subdomain.
volScalarField & S
Source term field.
volScalarField & nu
Diffusivity field.
void SetSource()
Define the source term function.
volScalarField solveFull(double _mu)
Performs a full order solution for a uniform value of mu.
void assemble_operator()
Construct the operator_list where each term of the affine decomposition is stored.
void offlineSolve(word folder="./ITHACAoutput/Offline/")
It perform an offline Solve.
Header file of the incrementalPOD class.
Header file of the laplacianProblem class.
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 exportSolution(GeometricField< Type, PatchField, GeoMesh > &s, fileName subfolder, fileName folder, word fieldName)
Export a field to file in a certain folder and subfolder.
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 L2Norm(const T v)
Compute the L2 norm of v.
void setBoxToValue(GeometricField< Type, fvPatchField, volMesh > &field, Eigen::MatrixXd Box, Type value)
Set value of a volScalarField to a constant inside a given box.