DOLFIN-X
DOLFIN-X C++ interface
petsc.h
1 // Copyright (C) 2018-2020 Garth N. Wells
2 //
3 // This file is part of DOLFINX (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 
7 #pragma once
8 
9 #include <dolfinx/la/PETScMatrix.h>
10 #include <dolfinx/la/PETScVector.h>
11 #include <memory>
12 #include <petscvec.h>
13 #include <vector>
14 
15 namespace dolfinx
16 {
17 namespace function
18 {
19 class FunctionSpace;
20 } // namespace function
21 
22 namespace fem
23 {
24 template <typename T>
25 class DirichletBC;
26 template <typename T>
27 class Form;
28 
32 la::PETScMatrix create_matrix(const Form<PetscScalar>& a);
33 
36 la::PETScMatrix create_matrix_block(
37  const Eigen::Ref<
38  const Eigen::Array<const fem::Form<PetscScalar>*, Eigen::Dynamic,
39  Eigen::Dynamic, Eigen::RowMajor>>& a);
40 
42 la::PETScMatrix create_matrix_nest(
43  const Eigen::Ref<
44  const Eigen::Array<const fem::Form<PetscScalar>*, Eigen::Dynamic,
45  Eigen::Dynamic, Eigen::RowMajor>>& a);
46 
48 la::PETScVector create_vector_block(
49  const std::vector<std::reference_wrapper<const common::IndexMap>>& maps);
50 
52 la::PETScVector
53 create_vector_nest(const std::vector<const common::IndexMap*>& maps);
54 
55 // -- Vectors ----------------------------------------------------------------
56 
66 void assemble_vector_petsc(Vec b, const Form<PetscScalar>& L);
67 
68 // FIXME: clarify how x0 is used
69 // FIXME: if bcs entries are set
70 
71 // FIXME: need to pass an array of Vec for x0?
72 // FIXME: clarify zeroing of vector
73 
87  Vec b, const std::vector<std::shared_ptr<const Form<PetscScalar>>>& a,
88  const std::vector<
89  std::vector<std::shared_ptr<const DirichletBC<PetscScalar>>>>& bcs1,
90  const std::vector<Vec>& x0, double scale);
91 
92 // -- Setting bcs ------------------------------------------------------------
93 
94 // FIXME: Move these function elsewhere?
95 
96 // FIXME: clarify x0
97 // FIXME: clarify what happens with ghosts
98 
102 void set_bc_petsc(
103  Vec b,
104  const std::vector<std::shared_ptr<const DirichletBC<PetscScalar>>>& bcs,
105  const Vec x0, double scale = 1.0);
106 
107 } // namespace fem
108 } // namespace dolfinx
dolfinx::fem::create_vector_nest
la::PETScVector create_vector_nest(const std::vector< const common::IndexMap * > &maps)
Create nested (VecNest) vector. Vector is not zeroed.
Definition: petsc.cpp:227
dolfinx::fem::set_bc_petsc
void set_bc_petsc(Vec b, const std::vector< std::shared_ptr< const DirichletBC< PetscScalar >>> &bcs, const Vec x0, double scale=1.0)
Set bc values in owned (local) part of the PETScVector, multiplied by 'scale'. The vectors b and x0 m...
Definition: petsc.cpp:313
dolfinx::fem::create_matrix_block
la::PETScMatrix create_matrix_block(const Eigen::Ref< const Eigen::Array< const fem::Form< PetscScalar > *, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor >> &a)
Initialise monolithic matrix for an array for bilinear forms. Matrix is not zeroed.
Definition: petsc.cpp:32
dolfinx::fem::create_vector_block
la::PETScVector create_vector_block(const std::vector< std::reference_wrapper< const common::IndexMap >> &maps)
Initialise monolithic vector. Vector is not zeroed.
Definition: petsc.cpp:191
dolfinx::fem::apply_lifting_petsc
void apply_lifting_petsc(Vec b, const std::vector< std::shared_ptr< const Form< PetscScalar >>> &a, const std::vector< std::vector< std::shared_ptr< const DirichletBC< PetscScalar >>>> &bcs1, const std::vector< Vec > &x0, double scale)
Modify b such that:
Definition: petsc.cpp:266
dolfinx::fem::create_matrix
la::PETScMatrix create_matrix(const Form< PetscScalar > &a)
Create a matrix.
Definition: petsc.cpp:16
dolfinx::fem::assemble_vector_petsc
void assemble_vector_petsc(Vec b, const Form< PetscScalar > &L)
Assemble linear form into an already allocated PETSc vector. Ghost contributions are not accumulated ...
Definition: petsc.cpp:252
dolfinx::fem::create_matrix_nest
la::PETScMatrix create_matrix_nest(const Eigen::Ref< const Eigen::Array< const fem::Form< PetscScalar > *, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor >> &a)
Create nested (MatNest) matrix. Matrix is not zeroed.
Definition: petsc.cpp:152