本文整理汇总了Python中pyomo.environ.ConcreteModel.dv方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.dv方法的具体用法?Python ConcreteModel.dv怎么用?Python ConcreteModel.dv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.dv方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import dv [as 别名]
def test_invalid(self):
m = ConcreteModel()
m.t = ContinuousSet(bounds=(0, 1))
m.x = ContinuousSet(bounds=(5, 10))
m.s = Set(initialize=[1, 2, 3])
m.v = Var(m.t)
m.v2 = Var(m.s, m.t)
m.v3 = Var(m.x, m.t)
m.y = Var()
# Not passing a Var as the first positional argument
with self.assertRaises(DAE_Error):
m.ds = DerivativeVar(m.s)
# Specifying both option aliases
with self.assertRaises(TypeError):
m.dv = DerivativeVar(m.v, wrt=m.t, withrespectto=m.t)
# Passing in Var not indexed by a ContinuousSet
with self.assertRaises(DAE_Error):
m.dy = DerivativeVar(m.y)
# Not specifying 'wrt' when Var indexed by multiple ContinuousSets
with self.assertRaises(DAE_Error):
m.dv3 = DerivativeVar(m.v3)
# 'wrt' is not a ContinuousSet
with self.assertRaises(DAE_Error):
m.dv2 = DerivativeVar(m.v2, wrt=m.s)
with self.assertRaises(DAE_Error):
m.dv2 = DerivativeVar(m.v2, wrt=(m.t, m.s))
# Specified ContinuousSet does not index the Var
with self.assertRaises(DAE_Error):
m.dv = DerivativeVar(m.v, wrt=m.x)
with self.assertRaises(DAE_Error):
m.dv2 = DerivativeVar(m.v2, wrt=[m.t, m.x])
# Declaring the same derivative twice
m.dvdt = DerivativeVar(m.v)
with self.assertRaises(DAE_Error):
m.dvdt2 = DerivativeVar(m.v)
m.dv2dt = DerivativeVar(m.v2, wrt=m.t)
with self.assertRaises(DAE_Error):
m.dv2dt2 = DerivativeVar(m.v2, wrt=m.t)
m.dv3 = DerivativeVar(m.v3, wrt=(m.x, m.x))
with self.assertRaises(DAE_Error):
m.dv4 = DerivativeVar(m.v3, wrt=(m.x, m.x))
示例2: test_reclassification
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import dv [as 别名]
def test_reclassification(self):
m = ConcreteModel()
m.t = ContinuousSet(bounds=(0, 1))
m.x = ContinuousSet(bounds=(5, 10))
m.s = Set(initialize=[1, 2, 3])
m.v = Var(m.t)
m.v2 = Var(m.s, m.t)
m.v3 = Var(m.x, m.t)
m.dv = DerivativeVar(m.v)
m.dv2 = DerivativeVar(m.v2, wrt=(m.t, m.t))
m.dv3 = DerivativeVar(m.v3, wrt=m.x)
TransformationFactory('dae.finite_difference').apply_to(m, wrt=m.t)
self.assertTrue(m.dv.type() is Var)
self.assertTrue(m.dv2.type() is Var)
self.assertTrue(m.dv.is_fully_discretized())
self.assertTrue(m.dv2.is_fully_discretized())
self.assertTrue(m.dv3.type() is DerivativeVar)
self.assertFalse(m.dv3.is_fully_discretized())
TransformationFactory('dae.collocation').apply_to(m, wrt=m.x)
self.assertTrue(m.dv3.type() is Var)
self.assertTrue(m.dv3.is_fully_discretized())
示例3: test_invalid_derivative
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import dv [as 别名]
def test_invalid_derivative(self):
m = ConcreteModel()
m.t = ContinuousSet(bounds=(0, 10))
m.v = Var(m.t)
m.dv = DerivativeVar(m.v, wrt=(m.t, m.t, m.t))
with self.assertRaises(DAE_Error):
TransformationFactory('dae.finite_difference').apply_to(m)
示例4: test_initialized_continuous_set
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import dv [as 别名]
def test_initialized_continuous_set(self):
m = ConcreteModel()
m.t = ContinuousSet(initialize=[0, 1, 2, 3, 4])
m.v = Var(m.t)
m.dv = DerivativeVar(m.v)
log_out = StringIO()
with LoggingIntercept(log_out, 'pyomo.dae'):
TransformationFactory('dae.finite_difference').apply_to(m, nfe=2)
self.assertIn('More finite elements', log_out.getvalue())
示例5: test_disc_second_order_1cp
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import dv [as 别名]
def test_disc_second_order_1cp(self):
m = ConcreteModel()
m.t = ContinuousSet(bounds=(0,1))
m.t2 = ContinuousSet(bounds=(0,10))
m.v = Var(m.t, m.t2)
m.dv = DerivativeVar(m.v, wrt=(m.t, m.t2))
TransformationFactory('dae.collocation').apply_to(m, nfe=2, ncp=1)
self.assertTrue(hasattr(m, 'dv_disc_eq'))
self.assertTrue(len(m.dv_disc_eq) == 4)
self.assertTrue(len(m.v) == 9)
示例6: test_valid
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import dv [as 别名]
def test_valid(self):
m = ConcreteModel()
m.t = ContinuousSet(bounds=(0, 1))
m.x = ContinuousSet(bounds=(5, 10))
m.s = Set()
m.v = Var(m.t)
m.dv = DerivativeVar(m.v)
m.dv2 = DerivativeVar(m.v, wrt=(m.t, m.t))
self.assertTrue(isinstance(m.dv, Var))
self.assertTrue(isinstance(m.dv, DerivativeVar))
self.assertTrue(m.dv._wrt[0] is m.t)
self.assertTrue(m.dv._sVar is m.v)
self.assertTrue(m.v._derivative[('t',)]() is m.dv)
self.assertTrue(m.dv.type() is DerivativeVar)
self.assertTrue(m.dv._index is m.t)
self.assertTrue(m.dv2._wrt[0] is m.t)
self.assertTrue(m.dv2._wrt[1] is m.t)
self.assertTrue(m.v._derivative[('t', 't')]() is m.dv2)
self.assertTrue(m.dv.get_state_var() is m.v)
self.assertTrue(m.dv2.get_state_var() is m.v)
del m.dv
del m.dv2
del m.v
m.v = Var(m.s, m.t)
m.dv = DerivativeVar(m.v)
m.dv2 = DerivativeVar(m.v, wrt=(m.t, m.t))
self.assertTrue(isinstance(m.dv, Var))
self.assertTrue(isinstance(m.dv, DerivativeVar))
self.assertTrue(m.dv._wrt[0] is m.t)
self.assertTrue(m.dv._sVar is m.v)
self.assertTrue(m.v._derivative[('t',)]() is m.dv)
self.assertTrue(m.dv.type() is DerivativeVar)
self.assertTrue(m.t in m.dv._implicit_subsets)
self.assertTrue(m.s in m.dv._implicit_subsets)
self.assertTrue(m.dv2._wrt[0] is m.t)
self.assertTrue(m.dv2._wrt[1] is m.t)
self.assertTrue(m.v._derivative[('t', 't')]() is m.dv2)
del m.dv
del m.dv2
del m.v
del m.v_index
del m.dv_index
del m.dv2_index
m.v = Var(m.x, m.t)
m.dv = DerivativeVar(m.v, wrt=m.x)
m.dv2 = DerivativeVar(m.v, wrt=m.t)
m.dv3 = DerivativeVar(m.v, wrt=(m.t, m.x))
m.dv4 = DerivativeVar(m.v, wrt=[m.t, m.t])
self.assertTrue(isinstance(m.dv, Var))
self.assertTrue(isinstance(m.dv, DerivativeVar))
self.assertTrue(m.dv._wrt[0] is m.x)
self.assertTrue(m.dv._sVar is m.v)
self.assertTrue(m.v._derivative[('x',)]() is m.dv)
self.assertTrue(m.v._derivative[('t',)]() is m.dv2)
self.assertTrue(m.v._derivative[('t', 'x')]() is m.dv3)
self.assertTrue(m.v._derivative[('t', 't')]() is m.dv4)
self.assertTrue(m.dv.type() is DerivativeVar)
self.assertTrue(m.x in m.dv._implicit_subsets)
self.assertTrue(m.t in m.dv._implicit_subsets)
self.assertTrue(m.dv3._wrt[0] is m.t)
self.assertTrue(m.dv3._wrt[1] is m.x)
self.assertTrue(m.dv4._wrt[0] is m.t)
self.assertTrue(m.dv4._wrt[1] is m.t)