Skip to content

Commit

Permalink
More "Julian" names and match prior convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy E Kozdon committed Jul 14, 2021
1 parent 5c5f286 commit d4d7924
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 122 deletions.
12 changes: 6 additions & 6 deletions examples/ksp/ex50.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function rhs!(
ksp::PETSc.AbstractKSP{PetscScalar},
b_vec::PETSc.AbstractVec{PetscScalar},
) where {PetscScalar}
dm = PETSc.KSPGetDM(ksp)
dm = PETSc.DMDA(ksp)
comm = PETSc.getcomm(ksp)
corners = PETSc.DMDAGetCorners(dm)
global_size = PETSc.DMDAGetInfo(dm).global_size[1:2]
corners = PETSc.getcorners(dm)
global_size = PETSc.getinfo(dm).global_size[1:2]

# Grid spacing in each direction
h = PetscScalar(1) ./ global_size
Expand Down Expand Up @@ -54,11 +54,11 @@ function jacobian!(
J::PETSc.AbstractMat{PetscScalar},
jac::PETSc.AbstractMat{PetscScalar},
) where {PetscScalar}
dm = PETSc.KSPGetDM(ksp)
corners = PETSc.DMDAGetCorners(dm)
dm = PETSc.DMDA(ksp)
corners = PETSc.getcorners(dm)
PetscInt = eltype(corners.size)

global_size = PETSc.DMDAGetInfo(dm).global_size[1:2]
global_size = PETSc.getinfo(dm).global_size[1:2]

# Grid spacing in each direction
h = PetscScalar(1) ./ global_size
Expand Down
134 changes: 79 additions & 55 deletions src/dm.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
const CDM = Ptr{Cvoid}

abstract type AbstractDM{PetscLib} end

"""
DMLocalVec(v::CVec, dm::AbstractDM)
Container for an PETSc vector we know is "local"
# External Links
$(_doc_external("Vec/Vec"))
"""
mutable struct DMLocalVec{PetscLib, T, T_DM} <: AbstractVec{T}
ptr::CVec
dm::T_DM
function DMLocalVec(ptr, dm::AbstractDM{PetscLib}) where {PetscLib}
new{PetscLib, scalartype(PetscLib), typeof(dm)}(ptr, dm)
end
end

"""
DMGlobalVec(v::CVec, dm::AbstractDM)
Container for an PETSc vector we know is "global"
# External Links
$(_doc_external("Vec/Vec"))
"""
mutable struct DMGlobalVec{PetscLib, T, T_DM} <: AbstractVec{T}
ptr::CVec
dm::T_DM
function DMGlobalVec(ptr, dm::AbstractDM{PetscLib}) where {PetscLib}
new{PetscLib, scalartype(PetscLib), typeof(dm)}(ptr, dm)
end
end

# Mainly for DM we do not know the type of, namely ones returned by PETSc
# functions such as `KSPGetDM`
mutable struct PetscDM{PetscLib} <: AbstractDM{PetscLib}
ptr::CDM
end


"""
DMSetUp!(da::DM, opts=da.opts)
setup!(da::DM, opts=da.opts)
# External Links
$(_doc_external("DM/DMSetUp"))
"""
function DMSetUp! end
function setup! end

@for_petsc function DMSetUp!(da::AbstractDM{$PetscLib}, opts::Options = da.opts)
@for_petsc function setup!(da::AbstractDM{$PetscLib}, opts::Options = da.opts)
with(opts) do
@chk ccall((:DMSetUp, $petsc_library), PetscErrorCode, (CDM,), da)
end
end

"""
DMSetFromOptions!(da::DM, opts=da.opts)
setfromoptions!(da::DM, opts=da.opts)
# External Links
$(_doc_external("DM/DMSetFromOptions"))
"""
function DMSetFromOptions! end
function setfromoptions! end

@for_petsc function DMSetFromOptions!(
@for_petsc function setfromoptions!(
da::AbstractDM{$PetscLib},
opts::Options = da.opts,
)
Expand Down Expand Up @@ -59,16 +89,16 @@ end
end

"""
DMGetDimension(dm::AbstractDM)
getdimension(dm::AbstractDM)
Return the topological dimension of the `dm`
# External Links
$(_doc_external("DM/DMGetDimension"))
"""
function DMGetDimension end
function getdimension(::AbstractDM) end

@for_petsc function DMGetDimension(dm::AbstractDM{$PetscLib})
@for_petsc function getdimension(dm::AbstractDM{$PetscLib})
dim = Ref{$PetscInt}()

@chk ccall(
Expand Down Expand Up @@ -129,16 +159,16 @@ function view(::AbstractDM) end
end

"""
DMCreateMatrix(dm::AbstractDM)
creatematrix(dm::AbstractDM)
Generates a matrix from the `dm` object.
# External Links
$(_doc_external("DM/DMCreateMatrix"))
"""
function DMCreateMatrix end
function creatematrix end

@for_petsc function DMCreateMatrix(dm::AbstractDM{$PetscLib})
@for_petsc function creatematrix(dm::AbstractDM{$PetscLib})
mat = Mat{$PetscScalar}(C_NULL)

@chk ccall(
Expand All @@ -153,17 +183,17 @@ function DMCreateMatrix end
end

"""
DMCreateLocalVector(dm::AbstractDM)
createlocalvector(dm::AbstractDM)
returns a local vector from the `dm` object.
# External Links
$(_doc_external("DM/DMCreateLocalVector"))
"""
function DMCreateLocalVector end
function createlocalvector end

@for_petsc function DMCreateLocalVector(dm::AbstractDM{$PetscLib})
vec = Vec{$PetscScalar}(C_NULL)
@for_petsc function createlocalvector(dm::AbstractDM{$PetscLib})
vec = DMLocalVec(C_NULL, dm)

@chk ccall(
(:DMCreateLocalVector, $petsc_library),
Expand All @@ -177,17 +207,17 @@ function DMCreateLocalVector end
end

"""
DMCreateGlobalVector(dm::DM; write::Bool = true, read::Bool = true)
createglobalvector(dm::DM; write::Bool = true, read::Bool = true)
returns a global vector from the `dm` object.
# External Links
$(_doc_external("DM/DMCreateGlobalVector"))
"""
function DMCreateGlobalVector end
function createglobalvector end

@for_petsc function DMCreateGlobalVector(dm::AbstractDM{$PetscLib})
vec = Vec{$PetscScalar}(C_NULL)
@for_petsc function createglobalvector(dm::AbstractDM{$PetscLib})
vec = DMGlobalVec(C_NULL, dm)

@chk ccall(
(:DMCreateGlobalVector, $petsc_library),
Expand All @@ -201,31 +231,30 @@ function DMCreateGlobalVector end
end

"""
DMLocalToGlobal!(
dm::AbstractDM
local_vec::AbstractVec,
update!(
global_vec::DMGlobalVec,
local_vec::DMLocalVec,
mode::InsertMode,
global_vec::AbstractVec,
)
Updates `global_vec` from `local_vec` using the `dm` with insert `mode`
Updates `global_vec` from `local_vec` with insert `mode`
# External Links
$(_doc_external("DM/DMLocalToGlobal"))
"""
function DMLocalToGlobal! end
update!(::DMGlobalVec, ::DMLocalVec, ::InsertMode)

@for_petsc function DMLocalToGlobal!(
dm::AbstractDM{$PetscLib},
local_vec::AbstractVec,
@for_petsc function update!(
global_vec::DMGlobalVec{$PetscLib},
local_vec::DMLocalVec{$PetscLib},
mode::InsertMode,
global_vec::AbstractVec,
)
@assert local_vec.dm === global_vec.dm
@chk ccall(
(:DMLocalToGlobal, $petsc_library),
PetscErrorCode,
(CDM, CVec, InsertMode, CVec),
dm,
local_vec.dm,
local_vec,
mode,
global_vec,
Expand All @@ -235,31 +264,30 @@ function DMLocalToGlobal! end
end

"""
DMGlobalToLocal!(
dm::DM
global_vec::AbstractVec,
update!(
local_vec::DMLocalVec,
global_vec::DMGlobalVec,
mode::InsertMode,
local_vec::AbstractVec,
)
Updates `local_vec` from `global_vec` using the `dm` with insert `mode`
Updates `local_vec` from `global_vec` with insert `mode`
# External Links
$(_doc_external("DM/DMGlobalToLocal"))
"""
function DMGlobalToLocal! end
update!(::DMLocalVec, ::DMGlobalVec, ::InsertMode)

@for_petsc function DMGlobalToLocal!(
dm::AbstractDM{$PetscLib},
global_vec::AbstractVec,
@for_petsc function update!(
local_vec::DMLocalVec{$PetscLib},
global_vec::DMGlobalVec{$PetscLib},
mode::InsertMode,
local_vec::AbstractVec,
)
@assert local_vec.dm === global_vec.dm
@chk ccall(
(:DMGlobalToLocal, $petsc_library),
PetscErrorCode,
(CDM, CVec, InsertMode, CVec),
dm,
global_vec.dm,
global_vec,
mode,
local_vec,
Expand All @@ -269,18 +297,16 @@ function DMGlobalToLocal! end
end

"""
DMGetCoordinateDM(
dm::AbstractDM
)
getcoordinateDM(dm::AbstractDM)
Create a `coord_dm` for the coordinates of `dm`.
# External Links
$(_doc_external("DM/DMGetCoordinateDM"))
"""
function DMGetCoordinateDM end
function getcoordinateDM end

@for_petsc function DMGetCoordinateDM(dm::AbstractDM{$PetscLib})
@for_petsc function getcoordinateDM(dm::AbstractDM{$PetscLib})
coord_dm = empty(dm)
@chk ccall(
(:DMGetCoordinateDM, $petsc_library),
Expand All @@ -296,19 +322,17 @@ function DMGetCoordinateDM end
end

"""
DMGetCoordinatesLocal(
dm::AbstractDM
)
getcoordinateslocal(dm::AbstractDM)
Gets a local vector with the coordinates associated with `dm`.
# External Links
$(_doc_external("DM/DMGetCoordinatesLocal"))
"""
function DMGetCoordinatesLocal end
function getcoordinateslocal end

@for_petsc function DMGetCoordinatesLocal(dm::AbstractDM{$PetscLib})
coord_vec = Vec{$PetscScalar}(C_NULL)
@for_petsc function getcoordinateslocal(dm::AbstractDM{$PetscLib})
coord_vec = DMLocalVec(C_NULL, dm)
@chk ccall(
(:DMGetCoordinatesLocal, $petsc_library),
PetscErrorCode,
Expand Down
Loading

0 comments on commit d4d7924

Please sign in to comment.