# Interpolated parameters into the PDESystems

**URL:** https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736
**Category:** Modelling & Simulations
**Tags:** question, pde
**Created:** [September 28, 2025, 9:05pm UTC](https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736 "2025-09-28T21:05:12Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sraghuram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sraghuram/32/218805_2.png) [@sraghuram](https://discourse.julialang.org/u/sraghuram)
#### Post date: [September 28, 2025, 9:05pm UTC](https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736/1 "2025-09-28T21:05:12Z")

</div>

Hey I am trying to solve a system of equations where my input parameters are altitude dependent values. These values should be supplied into system of equations after discretizing the equation. I have created an Interpolated function which has to be taken into the equations and has to solve. I made an example code here. Your help is appreciated.

using ModelingToolkit, DomainSets  
using MethodOfLines, OrdinaryDiffEq  
using Interpolations  
using Symbolics: Num  
using RuntimeGeneratedFunctions

# Independent variables

@parameters t x  
@variables u(..)

# Correct Symbolic Definition: Callable symbolic parameter

@parameters D\_param(..)

# Differentials

Dt = Differential(t)  
Dx = Differential(x)

# === INTERPOLATION SETUP ===

# Grid

x\_vals = 0.0:0.1:Float64(pi)  
const XMAX = Float64(pi)

# Parameter data (Diffusion coefficient)

D\_vals = ones(length(x\_vals)) \* 0.1

# Create Interpolation object

D\_fun = LinearInterpolation(x\_vals, D\_vals, extrapolation\_bc=Line())

# Correct parameter dictionary input:

param\_vals = Dict(D\_param(x) =\> x → D\_fun(x))

## Goal: While discretization D\_param(x) value should be taken from interpolated function while solving

# PDE equation: Only includes the D(x) term

eqs = [  
Dt(u(t,x)) ~ D\_param(x) \* Dx(Dx(u(t,x)))  
]

# Domains

tdom = Interval(0.0, 1.0)  
xdom = Interval(0.0, XMAX)  
domains = [t ∈ tdom, x ∈ xdom]

# Boundary Conditions (BCs)

bcs = [  
u(0.0, x) ~ sin(x), # IC at t=0  
u(t, 0.0) ~ 1e-3, # BC at x=0  
u(t, XMAX) ~ 0.0 # BC at x=π  
]

# Build PDESystem

@named pdesys = PDESystem(eqs, bcs, domains, [t,x], [u(t,x)], [D\_param(x)];  
defaults = param\_vals );

discretization = MOLFiniteDifference([x =\> 10], t;approx\_order = 2, use\_ODAE = false)  
sym\_prob = symbolic\_discretize(pdesys, discretization); ## I could see the discretized equations over 10 altitudes.  
prob = discretize(pdesys, discretization);

prob has threw the following error:  
The system of equations is:  
Equation[Differential(t)((u(t))[2]) - (8.207015875029361(u(t))[1] - 16.414031750058722(u(t))[2] …

MethodError: Cannot `convert` an object of type var"#110#111" to an object of type Number  
The function `convert` exists, but no method is defined for this combination of argument types.

Closest candidates are:  
convert(::Type{Number}, !Matched::Unitful.Quantity)  
@ Unitful ~/.julia/packages/Unitful/sxiHA/src/conversion.jl:166  
convert(::Type{T}, !Matched::Union{Static.StaticBool{N}, Static.StaticFloat64{N}, Static.StaticInt{N}} where N) where T\<:Number  
@ Static ~/.julia/packages/Static/SeEGr/src/Static.jl:427  
convert(::Type{T}, !Matched::Number) where T\<:Number  
@ Base number.jl:7  
…

After this I have to do the following one  
sol = solve(prob, Tsit5())

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [September 29, 2025, 1:45am UTC](https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736/2 "2025-09-29T01:45:34Z")

</div>

Interpolations.jl isn’t setup with the Symbolics.jl tooling yet. If you want to integrate an interpolation, you’ll need to use DataInterpolations.jl. That only does 1-dimensional interpolations though. If you need higher dimension interpolations then you’ll want [GitHub - SciML/DataInterpolationsND.jl: Interpolation of arbitrarily high dimensional array data](https://github.com/SciML/DataInterpolationsND.jl), though this integration is not complete yet:

> <https://github.com/SciML/DataInterpolationsND.jl/pull/30>
>
> \## Summary
> 
> This PR implements Symbolics.jl support for DataInterpolationsND.jl …to enable ModelingToolkit (MTK) compatibility as requested in issue #6.
> 
> The implementation follows the same pattern established in DataInterpolations.jl but is adapted for the N-dimensional case with support for partial derivatives.
> 
> \## Changes
> 
> \- \*\*New Extension\*\*: Created \`DataInterpolationsNDSymbolicsExt\` in \`ext/\` directory
> \- \*\*Symbolic Registration\*\*: Register \`NDInterpolation\` objects as symbolic functions  
> \- \*\*Partial Derivatives\*\*: Implement symbolic differentiation for ∂f/∂x₁, ∂f/∂x₂, etc.
> \- \*\*Higher-Order Derivatives\*\*: Support for mixed partial derivatives
> \- \*\*Test Suite\*\*: Comprehensive tests for symbolic functionality
> \- \*\*Project Configuration\*\*: Proper extension setup with weakdeps
> 
> \## Features
> 
> \### Symbolic Evaluation
> \`\`\`julia
> using DataInterpolationsND, Symbolics
> @variables x y
> itp = NDInterpolation(u, (LinearInterpolationDimension(t1), LinearInterpolationDimension(t2)))
> result = itp(x, y) # Returns symbolic expression
> \`\`\`
> 
> \### Symbolic Differentiation  
> \`\`\`julia
> ∂f\_∂x = Symbolics.derivative(result, x) # Partial derivative w.r.t. x
> ∂f\_∂y = Symbolics.derivative(result, y) # Partial derivative w.r.t. y
> \`\`\`
> 
> \### Value Substitution
> \`\`\`julia
> numerical\_value = Symbolics.substitute(result, Dict(x =\> 1.5, y =\> 0.5))
> \`\`\`
> 
> \## Technical Details
> 
> The extension uses:
> \- \`@register\_symbolic\` to register interpolation functions
> \- Custom \`PartialDerivative\` and \`MixedPartialDerivative\` types for symbolic differentiation
> \- Integration with DataInterpolationsND's existing \`derivative\_orders\` parameter system
> \- Weak dependency pattern to avoid forcing Symbolics as a hard dependency
> 
> \## Testing
> 
> The implementation has been thoroughly tested to verify:
> \- ✅ Symbolic expressions are created correctly
> \- ✅ Partial derivatives work for all dimensions  
> \- ✅ Mixed derivatives are supported
> \- ✅ Substitution produces correct numerical values matching direct evaluation
> \- ✅ Integration with existing DataInterpolationsND functionality
> 
> \## Test Plan
> 
> To test this PR:
> 
> 1. \*\*Basic functionality\*\*:
> \`\`\`julia
> using DataInterpolationsND, Symbolics
> t1, t2 = \[1.0, 2.0, 3.0\], \[0.0, 1.0, 2.0\] 
> u = \[i + j for i in t1, j in t2\]
> itp = NDInterpolation(u, (LinearInterpolationDimension(t1), LinearInterpolationDimension(t2)))
> @variables x y
> result = itp(x, y)
> @assert result isa Symbolics.Num
> \`\`\`
> 
> 2. \*\*Differentiation\*\*:
> \`\`\`julia
> ∂f\_∂x = Symbolics.derivative(result, x) 
> @assert ∂f\_∂x isa Symbolics.Num
> \`\`\`
> 
> 3. \*\*Numerical consistency\*\*:
> \`\`\`julia
> substituted = Symbolics.substitute(result, Dict(x =\> 1.5, y =\> 0.5))
> numerical = itp(1.5, 0.5)
> @assert substituted ≈ numerical
> \`\`\`
> 
> Resolves #6
> 
> 🤖 Generated with \[Claude Code\](https://claude.ai/code)

When that PR is merged this story for ND will be complete.

---

<div class="post-metadata">

### Author: ![sraghuram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sraghuram/32/218805_2.png) [@sraghuram](https://discourse.julialang.org/u/sraghuram)
#### Post date: [October 2, 2025, 8:47pm UTC](https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736/3 "2025-10-02T20:47:50Z")

</div>

Thanks for the quick help @ChrisRackauckas. I presented simple case of a large system. With Datainterpolation and I could solve the given example. But in the actual problem, I am solving equations using a reaction network coupled with method of lines. This requires Datainterpolation of input parameters multiple times depending on the chosen spatial grid that make my calculation very slow. Wondering if there is a better approach to avoid this Datainterpolation. Please let me know if any tutorial example. Thanks.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [October 3, 2025, 11:02am UTC](https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736/4 "2025-10-03T11:02:21Z")

</div>

Are you asking for the ND interpolation?

---

<div class="post-metadata">

### Author: ![sraghuram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sraghuram/32/218805_2.png) [@sraghuram](https://discourse.julialang.org/u/sraghuram)
#### Post date: [October 21, 2025, 6:29pm UTC](https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736/5 "2025-10-21T18:29:45Z")

</div>

thanks for the help. I understand that parameters have to be interpolated and the interpolated functions have to plugged into the equations system to solve the system of equations. I have constructed PDESystem of 15 equations with 84 parameters which are interpolated functions using DataInterpolations. But at the step prob = discretize(pdesys, discretization); it is taking unusual time for N = 45 spatial points. Wondering if there is a faster approach for this? Please suggest me.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [October 22, 2025, 9:09am UTC](https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736/6 "2025-10-22T09:09:35Z")

</div>

At this time no, we’re working on that exact problem right now though

---

<div class="post-metadata">

### Author: ![sraghuram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sraghuram/32/218805_2.png) [@sraghuram](https://discourse.julialang.org/u/sraghuram)
#### Post date: [October 22, 2025, 12:47pm UTC](https://discourse.julialang.org/t/interpolated-parameters-into-the-pdesystems/132736/7 "2025-10-22T12:47:42Z")

</div>

Ok. thanks…!!
