50 para->runTime.time().constant(),
53 IOobject::READ_IF_PRESENT,
58 xyz = autoPtr<IOList<label >>
65 para->runTime.time().constant(),
68 IOobject::READ_IF_PRESENT,
82 Eigen::VectorXd
rho(1);
85 label ind_max, c1, xyz_in;
86 double max =
MatrixModes.cwiseAbs().col(0).maxCoeff(& ind_max, & c1);
93 P.insert(ind_max, 0) = 1;
97 A =
P.transpose() *
U;
99 c =
A.fullPivLu().solve(b);
101 max = r.cwiseAbs().maxCoeff(& ind_max, & c1);
103 P.insert(ind_max,
i) = 1;
106 rho.conservativeResize(
i + 1);
110 xyz().append(xyz_in);
148 para->runTime.time().constant(),
151 IOobject::READ_IF_PRESENT,
163 para->runTime.time().constant(),
166 IOobject::READ_IF_PRESENT,
178 para->runTime.time().constant(),
181 IOobject::READ_IF_PRESENT,
193 para->runTime.time().constant(),
196 IOobject::READ_IF_PRESENT,
208 para->runTime.time().constant(),
211 IOobject::READ_IF_PRESENT,
216 xyz_B = autoPtr<IOList<label >>
223 para->runTime.time().constant(),
226 IOobject::READ_IF_PRESENT,
239 Eigen::SparseMatrix<double> rA;
240 Eigen::VectorXd rhoA(1);
244 label ind_rowA, ind_colA, xyz_rowA, xyz_colA;
245 ind_rowA = ind_colA = xyz_rowA = xyz_colA = 0;
248 label ind_rowAOF = ind_rowA;
249 label ind_colAOF = ind_colA;
257 Eigen::SparseMatrix<double> Pnow(std::get<0>(
Matrix_Modes)[0].rows(),
259 Pnow.insert(ind_rowA, ind_colA) = 1;
266 cA = AA.fullPivLu().solve(bA);
269 rhoA.conservativeResize(
i + 1);
271 label ind_rowAOF = ind_rowA;
272 label ind_colAOF = ind_colA;
279 Eigen::SparseMatrix<double> Pnow(std::get<0>(
Matrix_Modes)[0].rows(),
281 Pnow.insert(ind_rowA, ind_colA) = 1;
286 UA).fullPivLu().inverse();
292 Eigen::VectorXd rhoB(1);
293 label ind_rowB, xyz_rowB, c1;
294 double maxB = std::get<1>(
Matrix_Modes)[0].cwiseAbs().maxCoeff(& ind_rowB,
296 label ind_rowBOF = ind_rowB;
299 xyz_B().append(xyz_rowB);
303 PB.insert(ind_rowB, 0) = 1;
307 AB =
PB.transpose() *
UB;
309 cB = AB.fullPivLu().solve(bB);
311 maxB = rB.cwiseAbs().maxCoeff(& ind_rowB, & c1);
312 ind_rowBOF = ind_rowB;
314 xyz_B().append(xyz_rowB);
316 PB.insert(ind_rowB,
i) = 1;
319 rhoB.conservativeResize(
i + 1);
334 Eigen::MatrixXd aux =
PB.transpose() *
UB;
365 new IOList<labelList>
370 para->runTime.time().constant(),
373 IOobject::READ_IF_PRESENT,
385 para->runTime.time().constant(),
388 IOobject::READ_IF_PRESENT,
393 volScalarField Indici
398 mesh.time().timeName(),
404 dimensionedScalar(
FunctionName +
"_indices", dimensionSet(0, 0, 0, 0, 0, 0, 0),
407 submesh = autoPtr<fvMeshSubset>(
new fvMeshSubset(
mesh));
426 submesh->subMesh().fvSchemes::readOpt() =
mesh.fvSchemes::readOpt();
427 submesh->subMesh().fvSolution::readOpt() =
mesh.fvSolution::readOpt();
428 submesh->subMesh().fvSchemes::read();
429 submesh->subMesh().fvSolution::read();
431 S f =
submesh->interpolate(field).ref();
432 scalar zerodot25 = 0.25;
456 new IOList<labelList>
461 para->runTime.time().constant(),
464 IOobject::READ_IF_PRESENT,
475 "uniqueMagicPointsA",
476 para->runTime.time().constant(),
479 IOobject::READ_IF_PRESENT,
485 volScalarField Indici
490 mesh.time().timeName(),
496 dimensionedScalar(
MatrixName +
"_A_indices", dimensionSet(0, 0, 0, 0, 0, 0, 0),
499 submeshA = autoPtr<fvMeshSubset>(
new fvMeshSubset(
mesh));
514 submeshA->subMesh().fvSchemes::readOpt() =
mesh.fvSchemes::readOpt();
515 submeshA->subMesh().fvSolution::readOpt() =
mesh.fvSolution::readOpt();
516 submeshA->subMesh().fvSchemes::read();
517 submeshA->subMesh().fvSolution::read();
519 S f =
submeshA->interpolate(field).ref();
520 scalar zerodot25 = 0.25;
547 new IOList<labelList>
552 para->runTime.time().constant(),
555 IOobject::READ_IF_PRESENT,
566 "uniqueMagicPointsB",
567 para->runTime.time().constant(),
570 IOobject::READ_IF_PRESENT,
576 volScalarField Indici
581 mesh.time().timeName(),
587 dimensionedScalar(
MatrixName +
"_B_indices", dimensionSet(0, 0, 0, 0, 0, 0, 0),
590 submeshB = autoPtr<fvMeshSubset>(
new fvMeshSubset(
mesh));
603 std::cout.setstate(std::ios_base::failbit);
609 submeshB->subMesh().fvSchemes::readOpt() =
mesh.fvSchemes::readOpt();
610 submeshB->subMesh().fvSolution::readOpt() =
mesh.fvSolution::readOpt();
611 submeshB->subMesh().fvSchemes::read();
612 submeshB->subMesh().fvSolution::read();
614 S f =
submeshB->interpolate(field).ref();
615 scalar zerodot25 = 0.25;
637 List<label> localPoints;
639 for (label
i = 0;
i < points.size();
i++)
641 for (label j = 0; j <
submesh.cellMap().size(); j++)
643 if (
submesh.cellMap()[j] == points[
i])
645 localPoints.append(j);
662 else if (ind_rowA <
Ncells * 2)
665 ind_rowA = ind_rowA -
Ncells;
670 ind_rowA = ind_rowA - 2 *
Ncells;
677 else if (ind_colA <
Ncells * 2)
680 ind_colA = ind_colA -
Ncells;
685 ind_colA = ind_colA - 2 *
Ncells;
696 else if (ind_rowA <
Ncells * 2)
699 ind_rowA = ind_rowA -
Ncells;
704 ind_rowA = ind_rowA - 2 *
Ncells;
713 "You have to compute the magicPoints before calling this function, try to rerun generateSubmesh");
714 F f =
submesh().interpolate(field).ref();
723 "You have to compute the magicPointsA before calling this function, try to rerun generateSubmeshMatrix");
724 F f =
submeshA().interpolate(field).ref();
733 "You have to compute the magicPointsB before calling this function, try to rerun generateSubmeshVector");
734 F f =
submeshB().interpolate(field).ref();
756 word command =
"rm -r " +
Folder +
"/magicPoints";
758 command =
"rm -r " +
Folder +
"/xyz";
760 command =
"rm -r " +
Folder +
"/totalMagicPoints";
762 command =
"rm -r " +
Folder +
"/uniqueMagicPoints";
766 autoPtr<IOList<label >>
773 para->runTime.time().constant(),
776 IOobject::READ_IF_PRESENT,
783 for (label
i = 0;
i < newMagicPoints.size(); ++
i)
789 autoPtr<IOList<label >>
796 para->runTime.time().constant(),
799 IOobject::READ_IF_PRESENT,
806 for (label
i = 0;
i < newMagicPoints.size(); ++
i)
808 xyz().append(newxyz[
i]);
817 label MaxModesB, word MatrixName);
820 label MaxModesB, word MatrixName);
822 word FunctionName, word FieldName);
824 word FunctionName, word FieldName);
828 volVectorField& field);
830 volVectorField& field);
832 volScalarField& field);
834 volScalarField& field);
836 volTensorField& field);
838 volTensorField& field);
840 const volVectorField& field);
842 const volVectorField& field);
844 const volScalarField& field);
846 const volScalarField& field);
848 const volTensorField& field);
850 const volTensorField& field);
854 volScalarField& field);
856 volVectorField& field);
857template surfaceScalarField
859template surfaceVectorField
862 volScalarField& field);
864 volVectorField& field);
865template surfaceScalarField
867template surfaceVectorField
872 volScalarField& field);
874 volVectorField& field);
875template surfaceScalarField
877template surfaceVectorField
880 volScalarField& field);
882 volVectorField& field);
883template surfaceScalarField
885template surfaceVectorField
890 label layers,
const fvMesh&
mesh, volScalarField field,
893 label layers,
const fvMesh&
mesh, volVectorField field,
896 label layers,
const fvMesh&
mesh, volScalarField field,
899 label layers,
const fvMesh&
mesh, volVectorField field,
904 label layers,
const fvMesh&
mesh, volScalarField field, label secondTime);
906 label layers,
const fvMesh&
mesh, volVectorField field, label secondTime);
907template surfaceScalarField
909 surfaceScalarField field, label secondTime);
910template surfaceVectorField
912 surfaceVectorField field, label secondTime);
914 label layers,
const fvMesh&
mesh, volScalarField field, label secondTime);
916 label layers,
const fvMesh&
mesh, volVectorField field, label secondTime);
917template surfaceScalarField
919 surfaceScalarField field, label secondTime);
920template surfaceVectorField
922 surfaceVectorField field, label secondTime);
926 label layers,
const fvMesh&
mesh, volScalarField field, label secondTime);
928 label layers,
const fvMesh&
mesh, volVectorField field, label secondTime);
929template surfaceScalarField
931 surfaceScalarField field, label secondTime);
932template surfaceVectorField
934 surfaceVectorField field, label secondTime);
936 label layers,
const fvMesh&
mesh, volScalarField field, label secondTime);
938 label layers,
const fvMesh&
mesh, volVectorField field, label secondTime);
939template surfaceScalarField
941 surfaceScalarField field, label secondTime);
942template surfaceVectorField
944 surfaceVectorField field, label secondTime);
#define M_Assert(Expr, Msg)
autoPtr< fvMeshSubset > submeshA
Submesh of the DEIM method.
List< Eigen::SparseMatrix< double > > MatrixOnlineA
Online Matrices.
autoPtr< fvMeshSubset > submesh
Submesh of the DEIM method.
std::tuple< List< Eigen::SparseMatrix< double > >, List< Eigen::VectorXd > > Matrix_Modes
label MaxModes
The maximum number of modes to be considered.
autoPtr< IOList< label > > uniqueMagicPoints
List of unique indices that define the submesh.
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,...
List< label > localMagicPointsAcol
Indices of the local magic points in the subMesh.
S generateSubmesh(label layers, const fvMesh &mesh, S field, label secondTime=0)
Function to generate the submesh for the nonlinear function case.
autoPtr< IOList< label > > magicPointsAcol
Magic points in the case of the a matrix function (cols indices)
autoPtr< IOList< labelList > > totalMagicPointsA
Magic points and indices of the surrounding layers.
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.
autoPtr< IOList< label > > magicPoints
Magic points in the case of the a nonlinear function.
List< label > localMagicPointsB
Indices of the local magic points in the subMesh.
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 > > xyz
word MatrixName
The name of the matrix.
autoPtr< IOList< label > > xyz_B
DEIM(PtrList< T > &SnapShotsMatrix, label MaxModes, word FunctionName, word FieldName)
Construct DEIM for non-linear function.
List< label > localMagicPoints
Indices of the local magic points in the subMesh.
autoPtr< IOList< labelList > > totalMagicPoints
Magic points and indices of the surrounding layers.
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
autoPtr< IOList< label > > uniqueMagicPointsA
List of unique indices that define the submesh.
List< Eigen::SparseMatrix< double > > PA
List< label > localMagicPointsArow
Indices of the local magic points in the subMesh.
word Folder
Folder for nonlinear functions.
PtrList< fvScalarMatrix > modes
word FolderM
Folder in the matrix case.
autoPtr< IOList< label > > uniqueMagicPointsB
List of unique indices that define the submesh.
void check3DIndices(label &ind_rowA, label &ind_colA, label &xyz_rowA, label &xyz_colA)
check3DIndices in case of three dimensional fields
autoPtr< IOList< label > > magicPointsArow
Magic points in the case of the a matrix function (rows indices)
Eigen::SparseMatrix< double > P
autoPtr< IOList< labelList > > totalMagicPointsB
Magic points and indices of the surrounding layers.
autoPtr< IOList< label > > xyz_Acol
F generateSubField(F &field)
Function to generate a a subfield in the location of the magic points.
Eigen::MatrixXd MatrixOnline
Online Matrices.
bool runSubMesh
Bool variable to check if the SubMesh is available.
List< Eigen::SparseMatrix< double > > UA
autoPtr< fvMeshSubset > submeshB
Submesh of the DEIM method.
autoPtr< IOList< label > > magicPointsB
Magic points in the case of the a matrix function, right hand side.
label getNcells(label sizeM)
get the number of cells from the dimension of a LHS matrix
F generateSubFieldMatrix(F &field)
Function to generate a a subfield in the location of the magic points computed for the Matrix (LHS)
Eigen::SparseMatrix< double > PB
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.
word FunctionName
The name of the non-linear function.
List< label > global2local(List< label > &points, fvMeshSubset &submesh)
Get local indices in the submeshe from indices in the global ones.
bool runSubMeshA
Bool variable to check if the SubMesh is available.
bool runSubMeshB
Bool variable to check if the SubMesh is available.
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...
static ITHACAparameters * getInstance(fvMesh &mesh, Time &localTime)
Gets an instance of ITHACAparameters, to be used if the instance is not 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)
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))