anuga-community / anuga_core

ANUGA for the simulation of the shallow water equation
https://anuga.anu.edu.au
Other
34 stars 24 forks source link

Is reading from array of Q available for Inlet_operator()? #48

Closed geografin closed 3 months ago

geografin commented 5 months ago

Docs describe possible inflow setting with constant value or with lambda function. As far as I see in the code these are the only ways to provide the inflow to equations. lambda can be used as an iterator from lists as lambda t: value[time.index(t)] if value=[Q1...Qn] and time=[t1...tn]. Lengths should be same. So, can we use this approach to provide inflow time arrays? time array can be easily calculated from initial settings.

stoiver commented 5 months ago

@geografin I would normally use scipy.interpolate.interp1d to define an interpolating function, for example:

from scipy.interpolate import interp1d
rate_function = interp1d(time,value)

and then pass rate_function to the Inlet_operator. I do notice that this interp1d is depreciated in scipy but it is still available and is so simple to use. You can change the type argument to produce piecewise constant interpolation. Also there are options to define what to do if you need to evaluate outside the range of your values.

I haven't tried your idea using the index method. Does it work when t is not in the list time?