Chi-Tech
petsc_utils_02_createMat.cc
Go to the documentation of this file.
1#include "petsc_utils.h"
2
3#include "chi_log.h"
4
5//###################################################################
6/**Creates a general square matrix.
7 *
8 * This is a macro for:
9\code
10Mat A;
11MatCreate(PETSC_COMM_WORLD,&A);
12MatSetType(A,MATMPIAIJ);
13MatSetSizes(A,local_size, local_size,
14 global_size, global_size);
15
16MatMPIAIJSetPreallocation(A,1, nullptr,
17 0, nullptr);
18MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
19MatSetOption(A, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
20
21return A;
22\endcode
23
24*/
25Mat chi_math::PETScUtils::CreateSquareMatrix(int64_t local_size, int64_t global_size)
26{
27 Mat A;
28 MatCreate(PETSC_COMM_WORLD,&A);
29 MatSetType(A,MATMPIAIJ);
30 MatSetSizes(A,local_size, local_size,
31 global_size, global_size);
32
33 MatMPIAIJSetPreallocation(A,1, nullptr,
34 0, nullptr);
35 MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
36 MatSetOption(A, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
37
38 return A;
39}
40
41//###################################################################
42/**Creates a general square matrix.
43 *
44 * This is a macro for:
45\code
46MatCreate(PETSC_COMM_WORLD,&A);
47MatSetType(A,MATMPIAIJ);
48MatSetSizes(A,local_size, local_size,
49 global_size, global_size);
50
51MatMPIAIJSetPreallocation(A,1, nullptr,
52 0, nullptr);
53MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
54MatSetOption(A, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
55\endcode
56
57*/
59CreateSquareMatrix(Mat& A, int64_t local_size, int64_t global_size)
60{
61 MatCreate(PETSC_COMM_WORLD,&A);
62 MatSetType(A,MATMPIAIJ);
63 MatSetSizes(A,local_size, local_size,
64 global_size, global_size);
65
66 MatMPIAIJSetPreallocation(A,1, nullptr,
67 0, nullptr);
68 MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
69 MatSetOption(A, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
70}
71
72//###################################################################
73/**Initializes the sparsity pattern of a matrix.
74
75This is a macro for:
76\code
77MatMPIAIJSetPreallocation(A,0,nodal_nnz_in_diag.data(),
78 0,nodal_nnz_off_diag.data());
79MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
80MatSetOption(A, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
81MatSetUp(A);
82\endcode
83*/
85 Mat &A,
86 const std::vector<int64_t>& nodal_nnz_in_diag,
87 const std::vector<int64_t>& nodal_nnz_off_diag)
88{
89 MatMPIAIJSetPreallocation(A,0,nodal_nnz_in_diag.data(),
90 0,nodal_nnz_off_diag.data());
91 MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
92 MatSetOption(A, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
93 MatSetUp(A);
94}
95
96//###################################################################
97/**Initializes the sparsity pattern of a matrix.
98
99This is a macro for:
100\code
101MatMPIAIJSetPreallocation(A,0,nodal_nnz_in_diag.data(),
102 0,nodal_nnz_off_diag.data());
103MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
104MatSetOption(A, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
105MatSetUp(A);
106\endcode
107*/
109 Mat &A,
110 int64_t nodal_nnz_in_diag,
111 int64_t nodal_nnz_off_diag)
112{
113 MatMPIAIJSetPreallocation(A,nodal_nnz_in_diag, nullptr,
114 nodal_nnz_off_diag, nullptr);
115 MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
116 MatSetOption(A, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
117}
void InitMatrixSparsity(Mat &A, const std::vector< int64_t > &nodal_nnz_in_diag, const std::vector< int64_t > &nodal_nnz_off_diag)
Mat CreateSquareMatrix(int64_t local_size, int64_t global_size)
struct _p_Mat * Mat