Skip to content

Commit

Permalink
style: fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianM-C committed Sep 24, 2024
1 parent b881cc3 commit 008b84b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/Blocks/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ function cached_interpolation(interpolation_type, u, x, args)
# to update the cache if needed (and setindex! is not defined on ranges)
# with a view from MTKParameters, so we collect to get a vector
prev_x = DiffCache(collect(x))
interp = GeneralLazyBufferCache() do (u,x)
interp = GeneralLazyBufferCache() do (u, x)
interpolation_type(get_tmp(prev_u, u), get_tmp(prev_x, x), args...)
end

Expand All @@ -758,16 +758,17 @@ function cached_interpolation(interpolation_type, u, x, args)
if (u, x) (get_tmp(prev_u, u), get_tmp(prev_x, x))
get_tmp(prev_u, u) .= u
get_tmp(prev_x, x) .= x
interp.bufs[(u,x)] = interpolation_type(
interp.bufs[(u, x)] = interpolation_type(
get_tmp(prev_u, u), get_tmp(prev_x, x), args...)
else
interp[(u,x)]
interp[(u, x)]
end
end
end
end

@register_symbolic interpolation_builder(f::Function, u::AbstractArray, x::AbstractArray, args::Tuple)
@register_symbolic interpolation_builder(
f::Function, u::AbstractArray, x::AbstractArray, args::Tuple)
interpolation_builder(f, u, x, args) = f(u, x, args)

"""
Expand All @@ -790,7 +791,8 @@ such as `LinearInterpolation`, `ConstantInterpolation` or `CubicSpline`.
# Connectors:
- `output`: a [`RealOutput`](@ref) connector corresponding to the interpolated value
"""
function ParametrizedInterpolation(interp_type::T, u::AbstractVector, x::AbstractVector, args...; name) where {T}
function ParametrizedInterpolation(
interp_type::T, u::AbstractVector, x::AbstractVector, args...; name) where {T}
@parameters data[1:length(x)] = u
@parameters ts[1:length(x)] = x
@parameters interpolation_type::T=interp_type [tunable = false] interpolation_args::Tuple=args [tunable = false]
Expand All @@ -803,9 +805,11 @@ function ParametrizedInterpolation(interp_type::T, u::AbstractVector, x::Abstrac

eqs = [output.u ~ apply_interpolation(interpolator, t)]

ODESystem(eqs, t, [], [data, ts, interpolation_type, interpolation_args, interpolator, memoized_builder];
ODESystem(eqs, t, [],
[data, ts, interpolation_type, interpolation_args, interpolator, memoized_builder];
parameter_dependencies = [
interpolator => interpolation_builder(memoized_builder, data, ts, interpolation_args)
interpolator => interpolation_builder(
memoized_builder, data, ts, interpolation_args)
],
systems = [output],
name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Library to model iso-thermal compressible liquid fluid flow
Library to model iso-thermal compressible liquid fluid flow
"""
module IsothermalCompressible

Expand Down
5 changes: 3 additions & 2 deletions test/Blocks/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ end

@test SciMLBase.successful_retcode(sol)

prob2 = remake(prob, p=[i.data => ones(15)])
prob2 = remake(prob, p = [i.data => ones(15)])
sol2 = solve(prob2)

@test SciMLBase.successful_retcode(sol2)
Expand All @@ -525,7 +525,8 @@ end

set_data! = setp(prob, i.data)
of = OptimizationFunction(loss, AutoForwardDiff())
op = OptimizationProblem(of, u, (prob, set_data!), lb = zeros(15), ub = fill(2.0, 15))
op = OptimizationProblem(
of, u, (prob, set_data!), lb = zeros(15), ub = fill(2.0, 15))

# check that type changing works
@test length(ForwardDiff.gradient(x -> of(x, (prob, set_data!)), u)) == 15
Expand Down

0 comments on commit 008b84b

Please sign in to comment.