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 yields 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().
  • use_ODAE: If true, the discretization will use the ODAEproblem constructor. Defaults to false.
  • 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 information 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 dependent variable and create an array of symbolic variables to represent it in its discretized form.

Arguments

  • domain: The domain of the space.
  • vars: A VariableMap object that contains the dependent and independent variables and other important values.
  • discretization: The discretization algorithm.

Properties

  • : The vector of dependent variables.
  • args: The dictionary of the operations of dependent variables and the corresponding arguments, which include the time variable if given.
  • discvars: The dictionary of dependent 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.
  • : 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 of symbolic spatial variables and their step sizes.
  • Iaxies: The dictionary of the dependent 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 and 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[1](t)
  u[2](t)
  u[3](t)
  u[4](t)
  u[5](t)
  u[6](t)
  u[7](t)
  u[8](t)
  u[9](t)
 u[10](t)
 u[11](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