Advanced Multi-Physics (AMP)
On-Line Documentation
test_MatrixVectorFactory.h
Go to the documentation of this file.
1#ifndef included_AMP_test_MatrixVectorFactory
2#define included_AMP_test_MatrixVectorFactory
3
4#include "AMP/discretization/DOF_Manager.h"
5#include "AMP/matrices/Matrix.h"
6#include "AMP/utils/UnitTest.h"
7#include "AMP/vectors/Vector.h"
8#include "AMP/vectors/VectorBuilder.h"
9#include "AMP/vectors/testHelpers/VectorFactory.h"
10
11#if defined( AMP_USE_PETSC )
12 #include "AMP/matrices/petsc/PetscMatrix.h"
13 #include "AMP/vectors/petsc/PetscHelpers.h"
14 #include "AMP/vectors/petsc/PetscVector.h"
15 #include "AMP/vectors/testHelpers/petsc/PetscVectorFactory.h"
16 #include "petscmat.h"
17#endif
18
19#include "ProfilerApp.h"
20
21namespace AMP::LinearAlgebra {
22
23
24// Classes to serve as the vector factories
26{
27public:
28 explicit AmpInterfaceLeftVectorFactory( std::shared_ptr<AMP::LinearAlgebra::Matrix> matrix )
29 : d_matrix( matrix )
30 {
31 }
33 {
34 PROFILE( "AmpInterfaceLeftVectorFactory::getVector" );
35 auto vector = d_matrix->createOutputVector();
36 vector->setVariable( std::make_shared<AMP::LinearAlgebra::Variable>( "left" ) );
37 return vector;
38 }
39 std::string name() const override
40 {
41 return "AmpInterfaceLeftVectorFactory<" + getVector()->type() + ">";
42 }
43
44private:
45 std::shared_ptr<AMP::LinearAlgebra::Matrix> d_matrix;
46};
47
48
50{
51public:
52 explicit AmpInterfaceRightVectorFactory( std::shared_ptr<AMP::LinearAlgebra::Matrix> matrix )
53 : d_matrix( matrix )
54 {
55 }
57 {
58 PROFILE( "AmpInterfaceRightVectorFactory::getVector" );
59 auto vector = d_matrix->createInputVector();
60 vector->setVariable( std::make_shared<AMP::LinearAlgebra::Variable>( "right" ) );
61 return vector;
62 }
63 std::string name() const override
64 {
65 return "AmpInterfaceRightVectorFactory<" + getVector()->type() + ">";
66 }
67
68private:
69 std::shared_ptr<AMP::LinearAlgebra::Matrix> d_matrix;
70};
71
72
73#if defined( AMP_USE_PETSC )
74
76{
77public:
78 explicit PETScInterfaceLeftVectorFactory( std::shared_ptr<AMP::LinearAlgebra::Matrix> matrix )
79 : d_matrix( matrix )
80 {
81 }
83 {
84 PROFILE( "PETScInterfaceLeftVectorFactory::getVector" );
86 ::Mat m = view->getMat();
87 ::Vec v;
88 MatCreateVecs( m, &v, nullptr );
89 auto vector = createVector( v, true );
90 vector->setVariable( std::make_shared<AMP::LinearAlgebra::Variable>( "petsc_left" ) );
91 return vector;
92 }
93 std::shared_ptr<Vec> getVec( AMP::LinearAlgebra::Vector::shared_ptr vec ) const override
94 {
95 auto data = std::dynamic_pointer_cast<NativePetscVectorData>( vec->getVectorData() );
96 auto ptr = std::make_shared<Vec>( data->getVec() );
97 return ptr;
98 }
99 std::string name() const override { return "PETScInterfaceLeftVectorFactory"; };
100
101private:
102 std::shared_ptr<AMP::LinearAlgebra::Matrix> d_matrix;
103};
104
105
107{
108public:
109 explicit PETScInterfaceRightVectorFactory( std::shared_ptr<AMP::LinearAlgebra::Matrix> matrix )
110 : d_matrix( matrix )
111 {
112 }
114 {
115 PROFILE( "PETScInterfaceRightVectorFactory::getVector" );
117 ::Mat m = view->getMat();
118 ::Vec v;
119 MatCreateVecs( m, &v, nullptr );
120 auto vector = createVector( v, true );
121 vector->setVariable( std::make_shared<AMP::LinearAlgebra::Variable>( "petsc_right" ) );
122 return vector;
123 }
124 std::shared_ptr<Vec> getVec( AMP::LinearAlgebra::Vector::shared_ptr vec ) const override
125 {
126 auto data = std::dynamic_pointer_cast<NativePetscVectorData>( vec->getVectorData() );
127 auto ptr = std::make_shared<Vec>( data->getVec() );
128 return ptr;
129 }
130 std::string name() const override { return "PETScInterfaceRightVectorFactory"; }
131
132private:
133 std::shared_ptr<AMP::LinearAlgebra::Matrix> d_matrix;
134};
135
136#endif
137
138} // namespace AMP::LinearAlgebra
139
140#endif
struct _p_Mat * Mat
std::shared_ptr< AMP::LinearAlgebra::Matrix > d_matrix
AMP::LinearAlgebra::Vector::shared_ptr getVector() const override
AmpInterfaceLeftVectorFactory(std::shared_ptr< AMP::LinearAlgebra::Matrix > matrix)
AmpInterfaceRightVectorFactory(std::shared_ptr< AMP::LinearAlgebra::Matrix > matrix)
std::shared_ptr< AMP::LinearAlgebra::Matrix > d_matrix
AMP::LinearAlgebra::Vector::shared_ptr getVector() const override
AMP::LinearAlgebra::Vector::shared_ptr getVector() const override
std::shared_ptr< AMP::LinearAlgebra::Matrix > d_matrix
std::shared_ptr< Vec > getVec(AMP::LinearAlgebra::Vector::shared_ptr vec) const override
PETScInterfaceLeftVectorFactory(std::shared_ptr< AMP::LinearAlgebra::Matrix > matrix)
PETScInterfaceRightVectorFactory(std::shared_ptr< AMP::LinearAlgebra::Matrix > matrix)
std::shared_ptr< Vec > getVec(AMP::LinearAlgebra::Vector::shared_ptr vec) const override
std::shared_ptr< AMP::LinearAlgebra::Matrix > d_matrix
AMP::LinearAlgebra::Vector::shared_ptr getVector() const override
static std::shared_ptr< PetscMatrix > view(std::shared_ptr< Matrix > AmpMatrix)
If needed, create a PETSc wrapper for AmpMatrix. Otherwise, return AmpMatrix.
A helper class to generate vectors.
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
Definition Vector.h:60
AMP::LinearAlgebra::Vector::shared_ptr createVector(std::shared_ptr< AMP::Discretization::DOFManager > DOFs, std::shared_ptr< AMP::LinearAlgebra::Variable > variable, bool split=true)
This function will create a vector from an arbitrary DOFManager.
PETSc vector.



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:40.
Comments on this page