# Discretization

MethodOfLines.MOLFiniteDifferenceType
MOLFiniteDifference(dxs, time=nothing;
approx_order = 2, advection_scheme = UpwindScheme(),
grid_align = CenterAlignedGrid(), kwargs...)

A discretization algorithm.

Arguments

• dxs: A vector of pairs of parameters to the grid step in this dimension, i.e. [x=>0.2, y=>0.1]. For a non uniform rectilinear grid, replace any or all of the step sizes with the grid you'd like to use with that variable, must be an AbstractVector but not a StepRangeLen.
• time: Your choice of continuous variable, usually time. If time = nothing, then discretization yeilds a NonlinearProblem. Defaults to nothing.

Keyword Arguments

• approx_order: The order of the derivative approximation.
• advection_scheme: The scheme to be used to discretize advection terms, i.e. first order spatial derivatives and associated coefficients. Defaults to UpwindScheme(). WENOScheme() is also available, and is more stable and accurate at the cost of complexity.
• grid_align: The grid alignment types. See CenterAlignedGrid() and EdgeAlignedGrid().
• kwargs: Any other keyword arguments you want to pass to the ODEProblem.
source
MethodOfLines.DiscreteSpaceType
DiscreteSpace(domain, depvars, indepvars, discretization::MOLFiniteDifference)

A type that stores informations about the discretized space. It takes each independent variable defined on the space to be discretized and create a corresponding range. It then takes each dependant variable and create an array of symbolic variables to represent it in its discretized form.

Arguments

• domain: The domain of the space.
• depvars: The independent variables to be discretizated.
• indepvars: The independent variables.
• discretization: The discretization algorithm.

Fields

• ū: The vector of dependant variables.
• args: The dictionary of the operations of dependant variables and the corresponding arguments, which include the time variable if given.
• discvars: The dictionary of dependant variables and the discrete symbolic representation of them. Note that this includes the boundaries. See the example below.
• time: The time variable. nothing for steady state problems.
• x̄: The vector of symbolic spatial variables.
• axies: The dictionary of symbolic spatial variables and their numerical discretizations.
• grid: Same as axies if CenterAlignedGrid is used. For EdgeAlignedGrid, interpolation will need to be defined ±dx/2 above and below the edges of the simulation domain where dx is the step size in the direction of that edge.
• dxs: The discretization symbolic spatial variables and their step sizes.
• Iaxies: The dictionary of the dependant variables and their CartesianIndices of the discretization.
• Igrid: Same as axies if CenterAlignedGrid is used. For EdgeAlignedGrid, one more index will be needed for extrapolation.
• x2i: The dictionary of symbolic spatial variables their ordering.

Examples

julia> using MethodOfLines, DomainSets, ModelingToolkit
julia> using MethodOfLines:DiscreteSpace

julia> @parameters t x
julia> @variables u(..)
julia> Dt = Differential(t)
julia> Dxx = Differential(x)^2

julia> eq  = [Dt(u(t, x)) ~ Dxx(u(t, x))]
julia> bcs = [u(0, x) ~ cos(x),
u(t, 0) ~ exp(-t),
u(t, 1) ~ exp(-t) * cos(1)]

julia> domain = [t ∈ Interval(0.0, 1.0),
x ∈ Interval(0.0, 1.0)]

julia> dx = 0.1
julia> discretization = MOLFiniteDifference([x => dx], t)
julia> ds = DiscreteSpace(domain, [u(t,x).val], [x.val], discretization)

julia> ds.discvars[u(t,x)]
11-element Vector{Num}:
u(t)
u(t)
u(t)
u(t)
u(t)
u(t)
u(t)
u(t)
u(t)
u(t)
u(t)

julia> ds.axies
Dict{Sym{Real, Base.ImmutableDict{DataType, Any}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}} with 1 entry:
x => 0.0:0.1:1.0
source