Time dependent boundary conditions from an empirical function #612
-
I want to use time-dependent boundary conditions from an empirical function (interpolate measured values). The code snippet below shows what I tried so far starting from your example for time dependent boundary conditions. Only case 1 works. What else can I try? from pde import PDE, CartesianGrid, MemoryStorage, ScalarField, plot_kymograph
from sympy import Function, Symbol, sin
import numpy as np
def interp_nb(x_vals, x, y):
return np.interp(x_vals, x, y)
zeiten = np.arange(0, 20, .1)
zeitwerte = np.sin(zeiten)
t = Symbol('t')
class sini(Function):
@classmethod
def eval(cls, t):
cases = 1 # try the different cases
match cases:
case 1:
erg = sin(t) # ok
case 2:
erg = np.sin(t) # not working
case 3:
erg = np.interp(t, zeiten, zeitwerte) # not working
case 4:
erg = interp_nb(t, zeiten, zeitwerte) # not working
return erg
grid = CartesianGrid([[0, 10]], [64]) # generate grid
state = ScalarField(grid) # generate initial condition
eq = PDE({"c": "laplace(c)"}, bc={"value_expression": sini(t)})
storage = MemoryStorage()
eq.solve(state, t_range=20, dt=1e-4, tracker=storage.tracker(0.1))
# plot the trajectory as a space-time plot
plot_kymograph(storage) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I guess the right hand side of the expression is interpreted as a def sini(value, dx, x, t):
cases = 3 # try the different cases
match cases:
case 2:
erg = np.sin(t)
case 3:
erg = np.interp(t, zeiten, zeitwerte)
case 4:
erg = interp_nb(t, zeiten, zeitwerte)
return erg
eq = PDE({"c": "laplace(c)"}, bc={"value_expression": sini}) Note that I could not test this right now. Moreover, it might help to first get this to work without |
Beta Was this translation helpful? Give feedback.
I guess the right hand side of the expression is interpreted as a
sympy
expression, so it might not be surprising that only thesympy
implementation of the function works. Instead of using a sympy function, you could also directly use a python function with signaturefunc(value, dx, x, t)
, i.e., the following might work