Advanced Multi-Physics (AMP)
On-Line Documentation
PetscVectorFactory.h
Go to the documentation of this file.
1#ifndef included_AMP_test_PetscVectorFactory
2#define included_AMP_test_PetscVectorFactory
3
4#include "AMP/utils/AMP_MPI.h"
5#include "AMP/vectors/VectorBuilder.h"
6#include "AMP/vectors/petsc/NativePetscVectorData.h"
7#include "AMP/vectors/petsc/PetscHelpers.h"
8#include "AMP/vectors/testHelpers/VectorTests.h"
9#include "AMP/vectors/testHelpers/generateVectorFactories.h"
10
11#include "petscvec.h"
12
13
14namespace AMP::LinearAlgebra {
15
16
19{
20public:
21 PetscVecDeleter( std::shared_ptr<AMP::LinearAlgebra::PetscVector> vec ) : d_vec( vec ) {}
22 void operator()( Vec *ptr ) const
23 {
24 delete ptr;
25 d_vec.reset();
26 }
27
28private:
29 mutable std::shared_ptr<AMP::LinearAlgebra::PetscVector> d_vec;
30};
31
32
38{
39public:
41 virtual std::shared_ptr<Vec> getVec( AMP::LinearAlgebra::Vector::shared_ptr ) const = 0;
42
43protected:
46};
47
48
50{
51public:
53 explicit PetscCloneFactory( std::shared_ptr<const PetscVectorFactory> factory )
54 : d_factory( factory )
55 {
56 }
57 std::shared_ptr<Vec> getVec( AMP::LinearAlgebra::Vector::shared_ptr vec ) const override
58 {
59 return d_factory->getVec( vec );
60 }
62 {
63 return d_factory->getVector()->clone();
64 }
65 std::string name() const override { return "PetscCloneFactory<" + d_factory->name() + ">"; }
66
67private:
68 std::shared_ptr<const PetscVectorFactory> d_factory;
69};
70
71
73{
74public:
75 explicit PetscViewFactory( std::shared_ptr<const VectorFactory> factory ) : d_factory( factory )
76 {
77 }
78 std::shared_ptr<Vec> getVec( AMP::LinearAlgebra::Vector::shared_ptr vec ) const override
79 {
81 std::shared_ptr<Vec> ptr( new Vec( view->getVec() ), PetscVecDeleter( view ) );
82 return ptr;
83 }
85 {
86 return d_factory->getVector();
87 }
88 std::string name() const override { return "PetscViewFactory<" + d_factory->name() + ">"; }
89
90private:
91 std::shared_ptr<const VectorFactory> d_factory;
92};
93
94
96{
97public:
98 std::shared_ptr<Vec> getVec( AMP::LinearAlgebra::Vector::shared_ptr vec ) const override
99 {
100 auto data = std::dynamic_pointer_cast<NativePetscVectorData>( vec->getVectorData() );
101 std::shared_ptr<Vec> ptr( new Vec( data->getVec() ) );
102 return ptr;
103 }
105 {
106 Vec v;
107 AMP::AMP_MPI globalComm( AMP_COMM_WORLD );
108 VecCreate( globalComm.getCommunicator(), &v );
109 PetscInt local_size = 15;
110 VecSetSizes( v, local_size, PETSC_DECIDE );
111 VecSetType( v, VECMPI ); // this line will have to be modified for the no mpi and cuda cases
112 auto newVec = createVector( v, true );
113 VecSetFromOptions( v );
114 newVec->getVectorData()->assemble();
115 newVec->setVariable(
116 std::make_shared<AMP::LinearAlgebra::Variable>( "Test NativePetscVector" ) );
117 return newVec;
118 }
119 std::string name() const override { return "NativePetscVectorFactory"; }
120};
121
122
123} // namespace AMP::LinearAlgebra
124
125#endif
#define AMP_COMM_WORLD
Definition AMP_MPI.h:32
Provides C++ wrapper around MPI routines.
Definition AMP_MPI.h:63
const Comm & getCommunicator() const
std::shared_ptr< Vec > getVec(AMP::LinearAlgebra::Vector::shared_ptr vec) const override
AMP::LinearAlgebra::Vector::shared_ptr getVector() const override
PetscCloneFactory(std::shared_ptr< const PetscVectorFactory > factory)
std::shared_ptr< Vec > getVec(AMP::LinearAlgebra::Vector::shared_ptr vec) const override
std::shared_ptr< const PetscVectorFactory > d_factory
std::string name() const override
AMP::LinearAlgebra::Vector::shared_ptr getVector() const override
PetscVecDeleter(std::shared_ptr< AMP::LinearAlgebra::PetscVector > vec)
std::shared_ptr< AMP::LinearAlgebra::PetscVector > d_vec
A helper class to generate vectors.
PetscVectorFactory(const PetscVectorFactory &)
virtual std::shared_ptr< Vec > getVec(AMP::LinearAlgebra::Vector::shared_ptr) const =0
static std::shared_ptr< PetscVector > view(Vector::shared_ptr AmpVector)
If needed, create a PETSc wrapper for AmpVector. Otherwise, return AmpVector.
PetscViewFactory(std::shared_ptr< const VectorFactory > factory)
AMP::LinearAlgebra::Vector::shared_ptr getVector() const override
std::string name() const override
std::shared_ptr< const VectorFactory > d_factory
std::shared_ptr< Vec > getVec(AMP::LinearAlgebra::Vector::shared_ptr vec) const override
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:41.
Comments on this page