Hi everyone,
I have a simple idea: I want to create a Grid object containing the parameters of my model. I want the user to give values using Unitful to have units and to internally have consistent values without the units. I have managed to do what I want like this for example:
using Unitful
struct Grid
nx::Int
Lx::Float64
Δx::Float64
x::StepRangeLen
function Grid(nx, Lx)
Δx = Lx / (nx-1)
x = range(0, length=nx, stop= Lx)
new(nx, Lx, Δx, x)
end
end
# convert Lenght unit
function Grid(nx::Int, Lx::Unitful.Length)
Grid(nx, ustrip(u"m", Lx))
end
grid = Grid(101, 1000u"1000")
I am trying to do the same thing using Parameters.jl (to understand it and to see if it can simplify a bit the writing) and I didn’t manage to make it work. Here is my try:
using Unitful
using Parameters
@with_kw struct Grid
nx::Int
Lx::Float64
Δx::Float64 = Lx / (nx-1)
x::StepRangeLen = range(0, length=nx, stop= Lx)
end
# convert Lenght unit
function Grid(nx::Int, Lx::Unitful.Length)
Grid(nx, ustrip(u"m", Lx))
end
grid = Grid(101, 1000u"1000")
which yield ERROR: MethodError: no method matching Grid(::Int64, ::Int64)
Is what I am trying to do not possible?