API

FiniteVolumeMethod1D defines the mesh, endpoint boundary conditions, and problem description. The package also reexports solve from CommonSolve so an FVMProblem can be solved with a CommonSolve-compatible solver package.

FiniteVolumeMethod1D.FVMGeometryType
FVMGeometry(mesh_points)
FVMGeometry(mesh_points, spacings, volumes)

Stores the one-dimensional mesh geometry used by an FVMProblem.

Arguments

  • mesh_points::AbstractVector: Sorted coordinates of the finite-volume nodes.
  • spacings::AbstractVector: Distances between adjacent mesh points. Required only by the full constructor and must have one fewer entry than mesh_points.
  • volumes::AbstractVector: Control-volume widths at the mesh points. Required only by the full constructor and must have the same length as mesh_points.

Returns

  • FVMGeometry: A geometry object containing collected mesh points, spacings, and control-volume widths.

Throws

  • AssertionError: If mesh_points is not sorted or the input lengths are inconsistent.

Fields

  • mesh_points::T: Sorted mesh-point coordinates.
  • spacings::T: Distances between adjacent mesh points.
  • volumes::T: Widths of the associated control volumes.

Examples

mesh_points = range(0.0, 1.0; length = 11)
geometry = FVMGeometry(mesh_points)

See also FVMProblem.

source
FiniteVolumeMethod1D.BoundaryConditionsType
BoundaryConditions(lhs, rhs)
BoundaryConditions(; lhs, rhs)

Stores the left and right boundary conditions of an FVMProblem.

Fields

  • lhs::L: Boundary condition at the first mesh point.
  • rhs::R: Boundary condition at the last mesh point.

Returns

  • BoundaryConditions: A pair of endpoint boundary conditions.

Examples

boundary_conditions = BoundaryConditions(Dirichlet(0.0), Neumann(0.0))

See also Dirichlet and Neumann for the types of boundary conditions you can construct.

source
FiniteVolumeMethod1D.DirichletType
Dirichlet(f, p = nothing)
Dirichlet(; f, p = nothing)
Dirichlet(value::Number)

A Dirichlet boundary condition for an FVMProblem.

f must accept (u, t, p) and return the prescribed value at a boundary. Passing a number constructs a constant boundary condition. p stores optional parameters passed to f.

Fields

  • f: Function called as f(u, t, p).
  • p: Parameters passed to f.

Returns

  • Dirichlet: A callable boundary condition whose value is imposed at the endpoint.

Examples

left_boundary = Dirichlet(0.0)
right_boundary = Dirichlet((u, t, p) -> p * sin(t), 1.0)
source
FiniteVolumeMethod1D.NeumannType
Neumann(f, p = nothing)
Neumann(; f, p = nothing)
Neumann(value::Number)

A Neumann boundary condition for an FVMProblem.

f must accept (u, t, p) and return the boundary derivative. Passing a number constructs a constant derivative condition. p stores optional parameters passed to f.

Fields

  • f: Function called as f(u, t, p).
  • p: Parameters passed to f.

Returns

  • Neumann: A callable boundary condition whose flux is used at the endpoint.

Examples

left_boundary = Neumann(0.0)
right_boundary = Neumann((u, t, p) -> p * u, -0.5)
source
FiniteVolumeMethod1D.FVMProblemType
FVMProblem(;
    geometry, boundary_conditions, diffusion_function, initial_condition,
    final_time, diffusion_parameters = nothing, reaction_function = Returns(0.0),
    reaction_parameters = nothing, initial_time = 0.0
)
FVMProblem(mesh_points, lhs, rhs; kwargs...)

Defines a one-dimensional diffusion-reaction finite-volume problem.

Arguments

  • mesh_points: Mesh points for the positional constructor.
  • lhs: Left boundary condition for the positional constructor.
  • rhs: Right boundary condition for the positional constructor.

Keyword Arguments

  • geometry::FVMGeometry: Spatial mesh geometry.
  • boundary_conditions::BoundaryConditions: Endpoint boundary conditions.
  • diffusion_function: Function called as (u, x, t, p) to evaluate diffusion.
  • diffusion_parameters = nothing: Parameters passed to diffusion_function.
  • reaction_function = Returns(0.0): Function called as (u, x, t, p) for the reaction.
  • reaction_parameters = nothing: Parameters passed to reaction_function.
  • initial_condition: State values at initial_time.
  • initial_time = 0.0: Initial integration time.
  • final_time: Final integration time.

Fields

  • geometry::FVMGeometry{T}: Spatial mesh geometry.
  • boundary_conditions::BoundaryConditions{L, R}: Endpoint boundary conditions.
  • diffusion_function::DF: Diffusion function called as (u, x, t, p).
  • diffusion_parameters::DP: Parameters passed to diffusion_function.
  • reaction_function::RF: Reaction function called as (u, x, t, p).
  • reaction_parameters::RP: Parameters passed to reaction_function.
  • initial_condition::IC: State values at initial_time.
  • initial_time::FT: Initial integration time.
  • final_time::FT: Final integration time.

Returns

  • FVMProblem: A finite-volume problem containing the mesh, boundary conditions, callbacks, and model functions.

Examples

mesh_points = range(0.0, 1.0; length = 11)
problem = FVMProblem(
    mesh_points,
    Dirichlet(0.0),
    Dirichlet(1.0);
    diffusion_function = (u, x, t, p) -> 1.0,
    initial_condition = collect(mesh_points),
    final_time = 0.1,
)
source
CommonSolve.solveFunction
solve(prob::FVMProblem, alg; kwargs...)

Solves an FVMProblem with a CommonSolve-compatible algorithm.

Arguments

  • prob::FVMProblem: Finite-volume problem to solve.
  • alg: Algorithm supplied by a CommonSolve-compatible solver package.

Keyword Arguments

  • kwargs...: Forwarded to the converted ODEProblem and the solver.

Returns

  • SciMLBase.AbstractSciMLSolution: The solution returned by the selected solver.

Examples

using OrdinaryDiffEq

solution = solve(problem, Tsit5(); saveat = 0.01)
source