Commit b707ab3b authored by Gautier Bureau's avatar Gautier Bureau Committed by GILLES Sebastien
Browse files

#1135 Added some features for vectors and matrices.

parent 5c253ef3
......@@ -3289,6 +3289,9 @@
134584FD1C3FD4D600E96BF7 /* SConscript */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = SConscript; path = RivlinCube/SConscript; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.python; };
134DABD41C6E0D6A00C7C65B /* InitialCondition.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = InitialCondition.hpp; path = InitialCondition/InitialCondition.hpp; sourceTree = "<group>"; };
134DABD51C6E0D6A00C7C65B /* InitialCondition.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = InitialCondition.hxx; path = InitialCondition/InitialCondition.hxx; sourceTree = "<group>"; };
1353ED1D1F28D5350002D73D /* OutputDeformedMesh.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = OutputDeformedMesh.cpp; sourceTree = "<group>"; };
1353ED1E1F28D5350002D73D /* OutputDeformedMesh.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = OutputDeformedMesh.hpp; sourceTree = "<group>"; };
1353ED1F1F28D5350002D73D /* OutputDeformedMesh.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = OutputDeformedMesh.hxx; sourceTree = "<group>"; };
13546B761CAD4C4600383282 /* ElectricalActivation.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = ElectricalActivation.cpp; path = Parameter/ElectricalActivation/ElectricalActivation.cpp; sourceTree = "<group>"; };
13546B771CAD4C4600383282 /* ElectricalActivation.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = ElectricalActivation.hpp; path = Parameter/ElectricalActivation/ElectricalActivation.hpp; sourceTree = "<group>"; };
13546B781CAD4C4600383282 /* ElectricalActivation.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = ElectricalActivation.hxx; path = Parameter/ElectricalActivation/ElectricalActivation.hxx; sourceTree = "<group>"; };
......@@ -5934,6 +5937,16 @@
name = InitialCondition;
sourceTree = "<group>";
};
1353ED1C1F28D5350002D73D /* OutputDeformedMesh */ = {
isa = PBXGroup;
children = (
1353ED1D1F28D5350002D73D /* OutputDeformedMesh.cpp */,
1353ED1E1F28D5350002D73D /* OutputDeformedMesh.hpp */,
1353ED1F1F28D5350002D73D /* OutputDeformedMesh.hxx */,
);
path = OutputDeformedMesh;
sourceTree = "<group>";
};
13546B791CAD4C4B00383282 /* ElectricalActivation */ = {
isa = PBXGroup;
children = (
......@@ -8098,6 +8111,7 @@
BEACCC4F1E11D26300CBA4F2 /* File */,
0A2CBE901D05B87A007262F2 /* RefineMeshQuadranglesSpectral */,
BEE9346E1CFD8ACB00158440 /* ConvertLinearAlgebra */,
1353ED1C1F28D5350002D73D /* OutputDeformedMesh */,
BEEABA4A1A49BC8700A875C6 /* OutputFormat */,
BE93B31B1F0536DA004F84CF /* OutputDeformedMesh */,
BE469F001A49B5B6008C9B68 /* Data */,
......@@ -121,7 +121,7 @@ namespace HappyHeart
throw ExceptionNS::Exception(error_code, "MatCreate", invoking_file, invoking_line);
const Mat& internal = Internal(); // const is indeed ignored below as Mat is truly a pointer...
error_code = MatSetType(internal, MATSEQAIJ);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatSetType", invoking_file, invoking_line);
......@@ -302,6 +302,20 @@ namespace HappyHeart
}
void Matrix::ZeroRowsColumns(const std::vector<PetscInt>& row_indexes,
PetscScalar diagonal_value,
const char* invoking_file, int invoking_line)
{
int error_code = MatZeroRowsColumns(Internal(),
static_cast<PetscInt>(row_indexes.size()),
row_indexes.data(),
diagonal_value,
PETSC_NULL,
PETSC_NULL);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatZeroRows", invoking_file, invoking_line);
}
void Matrix::Assembly(const char* invoking_file, int invoking_line)
......@@ -624,6 +638,24 @@ namespace HappyHeart
if (error_code)
throw ExceptionNS::Exception(error_code, "MatGetInfo", invoking_file, invoking_line);
}
void Matrix::GetOption(MatOption op, PetscBool *flg, const char* invoking_file, int invoking_line)
{
int error_code = MatGetOption(Internal(), op, flg);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatGetOption", invoking_file, invoking_line);
}
void Matrix::SetOption(MatOption op, PetscBool flg, const char* invoking_file, int invoking_line)
{
int error_code = MatSetOption(Internal(), op, flg);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatSetOption", invoking_file, invoking_line);
}
} // namespace Petsc
......
......@@ -316,6 +316,18 @@ namespace HappyHeart
const char* invoking_file, int invoking_line);
/*!
* \brief Zeros all entries (except possibly the main diagonal) of a set of rows and columns of a matrix.
*
* \param[in] row_indexes Indexes of the row considered (C - numbering).
* \param[in] diagonal_value Value fior the diagonal term. Put 0. if you want it zeroed too.
* \copydoc doxygen_hide_invoking_file_and_line
*/
void ZeroRowsColumns(const std::vector<PetscInt>& row_indexes,
PetscScalar diagonal_value,
const char* invoking_file, int invoking_line);
/*!
* \brief Petsc Assembling of the matrix.
......@@ -534,6 +546,12 @@ namespace HappyHeart
//! Wrapper over MatGetInfo()
void GetInfo(MatInfo* infos, const char* invoking_file, int invoking_line);
//! Wrapper over MatGetOption()
void GetOption(MatOption op, PetscBool *flg, const char* invoking_file, int invoking_line);
//! Wrapper over MatSetOption()
void SetOption(MatOption op, PetscBool flg, const char* invoking_file, int invoking_line);
private:
......
......@@ -110,17 +110,6 @@ namespace HappyHeart
MatrixU& Y,
const char* invoking_file, int invoking_line);
/*!
* \brief Wrapper over MatShift, that performs M = M + a I, where a is a PetscScalar and I is the identity matrix.
*
* \param[in] matrix See formula above.
* \param[in] a See formula above.
* \copydoc doxygen_hide_invoking_file_and_line
*/
template<class MatrixT>
std::enable_if_t<std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value, void>
MatShift(const PetscScalar a, MatrixT& matrix, const char* invoking_file, int invoking_line);
/*!
* \brief Wrapper over MatShift, that performs M = M + a I, where a is a PetscScalar and I is the identity matrix.
......@@ -275,17 +264,19 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value,
void
>
MatMatMult(const MatrixT& m1,
const MatrixT& m2,
MatrixU& m3,
const MatrixU& m2,
MatrixV& m3,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix = DoReuseMatrix::no);
......@@ -303,18 +294,22 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV,
class MatrixW
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixW>::value,
void
>
MatMatMatMult(const MatrixT& m1,
const MatrixT& m2,
const MatrixT& m3,
MatrixU& m4,
const MatrixU& m2,
const MatrixV& m3,
MatrixW& m4,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix = DoReuseMatrix::no);
......@@ -329,14 +324,19 @@ namespace HappyHeart
* allocated!
* \copydoc doxygen_hide_invoking_file_and_line
*/
template<class MatrixT>
template
<
class MatrixT,
class MatrixU
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value,
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
void
>
MatCreateTranspose(const MatrixT& A,
MatrixT& transpose,
MatrixU& transpose,
const char* invoking_file, int invoking_line);
......@@ -368,17 +368,18 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value && std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value,
void
>
MatTransposeMatMult(const MatrixT& m1,
const MatrixT& m2,
MatrixU& m3,
const MatrixU& m2,
MatrixV& m3,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix = DoReuseMatrix::no);
......@@ -398,17 +399,19 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value,
void
>
MatMatTransposeMult(const MatrixT& matrix1,
const MatrixT& matrix2,
MatrixU& matrix3,
const MatrixU& matrix2,
MatrixV& matrix3,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix = DoReuseMatrix::no);
......@@ -444,17 +447,19 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value,
void
>
PtAP(const MatrixT& A,
const MatrixT& P,
MatrixU& out,
const MatrixU& P,
MatrixV& out,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix = DoReuseMatrix::no);
......@@ -483,7 +488,7 @@ namespace HappyHeart
/*!
* \brief Wrapper over MatLUFactor, that performs in-place LU factorization of matrix. .
* \brief Wrapper over MatLUFactor, that performs in-place LU factorization of matrix.
*
* \see http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatLUFactor.html#MatLUFactor
* for more details.
......@@ -532,6 +537,26 @@ namespace HappyHeart
const MatrixU& B,
MatrixV& X,
const char* invoking_file, int invoking_line);
/*!
* \brief Wrapper over MatCholeskyFactor, that performs in-place Cholesky factorization of a symmetric matrix.
*
* \see http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCholeskyFactor.html
* for more details.
*
* \param[in] mat Matrix to factor.
* \param[in] perm Result of the GetOrdering, row and column permutations.
* \param[in] info Info of CholeskyFactor.
* \copydetails doxygen_hide_invoking_file_and_line
*
*/
template<class MatrixT>
std::enable_if_t<std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value, void>
CholeskyFactor(MatrixT& mat,
IS perm,
const MatFactorInfo *info,
const char* invoking_file, int invoking_line);
......
......@@ -61,17 +61,19 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value,
void
>
MatMatMult(const MatrixT& matrix1,
const MatrixT& matrix2,
MatrixU& out,
const MatrixU& matrix2,
MatrixV& out,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix)
{
......@@ -110,18 +112,22 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV,
class MatrixW
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixW>::value,
void
>
MatMatMatMult(const MatrixT& matrix1,
const MatrixT& matrix2,
const MatrixT& matrix3,
MatrixU& out,
const MatrixU& matrix2,
const MatrixV& matrix3,
MatrixW& out,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix)
{
......@@ -264,14 +270,19 @@ namespace HappyHeart
template<class MatrixT>
template
<
class MatrixT,
class MatrixU
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value,
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
void
>
MatCreateTranspose(const MatrixT& A,
MatrixT& transpose,
MatrixU& transpose,
const char* invoking_file, int invoking_line)
{
Mat result;
......@@ -287,17 +298,19 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value,
void
>
MatTransposeMatMult(const MatrixT& matrix1,
const MatrixT& matrix2,
MatrixU& matrix3,
const MatrixU& matrix2,
MatrixV& matrix3,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix)
{
......@@ -341,17 +354,19 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value,
void
>
MatMatTransposeMult(const MatrixT& matrix1,
const MatrixT& matrix2,
MatrixU& matrix3,
const MatrixU& matrix2,
MatrixV& matrix3,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix)
{
......@@ -392,17 +407,19 @@ namespace HappyHeart
template
<
class MatrixT,
class MatrixU
class MatrixU,
class MatrixV
>
std::enable_if_t
<
std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value,
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixU>::value
&& std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixV>::value,
void
>
PtAP(const MatrixT& A,
const MatrixT& P,
MatrixU& out,
const MatrixU& P,
MatrixV& out,
const char* invoking_file, int invoking_line,
DoReuseMatrix do_reuse_matrix)
{
......@@ -498,6 +515,22 @@ namespace HappyHeart
if (error_code)
throw ExceptionNS::Exception(error_code, "MatMatSolve", invoking_file, invoking_line);
}
template<class MatrixT>
std::enable_if_t<std::is_base_of<Internal::Wrappers::Petsc::BaseMatrix, MatrixT>::value, void>
CholeskyFactor(MatrixT& mat,
IS perm,
const MatFactorInfo *info,
const char* invoking_file, int invoking_line)
{
int error_code = ::MatCholeskyFactor(mat.Internal(),
perm,
info);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatCholeskyFactor", invoking_file, invoking_line);
}
} //namespace Petsc
......
......@@ -308,6 +308,19 @@ namespace HappyHeart
}
void Vector::GetValues(const std::vector<PetscInt>& indexing,
std::vector<PetscScalar>& values,
const char* invoking_file, int invoking_line) const
{
values.resize(indexing.size());
int error_code = VecGetValues(Internal(), static_cast<PetscInt>(indexing.size()), indexing.data(), values.data());
if (error_code)
throw ExceptionNS::Exception(error_code, "VecGetValues", invoking_file, invoking_line);
}
PetscScalar Vector::GetValue(PetscInt index,
const char* invoking_file, int invoking_line) const
{
......
......@@ -338,7 +338,7 @@ namespace HappyHeart
/*!
* \brief Get the values of ta vctor on a current process.
* \brief Get the values of a vector on a current process.
*
* Used to get the values of a sequential vector (see AccessVectorContent for mpi vectors).
*
......@@ -350,6 +350,21 @@ namespace HappyHeart
std::vector<PetscScalar> GetValues(const std::vector<PetscInt>& indexing,
const char* invoking_file, int invoking_line) const;
/*!
* \brief Get the values of a vector on a current process.
*
* Used to get the values of a sequential vector (see AccessVectorContent for mpi vectors).
*
* \param[in] indexing All indexes which are required from the vector.
* \copydoc doxygen_hide_invoking_file_and_line
* \param[in] values Vector to containe the values. Should have been allocated before the call.
* \copydoc doxygen_hide_invoking_file_and_line
*
*/
void GetValues(const std::vector<PetscInt>& indexing,
std::vector<PetscScalar>& values,
const char* invoking_file, int invoking_line) const;
/*!
* \brief Same as GetValues() for a unique index.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment