Commit d3e43f2c authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#723 Petsc: implement a wrapper over ShellMatrix (shallow matrices to use in...

#723 Petsc: implement a wrapper over ShellMatrix (shallow matrices to use in KSP for essentially matrix-free operations).
parent 35f5ae42
......@@ -342,6 +342,9 @@
BE56978E1BE383AD00B2EC67 /* MatrixOperations.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE56978B1BE383AD00B2EC67 /* MatrixOperations.hpp */; };
BE56978F1BE383AD00B2EC67 /* MatrixOperations.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE56978C1BE383AD00B2EC67 /* MatrixOperations.hxx */; };
BE5697A81BE3878700B2EC67 /* BaseMatrix.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE5697A51BE3878700B2EC67 /* BaseMatrix.hpp */; };
BE5697AF1BE396E100B2EC67 /* ShellMatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE5697AC1BE396E100B2EC67 /* ShellMatrix.cpp */; };
BE5697B01BE396E100B2EC67 /* ShellMatrix.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE5697AD1BE396E100B2EC67 /* ShellMatrix.hpp */; };
BE5697B11BE396E100B2EC67 /* ShellMatrix.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE5697AE1BE396E100B2EC67 /* ShellMatrix.hxx */; };
BE58EB751B9087B1006899EA /* InitializeHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE58EB741B9087B1006899EA /* InitializeHelper.cpp */; };
BE58EB781B908827006899EA /* libModel.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE58EB4D1B908757006899EA /* libModel.a */; };
BE58EB7B1B90883E006899EA /* libModel.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE58EB4D1B908757006899EA /* libModel.a */; };
......@@ -3754,6 +3757,9 @@
BE56978B1BE383AD00B2EC67 /* MatrixOperations.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = MatrixOperations.hpp; sourceTree = "<group>"; };
BE56978C1BE383AD00B2EC67 /* MatrixOperations.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = MatrixOperations.hxx; sourceTree = "<group>"; };
BE5697A51BE3878700B2EC67 /* BaseMatrix.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = BaseMatrix.hpp; path = Private/BaseMatrix.hpp; sourceTree = "<group>"; };
BE5697AC1BE396E100B2EC67 /* ShellMatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShellMatrix.cpp; sourceTree = "<group>"; };
BE5697AD1BE396E100B2EC67 /* ShellMatrix.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ShellMatrix.hpp; sourceTree = "<group>"; };
BE5697AE1BE396E100B2EC67 /* ShellMatrix.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ShellMatrix.hxx; sourceTree = "<group>"; };
BE589C281A160ABD00D23130 /* UniqueId.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = UniqueId.hpp; path = Sources/Utilities/UniqueId/UniqueId.hpp; sourceTree = "<group>"; };
BE589C291A160ABD00D23130 /* UniqueId.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = UniqueId.hxx; path = Sources/Utilities/UniqueId/UniqueId.hxx; sourceTree = "<group>"; };
BE589C381A446A1200745D08 /* SConscript */ = {isa = PBXFileReference; explicitFileType = text.script.python; fileEncoding = 4; path = SConscript; sourceTree = "<group>"; };
......@@ -4130,7 +4136,6 @@
BEA9609F1BD4D43800A2E77B /* Hyperelasticity.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Hyperelasticity.hpp; sourceTree = "<group>"; };
BEA960A01BD4D43800A2E77B /* Hyperelasticity.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Hyperelasticity.hxx; sourceTree = "<group>"; };
BEA960A61BD4D49400A2E77B /* demo_input_fsi_ei_2_meshes.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = demo_input_fsi_ei_2_meshes.lua; path = Data/Lua/demo_input_fsi_ei_2_meshes.lua; sourceTree = SOURCE_ROOT; };
BEA960D01BD4EEBD00A2E77B /* demo_input_fsi_ei_P1.lua */ = {isa = PBXFileReference; lastKnownFileType = text; name = demo_input_fsi_ei_P1.lua; path = Data/Lua/demo_input_fsi_ei_P1.lua; sourceTree = SOURCE_ROOT; };
BEA9CB891A1E2532003A6276 /* GeometricMeshRegion_Connectivity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeometricMeshRegion_Connectivity.cpp; sourceTree = "<group>"; };
BEA9CB911A1E25BF003A6276 /* main_test_coloring.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main_test_coloring.cpp; sourceTree = "<group>"; };
BEA9CB971A1E25DD003A6276 /* TestColoring */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestColoring; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -7633,7 +7638,6 @@
BEBEBC171BDFB33E0011D835 /* Aitken */,
BE43DCA11BCD06480093EB01 /* SConscript */,
BEED77241B95B3A90006BE1F /* demo_input_fsi_ei.lua */,
BEA960D01BD4EEBD00A2E77B /* demo_input_fsi_ei_P1.lua */,
BEC57D311B909F3400F0F4B4 /* InputParameterList.hpp */,
BEC57D291B909F3400F0F4B4 /* ExplicitStepVariationalFormulation.cpp */,
BEC57D2A1B909F3400F0F4B4 /* ExplicitStepVariationalFormulation.hpp */,
......@@ -8003,6 +8007,9 @@
BEEFEF72196ECCC000C80FF1 /* Matrix.cpp */,
BEEFEF73196ECCC000C80FF1 /* Matrix.hpp */,
BEEFEF74196ECCC000C80FF1 /* Matrix.hxx */,
BE5697AC1BE396E100B2EC67 /* ShellMatrix.cpp */,
BE5697AD1BE396E100B2EC67 /* ShellMatrix.hpp */,
BE5697AE1BE396E100B2EC67 /* ShellMatrix.hxx */,
BEEFEF75196ECCC000C80FF1 /* MatrixPattern.cpp */,
BEEFEF76196ECCC000C80FF1 /* MatrixPattern.hpp */,
BEEFEF77196ECCC000C80FF1 /* MatrixPattern.hxx */,
......@@ -8626,6 +8633,7 @@
BE90E1991A24929A00CCAFDE /* Lm5.hpp in Headers */,
BE90E1651A24926E00CCAFDE /* EnumClass.hpp in Headers */,
BE90E17F1A24929A00CCAFDE /* ExtendedOps.hpp in Headers */,
BE5697B01BE396E100B2EC67 /* ShellMatrix.hpp in Headers */,
BE41A8CE1A24AA46004E4312 /* Mpi.hpp in Headers */,
BE90E1CF1A2492AA00CCAFDE /* PetscSys.hpp in Headers */,
BE90E1AD1A24929A00CCAFDE /* MatrixPattern.hpp in Headers */,
......@@ -8655,6 +8663,7 @@
BE6F5A2C1A8396840076DF90 /* HappyHeartPetscVector.hpp in Headers */,
BE90E1D21A2492AA00CCAFDE /* Seldon.hpp in Headers */,
BE90E1B31A24929A00CCAFDE /* AccessVectorContent.hpp in Headers */,
BE5697B11BE396E100B2EC67 /* ShellMatrix.hxx in Headers */,
BE90E1CA1A2492AA00CCAFDE /* Parmetis.hpp in Headers */,
BE6E4EE21B2ABE8B0049BB2D /* AccessGhostContent.hpp in Headers */,
BE1E87631B8DFB710002EE64 /* PrepareDefaultEntry.hpp in Headers */,
......@@ -10340,6 +10349,7 @@
BE90E1901A24929A00CCAFDE /* Folder.cpp in Sources */,
BE90E1AC1A24929A00CCAFDE /* MatrixPattern.cpp in Sources */,
BE4B17D51AA5B20D0073516A /* Print.cpp in Sources */,
BE5697AF1BE396E100B2EC67 /* ShellMatrix.cpp in Sources */,
BE90E16D1A24926E00CCAFDE /* BoolArray.cpp in Sources */,
BE41E96D1AC3F92A0072C8E6 /* EmptyString.cpp in Sources */,
BE90E1A91A24929A00CCAFDE /* Matrix.cpp in Sources */,
......
......@@ -9,6 +9,8 @@
#ifndef HAPPY_HEART_x_MODEL_INSTANCES_x_F_S_I_x_E_I_x_NEWTON_x_MODEL_FORWARD_HXX_
# define HAPPY_HEART_x_MODEL_INSTANCES_x_F_S_I_x_E_I_x_NEWTON_x_MODEL_FORWARD_HXX_
# include "ThirdParty/Wrappers/Petsc/Matrix/ShellMatrix.hpp"
namespace HappyHeart
{
......@@ -47,6 +49,13 @@ namespace HappyHeart
UpdateSolidDisplacementAfterSoF();
solid_displacement_after_dH_->Copy(GetSolidDisplacementAfterSoF(), __FILE__, __LINE__);
Wrappers::Petsc::ShellMatrix<std::false_type, self>(mpi,
0u, 0u,
0u, 0u,
this,
__FILE__, __LINE__);
dH();
}
......
......@@ -149,16 +149,7 @@ namespace HappyHeart
const MatrixPattern& matrix_pattern,
const Mpi& mpi, const char* invoking_file, int invoking_line);
void InitShellMatrix(unsigned int Nlocal_row, unsigned int Nlocal_column,
unsigned int Nglobal_row, unsigned int Nglobal_column
);
/*!
* \brief Handle over the internal Mat object.
*
......@@ -167,7 +158,7 @@ namespace HappyHeart
* Ideally it shouldn't be used at all except in the implementation of the Petsc Wrapper: a wrapper
* method should be implemented over the function that might need access to the Vec internal object.
*/
Mat Internal() const;
Mat Internal() const noexcept;
/*!
......
......@@ -24,7 +24,7 @@ namespace HappyHeart
inline Mat Matrix::Internal() const
inline Mat Matrix::Internal() const noexcept
{
assert(petsc_matrix_ != PETSC_NULL);
return petsc_matrix_;
......
......@@ -30,7 +30,7 @@ namespace HappyHeart
/*!
* \brief A very shall struct from which both Matrix and ShellMatrix should inherit.
* \brief A very shallow struct from which both Matrix and ShellMatrix should inherit.
*
* \internal It is there for a unique purpose: operations such as AXPY exist for both vectors and matrices.
* I want to define them once for Matrix and ShellMatrix, but if I use to do so a template classes
......
//
// ShellMatrix.cpp
// HappyHeart
//
// Created by Sebastien Gilles on 30/10/15.
// Copyright © 2015 Inria. All rights reserved.
//
#include "ThirdParty/Wrappers/Petsc/Matrix/ShellMatrix.hpp"
namespace HappyHeart
{
namespace Wrappers
{
namespace Petsc
{
} //namespace Petsc
} //namespace Wrappers
} // namespace HappyHeart
//
// ShellMatrix.hpp
// HappyHeart
//
// Created by Sebastien Gilles on 30/10/15.
// Copyright © 2015 Inria. All rights reserved.
//
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_SHELL_MATRIX_HPP_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_SHELL_MATRIX_HPP_
# include "ThirdParty/Wrappers/Mpi/Mpi.hpp"
# include "ThirdParty/IncludeWithoutWarning/Petsc/PetscSys.hpp"
# include "ThirdParty/IncludeWithoutWarning/Petsc/PetscMat.hpp"
# include "ThirdParty/Wrappers/Petsc/Matrix/Private/BaseMatrix.hpp"
# include "ThirdParty/Wrappers/Petsc/Exceptions/Petsc.hpp"
namespace HappyHeart
{
namespace Wrappers
{
namespace Petsc
{
template
<
class MatMultOpT,
class ContextT
>
class ShellMatrix : private Private::BaseMatrix
{
public:
//! Alias to self.
using self = ShellMatrix<MatMultOpT, ContextT>;
//! Alias to unique pointer.
using unique_ptr = std::unique_ptr<self>;
public:
/// \name Special members.
///@{
//! Constructor.
explicit ShellMatrix(const Wrappers::Mpi& mpi,
unsigned int Nlocal_row, unsigned int Nlocal_column,
unsigned int Nglobal_row, unsigned int Nglobal_column,
ContextT* context,
const char* invoking_file, int invoking_line);
//! Destructor.
~ShellMatrix();
//! Copy constructor.
ShellMatrix(const ShellMatrix&) = delete;
//! Move constructor.
ShellMatrix(ShellMatrix&&) = delete;
//! Copy affectation.
ShellMatrix& operator=(const ShellMatrix&) = delete;
//! Move affectation.
ShellMatrix& operator=(ShellMatrix&&) = delete;
///@}
/*!
* \brief Handle over the internal Mat object.
*
* \return Internal Mat object, which is indeed a pointer in Petsc.
*
* Ideally it shouldn't be used at all except in the implementation of the Petsc Wrapper: a wrapper
* method should be implemented over the function that might need access to the Vec internal object.
*/
Mat Internal() const noexcept;
private:
//! Underlying Petsc matrix.
Mat petsc_matrix_;
//! Context.
ContextT* context_;
};
} //namespace Petsc
} //namespace Wrappers
} // namespace HappyHeart
# include "ThirdParty/Wrappers/Petsc/Matrix/ShellMatrix.hxx"
#endif // HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_SHELL_MATRIX_HPP_
//
// ShellMatrix.hxx
// HappyHeart
//
// Created by Sebastien Gilles on 30/10/15.
// Copyright © 2015 Inria. All rights reserved.
//
#ifndef HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_SHELL_MATRIX_HXX_
# define HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_SHELL_MATRIX_HXX_
namespace HappyHeart
{
namespace Wrappers
{
namespace Petsc
{
template
<
class MatMultOpT,
class ContextT
>
ShellMatrix<MatMultOpT, ContextT>::~ShellMatrix()
{
assert(petsc_matrix_ != PETSC_NULL);
int error_code = MatDestroy(&petsc_matrix_);
assert(!error_code && "Error in Mat destruction."); // no exception in destructors!
static_cast<void>(error_code); // to avoid arning in release compilation.
}
template
<
class MatMultOpT,
class ContextT
>
ShellMatrix<MatMultOpT, ContextT>
::ShellMatrix(const Wrappers::Mpi& mpi,
unsigned int Nlocal_row, unsigned int Nlocal_column,
unsigned int Nglobal_row, unsigned int Nglobal_column,
ContextT* context,
const char* invoking_file, int invoking_line)
: context_(context)
{
int error_code = MatCreateShell(mpi.GetCommunicator(),
static_cast<PetscInt>(Nlocal_row),
static_cast<PetscInt>(Nlocal_column),
static_cast<PetscInt>(Nglobal_row),
static_cast<PetscInt>(Nglobal_column),
context,
&petsc_matrix_);
if (error_code)
throw ExceptionNS::Exception(error_code, "MatCreateShell", invoking_file, invoking_line);
// error_code = MatShellSetOperation(petsc_matrix_,
// MATOP_MULT,
// MatMultOpT());
//
// if (error_code)
// throw ExceptionNS::Exception(error_code, "MatShellSetOperation", invoking_file, invoking_line);
}
template
<
class MatMultOpT,
class ContextT
>
inline Mat ShellMatrix<MatMultOpT, ContextT>::Internal() const noexcept
{
assert(petsc_matrix_ != PETSC_NULL);
return petsc_matrix_;
}
} //namespace Petsc
} //namespace Wrappers
} // namespace HappyHeart
#endif // HAPPY_HEART_x_THIRD_PARTY_x_WRAPPERS_x_PETSC_x_MATRIX_x_SHELL_MATRIX_HXX_
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