32#include "simpleControl.H"
33#include "simpleControl.H"
34#include "fvMeshSubset.H"
49 volScalarField
yPos =
S.mesh().C().component(vector::Y).ref();
50 volScalarField
xPos =
S.mesh().C().component(vector::X).ref();
52 for (
auto i = 0;
i <
S.size();
i++)
54 S[
i] = std::exp(- 2 * std::pow(
xPos[
i] - mu(0) - 1,
55 2) - 2 * std::pow(
yPos[
i] - mu(1) - 0.5, 2));
62 Eigen::MatrixXd mu, List<label> nodesList)
64 Eigen::VectorXd ret(nodesList.size());
65 volScalarField
yPos =
S.mesh().C().component(vector::Y).ref();
66 volScalarField
xPos =
S.mesh().C().component(vector::X).ref();
68 for (
auto i = 0;
i < nodesList.size();
i++)
70 ret[
i] = std::exp(- 2 * std::pow(
xPos[nodesList[
i]] - mu(0) - 1,
71 2) - 2 * std::pow(
yPos[nodesList[
i]] - mu(1) - 0.5, 2));
92 volScalarField
yPos =
S.mesh().C().component(vector::Y).ref();
93 volScalarField
xPos =
S.mesh().C().component(vector::X).ref();
95 for (
auto i = 0;
i <
S.size();
i++)
97 S[
i][0] = std::exp(- 2 * std::pow(
xPos[
i] - mu(0) - 1,
98 2) - 2 * std::pow(
yPos[
i] - mu(1) - 0.5, 2));
99 S[
i][1] = std::exp(- 2 * std::pow(
xPos[
i] - mu(0) - 0.5,
100 2) - 2 * std::pow(
yPos[
i] - mu(1) - 0.5, 2));
101 S[
i][2] = std::exp(- 2 * std::pow(
xPos[
i] - mu(0) - 1.5,
102 2) - 2 * std::pow(
yPos[
i] - mu(1) - 0., 2));
109 Eigen::MatrixXd mu, List<label> nodesList)
111 Eigen::VectorXd ret(nodesList.size() * 3);
112 volScalarField
yPos =
S.mesh().C().component(vector::Y).ref();
113 volScalarField
xPos =
S.mesh().C().component(vector::X).ref();
115 for (
auto i = 0;
i < nodesList.size();
i++)
117 ret(
i) = std::exp(- 2 * std::pow(
xPos[nodesList[
i]] - mu(0) - 1,
118 2) - 2 * std::pow(
yPos[nodesList[
i]] - mu(1) - 0.5, 2));
119 ret(
i + nodesList.size()) = std::exp(- 2 * std::pow(
xPos[nodesList[
i]] - mu(
121 2) - 2 * std::pow(
yPos[nodesList[
i]] - mu(1) - 0.5, 2));
122 ret(
i + 2 * nodesList.size()) = std::exp(- 2 * std::pow(
123 xPos[nodesList[
i]] - mu(0) - 1.5,
124 2) - 2 * std::pow(
yPos[nodesList[
i]] - mu(1) - 0., 2));
139 HyperReduction<PtrList<volVectorField> &, PtrList<volScalarField> & >
144 volVectorField& V, volScalarField&
S, Eigen::MatrixXd mu)
146 volScalarField
yPos =
S.mesh().C().component(vector::Y).ref();
147 volScalarField
xPos =
S.mesh().C().component(vector::X).ref();
149 for (
auto i = 0;
i <
S.size();
i++)
151 V[
i][0] = std::exp(- 2 * std::pow(
xPos[
i] - mu(0) - 1,
152 2) - 2 * std::pow(
yPos[
i] - mu(1) - 0.5, 2));
153 V[
i][1] = std::exp(- 2 * std::pow(
xPos[
i] - mu(0) - 0.5,
154 2) - 2 * std::pow(
yPos[
i] - mu(1) - 0.5, 2));
155 V[
i][2] = std::exp(- 2 * std::pow(
xPos[
i] - mu(0) - 1.5,
156 2) - 2 * std::pow(
yPos[
i] - mu(1) - 0., 2));
157 S[
i] = std::exp(- 2 * std::pow(
xPos[
i] - mu(0) - 1,
158 2) - 2 * std::pow(
yPos[
i] - mu(1) - 0.5, 2));
161 return std::make_pair(V,
S);
165 Eigen::MatrixXd mu, List<label> nodesList)
167 Eigen::VectorXd ret(nodesList.size() * 4);
168 volScalarField
yPos =
S.mesh().C().component(vector::Y).ref();
169 volScalarField
xPos =
S.mesh().C().component(vector::X).ref();
171 for (
auto i = 0;
i < nodesList.size();
i++)
173 ret(
i) = std::exp(- 2 * std::pow(
xPos[nodesList[
i]] - mu(0) - 1,
174 2) - 2 * std::pow(
yPos[nodesList[
i]] - mu(1) - 0.5, 2));
175 ret(
i + nodesList.size()) = std::exp(- 2 * std::pow(
xPos[nodesList[
i]] - mu(
177 2) - 2 * std::pow(
yPos[nodesList[
i]] - mu(1) - 0.5, 2));
178 ret(
i + 2 * nodesList.size()) = std::exp(- 2 * std::pow(
179 xPos[nodesList[
i]] - mu(0) - 1.5,
180 2) - 2 * std::pow(
yPos[nodesList[
i]] - mu(1) - 0., 2));
181 ret(
i + 3 * nodesList.size()) = std::exp(- 2 * std::pow(
182 xPos[nodesList[
i]] - mu(0) - 1,
183 2) - 2 * std::pow(
yPos[nodesList[
i]] - mu(1) - 0.5, 2));
200 int n_modes =
para->ITHACAdict->lookupOrDefault<
int>(
"Modes", 15);
201 int n_nodes =
para->ITHACAdict->lookupOrDefault<
int>(
"Nodes", 15);
203 word methodName =
para->ITHACAdict->lookupOrDefault<word>(
"HyperReduction",
207 PtrList<volScalarField> Sp;
220 dimensionedScalar(
"zero", dimensionSet(0, 0, -1, 1, 0, 0, 0), 0)
223 Eigen::MatrixXd pars;
227 for (
int i = 0;
i < 100;
i++)
230 Sp.append((
S).clone());
235 Eigen::MatrixXd parTest;
238 Eigen::VectorXi initSeeds;
241 if (methodName ==
"GappyDEIM")
244 Eigen::MatrixXd snapshotsModes;
245 Eigen::VectorXd normalizingWeights;
249 unsigned int layers{2};
252 PtrList<volScalarField> testTrueFields;
253 PtrList<volScalarField> testRecFields;
255 for (
unsigned int idTest = 0; idTest < parTest.rows(); idTest++)
259 parTest.row(idTest));
264 testRecFields.append(S2.clone());
265 testTrueFields.append(
S.clone());
272 Info <<
"GappyDEIM max relative error: " << err.maxCoeff() << endl;
273 Info <<
"GappyDEIM mean relative error: " << err.array().mean() << endl;
275 else if (methodName ==
"ECP")
278 bool saveOFModes{
true};
279 Eigen::MatrixXd snapshotsModes;
280 Eigen::VectorXd normalizingWeights;
283 c.
offlineECP(snapshotsModes, normalizingWeights);
285 unsigned int layers{2};
288 Eigen::VectorXd results(parTest.rows());
290 for (
unsigned int idTest = 0; idTest < parTest.rows(); idTest++)
296 parTest.row(idTest)));
297 double trueIntegral = (normalizingWeights.cwiseInverse().asDiagonal() *
299 double testIntegral = (c.
wPU * f).array().sum();
302 results(idTest) = trueIntegral - testIntegral;
305 Info <<
"ECP max error: " << results.cwiseAbs().maxCoeff() << endl;
306 Info <<
"ECP mean error: " << results.cwiseAbs().mean() << endl;
313 int n_modes =
para->ITHACAdict->lookupOrDefault<
int>(
"Modes", 15);
314 int n_nodes =
para->ITHACAdict->lookupOrDefault<
int>(
"Nodes", 15);
316 word methodName =
para->ITHACAdict->lookupOrDefault<word>(
"HyperReduction",
320 PtrList<volVectorField> Sp;
333 dimensionedVector(
"zero", dimensionSet(0, 0, -1, 1, 0, 0, 0), vector(0, 0, 0))
336 Eigen::MatrixXd pars;
340 for (
int i = 0;
i < 100;
i++)
343 Sp.append((
S).clone());
348 Eigen::MatrixXd parTest;
351 Eigen::VectorXi initSeeds;
354 if (methodName ==
"GappyDEIM")
357 "Gaussian_function", Sp);
358 Eigen::MatrixXd snapshotsModes;
359 Eigen::VectorXd normalizingWeights;
363 unsigned int layers{2};
366 PtrList<volVectorField> testTrueFields;
367 PtrList<volVectorField> testRecFields;
369 for (
unsigned int idTest = 0; idTest < parTest.rows(); idTest++)
373 parTest.row(idTest));
378 testRecFields.append(S2.clone());
379 testTrueFields.append(
S.clone());
386 Info <<
"GappyDEIM max relative error: " << err.maxCoeff() << endl;
387 Info <<
"GappyDEIM mean relative error: " << err.array().mean() << endl;
389 else if (methodName ==
"ECP")
392 "Gaussian_function", Sp);
393 bool saveOFModes{
true};
394 Eigen::MatrixXd snapshotsModes;
395 Eigen::VectorXd normalizingWeights;
398 c.
offlineECP(snapshotsModes, normalizingWeights);
400 unsigned int layers{2};
403 Eigen::VectorXd results(parTest.rows());
405 for (
unsigned int idTest = 0; idTest < parTest.rows(); idTest++)
412 double trueIntegral = (normalizingWeights.cwiseInverse().asDiagonal() *
414 double testIntegral = (c.
wPU * f).array().sum();
417 results(idTest) = trueIntegral - testIntegral;
420 Info <<
"ECP max error: " << results.cwiseAbs().maxCoeff() << endl;
421 Info <<
"ECP mean error: " << results.cwiseAbs().mean() << endl;
428 int n_modes =
para->ITHACAdict->lookupOrDefault<
int>(
"Modes", 15);
429 int n_nodes =
para->ITHACAdict->lookupOrDefault<
int>(
"Nodes", 15);
431 word methodName =
para->ITHACAdict->lookupOrDefault<word>(
"HyperReduction",
435 PtrList<volVectorField> Vp;
436 PtrList<volScalarField> Sp;
449 dimensionedVector(
"zero", dimensionSet(0, 0, -1, 1, 0, 0, 0), vector(0, 0, 0))
463 dimensionedScalar(
"zero", dimensionSet(0, 0, -1, 1, 0, 0, 0), 0)
466 Eigen::MatrixXd pars;
470 for (
int i = 0;
i < 100;
i++)
473 Vp.append((V).clone());
474 Sp.append((
S).clone());
480 Eigen::MatrixXd parTest;
483 Eigen::VectorXi initSeeds;
486 if (methodName ==
"GappyDEIM")
489 "Gaussian_function", Vp, Sp);
490 Eigen::MatrixXd snapshotsModes;
491 Eigen::VectorXd normalizingWeights;
495 unsigned int layers{2};
499 PtrList<volVectorField> testTrueFieldsV;
500 PtrList<volVectorField> testRecFieldsV;
501 PtrList<volScalarField> testTrueFieldsS;
502 PtrList<volScalarField> testRecFieldsS;
504 for (
unsigned int idTest = 0; idTest < parTest.rows(); idTest++)
507 auto theta = c.
onlineCoeffs(sfield(), parTest.row(idTest));
509 Eigen::VectorXd recvec = aprfield.head(3 *
S.size());
510 Eigen::VectorXd recsca = aprfield.tail(
S.size());
516 parTest.row(idTest));
517 testRecFieldsV.append(V2.clone());
518 testTrueFieldsV.append(V.clone());
521 testRecFieldsS.append(S2.clone());
522 testTrueFieldsS.append(
S.clone());
529 Info <<
"GappyDEIM vector field max relative error: " << errV.maxCoeff() <<
531 Info <<
"GappyDEIM vector field mean relative error: " << errV.array().mean() <<
534 Info <<
"GappyDEIM scalar max relative error: " << errS.maxCoeff() << endl;
535 Info <<
"GappyDEIM scalar mean relative error: " << errS.array().mean() << endl;
537 else if (methodName ==
"ECP")
540 "Gaussian_function", Vp, Sp);
541 bool saveOFModes{
true};
542 Eigen::MatrixXd snapshotsModes;
543 Eigen::VectorXd normalizingWeights;
546 c.
offlineECP(snapshotsModes, normalizingWeights);
548 unsigned int layers{2};
552 Eigen::VectorXd results(parTest.rows());
554 for (
unsigned int idTest = 0; idTest < parTest.rows(); idTest++)
560 parTest.row(idTest));
563 Eigen::VectorXd ff(ffV.rows() + ffS.rows());
564 ff.head(ffV.rows()) = ffV;
565 ff.tail(ffS.rows()) = ffS;
566 double trueIntegral = (normalizingWeights.cwiseInverse().asDiagonal() *
568 double testIntegral = (c.
wPU * f).array().sum();
571 results(idTest) = trueIntegral - testIntegral;
574 Info <<
"ECP max error: " << results.cwiseAbs().maxCoeff() << endl;
575 Info <<
"ECP mean error: " << results.cwiseAbs().mean() << endl;
579int main(
int argc,
char* argv[])
582 argList::addOption(
"test",
"scalar",
"Perform scalar test");
583 argList::addOption(
"test",
"vector",
"Perform vector test");
584 argList::addOption(
"test",
"vs",
"Perform (vector, scalar) test");
586 HashTable<string> validParOptions;
603#include "setRootCase.H"
604 Foam::Time
runTime(Foam::Time::controlDictName, args);
609 Foam::fvMesh::defaultRegion,
612 Foam::IOobject::MUST_READ
617 if (args.get(
"test").match(
"scalar"))
619 Info <<
"Init scalar testcase\n";
622 else if (args.get(
"test").match(
"vector"))
624 Info <<
"Init vector testcase\n";
627 else if (args.get(
"test").match(
"vs"))
629 Info <<
"Init vector scalar testcase\n";
634 Info <<
"Pass '-test scalar', '-test vector', '-test vs'" << endl;
int main(int argc, char *argv[])
void test_vector(ITHACAparameters *para, Foam::fvMesh &mesh, Foam::Time &runTime)
void test_vector_scalar(ITHACAparameters *para, Foam::fvMesh &mesh, Foam::Time &runTime)
void test_scalar(ITHACAparameters *para, Foam::fvMesh &mesh, Foam::Time &runTime)
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.
static GeometricField< scalar, PatchField, GeoMesh > Eigen2field(GeometricField< scalar, PatchField, GeoMesh > &field, Eigen::VectorXd &eigen_vector, bool correctBC=true)
Convert a vector in Eigen format into an OpenFOAM scalar GeometricField.
static Eigen::VectorXd field2Eigen(GeometricField< tensor, PatchField, GeoMesh > &field)
Convert a vector OpenFOAM field into an Eigen Vector.
Eigen::VectorXd onlineCoeffs(volScalarField &S, Eigen::MatrixXd mu)
HyperReduction(label n_modes, label n_nodes, Eigen::VectorXi initialSeeds, word problemName, SnapshotsLists &&...snapshotsLists)
Construct HyperReduction class, interpolation-based.
static volScalarField evaluate_expression(volScalarField &S, Eigen::MatrixXd mu)
static Eigen::VectorXd evaluate_expression(volScalarField &S, Eigen::MatrixXd mu, List< label > nodesList)
static volVectorField evaluate_expression(volVectorField &S, Eigen::MatrixXd mu)
HyperReduction(label n_modes, label n_nodes, Eigen::VectorXi initialSeeds, word problemName, SnapshotsLists &&...snapshotsLists)
Construct HyperReduction class, interpolation-based.
Eigen::VectorXd onlineCoeffs(volVectorField &S, Eigen::MatrixXd mu)
static Eigen::VectorXd evaluate_expression(volVectorField &S, Eigen::MatrixXd mu, List< label > nodesList)
Eigen::VectorXd onlineCoeffs(volScalarField &S, Eigen::MatrixXd mu)
static Eigen::VectorXd evaluate_expression(volScalarField &S, Eigen::MatrixXd mu, List< label > nodesList)
HyperReduction(label n_modes, label n_nodes, Eigen::VectorXi initialSeeds, word problemName, SnapshotsLists &&...snapshotsLists)
Construct HyperReduction class, interpolation-based.
static std::pair< volVectorField, volScalarField > evaluate_expression(volVectorField &V, volScalarField &S, Eigen::MatrixXd mu)
SnapshotsListTuple snapshotsListTuple
The snapshots matrix containing the nonlinear function or operator.
void generateSubmesh(label layers, const fvMesh &mesh)
Compute the submesh common to all fields in SnapshotsLists.
autoPtr< FieldType > interpolateField(const FieldType &field)
TODO.
Eigen::MatrixXd renormalizedBasisMatrix
Renormalized basis of HR.
void offlineGappyDEIM(Eigen::MatrixXd &snapshotsModes, Eigen::VectorXd &normalizingWeights)
Methods implemented: 'GappyDEIM' from "DEIM, Chaturantabut, Saifon, and Danny C. Sorensen....
List< label > localNodePoints
void offlineECP(Eigen::MatrixXd &snapshotsModes, Eigen::VectorXd &normalizingWeights)
Methods implemented: 'ECP' from "ECP, Hernandez, Joaquin Alberto, Manuel Alejandro Caicedo,...
HyperReduction(label n_modes, label n_nodes, Eigen::VectorXi initialSeeds, word problemName, SnapshotsLists &&...snapshotsLists)
Construct HyperReduction class, interpolation-based.
void getModesSVD(SnapshotsListTuple &SnapshotsListTuple, Eigen::MatrixXd &modesSVD, Eigen::VectorXd &fieldWeights, bool saveModesFlag=false)
TODO.
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.
void exportSolution(GeometricField< Type, PatchField, GeoMesh > &s, fileName subfolder, fileName folder, word fieldName)
Export a field to file in a certain folder and subfolder.
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.
Eigen::Matrix< T, -1, dim > load(Eigen::Matrix< T, -1, dim > &mat, const std::string fname)
simpleControl simple(mesh)
volScalarField S(IOobject("S", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), T.mesh(), dimensionedScalar("zero", dimensionSet(0, 0, -1, 1, 0, 0, 0), 0))