Enter code here...
self.block.all_time = Set(initialize=range(n_steps), ordered=True)
self.block.all_x = Set(initialize=range(1, self.n_nodes + 1), ordered=True)
self.block.temperature_out_cv = Var(lines, self.block.all_time, self.block.all_x)
for j in self.block.all_x:
def _bc_temp_out(b, l, t):
if mass_flow.all() == 0:
return Constraint.Skip
elif t == 0:
return b.temperature_out_cv[l, t, j] == float(self.params['temperature_init_cv_' + l].v())
else:
for i in range(t+1):
if i == 0:
b.temperature_out_cv[l, i, j] = float(self.params['temperature_init_cv_' + l].v())
else:
if j == 1:
return b.temperature_out_cv[l, i, j] == (b.temperature_out_cv[l, i - 1, j] + b.u[
i] * time_step / self.params['delta_x'].v() * b.temperatures[l, i]
+ time_step / Z * Tg[i]) / (
1 + b.u[i] * time_step / self.params[
'delta_x'].v()
+ time_step / Z)
else:
return b.temperature_out_cv[l, i, j] == (b.temperature_out_cv[l, i - 1, j] + b.u[
i] * time_step / self.params['delta_x'].v() * b.temperature_out_cv[
l, i, j - 1]
+ time_step / Z * Tg[i]) / (
1 + b.u[i] * time_step / self.params[
'delta_x'].v()
+ time_step / Z)
self.block.add_component('_bc_temp_out' + str(j), Constraint(lines, self.block.all_time, rule=_bc_temp_out))
ERROR: Rule failed when generating expression for constraint
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pyomo\core\base\constraint.py", line 779, in construct
bbThor._bc_temp_out1 with index ('supply', 1): AttributeError: 'Series'
ndx)
object has no attribute 'is_expression_type'
ERROR: Constructing component 'bbThor._bc_temp_out1' from data=None failed:
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pyomo\core\base\misc.py", line 57, in apply_indexed_rule
return rule(model, *index)
File "C:\Users\Armaghan Bhr\Desktop\modesto-master\modesto\pipe.py", line 1723, in _bc_temp_out
AttributeError: 'Series' object has no attribute 'is_expression_type'
+ time_step / Z * Tg[i]) / (
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pyomo\core\expr\numvalue.py", line 772, in __add__
return _generate_sum_expression(_add,self,other)
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pyomo\core\expr\numeric_expr.py", line 1720, in _generate_sum_expression
if not (_other.__class__ in native_types or _other.is_expression_type()):
File "C:\Users\Armaghan Bhr\Anaconda3\envs\dhopt\lib\site-packages\pandas\core\generic.py", line 5179, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'is_expression_type'
You can't use a Pandas Series object directly in a Pyomo expression. You have to extract the desired constant value from the Series.
Bethany
def create_params(self): params = Component.create_params(self) params.update({ 'diameter': DesignParameter('diameter', 'Pipe diameter', 'DN (mm)', mutable=True), 'Tg': WeatherDataParameter('Tg', 'Undisturbed ground temperature', 'K')})
Tg = self.params['Tg'].v() # ground temperature (T_out in equation 4)
time_index = pd.DatetimeIndex(start=start_time, freq=str(time_step) + 'S', periods=n_steps)
# Ground temperature
t_g = pd.Series(12 + 273.15, index=t_amb.index)
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo...@googlegroups.com.