34DEIM<T>::DEIM (PtrList<T>& s, label MaxModes, word FunctionName, word FieldName)
38 FunctionName(FunctionName)
49 para->
runTime.time().constant(),
52 IOobject::READ_IF_PRESENT,
57 xyz = autoPtr<IOList<label>>
64 para->runTime.time().constant(),
67 IOobject::READ_IF_PRESENT,
81 Eigen::VectorXd rho(1);
84 label ind_max, c1, xyz_in;
85 double max =
MatrixModes.cwiseAbs().col(0).maxCoeff(&ind_max, &c1);
92 P.insert(ind_max, 0) = 1;
96 A =
P.transpose() *
U;
98 c =
A.fullPivLu().solve(b);
100 max = r.cwiseAbs().maxCoeff(&ind_max, &c1);
102 P.insert(ind_max,
i) = 1;
105 rho.conservativeResize(
i + 1);
109 xyz().append(xyz_in);
126DEIM<T>::DEIM (PtrList<T>& s, label MaxModesA, label MaxModesB, word MatrixName)
129 MaxModesA(MaxModesA),
130 MaxModesB(MaxModesB),
131 MatrixName(MatrixName),
146 para->
runTime.time().constant(),
149 IOobject::READ_IF_PRESENT,
161 para->
runTime.time().constant(),
164 IOobject::READ_IF_PRESENT,
176 para->
runTime.time().constant(),
179 IOobject::READ_IF_PRESENT,
191 para->
runTime.time().constant(),
194 IOobject::READ_IF_PRESENT,
206 para->
runTime.time().constant(),
209 IOobject::READ_IF_PRESENT,
214 xyz_B = autoPtr<IOList<label>>
221 para->
runTime.time().constant(),
224 IOobject::READ_IF_PRESENT,
237 Eigen::SparseMatrix<double> rA;
238 Eigen::VectorXd rhoA(1);
242 label ind_rowA, ind_colA, xyz_rowA, xyz_colA;
243 ind_rowA = ind_colA = xyz_rowA = xyz_colA = 0;
246 label ind_rowAOF = ind_rowA;
247 label ind_colAOF = ind_colA;
257 Pnow.insert(ind_rowA, ind_colA) = 1;
264 cA = AA.fullPivLu().solve(bA);
267 rhoA.conservativeResize(
i + 1);
269 label ind_rowAOF = ind_rowA;
270 label ind_colAOF = ind_colA;
277 Eigen::SparseMatrix<double> Pnow(std::get<0>(
Matrix_Modes)[0].rows(),
279 Pnow.insert(ind_rowA, ind_colA) = 1;
284 UA).fullPivLu().inverse();
290 Eigen::VectorXd rhoB(1);
291 label ind_rowB, xyz_rowB, c1;
292 double maxB = std::get<1>(
Matrix_Modes)[0].cwiseAbs().maxCoeff(&ind_rowB,
294 label ind_rowBOF = ind_rowB;
297 xyz_B().append(xyz_rowB);
300 PB.resize(
UB.rows(), 1);
301 PB.insert(ind_rowB, 0) = 1;
305 AB =
PB.transpose() *
UB;
307 cB = AB.fullPivLu().solve(bB);
309 maxB = rB.cwiseAbs().maxCoeff(&ind_rowB, &c1);
310 ind_rowBOF = ind_rowB;
312 xyz_B().append(xyz_rowB);
314 PB.insert(ind_rowB,
i) = 1;
317 rhoB.conservativeResize(
i + 1);
332 Eigen::MatrixXd aux =
PB.transpose() *
UB;
361 totalMagicPoints = autoPtr<IOList<labelList>>
363 new IOList<labelList>
368 para->
runTime.time().constant(),
371 IOobject::READ_IF_PRESENT,
376 uniqueMagicPoints = autoPtr<IOList<label>>
383 para->
runTime.time().constant(),
386 IOobject::READ_IF_PRESENT,
391 volScalarField Indici
395 FunctionName +
"_indices",
396 mesh.time().timeName(),
402 dimensionedScalar(FunctionName +
"_indices", dimensionSet(0, 0, 0, 0, 0, 0, 0),
405 submesh = autoPtr<fvMeshSubset>(
new fvMeshSubset(
mesh));
407 if (!totalMagicPoints().headerOk())
411 for (label
i = 0;
i < magicPoints().size();
i++)
414 totalMagicPoints().append(indices);
421 submesh->setCellSubset(uniqueMagicPoints());
423 submesh->setLargeCellSubset(uniqueMagicPoints());
425 submesh->subMesh().fvSchemes::readOpt() =
mesh.fvSchemes::readOpt();
426 submesh->subMesh().fvSolution::readOpt() =
mesh.fvSolution::readOpt();
427 submesh->subMesh().fvSchemes::read();
428 submesh->subMesh().fvSolution::read();
430 S f = submesh->interpolate(field).ref();
431 scalar zerodot25 = 0.25;
433 uniqueMagicPoints().List<label>::clone()());
438 localMagicPoints = global2local(magicPoints(), submesh());
443 totalMagicPoints().write();
444 uniqueMagicPoints().write();
454 totalMagicPointsA = autoPtr<IOList<labelList>>
456 new IOList<labelList>
461 para->
runTime.time().constant(),
464 IOobject::READ_IF_PRESENT,
469 uniqueMagicPointsA = autoPtr<IOList<label>>
475 "uniqueMagicPointsA",
476 para->
runTime.time().constant(),
479 IOobject::READ_IF_PRESENT,
485 volScalarField Indici
489 MatrixName +
"_A_indices",
490 mesh.time().timeName(),
496 dimensionedScalar(MatrixName +
"_A_indices", dimensionSet(0, 0, 0, 0, 0, 0, 0),
499 submeshA = autoPtr<fvMeshSubset>(
new fvMeshSubset(
mesh));
501 for (label
i = 0;
i < magicPointsArow().size();
i++)
506 totalMagicPointsA().append(indices);
511 submeshA->setCellSubset(uniqueMagicPointsA());
513 submeshA->setLargeCellSubset(uniqueMagicPointsA());
515 submeshA->subMesh().fvSchemes::readOpt() =
mesh.fvSchemes::readOpt();
516 submeshA->subMesh().fvSolution::readOpt() =
mesh.fvSolution::readOpt();
517 submeshA->subMesh().fvSchemes::read();
518 submeshA->subMesh().fvSolution::read();
520 S f = submeshA->interpolate(field).ref();
521 scalar zerodot25 = 0.25;
523 uniqueMagicPointsA().List<label>::clone()());
529 localMagicPointsArow = global2local(magicPointsArow(), submeshA());
530 localMagicPointsAcol = global2local(magicPointsAcol(), submeshA());
533 totalMagicPointsA().write();
534 uniqueMagicPointsA().write();
547 totalMagicPointsB = autoPtr<IOList<labelList>>
549 new IOList<labelList>
554 para->
runTime.time().constant(),
557 IOobject::READ_IF_PRESENT,
562 uniqueMagicPointsB = autoPtr<IOList<label>>
568 "uniqueMagicPointsB",
569 para->
runTime.time().constant(),
572 IOobject::READ_IF_PRESENT,
578 volScalarField Indici
582 MatrixName +
"_B_indices",
583 mesh.time().timeName(),
589 dimensionedScalar(MatrixName +
"_B_indices", dimensionSet(0, 0, 0, 0, 0, 0, 0),
592 submeshB = autoPtr<fvMeshSubset>(
new fvMeshSubset(
mesh));
594 for (label
i = 0;
i < magicPointsB().size();
i++)
597 totalMagicPointsB().append(indices);
606 std::cout.setstate(std::ios_base::failbit);
608 submeshB->setCellSubset(uniqueMagicPointsB());
610 submeshB->setLargeCellSubset(uniqueMagicPointsB());
612 submeshB->subMesh().fvSchemes::readOpt() =
mesh.fvSchemes::readOpt();
613 submeshB->subMesh().fvSolution::readOpt() =
mesh.fvSolution::readOpt();
614 submeshB->subMesh().fvSchemes::read();
615 submeshB->subMesh().fvSolution::read();
617 S f = submeshB->interpolate(field).ref();
618 scalar zerodot25 = 0.25;
620 uniqueMagicPointsB().List<label>::clone()());
625 localMagicPointsB = global2local(magicPointsB(), submeshB());
628 totalMagicPointsB().write();
629 uniqueMagicPointsB().write();
639 fvMeshSubset& submesh)
641 List<label> localPoints;
643 for (label
i = 0;
i < points.size();
i++)
645 for (label j = 0; j < submesh.cellMap().size(); j++)
647 if (submesh.cellMap()[j] == points[
i])
649 localPoints.append(j);
662 if (ind_rowA < Ncells)
666 else if (ind_rowA < Ncells * 2)
669 ind_rowA = ind_rowA - Ncells;
674 ind_rowA = ind_rowA - 2 * Ncells;
677 if (ind_colA < Ncells )
681 else if (ind_colA < Ncells * 2)
684 ind_colA = ind_colA - Ncells;
689 ind_colA = ind_colA - 2 * Ncells;
696 if (ind_rowA < Ncells)
700 else if (ind_rowA < Ncells * 2)
703 ind_rowA = ind_rowA - Ncells;
708 ind_rowA = ind_rowA - 2 * Ncells;
717 "You have to compute the magicPoints before calling this function, try to rerun generateSubmesh");
718 F f = submesh().interpolate(field).ref();
727 "You have to compute the magicPointsA before calling this function, try to rerun generateSubmeshMatrix");
728 F f = submeshA().interpolate(field).ref();
737 "You have to compute the magicPointsB before calling this function, try to rerun generateSubmeshVector");
738 F f = submeshB().interpolate(field).ref();
745 label Ncells = sizeM;
751 label Ncells = sizeM / 3;
758 Folder =
"ITHACAoutput/DEIM/" + FunctionName;
760 word command =
"rm -r " + Folder +
"/magicPoints";
762 command =
"rm -r " + Folder +
"/xyz";
764 command =
"rm -r " + Folder +
"/totalMagicPoints";
766 command =
"rm -r " + Folder +
"/uniqueMagicPoints";
770 autoPtr<IOList<label>>
777 para->
runTime.time().constant(),
780 IOobject::READ_IF_PRESENT,
787 for (label
i = 0;
i < newMagicPoints.size(); ++
i)
789 magicPoints().append(newMagicPoints[
i]);
794 autoPtr<IOList<label>>
801 para->
runTime.time().constant(),
804 IOobject::READ_IF_PRESENT,
811 for (label
i = 0;
i < newMagicPoints.size(); ++
i)
813 xyz().append(newxyz[
i]);
816 magicPoints().write();
823 label MaxModesB, word MatrixName);
826 label MaxModesB, word MatrixName);
828 word FunctionName, word FieldName);
830 word FunctionName, word FieldName);
834 volVectorField& field);
836 volVectorField& field);
838 volScalarField& field);
840 volScalarField& field);
842 volTensorField& field);
844 volTensorField& field);
846 const volVectorField& field);
848 const volVectorField& field);
850 const volScalarField& field);
852 const volScalarField& field);
854 const volTensorField& field);
856 const volTensorField& field);
860 volScalarField& field);
862 volVectorField& field);
863template surfaceScalarField
865template surfaceVectorField
868 volScalarField& field);
870 volVectorField& field);
871template surfaceScalarField
873template surfaceVectorField
878 volScalarField& field);
880 volVectorField& field);
881template surfaceScalarField
883template surfaceVectorField
886 volScalarField& field);
888 volVectorField& field);
889template surfaceScalarField
891template surfaceVectorField
896 label layers,
const fvMesh&
mesh, volScalarField field,
899 label layers,
const fvMesh&
mesh, volVectorField field,
902 label layers,
const fvMesh&
mesh, volScalarField field,
905 label layers,
const fvMesh&
mesh, volVectorField field,
910 label layers,
const fvMesh&
mesh, volScalarField field, label secondTime);
912 label layers,
const fvMesh&
mesh, volVectorField field, label secondTime);
913template surfaceScalarField
915 surfaceScalarField field, label secondTime);
916template surfaceVectorField
918 surfaceVectorField field, label secondTime);
920 label layers,
const fvMesh&
mesh, volScalarField field, label secondTime);
922 label layers,
const fvMesh&
mesh, volVectorField field, label secondTime);
923template surfaceScalarField
925 surfaceScalarField field, label secondTime);
926template surfaceVectorField
928 surfaceVectorField field, label secondTime);
932 label layers,
const fvMesh&
mesh, volScalarField field, label secondTime);
934 label layers,
const fvMesh&
mesh, volVectorField field, label secondTime);
935template surfaceScalarField
937 surfaceScalarField field, label secondTime);
938template surfaceVectorField
940 surfaceVectorField field, label secondTime);
942 label layers,
const fvMesh&
mesh, volScalarField field, label secondTime);
944 label layers,
const fvMesh&
mesh, volVectorField field, label secondTime);
945template surfaceScalarField
947 surfaceScalarField field, label secondTime);
948template surfaceVectorField
950 surfaceVectorField field, label secondTime);
#define M_Assert(Expr, Msg)
autoPtr< IOList< label > > magicPointsAcol
Magic points in the case of the a matrix function (cols indices)
autoPtr< IOList< label > > xyz
Definition of the x, y, z coordinate of the identified element in the matrix or source term 0 for x,...
label MaxModes
The maximum number of modes to be considered.
S generateSubmesh(label layers, const fvMesh &mesh, S field, label secondTime=0)
Function to generate the submesh for the nonlinear function case.
S generateSubmeshMatrix(label layers, const fvMesh &mesh, S field, label secondTime=0)
Function to generate the submesh for the nonlinear matrix function case (RHS)
Eigen::MatrixXd MatrixOnlineB
Online Matrices.
S generateSubmeshVector(label layers, const fvMesh &mesh, S field, label secondTime=0)
Function to generate the submesh for the nonlinear matrix function case (LHS)
autoPtr< IOList< label > > magicPoints
Magic points in the case of the a nonlinear function.
List< Eigen::SparseMatrix< double > > UA
The U matrix of the DEIM method.
autoPtr< IOList< label > > xyz_Acol
Definition of the x, y, z coordinate of the identified element in the matrix or source term 0 for x,...
word MatrixName
The name of the matrix.
Eigen::MatrixXd U
The U matrix of the DEIM method.
DEIM(PtrList< T > &SnapShotsMatrix, label MaxModes, word FunctionName, word FieldName)
Construct DEIM for non-linear function.
F generateSubFieldVector(F &field)
Function to generate a a subfield in the location of the magic points computed for the Matrix (RHS)
Eigen::MatrixXd MatrixModes
The matrix containing the modes.
autoPtr< IOList< label > > magicPointsArow
Magic points in the case of the a matrix function (rows indices)
word Folder
Folder for nonlinear functions.
std::tuple< List< Eigen::SparseMatrix< double > >, List< Eigen::VectorXd > > Matrix_Modes
Matrix Modes.
PtrList< T > modes
The POD modes of the DEIM procedure that can be.
word FolderM
Folder in the matrix case.
void check3DIndices(label &ind_rowA, label &ind_colA, label &xyz_rowA, label &xyz_colA)
check3DIndices in case of three dimensional fields
Eigen::SparseMatrix< double > P
The P matrix of the DEIM method.
F generateSubField(F &field)
Function to generate a a subfield in the location of the magic points.
autoPtr< IOList< label > > xyz_Arow
Definition of the x, y, z coordinate of the identified element in the matrix or source term 0 for x,...
Eigen::MatrixXd MatrixOnline
Online Matrices.
List< Eigen::SparseMatrix< double > > MatrixOnlineA
Online Matrices.
label getNcells(label sizeM)
get the number of cells from the dimension of a LHS matrix
autoPtr< IOList< label > > xyz_B
Definition of the x, y, z coordinate of the identified element in the matrix or source term 0 for x,...
F generateSubFieldMatrix(F &field)
Function to generate a a subfield in the location of the magic points computed for the Matrix (LHS)
autoPtr< IOList< label > > magicPointsB
Magic points in the case of the a matrix function, right hand side.
Eigen::SparseMatrix< double > PB
The P matrix of the DEIM method.
void setMagicPoints(labelList &newMagicPoints, labelList &newxyz)
Function to set the magic points externally.
PtrList< T > SnapShotsMatrix
The snapshots matrix containing the nonlinear function or operator.
label Ncells
Int Number of Cells;.
Eigen::MatrixXd UB
The U matrix of the DEIM method.
word FunctionName
The name of the non-linear function.
List< Eigen::SparseMatrix< double > > PA
The P matrix of the DEIM method.
List< label > global2local(List< label > &points, fvMeshSubset &submesh)
Get local indices in the submeshe from indices in the global ones.
static Eigen::MatrixXd PtrList2Eigen(PtrList< GeometricField< Type, PatchField, GeoMesh > > &fields, label Nfields=-1)
Convert a PtrList of snapshots to Eigen matrix (only internal field)
Class for the definition of some general parameters, the parameters must be defined from the file ITH...
Time & runTime
runTime defined locally
fvMesh & mesh
Mesh object defined locally.
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
Eigen::SparseMatrix< T > MVproduct(List< Eigen::SparseMatrix< T > > &A, Eigen::DenseBase< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > > &C)
Sparse Matrix-Vector product between a list of sparse matrices and a vector of coefficients.
T max(Eigen::SparseMatrix< T > &mat, label &ind_row, label &ind_col)
Find the maximum of a sparse Matrix (Useful for DEIM)
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > innerProduct(List< Eigen::SparseMatrix< T > > &A, List< Eigen::SparseMatrix< T > > &B)
Perform Frobenius inner Product between two list of sparse matrices A and B.
List< Eigen::SparseMatrix< T > > MMproduct(List< Eigen::SparseMatrix< T > > &A, Eigen::DenseBase< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > > &C)
Sparse Matrix - Dense Matrix product between a list of sparse matrices and a dense matrix.
std::tuple< List< Eigen::SparseMatrix< double > >, List< Eigen::VectorXd > > DEIMmodes(List< Eigen::SparseMatrix< double > > &A, List< Eigen::VectorXd > &b, label nmodesA, label nmodesB, word MatrixName)
Get the DEIM modes for a generic non a parametrized matrix coming from a differential operator functi...
void save(const List< Eigen::SparseMatrix< T > > &MatrixList, word folder, word MatrixName)
void load(List< Eigen::SparseMatrix< T > > &MatrixList, word folder, word MatrixName)
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 assignIF(GeometricField< Type, fvPatchField, volMesh > &s, Type value)
Assign internal field.
List< label > getIndices(const fvMesh &mesh, int index, int layers)
Gets the indices of the cells around a certain cell.
void assignONE(volScalarField &s, List< label > &L)
Assign one to volScalarField.
List< T > combineList(List< List< T > > &doubleList)
Combine a list of list into a single list with unique elements.
void save(const Eigen::Matrix< T, -1, dim > &mat, const std::string fname)
Eigen::Matrix< T, -1, dim > load(Eigen::Matrix< T, -1, dim > &mat, const std::string fname, std::string order="rowMajor")
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))