Hello, I’m currently developing a package of a numerical solver to a certain kind of Stochastic PDE (Stochastic Neural Field Equations) in 1 and 2-dimensional space in a
DifferentialEquations.jl fashion, i.e. with the user interface:
prob = probSNFE(inputs) sol = solveSNFE(prob)
And I’m having a hard time to properly wrap my inputs in order to maintain a fairly simple user interface like the one I’ve mentioned.
Let me be more specific, the equation has the form:
where the functions I, K and S are given as inputs.
So, we can say that there are 3 types of inputs:
The equation’s parameters:
- α - Temporal decay
- v - Propagation velocity
- V0 - Initial condition
- ϵ - Noise level
- ξ - Correlation parameter
- np - Number of trajectories
- I, K and S
The domain’s parameters:
- L - Field’s length
- N - Number of nodes to discretise space
- T - Time span
- n - Number of nodes to discretise time
My first approach was to wrap the equation and domain’s parameters in 2 tuples and defining the 3 functions, in order to have the following:
using SNFE prob = probSNFE(tupEqparam, tupDomain, I, K, S) sol = solveSNFE(prob,saveat)
This approach is a bit messy when it comes to declare the parameters in the right order in the tuples. The
probSNFE signature is a bit too long and the most important, I’m not seeing any way to use multiple dispatch to distinguish 1D from 2D case.
To overcome some of these issues, I’ve decided to export 2 structures (for 1 and 2D) and use them as inputs to
abstract type Problem end abstract type OneDim <: Problem end abstract type TwoDim <: Problem end struct Input1D <: OneDim α::Float64 v::Float64 # ... I::Function #... end struct Input2D <: TwoDim #... end function probSNFE(in1d::Input1D) # stuff end function probSNFE(in2d::Input2D) # stuff end
So, the user has to do something like this:
using SNFE #load the package I(x,t)=... K(x)=... S(V)=... in1d = Input1D(α,v,thresh,V0,L,N,T,n,I,K,S) prob = probSNFE(in1d) sol = solveSNFE(prob,saveat,[ϵ,ξ,np])
The only con I see here is the user has to know the order of the inputs to create the structure
Am I approaching this in a good (“julian”) way? Is it bad to functions be fields of a structure? Any suggestions to improve?