-
Notifications
You must be signed in to change notification settings - Fork 9
/
Config.jl
92 lines (77 loc) · 2.18 KB
/
Config.jl
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Julia alias to `PetscErrorCode` C type.
See [PETSc manual](https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscErrorCode.html).
"""
const PetscErrorCode = Cint
"""
Julia alias to `PetscBool` C enum.
See [PETSc manual](https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscBool.html).
"""
@enum PetscBool PETSC_FALSE PETSC_TRUE
"""
Julia alias to `PetscDataType` C enum.
See [PETSc manual](https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscDataType.html).
"""
@enum PetscDataType begin
PETSC_DATATYPE_UNKNOWN = 0
PETSC_DOUBLE = 1
PETSC_COMPLEX = 2
PETSC_LONG = 3
PETSC_SHORT = 4
PETSC_FLOAT = 5
PETSC_CHAR = 6
PETSC_BIT_LOGICAL = 7
PETSC_ENUM = 8
PETSC_BOOL = 9
PETSC___FLOAT128 = 10
PETSC_OBJECT = 11
PETSC_FUNCTION = 12
PETSC_STRING = 13
PETSC___FP16 = 14
PETSC_STRUCT = 15
PETSC_INT = 16
PETSC_INT64 = 17
end
"""
PetscDataTypeFromString(name,ptype,found)
See [PETSc manual](https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscDataTypeFromString.html).
"""
function PetscDataTypeFromString(name,ptype,found)
ccall(
Libdl.dlsym(libpetsc_handle[],:PetscDataTypeFromString),
PetscErrorCode,(Cstring,Ptr{PetscDataType},Ptr{PetscBool}),
name,ptype,found)
end
"""
PetscDataTypeGetSize(ptype,size)
See [PETSc manual](https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscDataTypeGetSize.html).
"""
function PetscDataTypeGetSize(ptype,size)
ccall(
Libdl.dlsym(libpetsc_handle[],:PetscDataTypeGetSize),
PetscErrorCode,(PetscDataType,Ptr{Csize_t}),
ptype,size)
end
"""
struct PetscError <: Exception
code::PetscErrorCode
end
Custom `Exception` thrown by [`@check_error_code`](@ref).
"""
struct PetscError <: Exception
code::PetscErrorCode
end
Base.showerror(io::IO, e::PetscError) = print(io, "Petsc returned with error code: $(Int(e.code)) ")
"""
@check_error_code expr
Check if `expr` returns an error code equal to `zero(PetscErrorCode)`.
If not, throw an instance of [`PetscError`](@ref).
"""
macro check_error_code(expr)
quote
code = $(esc(expr))
if code != zero(PetscErrorCode)
throw(PetscError(code))
end
end
end