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
@@ -45,7 +46,7 @@ function DMSetFromOptions! end
4546end
4647
4748@for_petsc begin
48- function destroy (da:: DM {$PetscLib} )
49+ function destroy (da:: AbstractDM {$PetscLib} )
4950 finalized ($ PetscScalar) || @chk ccall (
5051 (:DMDestroy , $ petsc_library),
5152 PetscErrorCode,
5859end
5960
6061"""
61- DMGetDimension(dm::DM )
62+ DMGetDimension(dm::AbstractDM )
6263
6364Return the topological dimension of the `dm`
6465
@@ -67,7 +68,7 @@ $(_doc_external("DM/DMGetDimension"))
6768"""
6869function DMGetDimension end
6970
70- @for_petsc function DMGetDimension (dm:: DM {$PetscLib} )
71+ @for_petsc function DMGetDimension (dm:: AbstractDM {$PetscLib} )
7172 dim = Ref {$PetscInt} ()
7273
7374 @chk ccall (
@@ -82,16 +83,16 @@ function DMGetDimension end
8283end
8384
8485"""
85- gettype(dm::DM )
86+ gettype(dm::AbstractDM )
8687
8788Gets type name of the `dm`
8889
8990# External Links
9091$(_doc_external (" DM/DMGetType" ))
9192"""
92- function gettype (:: DM ) end
93+ function gettype (:: AbstractDM ) end
9394
94- @for_petsc function gettype (dm:: DM {$PetscLib} )
95+ @for_petsc function gettype (dm:: AbstractDM {$PetscLib} )
9596 t_r = Ref {Cstring} ()
9697 @chk ccall (
9798 (:DMGetType , $ petsc_library),
@@ -104,17 +105,17 @@ function gettype(::DM) end
104105end
105106
106107"""
107- view(dm::DM , viewer::Viewer=ViewerStdout(petsclib, getcomm(dm)))
108+ view(dm::AbstractDM , viewer::Viewer=ViewerStdout(petsclib, getcomm(dm)))
108109
109110view a `dm` with `viewer`
110111
111112# External Links
112113$(_doc_external (" DM/DMView" ))
113114"""
114- function view (:: DM ) end
115+ function view (:: AbstractDM ) end
115116
116117@for_petsc function view (
117- dm:: DM {$PetscLib} ,
118+ dm:: AbstractDM {$PetscLib} ,
118119 viewer:: AbstractViewer{$PetscLib} = ViewerStdout ($ petsclib, getcomm (dm)),
119120)
120121 @chk ccall (
@@ -128,7 +129,7 @@ function view(::DM) end
128129end
129130
130131"""
131- DMCreateMatrix(dm::DM )
132+ DMCreateMatrix(dm::AbstractDM )
132133
133134Generates a matrix from the `dm` object.
134135
@@ -137,7 +138,7 @@ $(_doc_external("DM/DMCreateMatrix"))
137138"""
138139function DMCreateMatrix end
139140
140- @for_petsc function DMCreateMatrix (dm:: DM {$PetscLib} )
141+ @for_petsc function DMCreateMatrix (dm:: AbstractDM {$PetscLib} )
141142 mat = Mat {$PetscScalar} (C_NULL )
142143
143144 @chk ccall (
@@ -152,7 +153,7 @@ function DMCreateMatrix end
152153end
153154
154155"""
155- DMCreateLocalVector(dm::DM )
156+ DMCreateLocalVector(dm::AbstractDM )
156157
157158returns a local vector from the `dm` object.
158159
@@ -161,7 +162,7 @@ $(_doc_external("DM/DMCreateLocalVector"))
161162"""
162163function DMCreateLocalVector end
163164
164- @for_petsc function DMCreateLocalVector (dm:: DM {$PetscLib} )
165+ @for_petsc function DMCreateLocalVector (dm:: AbstractDM {$PetscLib} )
165166 vec = Vec {$PetscScalar} (C_NULL )
166167
167168 @chk ccall (
@@ -185,7 +186,7 @@ $(_doc_external("DM/DMCreateGlobalVector"))
185186"""
186187function DMCreateGlobalVector end
187188
188- @for_petsc function DMCreateGlobalVector (dm:: DM {$PetscLib} )
189+ @for_petsc function DMCreateGlobalVector (dm:: AbstractDM {$PetscLib} )
189190 vec = Vec {$PetscScalar} (C_NULL )
190191
191192 @chk ccall (
201202
202203"""
203204 DMLocalToGlobal!(
204- dm::DM
205+ dm::AbstractDM
205206 local_vec::AbstractVec,
206207 mode::InsertMode,
207208 global_vec::AbstractVec,
@@ -215,7 +216,7 @@ $(_doc_external("DM/DMLocalToGlobal"))
215216function DMLocalToGlobal! end
216217
217218@for_petsc function DMLocalToGlobal! (
218- dm:: DM {$PetscLib} ,
219+ dm:: AbstractDM {$PetscLib} ,
219220 local_vec:: AbstractVec ,
220221 mode:: InsertMode ,
221222 global_vec:: AbstractVec ,
@@ -249,7 +250,7 @@ $(_doc_external("DM/DMGlobalToLocal"))
249250function DMGlobalToLocal! end
250251
251252@for_petsc function DMGlobalToLocal! (
252- dm:: DM {$PetscLib} ,
253+ dm:: AbstractDM {$PetscLib} ,
253254 global_vec:: AbstractVec ,
254255 mode:: InsertMode ,
255256 local_vec:: AbstractVec ,
@@ -269,34 +270,34 @@ end
269270
270271"""
271272 DMGetCoordinateDM(
272- dm::DM
273+ dm::AbstractDM
273274 )
274275
275- Create a `DM ` for the coordinates of `dm`.
276+ Create a `coord_dm ` for the coordinates of `dm`.
276277
277278# External Links
278279$(_doc_external (" DM/DMGetCoordinateDM" ))
279280"""
280281function DMGetCoordinateDM end
281282
282- @for_petsc function DMGetCoordinateDM (
283- dm:: DM{$PetscLib} ,
284- )
285- coord_dm = DM {$PetscLib} (C_NULL )
283+ @for_petsc function DMGetCoordinateDM (dm:: AbstractDM{$PetscLib} )
284+ coord_dm = empty (dm)
286285 @chk ccall (
287286 (:DMGetCoordinateDM , $ petsc_library),
288287 PetscErrorCode,
289288 (CDM, Ptr{CDM}),
290289 dm,
291290 coord_dm,
292291 )
292+ # If this fails then the `empty` call above is probably a bad idea!
293+ @assert gettype (dm) == gettype (coord_dm)
293294
294295 return coord_dm
295296end
296297
297298"""
298299 DMGetCoordinatesLocal(
299- dm::DM
300+ dm::AbstractDM
300301 )
301302
302303Gets a local vector with the coordinates associated with `dm`.
@@ -306,9 +307,7 @@ $(_doc_external("DM/DMGetCoordinatesLocal"))
306307"""
307308function DMGetCoordinatesLocal end
308309
309- @for_petsc function DMGetCoordinatesLocal (
310- dm:: DM{$PetscLib} ,
311- )
310+ @for_petsc function DMGetCoordinatesLocal (dm:: AbstractDM{$PetscLib} )
312311 coord_vec = Vec {$PetscScalar} (C_NULL )
313312 @chk ccall (
314313 (:DMGetCoordinatesLocal , $ petsc_library),
0 commit comments