Help> Using Interpolation in Pyomo.Dae

59 views
Skip to first unread message

Mayowa Oladele

unread,
Sep 22, 2022, 9:26:15 AM9/22/22
to Pyomo Forum
Hello,

I have some time steps values that I already defined in my data but I don't wanna make use of it. I instead want to make use of the discretized points from the continuous set as my new time span.

I tried interpolating my data after applying the discretization but after running it, I noticed three things:
1. my constraints were more than my variables.
2. when I print my parameters, it shows the interpolated time points but no value is attached to those time points.
3. I also noticed the discretization is adding additional points than what I specified (I don't think this is right).

I can't really figure out where the error is coming from.

Below is my code and a picture of the error:

df = pd.read_csv('digester_influent_PyADM13.csv')
model = m = ConcreteModel()
m.t = ContinuousSet(bounds=(0,1))

m.Ssu_in = Param(m.t, mutable=True)
m.Saa_in = Param(m.t, mutable=True)
m.Sfa_in = Param(m.t, mutable=True)
m.Q = Param(m.t, mutable=True)
m.V_liq = Param(initialize=3400, within=PositiveReals) 

discretizer = TransformationFactory('dae.finite_difference')
discretizer.apply_to(m,nfe=(96*1+1),wrt=m.t,scheme='BACKWARD')

# Interpolate the data
timepoints = list(ContinuousSet(bounds=(0,1)))
data_timepoints = df['time'].tolist()
data_profiles1 = df['S_su'].tolist()
data_profiles2 = df['S_aa'].tolist()
data_profiles3 = df['S_fa'].tolist()
data_profiles4 = df['Q'].tolist()

interp_Ssu_values = np.interp(timepoints, data_timepoints, data_profiles1)
interp_Saa_values = np.interp(timepoints, data_timepoints, data_profiles2)
interp_Sfa_values = np.interp(timepoints, data_timepoints, data_profiles3)
interp_Q_values = np.interp(timepoints, data_timepoints, data_profiles4)

for i,t in enumerate(timepoints):
    m.Ssu_in[t] = interp_Ssu_values[i]
    m.Saa_in[t] = interp_Saa_values[i]
    m.Sfa_in[t] = interp_Sfa_values[i]
    m.Q[t] = interp_Q_values[i]

# Variables
m.S_su = Var(m.t, initialize=0.012394, domain=PositiveReals, bounds=(0.001,1))               
m.S_aa = Var(m.t, initialize=0.0055432, domain=PositiveReals, bounds=(0,0.1))                  
m.S_fa = Var(m.t, initialize=0.10741, domain=PositiveReals, bounds=(0.001,2)) 
m.dS_su_dt = DerivativeVar(m.S_su, wrt=m.t)
m.dS_aa_dt = DerivativeVar(m.S_aa, wrt=m.t)
m.dS_fa_dt = DerivativeVar(m.S_fa, wrt=m.t)

# Initial Values
m.S_su[0].fix(0.012394)
m.S_aa[0].fix(0.0055432)
m.S_fa[0].fix(0.10741)

# Differential equations
def S_su_out_bal(m,t):
    return m.dS_su_dt[t] == (m.Q[t]/m.V_liq) * (m.Ssu_in[t] - m.S_su[t]) + 0.000662979
m.Ssu_outcon = Constraint(m.t, rule=S_su_out_bal)

def S_aa_out_bal(m,t):
    return m.dS_aa_dt[t] == (m.Q[t]/m.V_liq) * (m.Saa_in[t] - m.S_aa[t]) - 0.00202160
m.Saa_outcon = Constraint(m.t, rule=S_aa_out_bal)

def S_fa_out_bal(m,t):
    return m.dS_fa_dt[t] == (m.Q[t]/m.V_liq) * (m.Sfa_in[t] - m.S_fa[t]) + 0.005667982
m.Sfa_outcon = Constraint(m.t, rule=S_fa_out_bal)
error.png

Thank you!

Mayowa Oladele

unread,
Sep 26, 2022, 1:58:36 AM9/26/22
to Pyomo Forum
Please I need  help with this. Can anyone please respond?
Reply all
Reply to author
Forward
0 new messages