def get_pyomo_model(): m = aml.ConcreteModel() m.x = aml.Var(initialize=10.0) m.y = aml.Var(initialize=0.0) m.c0 = aml.Constraint(expr=aml.asin(m.x) >= 0) m.c1 = aml.Constraint(expr=aml.asin(m.y) >= 0) m.o = aml.Objective(expr=aml.asin(m.x)) return m
def test_asin(self): m = pe.Block(concrete=True) m.x = pe.Var() m.c = pe.Constraint(expr=pe.inequality(body=pe.asin(m.x), lower=-0.5, upper=0.5)) fbbt(m) self.assertAlmostEqual(pe.value(m.x.lb), math.sin(-0.5)) self.assertAlmostEqual(pe.value(m.x.ub), math.sin(0.5))
def test_asin(self): m = pyo.ConcreteModel() m.x = pyo.Var(initialize=0.5) e = pyo.asin(m.x) derivs = reverse_ad(e) symbolic = reverse_sd(e) self.assertAlmostEqual(derivs[m.x], pyo.value(symbolic[m.x]), tol + 3) self.assertAlmostEqual(derivs[m.x], approx_deriv(e, m.x), tol)
def test_asin(self): m = pe.ConcreteModel() m.x = pe.Var(initialize=0.5) e = pe.asin(m.x) derivs = reverse_ad(e) symbolic = reverse_sd(e) self.assertAlmostEqual(derivs[m.x], pe.value(symbolic[m.x]), tol+3) self.assertAlmostEqual(derivs[m.x], approx_deriv(e, m.x), tol)
def test_trig_fuctions(self): m = ConcreteModel() m.x = Var() e = differentiate(sin(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s(cos(m.x))) e = differentiate(cos(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s(-1.0*sin(m.x))) e = differentiate(tan(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s(1.+tan(m.x)**2.)) e = differentiate(sinh(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s(cosh(m.x))) e = differentiate(cosh(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s(sinh(m.x))) e = differentiate(tanh(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s(1.0-tanh(m.x)**2.0)) e = differentiate(asin(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s((1.0 + (-1.0)*m.x**2.)**-0.5)) e = differentiate(acos(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s(-1.*(1.+ (-1.0)*m.x**2.)**-0.5)) e = differentiate(atan(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s((1.+m.x**2.)**-1.)) e = differentiate(asinh(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s((1.+m.x**2)**-.5)) e = differentiate(acosh(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s((-1.+m.x**2.)**-.5)) e = differentiate(atanh(m.x), wrt=m.x) self.assertTrue(e.is_expression_type()) self.assertEqual(s(e), s((1.+(-1.0)*m.x**2.)**-1.))
def eq_cosine_partition(lower_bound, upper_bound, Q): #Divides the domain [lower_bound, upper_bound] into Q pieces of equal curvature for the cosine function. Domain must be contained in (-pi/2, pi/2) if Q == 1: return [lower_bound, upper_bound] total_curvature = pe.atan(pe.sin(upper_bound)) - pe.atan( pe.sin(lower_bound)) breakpoints = [lower_bound] for i in range(Q - 1): breakpoints.append( pe.asin( pe.tan(total_curvature / Q + pe.atan(pe.sin(breakpoints[i]))))) breakpoints.append(upper_bound) return breakpoints
def test_unary_expressions(self): m = ConcreteModel() m.x = Var() m.y = Var() m.z = Var() m.a = Var() m.b = Var() m.c = Var() m.d = Var() m.c1 = Constraint(expr=0 <= sin(m.x)) m.c2 = Constraint(expr=0 <= cos(m.y)) m.c3 = Constraint(expr=0 <= tan(m.z)) m.c4 = Constraint(expr=0 <= asin(m.a)) m.c5 = Constraint(expr=0 <= acos(m.b)) m.c6 = Constraint(expr=0 <= atan(m.c)) m.c7 = Constraint(expr=0 <= sqrt(m.d)) m.o = Objective(expr=m.x) self.assertTrue(satisfiable(m) is not False)
def test_arcfcn_to_string(self): m = ConcreteModel() m.x = Var() lbl = NumericLabeler('x') smap = SymbolMap(lbl) tc = StorageTreeChecker(m) self.assertEqual(expression_to_string(asin(m.x), tc, lbl, smap=smap), ("arcsin(x1)", False)) self.assertEqual(expression_to_string(acos(m.x), tc, lbl, smap=smap), ("arccos(x1)", False)) self.assertEqual(expression_to_string(atan(m.x), tc, lbl, smap=smap), ("arctan(x1)", False)) with self.assertRaisesRegexp( RuntimeError, "GAMS files cannot represent the unary function asinh"): expression_to_string(asinh(m.x), tc, lbl, smap=smap) with self.assertRaisesRegexp( RuntimeError, "GAMS files cannot represent the unary function acosh"): expression_to_string(acosh(m.x), tc, lbl, smap=smap) with self.assertRaisesRegexp( RuntimeError, "GAMS files cannot represent the unary function atanh"): expression_to_string(atanh(m.x), tc, lbl, smap=smap)
def alpha(b, t): return asin((b.level[t] - b.r_shell) / b.r_shell)
def test_get_check_units_on_all_expressions(self): # this method is going to test all the expression types that should work # to be defensive, we will also test that we actually have the expected expression type # therefore, if the expression system changes and we get a different expression type, # we will know we need to change these tests uc = units kg = uc.kg m = uc.m model = ConcreteModel() model.x = Var() model.y = Var() model.z = Var() model.p = Param(initialize=42.0, mutable=True) model.xkg = Var(units=kg) model.ym = Var(units=m) # test equality self._get_check_units_ok(3.0*kg == 1.0*kg, uc, 'kg', EXPR.EqualityExpression) self._get_check_units_fail(3.0*kg == 2.0*m, uc, EXPR.EqualityExpression) # test inequality self._get_check_units_ok(3.0*kg <= 1.0*kg, uc, 'kg', EXPR.InequalityExpression) self._get_check_units_fail(3.0*kg <= 2.0*m, uc, EXPR.InequalityExpression) self._get_check_units_ok(3.0*kg >= 1.0*kg, uc, 'kg', EXPR.InequalityExpression) self._get_check_units_fail(3.0*kg >= 2.0*m, uc, EXPR.InequalityExpression) # test RangedExpression self._get_check_units_ok(inequality(3.0*kg, 4.0*kg, 5.0*kg), uc, 'kg', EXPR.RangedExpression) self._get_check_units_fail(inequality(3.0*m, 4.0*kg, 5.0*kg), uc, EXPR.RangedExpression) self._get_check_units_fail(inequality(3.0*kg, 4.0*m, 5.0*kg), uc, EXPR.RangedExpression) self._get_check_units_fail(inequality(3.0*kg, 4.0*kg, 5.0*m), uc, EXPR.RangedExpression) # test SumExpression, NPV_SumExpression self._get_check_units_ok(3.0*model.x*kg + 1.0*model.y*kg + 3.65*model.z*kg, uc, 'kg', EXPR.SumExpression) self._get_check_units_fail(3.0*model.x*kg + 1.0*model.y*m + 3.65*model.z*kg, uc, EXPR.SumExpression) self._get_check_units_ok(3.0*kg + 1.0*kg + 2.0*kg, uc, 'kg', EXPR.NPV_SumExpression) self._get_check_units_fail(3.0*kg + 1.0*kg + 2.0*m, uc, EXPR.NPV_SumExpression) # test ProductExpression, NPV_ProductExpression self._get_check_units_ok(model.x*kg * model.y*m, uc, 'kg*m', EXPR.ProductExpression) self._get_check_units_ok(3.0*kg * 1.0*m, uc, 'kg*m', EXPR.NPV_ProductExpression) self._get_check_units_ok(3.0*kg*m, uc, 'kg*m', EXPR.NPV_ProductExpression) # I don't think that there are combinations that can "fail" for products # test MonomialTermExpression self._get_check_units_ok(model.x*kg, uc, 'kg', EXPR.MonomialTermExpression) # test DivisionExpression, NPV_DivisionExpression self._get_check_units_ok(1.0/(model.x*kg), uc, '1/kg', EXPR.DivisionExpression) self._get_check_units_ok(2.0/kg, uc, '1/kg', EXPR.NPV_DivisionExpression) self._get_check_units_ok((model.x*kg)/1.0, uc, 'kg', EXPR.MonomialTermExpression) self._get_check_units_ok(kg/2.0, uc, 'kg', EXPR.NPV_DivisionExpression) self._get_check_units_ok(model.y*m/(model.x*kg), uc, 'm/kg', EXPR.DivisionExpression) self._get_check_units_ok(m/kg, uc, 'm/kg', EXPR.NPV_DivisionExpression) # I don't think that there are combinations that can "fail" for products # test PowExpression, NPV_PowExpression # ToDo: fix the str representation to combine the powers or the expression system self._get_check_units_ok((model.x*kg**2)**3, uc, 'kg**6', EXPR.PowExpression) # would want this to be kg**6 self._get_check_units_fail(kg**model.x, uc, EXPR.PowExpression, UnitsError) self._get_check_units_fail(model.x**kg, uc, EXPR.PowExpression, UnitsError) self._get_check_units_ok(kg**2, uc, 'kg**2', EXPR.NPV_PowExpression) self._get_check_units_fail(3.0**kg, uc, EXPR.NPV_PowExpression, UnitsError) # test NegationExpression, NPV_NegationExpression self._get_check_units_ok(-(kg*model.x*model.y), uc, 'kg', EXPR.NegationExpression) self._get_check_units_ok(-kg, uc, 'kg', EXPR.NPV_NegationExpression) # don't think there are combinations that fan "fail" for negation # test AbsExpression, NPV_AbsExpression self._get_check_units_ok(abs(kg*model.x), uc, 'kg', EXPR.AbsExpression) self._get_check_units_ok(abs(kg), uc, 'kg', EXPR.NPV_AbsExpression) # don't think there are combinations that fan "fail" for abs # test the different UnaryFunctionExpression / NPV_UnaryFunctionExpression types # log self._get_check_units_ok(log(3.0*model.x), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(log(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(log(3.0*model.p), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(log(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # log10 self._get_check_units_ok(log10(3.0*model.x), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(log10(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(log10(3.0*model.p), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(log10(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # sin self._get_check_units_ok(sin(3.0*model.x*uc.radians), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(sin(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_fail(sin(3.0*kg*model.x*uc.kg), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(sin(3.0*model.p*uc.radians), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(sin(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # cos self._get_check_units_ok(cos(3.0*model.x*uc.radians), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(cos(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_fail(cos(3.0*kg*model.x*uc.kg), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(cos(3.0*model.p*uc.radians), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(cos(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # tan self._get_check_units_ok(tan(3.0*model.x*uc.radians), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(tan(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_fail(tan(3.0*kg*model.x*uc.kg), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(tan(3.0*model.p*uc.radians), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(tan(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # sin self._get_check_units_ok(sinh(3.0*model.x*uc.radians), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(sinh(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_fail(sinh(3.0*kg*model.x*uc.kg), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(sinh(3.0*model.p*uc.radians), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(sinh(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # cos self._get_check_units_ok(cosh(3.0*model.x*uc.radians), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(cosh(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_fail(cosh(3.0*kg*model.x*uc.kg), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(cosh(3.0*model.p*uc.radians), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(cosh(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # tan self._get_check_units_ok(tanh(3.0*model.x*uc.radians), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(tanh(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_fail(tanh(3.0*kg*model.x*uc.kg), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(tanh(3.0*model.p*uc.radians), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(tanh(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # asin self._get_check_units_ok(asin(3.0*model.x), uc, 'rad', EXPR.UnaryFunctionExpression) self._get_check_units_fail(asin(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(asin(3.0*model.p), uc, 'rad', EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(asin(3.0*model.p*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # acos self._get_check_units_ok(acos(3.0*model.x), uc, 'rad', EXPR.UnaryFunctionExpression) self._get_check_units_fail(acos(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(acos(3.0*model.p), uc, 'rad', EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(acos(3.0*model.p*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # atan self._get_check_units_ok(atan(3.0*model.x), uc, 'rad', EXPR.UnaryFunctionExpression) self._get_check_units_fail(atan(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(atan(3.0*model.p), uc, 'rad', EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(atan(3.0*model.p*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # exp self._get_check_units_ok(exp(3.0*model.x), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_fail(exp(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(exp(3.0*model.p), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(exp(3.0*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # sqrt self._get_check_units_ok(sqrt(3.0*model.x), uc, None, EXPR.UnaryFunctionExpression) self._get_check_units_ok(sqrt(3.0*model.x*kg**2), uc, 'kg', EXPR.UnaryFunctionExpression) self._get_check_units_ok(sqrt(3.0*model.x*kg), uc, 'kg**0.5', EXPR.UnaryFunctionExpression) self._get_check_units_ok(sqrt(3.0*model.p), uc, None, EXPR.NPV_UnaryFunctionExpression) self._get_check_units_ok(sqrt(3.0*model.p*kg**2), uc, 'kg', EXPR.NPV_UnaryFunctionExpression) self._get_check_units_ok(sqrt(3.0*model.p*kg), uc, 'kg**0.5', EXPR.NPV_UnaryFunctionExpression) # asinh self._get_check_units_ok(asinh(3.0*model.x), uc, 'rad', EXPR.UnaryFunctionExpression) self._get_check_units_fail(asinh(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(asinh(3.0*model.p), uc, 'rad', EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(asinh(3.0*model.p*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # acosh self._get_check_units_ok(acosh(3.0*model.x), uc, 'rad', EXPR.UnaryFunctionExpression) self._get_check_units_fail(acosh(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(acosh(3.0*model.p), uc, 'rad', EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(acosh(3.0*model.p*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # atanh self._get_check_units_ok(atanh(3.0*model.x), uc, 'rad', EXPR.UnaryFunctionExpression) self._get_check_units_fail(atanh(3.0*kg*model.x), uc, EXPR.UnaryFunctionExpression, UnitsError) self._get_check_units_ok(atanh(3.0*model.p), uc, 'rad', EXPR.NPV_UnaryFunctionExpression) self._get_check_units_fail(atanh(3.0*model.p*kg), uc, EXPR.NPV_UnaryFunctionExpression, UnitsError) # ceil self._get_check_units_ok(ceil(kg*model.x), uc, 'kg', EXPR.UnaryFunctionExpression) self._get_check_units_ok(ceil(kg), uc, 'kg', EXPR.NPV_UnaryFunctionExpression) # don't think there are combinations that fan "fail" for ceil # floor self._get_check_units_ok(floor(kg*model.x), uc, 'kg', EXPR.UnaryFunctionExpression) self._get_check_units_ok(floor(kg), uc, 'kg', EXPR.NPV_UnaryFunctionExpression) # don't think there are combinations that fan "fail" for floor # test Expr_ifExpression # consistent if, consistent then/else self._get_check_units_ok(EXPR.Expr_if(IF=model.x*kg + kg >= 2.0*kg, THEN=model.x*kg, ELSE=model.y*kg), uc, 'kg', EXPR.Expr_ifExpression) # unitless if, consistent then/else self._get_check_units_ok(EXPR.Expr_if(IF=model.x >= 2.0, THEN=model.x*kg, ELSE=model.y*kg), uc, 'kg', EXPR.Expr_ifExpression) # consistent if, unitless then/else self._get_check_units_ok(EXPR.Expr_if(IF=model.x*kg + kg >= 2.0*kg, THEN=model.x, ELSE=model.x), uc, None, EXPR.Expr_ifExpression) # inconsistent then/else self._get_check_units_fail(EXPR.Expr_if(IF=model.x >= 2.0, THEN=model.x*m, ELSE=model.y*kg), uc, EXPR.Expr_ifExpression) # inconsistent then/else NPV self._get_check_units_fail(EXPR.Expr_if(IF=model.x >= 2.0, THEN=model.p*m, ELSE=model.p*kg), uc, EXPR.Expr_ifExpression) # inconsistent then/else NPV units only self._get_check_units_fail(EXPR.Expr_if(IF=model.x >= 2.0, THEN=m, ELSE=kg), uc, EXPR.Expr_ifExpression) # test EXPR.IndexTemplate and GetItemExpression model.S = Set() i = EXPR.IndexTemplate(model.S) j = EXPR.IndexTemplate(model.S) self._get_check_units_ok(i, uc, None, EXPR.IndexTemplate) model.mat = Var(model.S, model.S) self._get_check_units_ok(model.mat[i,j+1], uc, None, EXPR.GetItemExpression) # test ExternalFunctionExpression, NPV_ExternalFunctionExpression model.ef = ExternalFunction(python_callback_function) self._get_check_units_ok(model.ef(model.x, model.y), uc, None, EXPR.ExternalFunctionExpression) self._get_check_units_ok(model.ef(1.0, 2.0), uc, None, EXPR.NPV_ExternalFunctionExpression) self._get_check_units_fail(model.ef(model.x*kg, model.y), uc, EXPR.ExternalFunctionExpression, UnitsError) self._get_check_units_fail(model.ef(2.0*kg, 1.0), uc, EXPR.NPV_ExternalFunctionExpression, UnitsError) # test ExternalFunctionExpression, NPV_ExternalFunctionExpression model.ef2 = ExternalFunction(python_callback_function, units=uc.kg) self._get_check_units_ok(model.ef2(model.x, model.y), uc, 'kg', EXPR.ExternalFunctionExpression) self._get_check_units_ok(model.ef2(1.0, 2.0), uc, 'kg', EXPR.NPV_ExternalFunctionExpression) self._get_check_units_fail(model.ef2(model.x*kg, model.y), uc, EXPR.ExternalFunctionExpression, UnitsError) self._get_check_units_fail(model.ef2(2.0*kg, 1.0), uc, EXPR.NPV_ExternalFunctionExpression, UnitsError) # test ExternalFunctionExpression, NPV_ExternalFunctionExpression model.ef3 = ExternalFunction(python_callback_function, units=uc.kg, arg_units=[uc.kg, uc.m]) self._get_check_units_fail(model.ef3(model.x, model.y), uc, EXPR.ExternalFunctionExpression) self._get_check_units_fail(model.ef3(1.0, 2.0), uc, EXPR.NPV_ExternalFunctionExpression) self._get_check_units_fail(model.ef3(model.x*kg, model.y), uc, EXPR.ExternalFunctionExpression, UnitsError) self._get_check_units_fail(model.ef3(2.0*kg, 1.0), uc, EXPR.NPV_ExternalFunctionExpression, UnitsError) self._get_check_units_ok(model.ef3(2.0*kg, 1.0*uc.m), uc, 'kg', EXPR.NPV_ExternalFunctionExpression) self._get_check_units_ok(model.ef3(model.x*kg, model.y*m), uc, 'kg', EXPR.ExternalFunctionExpression) self._get_check_units_ok(model.ef3(model.xkg, model.ym), uc, 'kg', EXPR.ExternalFunctionExpression) self._get_check_units_fail(model.ef3(model.ym, model.xkg), uc, EXPR.ExternalFunctionExpression, InconsistentUnitsError)
def alpha_tube(b): return asin(b.thk_fin_half / b.radius_out)
def alpha(b, t): return asin((b.level[t]-b.heater_radius)/b.heater_radius)
def alpha_slag(b, t): return asin((b.fin_thickness_half + b.slag_thickness[t]) / (b.radius_outer + b.slag_thickness[t]))
def alpha_tube(b): return asin(b.fin_thickness_half/b.radius_outer)
def alpha_drum(b, t): return asin((b.level[t] - b.radius_drum) / b.radius_drum)
def alpha_drum(b, t): return asin((b.drum_level[t]-b.drum_radius)/b.drum_radius)
def alpha_slag(b, t): return asin((b.thk_fin_half + b.thk_slag[t]) / (b.radius_out + b.thk_slag[t]))
# pick a value in the domain of all of these functions model.ONE = Var(initialize=1) model.ZERO = Var(initialize=0) model.obj = Objective(expr=model.ONE + model.ZERO) model.c_log = Constraint(expr=log(model.ONE) == 0) model.c_log10 = Constraint(expr=log10(model.ONE) == 0) model.c_sin = Constraint(expr=sin(model.ZERO) == 0) model.c_cos = Constraint(expr=cos(model.ZERO) == 1) model.c_tan = Constraint(expr=tan(model.ZERO) == 0) model.c_sinh = Constraint(expr=sinh(model.ZERO) == 0) model.c_cosh = Constraint(expr=cosh(model.ZERO) == 1) model.c_tanh = Constraint(expr=tanh(model.ZERO) == 0) model.c_asin = Constraint(expr=asin(model.ZERO) == 0) model.c_acos = Constraint(expr=acos(model.ZERO) == pi / 2) model.c_atan = Constraint(expr=atan(model.ZERO) == 0) model.c_asinh = Constraint(expr=asinh(model.ZERO) == 0) model.c_acosh = Constraint(expr=acosh((e**2 + model.ONE) / (2 * e)) == 0) model.c_atanh = Constraint(expr=atanh(model.ZERO) == 0) model.c_exp = Constraint(expr=exp(model.ZERO) == 1) model.c_sqrt = Constraint(expr=sqrt(model.ONE) == 1) model.c_ceil = Constraint(expr=ceil(model.ONE) == 1) model.c_floor = Constraint(expr=floor(model.ONE) == 1) model.c_abs = Constraint(expr=abs(model.ONE) == 1)
def alpha_slag(b, t): return asin((0.5 * b.fin_thickness + b.slag_thickness[t]) / (b.radius_out + b.slag_thickness[t]))
def alpha_tube(b): return asin(0.5 * b.fin_thickness / b.radius_out)