StreamMacros.jl

StreamMacros.substitutionsFunction
substitutions(code::Expr, variable::Symbol, knowns = [])

Perform all substitutions that are defined in code until the resulting expression does not contain free variables. Variables can be bound by knowns.

source
StreamMacros.@define_streamMacro
@define_stream(name::Symbol, code::Expr)

Define a scalar stream function on $R^2$. The defining code can be a series of definitions in an enclosing begin ... end-block and is treated as a series of symbolic substitutions. Starting from the symbol name, substitutions are performed until the resulting expression only depends on x, y and t.

The symbol name is not brought into the namespace. To access the resulting vector field and variational equation use @velo_from_stream name and @var_velo_from_stream name

This is a convenience macro for the case where you want to use @velo_from_stream and @var_velo_from_stream without typing the code twice. If you only use one, you might as well use @velo_from_stream name code or @var_velo_from_stream directly.

source
StreamMacros.@var_velo_from_streamMacro
@var_velo_from_stream(name::Symbol, [code::Expr])

Get the (state and tangent space) velocity field corresponding to a stream function on $\mathbb{R}^2$. The defining code can be a series of definitions (in an enclosing begin ... end-block and is treated as a series of symbolic substitutions. Starting from the symbol name, substitutions are performed until the resulting expression only depends on x, y and t.

The macro returns an ODEFunction with signature (U,p,t) that returns an SMatrix{2,3}: in the first column, one has the usual velocity, in the second to third column, one has the linearized velocity, both at position u = U[:,1] at time t. The parameter slot is not used and can be filled with nothing when calling.

The macro can be called without the code if the stream name has been defined beforehand via @define_stream.

Sign convention

We follow the "oceanographic" sign convention, whereby the velocity $v$ is derived from the stream function $\psi$ by $v = (-\partial_y\psi, \partial_x\psi).$

source
StreamMacros.@velo_from_streamMacro
@velo_from_stream(name::Symbol, [code::Expr])

Get the velocity field corresponding to a stream function on $\mathbb{R}^2$. The defining code can be a series of definitions (in an enclosing begin ... end-block and is treated as a series of symbolic substitutions. Starting from the symbol name, substitutions are performed until the resulting expression only depends on x, y and t.

The macro returns an ODEFunction with signature (u, p, t) that returns an SVector{2} corresponding to the vector field at position u at time t. The parameter slot is not used and can be filled with nothing when calling.

The macro can be called without the code if the stream name has been defined beforehand via @define_stream.

Sign convention

We follow the "oceanographic" sign convention, whereby the velocity $v$ is derived from the stream function $\psi$ by $v = (-\partial_y\psi, \partial_x\psi).$

Examples

julia> using CoherentStructures

julia> f = @velo_from_stream Ψ_ellipse begin
               Ψ_ellipse = a*x^2 + b*y^2
               a = t
               b = 3
           end
(#3) #1 (generic function with 1 method)

julia> f([1.0,1.0], nothing, 1.0)
2-element StaticArrays.SArray{Tuple{2},Float64,1,2}:
 -6.0
  2.0
julia> using CoherentStructures

julia> @define_stream Ψ_circular begin
           Ψ_circular = f(x) + g(y)
           # naming of function variables
           # does not matter:
           f(a) = a^2
           g(y) = y^2
       end

julia> f2 = @velo_from_stream Ψ_circular
(#5) #1 (generic function with 1 method)

julia> f2([1.0,1.0], nothing, 0.0)
2-element StaticArrays.SArray{Tuple{2},Float64,1,2}:
 -2.0
  2.0
source
StreamMacros.@vorticity_from_streamMacro
@vorticity_from_stream(name::Symbol, [code::Expr])

Get the vorticity field as a function of (x, y, t) corresponding to a stream function on $\mathbb{R}^2$.

Sign convention

The vorticity $\omega$ of the velocity field $v = (v_x, v_y)$ is defined as derived from the stream function $\psi$ by $\omega = \partial_x v_x - \partial_y v_y = tr(\nabla^2\psi)$, i.e., the trace of the Hessian of the stream function.

source