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);
113 MatrixOnline = U * ((
P.transpose() * U).fullPivLu().inverse());
131 MaxModesA(MaxModesA),
132 MaxModesB(MaxModesB),
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;
262 for (label i = 1; i < MaxModesA; i++)
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);
302 PB.resize(
UB.rows(), 1);
303 PB.insert(ind_rowB, 0) = 1;
305 for (label i = 1; i < MaxModesB; i++)
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);
315 PB.conservativeResize((std::get<1>(
Matrix_Modes)[i]).size(), i + 1);
316 PB.insert(ind_rowB, i) = 1;
317 UB.conservativeResize((std::get<1>(
Matrix_Modes)[i]).size(), i + 1);
319 rhoB.conservativeResize(i + 1);
324 if (MaxModesB == 1 && std::get<1>(
Matrix_Modes)[0].norm() < 1e-8)
328 else if (MaxModesB != 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));
427 submesh->subMesh().fvSchemes::readOpt() = mesh.fvSchemes::readOpt();
428 submesh->subMesh().fvSolution::readOpt() = mesh.fvSolution::readOpt();
429 submesh->subMesh().fvSchemes::read();
430 submesh->subMesh().fvSolution::read();
432 S f =
submesh->interpolate(field).ref();
433 scalar zerodot25 = 0.25;
458 new IOList<labelList>
463 para->runTime.time().constant(),
466 IOobject::READ_IF_PRESENT,
477 "uniqueMagicPointsA",
478 para->runTime.time().constant(),
481 IOobject::READ_IF_PRESENT,
487 volScalarField Indici
492 mesh.time().timeName(),
498 dimensionedScalar(
MatrixName +
"_A_indices", dimensionSet(0, 0, 0, 0, 0, 0, 0),
501 submeshA = autoPtr<fvMeshSubset>(
new fvMeshSubset(mesh));
517 submeshA->subMesh().fvSchemes::readOpt() = mesh.fvSchemes::readOpt();
518 submeshA->subMesh().fvSolution::readOpt() = mesh.fvSolution::readOpt();
519 submeshA->subMesh().fvSchemes::read();
520 submeshA->subMesh().fvSolution::read();
522 S f =
submeshA->interpolate(field).ref();
523 scalar zerodot25 = 0.25;
551 new IOList<labelList>
556 para->runTime.time().constant(),
559 IOobject::READ_IF_PRESENT,
570 "uniqueMagicPointsB",
571 para->runTime.time().constant(),
574 IOobject::READ_IF_PRESENT,
580 volScalarField Indici
585 mesh.time().timeName(),
591 dimensionedScalar(
MatrixName +
"_B_indices", dimensionSet(0, 0, 0, 0, 0, 0, 0),
594 submeshB = autoPtr<fvMeshSubset>(
new fvMeshSubset(mesh));
608 std::cout.setstate(std::ios_base::failbit);
614 submeshB->subMesh().fvSchemes::readOpt() = mesh.fvSchemes::readOpt();
615 submeshB->subMesh().fvSolution::readOpt() = mesh.fvSolution::readOpt();
616 submeshB->subMesh().fvSchemes::read();
617 submeshB->subMesh().fvSolution::read();
619 S f =
submeshB->interpolate(field).ref();
620 scalar zerodot25 = 0.25;
643 List<label> localPoints;
645 for (label i = 0; i < points.size(); i++)
647 for (label j = 0; j <
submesh.cellMap().size(); j++)
649 if (
submesh.cellMap()[j] == points[i])
651 localPoints.append(j);
668 else if (ind_rowA <
Ncells * 2)
671 ind_rowA = ind_rowA -
Ncells;
676 ind_rowA = ind_rowA - 2 *
Ncells;
683 else if (ind_colA <
Ncells * 2)
686 ind_colA = ind_colA -
Ncells;
691 ind_colA = ind_colA - 2 *
Ncells;
702 else if (ind_rowA <
Ncells * 2)
705 ind_rowA = ind_rowA -
Ncells;
710 ind_rowA = ind_rowA - 2 *
Ncells;
719 "You have to compute the magicPoints before calling this function, try to rerun generateSubmesh");
720 F f =
submesh().interpolate(field).ref();
729 "You have to compute the magicPointsA before calling this function, try to rerun generateSubmeshMatrix");
730 F f =
submeshA().interpolate(field).ref();
739 "You have to compute the magicPointsB before calling this function, try to rerun generateSubmeshVector");
740 F f =
submeshB().interpolate(field).ref();
747 label Ncells = sizeM;
753 label Ncells = sizeM / 3;
762 word command =
"rm -r " +
Folder +
"/magicPoints";
764 command =
"rm -r " +
Folder +
"/xyz";
766 command =
"rm -r " +
Folder +
"/totalMagicPoints";
768 command =
"rm -r " +
Folder +
"/uniqueMagicPoints";
772 autoPtr<IOList<label >>
779 para->runTime.time().constant(),
782 IOobject::READ_IF_PRESENT,
789 for (label i = 0; i < newMagicPoints.size(); ++i)
796 autoPtr<IOList<label >>
803 para->runTime.time().constant(),
806 IOobject::READ_IF_PRESENT,
813 for (label i = 0; i < newMagicPoints.size(); ++i)
815 xyz().append(newxyz[i]);
825 label MaxModesB, word MatrixName);
828 label MaxModesB, word MatrixName);
830 word FunctionName, word FieldName);
832 word FunctionName, word FieldName);
836 volVectorField& field);
838 volVectorField& field);
840 volScalarField& field);
842 volScalarField& field);
844 volTensorField& field);
846 volTensorField& field);
848 const volVectorField& field);
850 const volVectorField& field);
852 const volScalarField& field);
854 const volScalarField& field);
856 const volTensorField& field);
858 const volTensorField& field);
862 volScalarField& field);
864 volVectorField& field);
865template surfaceScalarField
867template surfaceVectorField
870 volScalarField& field);
872 volVectorField& field);
873template surfaceScalarField
875template surfaceVectorField
880 volScalarField& field);
882 volVectorField& field);
883template surfaceScalarField
885template surfaceVectorField
888 volScalarField& field);
890 volVectorField& field);
891template surfaceScalarField
893template surfaceVectorField
898 label layers,
const fvMesh& mesh, volScalarField field,
901 label layers,
const fvMesh& mesh, volVectorField field,
904 label layers,
const fvMesh& mesh, volScalarField field,
907 label layers,
const fvMesh& mesh, volVectorField field,
912 label layers,
const fvMesh& mesh, volScalarField field, label secondTime);
914 label layers,
const fvMesh& mesh, volVectorField field, label secondTime);
915template surfaceScalarField
917 surfaceScalarField field, label secondTime);
918template surfaceVectorField
920 surfaceVectorField field, label secondTime);
922 label layers,
const fvMesh& mesh, volScalarField field, label secondTime);
924 label layers,
const fvMesh& mesh, volVectorField field, label secondTime);
925template surfaceScalarField
927 surfaceScalarField field, label secondTime);
928template surfaceVectorField
930 surfaceVectorField field, label secondTime);
934 label layers,
const fvMesh& mesh, volScalarField field, label secondTime);
936 label layers,
const fvMesh& mesh, volVectorField field, label secondTime);
937template surfaceScalarField
939 surfaceScalarField field, label secondTime);
940template surfaceVectorField
942 surfaceVectorField field, label secondTime);
944 label layers,
const fvMesh& mesh, volScalarField field, label secondTime);
946 label layers,
const fvMesh& mesh, volVectorField field, label secondTime);
947template surfaceScalarField
949 surfaceScalarField field, label secondTime);
950template surfaceVectorField
952 surfaceVectorField field, label secondTime);
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(const 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 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.