Skip to content

Commit ded3b0b

Browse files
author
Jeremy E Kozdon
committed
Call DMSetUp! & DMSetFromOptions! in DMDACreateXd
1 parent df96fb0 commit ded3b0b

4 files changed

Lines changed: 47 additions & 15 deletions

File tree

examples/ksp/ex50.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ function main(petsclib; comm = MPI.COMM_WORLD, options...)
163163
opts...,
164164
)
165165

166-
PETSc.DMSetUp!(da)
167-
168166
ksp = PETSc.KSP(da; opts...)
169167

170168
PETSc.KSPSetComputeRHS!(ksp, rhs!)

src/dm.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,38 @@ mutable struct DM{PetscLib} <: AbstractDM{PetscLib}
99
end
1010

1111
"""
12-
DMSetUp!(da::DM)
12+
DMSetUp!(da::DM, opts=da.opts)
1313
1414
# External Links
1515
$(_doc_external("DM/DMSetUp"))
1616
"""
1717
function DMSetUp! end
1818

19-
@for_petsc function DMSetUp!(da::DM{$PetscLib})
20-
with(da.opts) do
19+
@for_petsc function DMSetUp!(da::AbstractDM{$PetscLib}, opts::Options = da.opts)
20+
with(opts) do
21+
@chk ccall((:DMSetUp, $petsc_library), PetscErrorCode, (CDM,), da)
22+
end
23+
end
24+
25+
"""
26+
DMSetFromOptions!(da::DM, opts=da.opts)
27+
28+
# External Links
29+
$(_doc_external("DM/DMSetFromOptions"))
30+
"""
31+
function DMSetFromOptions! end
32+
33+
@for_petsc function DMSetFromOptions!(
34+
da::AbstractDM{$PetscLib},
35+
opts::Options = da.opts,
36+
)
37+
with(opts) do
2138
@chk ccall(
2239
(:DMSetFromOptions, $petsc_library),
2340
PetscErrorCode,
2441
(CDM,),
2542
da,
2643
)
27-
28-
@chk ccall((:DMSetUp, $petsc_library), PetscErrorCode, (CDM,), da)
2944
end
3045
end
3146

src/dmda.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ end
2222
dof_per_node,
2323
stencil_width,
2424
points_per_proc::Union{Nothing, Vector{PetscInt}};
25+
dmsetfromoptions=true,
26+
dmsetup=true,
2527
options...
2628
)
2729
2830
Creates a 1-D distributed array with the options specified using keyword
2931
arguments.
3032
33+
If keyword argument `dmsetfromoptions == true` then `DMSetFromOptions!` called.
34+
If keyword argument `dmsetup == true` then `DMSetUp!` is called.
35+
3136
# External Links
3237
$(_doc_external("DMDA/DMDACreate1d"))
3338
"""
@@ -41,6 +46,8 @@ function DMDACreate1d end
4146
dof_per_node,
4247
stencil_width,
4348
points_per_proc::Union{Nothing, Vector{$PetscInt}};
49+
dmsetfromoptions=true,
50+
dmsetup=true,
4451
options...,
4552
)
4653
opts = Options($petsclib, options...)
@@ -73,6 +80,8 @@ function DMDACreate1d end
7380
da,
7481
)
7582
end
83+
dmsetfromoptions && DMSetFromOptions!(da)
84+
dmsetup && DMSetUp!(da)
7685
# We can only let the garbage collect finalize when we do not need to
7786
# worry about MPI (since garbage collection is asyncronous)
7887
if comm == MPI.COMM_SELF
@@ -96,12 +105,17 @@ end
96105
stencil_width,
97106
points_per_proc_x::Union{Nothing, Vector{PetscInt}};
98107
points_per_proc_y::Union{Nothing, Vector{PetscInt}};
108+
dmsetfromoptions=true,
109+
dmsetup=true,
99110
options...
100111
)
101112
102113
Creates a 2-D distributed array with the options specified using keyword
103114
arguments.
104115
116+
If keyword argument `dmsetfromoptions == true` then `DMSetFromOptions!` called.
117+
If keyword argument `dmsetup == true` then `DMSetUp!` is called.
118+
105119
# External Links
106120
$(_doc_external("DMDA/DMDACreate2d"))
107121
"""
@@ -121,6 +135,8 @@ function DMDACreate2d end
121135
stencil_width,
122136
points_per_proc_x::Union{Nothing, Vector{$PetscInt}},
123137
points_per_proc_y::Union{Nothing, Vector{$PetscInt}};
138+
dmsetfromoptions=true,
139+
dmsetup=true,
124140
options...,
125141
)
126142
opts = Options($petsclib, options...)
@@ -171,6 +187,8 @@ function DMDACreate2d end
171187
da,
172188
)
173189
end
190+
dmsetfromoptions && DMSetFromOptions!(da)
191+
dmsetup && DMSetUp!(da)
174192
# We can only let the garbage collect finalize when we do not need to
175193
# worry about MPI (since garbage collection is asyncronous)
176194
if comm == MPI.COMM_SELF
@@ -199,12 +217,17 @@ end
199217
points_per_proc_x::Union{Nothing, Vector{PetscInt}};
200218
points_per_proc_y::Union{Nothing, Vector{PetscInt}};
201219
points_per_proc_z::Union{Nothing, Vector{PetscInt}};
220+
dmsetfromoptions=true,
221+
dmsetup=true,
202222
options...
203223
)
204224
205225
Creates a 3-D distributed array with the options specified using keyword
206226
arguments.
207227
228+
If keyword argument `dmsetfromoptions == true` then `DMSetFromOptions!` called.
229+
If keyword argument `dmsetup == true` then `DMSetUp!` is called.
230+
208231
# External Links
209232
$(_doc_external("DMDA/DMDACreate3d"))
210233
"""
@@ -228,6 +251,8 @@ function DMDACreate3d end
228251
points_per_proc_x::Union{Nothing, Vector{$PetscInt}},
229252
points_per_proc_y::Union{Nothing, Vector{$PetscInt}},
230253
points_per_proc_z::Union{Nothing, Vector{$PetscInt}};
254+
dmsetfromoptions=true,
255+
dmsetup=true,
231256
options...,
232257
)
233258
opts = Options($petsclib, options...)
@@ -292,6 +317,8 @@ function DMDACreate3d end
292317
da,
293318
)
294319
end
320+
dmsetfromoptions && DMSetFromOptions!(da)
321+
dmsetup && DMSetUp!(da)
295322
# We can only let the garbage collect finalize when we do not need to
296323
# worry about MPI (since garbage collection is asyncronous)
297324
if comm == MPI.COMM_SELF

test/dmda.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ PETSc.initialize()
4141
stencil_width,
4242
points_per_proc,
4343
)
44-
PETSc.DMSetUp!(da)
4544

4645
@test PETSc.gettype(da) == "da"
4746
@test PETSc.DMGetDimension(da) == 1
@@ -83,7 +82,6 @@ PETSc.initialize()
8382
nothing;
8483
da_refine = da_refine,
8584
)
86-
PETSc.DMSetUp!(da)
8785
@test PETSc.gettype(da) == "da"
8886
@test PETSc.DMGetDimension(da) == 1
8987

@@ -157,7 +155,6 @@ end
157155
nothing,
158156
nothing,
159157
)
160-
PETSc.DMSetUp!(da)
161158
@test PETSc.gettype(da) == "da"
162159
@test PETSc.DMGetDimension(da) == 2
163160

@@ -189,7 +186,6 @@ end
189186
nothing;
190187
da_refine = da_refine,
191188
)
192-
PETSc.DMSetUp!(da)
193189
@test PETSc.gettype(da) == "da"
194190
@test PETSc.DMGetDimension(da) == 2
195191

@@ -271,7 +267,6 @@ end
271267
nothing,
272268
nothing,
273269
)
274-
PETSc.DMSetUp!(da)
275270
@test PETSc.gettype(da) == "da"
276271
@test PETSc.DMGetDimension(da) == 3
277272

@@ -308,7 +303,6 @@ end
308303
nothing;
309304
da_refine = da_refine,
310305
)
311-
PETSc.DMSetUp!(da)
312306
@test PETSc.gettype(da) == "da"
313307
@test PETSc.DMGetDimension(da) == 3
314308

@@ -369,7 +363,6 @@ end
369363
stencil_width,
370364
points_per_proc,
371365
)
372-
PETSc.DMSetUp!(da)
373366
mat = PETSc.DMCreateMatrix(da)
374367

375368
# Build the 1-D Laplacian FD matrix
@@ -426,7 +419,6 @@ end
426419
stencil_width,
427420
points_per_proc,
428421
)
429-
PETSc.DMSetUp!(da)
430422

431423
corners = PETSc.DMDAGetCorners(da)
432424

0 commit comments

Comments
 (0)