BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
petsctools.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_PETSCTOOLS_HPP
13#define BELFEM_PETSCTOOLS_HPP
14
15
16#ifdef BELFEM_PETSC
17#include <petscksp.h>
18#else
19
20typedef int PetscInt;
21typedef double PetscReal ;
22typedef int PetscErrorCode ;
23// vector class
24class Vec { public: Vec() = default ; ~Vec() = default ; };
25
26// matrix class
27class Mat { public: Mat() = default ; ~Mat() = default ; };
28
29// Preconditioner context
30class PC { public: PC() = default ; ~PC() = default ; };
31
32// solver class
33class KSP { public: KSP() = default ; ~KSP() = default ; };
34
35#define PETSC_DECIDE 0
36#endif
37
38
39#ifndef BELFEM_MPI
40typedef int MPI_Comm ;
41#endif
42
43#include "typedefs.hpp"
44
45#include "cl_Vector.hpp"
47
48namespace belfem
49{
50//------------------------------------------------------------------------------
51 namespace sparse
52 {
53#ifdef BELFEM_PETSC
54 typedef DistMatrixAIJ< PetscInt > PETScAIJ ;
55#else
56 typedef void PETScAIJ ;
57#endif
58 }
59//------------------------------------------------------------------------------
60
61 string
63
64//------------------------------------------------------------------------------
65
68 MPI_Comm aComm,
69 Vec & aVec,
70 const PetscInt aGlobalLength,
71 const PetscInt aLocalLength=PETSC_DECIDE
72 );
73
74//------------------------------------------------------------------------------
75
85 const Vector <PetscReal> & aVector,
86 const Vector <PetscInt> & aIndices,
87 Vec & aVec );
88
89//------------------------------------------------------------------------------
90
102 Vec & aVec,
103 const Vector <PetscInt> & aIndices,
104 Vector< PetscReal > & aVector );
105
106//------------------------------------------------------------------------------
107
118 Vec & aVec,
119 Vector< PetscReal > & aVector );
120
121//------------------------------------------------------------------------------
122
133 const Vector< PetscReal > & aVector,
134 Vec & aVec );
135
136//------------------------------------------------------------------------------
137
140 sparse::PETScAIJ * aDistMatrix,
141 Mat & aMat );
142
143//------------------------------------------------------------------------------
144
147 sparse::PETScAIJ * aDistMatrix,
148 Mat & aMat );
149
150//------------------------------------------------------------------------------
151
154 COMM_TYPE aComm,
155 SpMatrix & aMatrix,
156 Mat & aMat );
157
158//------------------------------------------------------------------------------
159
162
163//------------------------------------------------------------------------------
164
165}
166#endif //BELFEM_PETSCTOOLS_HPP
#define COMM_TYPE
Definition cl_Communicator.hpp:20
KSP()=default
Definition petsctools.hpp:27
Mat()=default
PC()=default
Definition petsctools.hpp:24
Vec()=default
Sparse matrix in CSR or CSC format.
Definition cl_SpMatrix.hpp:52
Column vector.
Definition cl_BZ_Vector.hpp:41
void PETScAIJ
Definition petsctools.hpp:56
USER GUIDES:
Definition cl_Capacitor.cpp:16
PetscErrorCode petsctools_notify_matrix_update(Mat &aMat)
Definition petsctools.cpp:444
PetscErrorCode petsctools_get_vector(Vec &aVec, const Vector< PetscInt > &aIndices, Vector< PetscReal > &aVector)
convert a PETSC vector to a BELFEM vector
Definition petsctools.cpp:209
PetscErrorCode petsctools_link_matrix(COMM_TYPE aComm, SpMatrix &aMatrix, Mat &aMat)
Definition petsctools.cpp:397
PetscErrorCode petsctools_set_local_vector(const Vector< PetscReal > &aVector, Vec &aVec)
Set the local portion of a distributed PETSC vector from a BELFEM vector.
Definition petsctools.cpp:268
PetscErrorCode petsctools_set_vector(const Vector< PetscReal > &aVector, const Vector< PetscInt > &aIndices, Vec &aVec)
convert a BELFEM vector to a PETSC vector aVac must have been initialized.
Definition petsctools.cpp:165
PetscErrorCode petsctools_update_matrix(sparse::PETScAIJ *aDistMatrix, Mat &aMat)
Definition petsctools.cpp:355
PetscErrorCode petsctools_get_local_vector(Vec &aVec, Vector< PetscReal > &aVector)
Extract the local portion of a distributed PETSC vector to a BELFEM vector.
Definition petsctools.cpp:232
string petsctools_error_message(const PetscErrorCode aStatus)
Definition petsctools.cpp:19
PetscErrorCode petsctools_allocate_vector(MPI_Comm aComm, Vec &aVec, const PetscInt aGlobalLength, const PetscInt aLocalLength)
Definition petsctools.cpp:121
PetscErrorCode petsctools_create_matrix(sparse::PETScAIJ *aDistMatrix, Mat &aMat)
Definition petsctools.cpp:304
int PetscInt
Definition petsctools.hpp:20
int MPI_Comm
Definition petsctools.hpp:40
#define PETSC_DECIDE
Definition petsctools.hpp:35
int PetscErrorCode
Definition petsctools.hpp:22
double PetscReal
Definition petsctools.hpp:21