11const CDM = Ptr{Cvoid}
22
33abstract type AbstractDM{PetscLib} end
4- mutable struct DM{PetscLib} <: AbstractDM{PetscLib}
4+
5+ # Mainly for DM we do not know the type of, namely ones returned by PETSc
6+ # functions such as `KSPGetDM`
7+ mutable struct PetscDM{PetscLib} <: AbstractDM{PetscLib}
58 ptr:: CDM
6- opts:: Options{PetscLib}
7- DM {PetscLib} (ptr, opts = Options (PetscLib)) where {PetscLib} =
8- new {PetscLib} (ptr, opts)
99end
1010
11+
1112"""
1213 DMSetUp!(da::DM, opts=da.opts)
1314
@@ -17,7 +18,7 @@ $(_doc_external("DM/DMSetUp"))
1718"""
1819function DMSetUp! end
1920
20- @for_petsc function DMSetUp! (da:: DM {$PetscLib} , opts:: Options = da. opts)
21+ @for_petsc function DMSetUp! (da:: AbstractDM {$PetscLib} , opts:: Options = da. opts)
2122 with (opts) do
2223 @chk ccall (
2324 (:DMSetFromOptions , $ petsc_library),
@@ -31,7 +32,7 @@ function DMSetUp! end
3132end
3233
3334@for_petsc begin
34- function destroy (da:: DM {$PetscLib} )
35+ function destroy (da:: AbstractDM {$PetscLib} )
3536 finalized ($ PetscScalar) || @chk ccall (
3637 (:DMDestroy , $ petsc_library),
3738 PetscErrorCode,
4445end
4546
4647"""
47- DMGetDimension(dm::DM )
48+ DMGetDimension(dm::AbstractDM )
4849
4950Return the topological dimension of the `dm`
5051
@@ -53,7 +54,7 @@ $(_doc_external("DM/DMGetDimension"))
5354"""
5455function DMGetDimension end
5556
56- @for_petsc function DMGetDimension (dm:: DM {$PetscLib} )
57+ @for_petsc function DMGetDimension (dm:: AbstractDM {$PetscLib} )
5758 dim = Ref {$PetscInt} ()
5859
5960 @chk ccall (
@@ -68,16 +69,16 @@ function DMGetDimension end
6869end
6970
7071"""
71- gettype(dm::DM )
72+ gettype(dm::AbstractDM )
7273
7374Gets type name of the `dm`
7475
7576# External Links
7677$(_doc_external (" DM/DMGetType" ))
7778"""
78- function gettype (:: DM ) end
79+ function gettype (:: AbstractDM ) end
7980
80- @for_petsc function gettype (dm:: DM {$PetscLib} )
81+ @for_petsc function gettype (dm:: AbstractDM {$PetscLib} )
8182 t_r = Ref {Cstring} ()
8283 @chk ccall (
8384 (:DMGetType , $ petsc_library),
@@ -90,17 +91,17 @@ function gettype(::DM) end
9091end
9192
9293"""
93- view(dm::DM , viewer::Viewer=ViewerStdout(petsclib, getcomm(dm)))
94+ view(dm::AbstractDM , viewer::Viewer=ViewerStdout(petsclib, getcomm(dm)))
9495
9596view a `dm` with `viewer`
9697
9798# External Links
9899$(_doc_external (" DM/DMView" ))
99100"""
100- function view (:: DM ) end
101+ function view (:: AbstractDM ) end
101102
102103@for_petsc function view (
103- dm:: DM {$PetscLib} ,
104+ dm:: AbstractDM {$PetscLib} ,
104105 viewer:: AbstractViewer{$PetscLib} = ViewerStdout ($ petsclib, getcomm (dm)),
105106)
106107 @chk ccall (
@@ -114,7 +115,7 @@ function view(::DM) end
114115end
115116
116117"""
117- DMCreateMatrix(dm::DM )
118+ DMCreateMatrix(dm::AbstractDM )
118119
119120Generates a matrix from the `dm` object.
120121
@@ -123,7 +124,7 @@ $(_doc_external("DM/DMCreateMatrix"))
123124"""
124125function DMCreateMatrix end
125126
126- @for_petsc function DMCreateMatrix (dm:: DM {$PetscLib} )
127+ @for_petsc function DMCreateMatrix (dm:: AbstractDM {$PetscLib} )
127128 mat = Mat {$PetscScalar} (C_NULL )
128129
129130 @chk ccall (
@@ -138,7 +139,7 @@ function DMCreateMatrix end
138139end
139140
140141"""
141- DMCreateLocalVector(dm::DM )
142+ DMCreateLocalVector(dm::AbstractDM )
142143
143144returns a local vector from the `dm` object.
144145
@@ -147,7 +148,7 @@ $(_doc_external("DM/DMCreateLocalVector"))
147148"""
148149function DMCreateLocalVector end
149150
150- @for_petsc function DMCreateLocalVector (dm:: DM {$PetscLib} )
151+ @for_petsc function DMCreateLocalVector (dm:: AbstractDM {$PetscLib} )
151152 vec = Vec {$PetscScalar} (C_NULL )
152153
153154 @chk ccall (
@@ -171,7 +172,7 @@ $(_doc_external("DM/DMCreateGlobalVector"))
171172"""
172173function DMCreateGlobalVector end
173174
174- @for_petsc function DMCreateGlobalVector (dm:: DM {$PetscLib} )
175+ @for_petsc function DMCreateGlobalVector (dm:: AbstractDM {$PetscLib} )
175176 vec = Vec {$PetscScalar} (C_NULL )
176177
177178 @chk ccall (
187188
188189"""
189190 DMLocalToGlobal!(
190- dm::DM
191+ dm::AbstractDM
191192 local_vec::AbstractVec,
192193 mode::InsertMode,
193194 global_vec::AbstractVec,
@@ -201,7 +202,7 @@ $(_doc_external("DM/DMLocalToGlobal"))
201202function DMLocalToGlobal! end
202203
203204@for_petsc function DMLocalToGlobal! (
204- dm:: DM {$PetscLib} ,
205+ dm:: AbstractDM {$PetscLib} ,
205206 local_vec:: AbstractVec ,
206207 mode:: InsertMode ,
207208 global_vec:: AbstractVec ,
@@ -235,7 +236,7 @@ $(_doc_external("DM/DMGlobalToLocal"))
235236function DMGlobalToLocal! end
236237
237238@for_petsc function DMGlobalToLocal! (
238- dm:: DM {$PetscLib} ,
239+ dm:: AbstractDM {$PetscLib} ,
239240 global_vec:: AbstractVec ,
240241 mode:: InsertMode ,
241242 local_vec:: AbstractVec ,
@@ -255,34 +256,35 @@ end
255256
256257"""
257258 DMGetCoordinateDM(
258- dm::DM
259+ dm::AbstractDM
259260 )
260261
261- Create a `DM ` for the coordinates of `dm`.
262+ Create a `coord_dm ` for the coordinates of `dm`.
262263
263264# External Links
264265$(_doc_external (" DM/DMGetCoordinateDM" ))
265266"""
266267function DMGetCoordinateDM end
267268
268269@for_petsc function DMGetCoordinateDM (
269- dm:: DM {$PetscLib} ,
270+ dm:: AbstractDM {$PetscLib} ,
270271)
271- coord_dm = DM {$PetscLib} ( C_NULL )
272+ coord_dm = empty (dm )
272273 @chk ccall (
273274 (:DMGetCoordinateDM , $ petsc_library),
274275 PetscErrorCode,
275276 (CDM, Ptr{CDM}),
276277 dm,
277278 coord_dm,
278279 )
280+ @assert gettype (dm) == gettype (coord_dm)
279281
280282 return coord_dm
281283end
282284
283285"""
284286 DMGetCoordinatesLocal(
285- dm::DM
287+ dm::AbstractDM
286288 )
287289
288290Gets a local vector with the coordinates associated with `dm`.
@@ -293,7 +295,7 @@ $(_doc_external("DM/DMGetCoordinatesLocal"))
293295function DMGetCoordinatesLocal end
294296
295297@for_petsc function DMGetCoordinatesLocal (
296- dm:: DM {$PetscLib} ,
298+ dm:: AbstractDM {$PetscLib} ,
297299)
298300 coord_vec = Vec {$PetscScalar} (C_NULL )
299301 @chk ccall (
0 commit comments