Skip to content

Commit

Permalink
Undo Stencil naming
Browse files Browse the repository at this point in the history
  • Loading branch information
zjwegert committed Apr 10, 2024
1 parent ae39c6c commit 7603a89
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
16 changes: 8 additions & 8 deletions docs/src/reference/levelsetevolution.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# LevelSetEvolution
In LevelSetTopOpt, the level set is evolved and reinitialised using a `LevelSetEvolution` method. The most standard of these is the Hamilton-Jacobi evolution equation solved using a first order upwind finite difference scheme. A forward Euler in time method is provided below via `HamiltonJacobiEvolution <: LevelSetEvolution` along with an upwind finite difference stencil for the spatial discretisation via `FirstOrderStencil`.

This can be extended in several ways. For example, higher order spatial stencils can be implemented by extending the `SpatialStencil` interface below. In addition, more advanced ODE solvers could be implemented (e.g., Runge–Kutta methods) or entirely different level set evolution methods by extending the `LevelSetEvolution` interface below.
This can be extended in several ways. For example, higher order spatial stencils can be implemented by extending the `Stencil` interface below. In addition, more advanced ODE solvers could be implemented (e.g., Runge–Kutta methods) or entirely different level set evolution methods by extending the `LevelSetEvolution` interface below.

## `HamiltonJacobiEvolution`
```@docs
LevelSetTopOpt.HamiltonJacobiEvolution
LevelSetTopOpt.HamiltonJacobiEvolution(stencil::LevelSetTopOpt.SpatialStencil,model,space,tol=1.e-3,max_steps=100,max_steps_reinit=2000)
LevelSetTopOpt.HamiltonJacobiEvolution(stencil::LevelSetTopOpt.Stencil,model,space,tol=1.e-3,max_steps=100,max_steps_reinit=2000)
LevelSetTopOpt.evolve!
LevelSetTopOpt.reinit!
LevelSetTopOpt.get_dof_Δ(m::HamiltonJacobiEvolution)
Expand All @@ -18,18 +18,18 @@ LevelSetTopOpt.get_dof_Δ(m::HamiltonJacobiEvolution)
LevelSetTopOpt.FirstOrderStencil
```

## Custom `SpatialStencil`
## Custom `Stencil`

```@docs
LevelSetTopOpt.SpatialStencil
LevelSetTopOpt.evolve!(::LevelSetTopOpt.SpatialStencil,φ,vel,Δt,Δx,isperiodic,caches)
LevelSetTopOpt.reinit!(::LevelSetTopOpt.SpatialStencil,φ_new,φ,vel,Δt,Δx,isperiodic,caches)
LevelSetTopOpt.allocate_caches(::LevelSetTopOpt.SpatialStencil,φ,vel)
LevelSetTopOpt.Stencil
LevelSetTopOpt.evolve!(::LevelSetTopOpt.Stencil,φ,vel,Δt,Δx,isperiodic,caches)
LevelSetTopOpt.reinit!(::LevelSetTopOpt.Stencil,φ_new,φ,vel,Δt,Δx,isperiodic,caches)
LevelSetTopOpt.allocate_caches(::LevelSetTopOpt.Stencil,φ,vel)
LevelSetTopOpt.check_order
```

## Custom `LevelSetEvolution`
To implement a custom level set evolution method, we can extend the methods below. For example, one could consider Reaction-Diffusion-based evolution of the level set function. This can be solved with a finite element method and so we can implement a new type that inherits from `LevelSetEvolution` independently of the `SpatialStencil` types.
To implement a custom level set evolution method, we can extend the methods below. For example, one could consider Reaction-Diffusion-based evolution of the level set function. This can be solved with a finite element method and so we can implement a new type that inherits from `LevelSetEvolution` independently of the `Stencil` types.

```@docs
LevelSetTopOpt.LevelSetEvolution
Expand Down
14 changes: 7 additions & 7 deletions src/LevelSetEvolution/HamiltonJacobiEvolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ Based on the scheme by Osher and Fedkiw ([link](https://doi.org/10.1007/b98879))
# Parameters
- `stencil::SpatialStencil`: Spatial finite difference stencil for a single step HJ
- `stencil::Stencil`: Spatial finite difference stencil for a single step HJ
equation and reinitialisation equation.
- `model`: A `CartesianDiscreteModel`.
- `space`: FE space for level-set function
- `perm`: A permutation vector
- `params`: Tuple of additional params
- `cache`: SpatialStencil cache
- `cache`: Stencil cache
"""
struct HamiltonJacobiEvolution{O} <: LevelSetEvolution
stencil :: SpatialStencil
stencil :: Stencil
model
space
perm
Expand All @@ -27,14 +27,14 @@ struct HamiltonJacobiEvolution{O} <: LevelSetEvolution
end

"""
HamiltonJacobiEvolution(stencil::SpatialStencil,model,space,tol,max_steps,max_steps_reinit)
HamiltonJacobiEvolution(stencil::Stencil,model,space,tol,max_steps,max_steps_reinit)
Create an instance of `HamiltonJacobiEvolution` given a stencil, model, FE space, and
additional optional arguments. This automatically creates the DoF permutation
to handle high-order finite elements.
"""
function HamiltonJacobiEvolution(
stencil::SpatialStencil,
stencil::Stencil,
model,
space,
tol=1.e-3,
Expand Down Expand Up @@ -302,15 +302,15 @@ function PartitionedArrays.permute_indices(indices::LocalIndices,perm)
return LocalIndices(n_glob,id,l2g,l2o)
end

function allocate_caches(s::SpatialStencil::Vector,vel::Vector,perm,order,ndofs)
function allocate_caches(s::Stencil::Vector,vel::Vector,perm,order,ndofs)
stencil_caches = allocate_caches(s,reshape(φ,ndofs),reshape(vel,ndofs))
φ_tmp = similar(φ)
vel_tmp = similar(vel)
perm_caches = (order >= 2) ? (similar(φ), similar(vel)) : nothing
return φ_tmp, vel_tmp, perm_caches, stencil_caches
end

function allocate_caches(s::SpatialStencil::PVector,vel::PVector,perm,order,local_ndofs)
function allocate_caches(s::Stencil::PVector,vel::PVector,perm,order,local_ndofs)
local_stencil_caches = map(local_views(φ),local_views(vel),local_views(local_ndofs)) do φ,vel,ndofs
allocate_caches(s,reshape(φ,ndofs),reshape(vel,ndofs))
end
Expand Down
2 changes: 1 addition & 1 deletion src/LevelSetEvolution/LevelSetEvolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ function get_dof_Δ(::LevelSetEvolution)
@abstractmethod
end

include("SpatialStencil.jl")
include("Stencil.jl")
include("HamiltonJacobiEvolution.jl")
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
"""
abstract type SpatialStencil
abstract type Stencil
Spatial finite difference stencil for a single step of the Hamilton-Jacobi
Finite difference stencil for a single step of the Hamilton-Jacobi
evolution equation and reinitialisation equation.
Your own spatial stencil can be implemented by extending the methods below.
"""
abstract type SpatialStencil end
abstract type Stencil end

"""
allocate_caches(::SpatialStencil,φ,vel)
allocate_caches(::Stencil,φ,vel)
Allocate caches for a given `SpatialStencil`.
Allocate caches for a given `Stencil`.
"""
function allocate_caches(::SpatialStencil,φ,vel)
function allocate_caches(::Stencil,φ,vel)
nothing # By default, no caches are required.
end

"""
check_order(::SpatialStencil,order)
check_order(::Stencil,order)
Throw error if insufficient reference element order
to implement stencil in parallel.
"""
function check_order(::SpatialStencil,order)
function check_order(::Stencil,order)
@abstractmethod
end

"""
reinit!(::SpatialStencil,φ_new,φ,vel,Δt,Δx,isperiodic,caches) -> φ
reinit!(::Stencil,φ_new,φ,vel,Δt,Δx,isperiodic,caches) -> φ
Single finite difference step of the reinitialisation equation for a given `SpatialStencil`.
Single finite difference step of the reinitialisation equation for a given `Stencil`.
"""
function reinit!(::SpatialStencil,φ_new,φ,vel,Δt,Δx,isperiodic,caches)
function reinit!(::Stencil,φ_new,φ,vel,Δt,Δx,isperiodic,caches)
@abstractmethod
end

"""
evolve!(::SpatialStencil,φ,vel,Δt,Δx,isperiodic,caches) -> φ
evolve!(::Stencil,φ,vel,Δt,Δx,isperiodic,caches) -> φ
Single finite difference step of the Hamilton-Jacobi evoluation equation for a given
`SpatialStencil`.
`Stencil`.
"""
function evolve!(::SpatialStencil,φ,vel,Δt,Δx,isperiodic,caches)
function evolve!(::Stencil,φ,vel,Δt,Δx,isperiodic,caches)
@abstractmethod
end

"""
struct FirstOrderStencil{D,T} <: SpatialStencil end
struct FirstOrderStencil{D,T} <: Stencil end
A first order upwind difference scheme based on Osher and Fedkiw
([link](https://doi.org/10.1007/b98879)).
"""
struct FirstOrderStencil{D,T} <: SpatialStencil
struct FirstOrderStencil{D,T} <: Stencil
function FirstOrderStencil(D::Integer,::Type{T}) where T<:Real
new{D,T}()
end
Expand Down

0 comments on commit 7603a89

Please sign in to comment.