Do you intend for `m.d` to be a single value or to have different values depending on the index?
Bethany
--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
pyomo-forum...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyomo-forum/9641a9c0-d326-437c-8772-2b57ded32505%40googlegroups.com.
I intend m.d to be a single value for all index, but make it as a fitting parameter that I can optimize RMSE by changing m.d.
(In the PDE, I have been changing the m.d value and achieves optimum value that minimize RMSE between the experimental values.)
m = ConcreteModel()
m.r = Param(initialize = 10) m.d = Var(initialize = 2, bounds = (0.01, 100))m.pi = Param(initialize=3.1416)
m.a = ContinuousSet(bounds=(-m.pi/2, m.pi/2)) m.x = ContinuousSet(bounds = (0, 1))
m.p = Var(m.a, m.x)m.dpdx = DerivativeVar(m.p, wrt = m.x)m.dpda2 = DerivativeVar(m.p, wrt = (m.a, m.a))m.dpda = DerivativeVar(m.p, wrt = m.a)
def _ux_rule(m, j): return 1/(1-(1-1/m.r)*(j))m.ux = Expression(m.x, rule=_ux_rule)
def _a_rule(m, i): return im.aa = Expression(m.a, rule=_a_rule)
def _dudx_rule(m, j): return (1-1/m.r)/((1-(1-1/m.r)*(j))**2)m.dudx = Expression(m.x, rule=_dudx_rule)
def _pde(m, i, j): if j ==0: #or i == m.pi/2 or i == -m.pi/2: return Constraint.Skip return m.ux[j]*m.dpdx[i,j] == m.d*m.dpda2[i,j] + m.r*(2*m.p[i,j]*cos(2*m.aa[i])+sin(2*m.aa[i])*m.dpda[i,j])
m.pde = Constraint(m.a, m.x, rule=_pde)
def _con1(m, j): if j == 0: return Constraint.Skip return m.dpda[-m.pi/2, j] == m.dpda[m.pi/2, j]m.con1 = Constraint(m.x, rule=_con1)
def _con2(m, i): return m.p[i, 0] == 1/m.pim.con2 = Constraint(m.a, rule=_con2)
def _con3(m, j): if j == 0: return Constraint.Skip return m.p[-m.pi/2, j] == m.p[m.pi/2, j]m.con3 = Constraint(m.x, rule=_con3)
discretizer = TransformationFactory('dae.finite_difference')discretizer2 = TransformationFactory('dae.collocation')
discretizer.apply_to(m, nfe=20, wrt=m.x, scheme='BACKWARD')discretizer2.apply_to(m, nfe=100, ncp=10, wrt=m.a) # change nfe to 170
'''def _intp(m, i, j): return m.p[i, j]m.intp = IndexedIntegral(m.a, m.x, wrt=m.a, rule=_intp)
def _con4(m, j): return m.intp[j] == 1m.con4 = Constraint(m.x, rule=_con4)
def _con5(m, i, j): return m.p[i, j] >= 0m.con5 = Constraint(m.a, m.x, rule=_con5)'''
def _obj(m): cxz = {} for i in range(len(sorted(m.a))): cxz[(sorted(m.a)[i])] = est.predict(np.array(m.a).reshape(-1,1))[i][0] return sum((m.p[i, 0.75] - cxz[i])**2 for i in m.a)
m.obj = Objective(rule = _obj, sense=minimize)
solver = SolverFactory('ipopt')results = solver.solve(m, tee=True)'''solver = SolverFactory('gurobi', solver_io='direct')solver.solve(m)'''
#solver=SolverFactory('gams')#solver.solve(m,solver='baron', tee=True)#solver.solve(m,solver='XPRESS', tee=True)
print(value(m.d))