-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhypreCreate.m
31 lines (25 loc) · 1.1 KB
/
hypreCreate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function pc = hypreCreate(row_ptr, col_ind, val, opts)
% hypreCreate Create a hypre preconditioner for a matrix
%
% pc = hypreCreate(row_ptr, col_ind, val, opts)
%
% Input Arguments:
% row_ptr, col_ind, val: contents of CRS matrix
% opts: character string containing the PETSc options such as
% ' -pc_hypre_boomeramg_interp_type classical'
%
% Output Argument:
% pc: The preconditioner object
%
% SEE ALSO:
% hypreApply, hypreDestroy
if nargin >= 4 && ~isempty(opts)
errCode = petscOptionsInsert(opts); assert(errCode==int32(0), 'petscOptionsInsert failed');
end
[pc, errCode] = petscPCCreate(MPI_COMM_WORLD); assert(errCode==int32(0), 'petscPCCreate failed');
errCode = petscPCSetType(pc, PETSC_PCHYPRE); assert(errCode==int32(0), 'petscPCSetType failed');
errCode = petscPCSetFromOptions(pc); assert(errCode==int32(0), 'PCSetFromOptions failed');
mat = petscMatCreateAIJFromCRS(row_ptr, col_ind, PetscScalar(val));
errCode = petscPCSetOperators(pc, mat, mat); assert(errCode==int32(0), 'petscPCSetOperators failed');
errCode = petscPCSetUp(pc); assert(errCode==int32(0), 'petscPCSetUp failed');
end