Expressions

This package supports type-stable expression functions that can be parsed from strings at runtime. This enables arbitrary boundary condition support in compiled binaries. This feature heavily leverages the package DynamicExpressions.jl

ScalarExpressionFunction

julia> import FiniteElementContainers.Expressions: ScalarExpressionFunction
julia> using StaticArrays
julia> expr = "5.0 * exp(-2 * t) * cos(2 * pi * t)""5.0 * exp(-2 * t) * cos(2 * pi * t)"
julia> var_names = ["x", "y", "z", "t"]4-element Vector{String}: "x" "y" "z" "t"
julia> func = ScalarExpressionFunction{Float64}(expr, var_names)(::FiniteElementContainers.Expressions.ScalarExpressionFunction{Float64}) (generic function with 4 methods)
julia> X = SVector{3, Float64}(1., 2., 3.)3-element StaticArraysCore.SVector{3, Float64} with indices SOneTo(3): 1.0 2.0 3.0
julia> t = 5.05.0
julia> val = func(X, t)0.00022699964881242428

VectorExpressionFunction

julia> import FiniteElementContainers.Expressions: VectorExpressionFunction
julia> using StaticArrays
julia> exprs = ["0", "5.0 * exp(-2 * t) * cos(2 * pi * t)", "0"]3-element Vector{String}: "0" "5.0 * exp(-2 * t) * cos(2 * pi * t)" "0"
julia> var_names = ["x", "y", "z", "t"]4-element Vector{String}: "x" "y" "z" "t"
julia> func = VectorExpressionFunction{3, Float64}(exprs, var_names)(::FiniteElementContainers.Expressions.VectorExpressionFunction{3, Float64}) (generic function with 4 methods)
julia> X = SVector{3, Float64}(1., 2., 3.)3-element StaticArraysCore.SVector{3, Float64} with indices SOneTo(3): 1.0 2.0 3.0
julia> t = 5.05.0
julia> val = func(X, t)3-element StaticArraysCore.SVector{3, Float64} with indices SOneTo(3): 0.0 0.00022699964881242428 0.0

API

FiniteElementContainers.Expressions.ScalarExpressionFunctionType
  • expr::DynamicExpressions.ExpressionModule.Expression{T, DynamicExpressions.NodeModule.Node{T, 2}, @NamedTuple{operators::DynamicExpressions.OperatorEnumModule.OperatorEnum{Tuple{Tuple{typeof(cos), typeof(cosh), typeof(exp), typeof(log), typeof(FiniteElementContainers.Expressions._minus), typeof(sin), typeof(sinh), typeof(sqrt), typeof(tan), typeof(tanh)}, Tuple{typeof(+), typeof(-), typeof(*), typeof(/), typeof(^)}}}, var_names::Vector{String}}} where T<:Number

  • num_vars::Int64

struct ScalarExpressionFunction{T<:Number} <: FiniteElementContainers.Expressions.AbstractExpressionFunction{T<:Number, DynamicExpressions.NodeModule.Node{T<:Number, 2}, @NamedTuple{operators::DynamicExpressions.OperatorEnumModule.OperatorEnum{Tuple{Tuple{typeof(cos), typeof(cosh), typeof(exp), typeof(log), typeof(FiniteElementContainers.Expressions._minus), typeof(sin), typeof(sinh), typeof(sqrt), typeof(tan), typeof(tanh)}, Tuple{typeof(+), typeof(-), typeof(*), typeof(/), typeof(^)}}}, var_names::Vector{String}}}
source
FiniteElementContainers.Expressions.VectorExpressionFunctionType
  • exprs::StaticArraysCore.SArray{Tuple{N}, FiniteElementContainers.Expressions.ScalarExpressionFunction{T}, 1, N} where {N, T<:Number}

  • num_vars::Int64

struct VectorExpressionFunction{N, T<:Number} <: FiniteElementContainers.Expressions.AbstractExpressionFunction{T<:Number, DynamicExpressions.NodeModule.Node{T<:Number, 2}, @NamedTuple{operators::DynamicExpressions.OperatorEnumModule.OperatorEnum{Tuple{Tuple{typeof(cos), typeof(cosh), typeof(exp), typeof(log), typeof(FiniteElementContainers.Expressions._minus), typeof(sin), typeof(sinh), typeof(sqrt), typeof(tan), typeof(tanh)}, Tuple{typeof(+), typeof(-), typeof(*), typeof(/), typeof(^)}}}, var_names::Vector{String}}}
source