@@ -1231,14 +1231,7 @@ def get_attr_value(obj, attr_name, multiplier=1):
12311231 # Write last line
12321232 file .write (f"{ self .thrust .source [- 1 , 0 ]:.4f} { 0 :.3f} \n " )
12331233
1234- def to_dict (self , include_outputs = False ):
1235- thrust_source = self .thrust_source
1236-
1237- if isinstance (thrust_source , str ):
1238- thrust_source = self .thrust .source
1239- elif callable (thrust_source ) and not isinstance (thrust_source , Function ):
1240- thrust_source = Function (thrust_source )
1241-
1234+ def to_dict (self , ** kwargs ):
12421235 data = {
12431236 "thrust_source" : self .thrust ,
12441237 "dry_I_11" : self .dry_I_11 ,
@@ -1258,31 +1251,94 @@ def to_dict(self, include_outputs=False):
12581251 "reference_pressure" : self .reference_pressure ,
12591252 }
12601253
1261- if include_outputs :
1254+ if kwargs .get ("include_outputs" , False ):
1255+ total_mass = self .total_mass
1256+ propellant_mass = self .propellant_mass
1257+ mass_flow_rate = self .total_mass_flow_rate
1258+ center_of_mass = self .center_of_mass
1259+ center_of_propellant_mass = self .center_of_propellant_mass
1260+ exhaust_velocity = self .exhaust_velocity
1261+ I_11 = self .I_11
1262+ I_22 = self .I_22
1263+ I_33 = self .I_33
1264+ I_12 = self .I_12
1265+ I_13 = self .I_13
1266+ I_23 = self .I_23
1267+ propellant_I_11 = self .propellant_I_11
1268+ propellant_I_22 = self .propellant_I_22
1269+ propellant_I_33 = self .propellant_I_33
1270+ propellant_I_12 = self .propellant_I_12
1271+ propellant_I_13 = self .propellant_I_13
1272+ propellant_I_23 = self .propellant_I_23
1273+ if kwargs .get ("discretize" , False ):
1274+ total_mass = total_mass .set_discrete_based_on_model (
1275+ self .thrust , mutate_self = False
1276+ )
1277+ propellant_mass = propellant_mass .set_discrete_based_on_model (
1278+ self .thrust , mutate_self = False
1279+ )
1280+ mass_flow_rate = mass_flow_rate .set_discrete_based_on_model (
1281+ self .thrust , mutate_self = False
1282+ )
1283+ center_of_mass = center_of_mass .set_discrete_based_on_model (
1284+ self .thrust , mutate_self = False
1285+ )
1286+ center_of_propellant_mass = (
1287+ center_of_propellant_mass .set_discrete_based_on_model (
1288+ self .thrust , mutate_self = False
1289+ )
1290+ )
1291+ exhaust_velocity = exhaust_velocity .set_discrete_based_on_model (
1292+ self .thrust , mutate_self = False
1293+ )
1294+ I_11 = I_11 .set_discrete_based_on_model (self .thrust , mutate_self = False )
1295+ I_22 = I_22 .set_discrete_based_on_model (self .thrust , mutate_self = False )
1296+ I_33 = I_33 .set_discrete_based_on_model (self .thrust , mutate_self = False )
1297+ I_12 = I_12 .set_discrete_based_on_model (self .thrust , mutate_self = False )
1298+ I_13 = I_13 .set_discrete_based_on_model (self .thrust , mutate_self = False )
1299+ I_23 = I_23 .set_discrete_based_on_model (self .thrust , mutate_self = False )
1300+ propellant_I_11 = propellant_I_11 .set_discrete_based_on_model (
1301+ self .thrust , mutate_self = False
1302+ )
1303+ propellant_I_22 = propellant_I_22 .set_discrete_based_on_model (
1304+ self .thrust , mutate_self = False
1305+ )
1306+ propellant_I_33 = propellant_I_33 .set_discrete_based_on_model (
1307+ self .thrust , mutate_self = False
1308+ )
1309+ propellant_I_12 = propellant_I_12 .set_discrete_based_on_model (
1310+ self .thrust , mutate_self = False
1311+ )
1312+ propellant_I_13 = propellant_I_13 .set_discrete_based_on_model (
1313+ self .thrust , mutate_self = False
1314+ )
1315+ propellant_I_23 = propellant_I_23 .set_discrete_based_on_model (
1316+ self .thrust , mutate_self = False
1317+ )
12621318 data .update (
12631319 {
12641320 "vacuum_thrust" : self .vacuum_thrust ,
1265- "total_mass" : self . total_mass ,
1266- "propellant_mass" : self . propellant_mass ,
1267- "mass_flow_rate" : self . mass_flow_rate ,
1268- "center_of_mass" : self . center_of_mass ,
1269- "center_of_propellant_mass" : self . center_of_propellant_mass ,
1321+ "total_mass" : total_mass ,
1322+ "propellant_mass" : propellant_mass ,
1323+ "mass_flow_rate" : mass_flow_rate ,
1324+ "center_of_mass" : center_of_mass ,
1325+ "center_of_propellant_mass" : center_of_propellant_mass ,
12701326 "total_impulse" : self .total_impulse ,
1271- "exhaust_velocity" : self . exhaust_velocity ,
1327+ "exhaust_velocity" : exhaust_velocity ,
12721328 "propellant_initial_mass" : self .propellant_initial_mass ,
12731329 "structural_mass_ratio" : self .structural_mass_ratio ,
1274- "I_11" : self . I_11 ,
1275- "I_22" : self . I_22 ,
1276- "I_33" : self . I_33 ,
1277- "I_12" : self . I_12 ,
1278- "I_13" : self . I_13 ,
1279- "I_23" : self . I_23 ,
1280- "propellant_I_11" : self . propellant_I_11 ,
1281- "propellant_I_22" : self . propellant_I_22 ,
1282- "propellant_I_33" : self . propellant_I_33 ,
1283- "propellant_I_12" : self . propellant_I_12 ,
1284- "propellant_I_13" : self . propellant_I_13 ,
1285- "propellant_I_23" : self . propellant_I_23 ,
1330+ "I_11" : I_11 ,
1331+ "I_22" : I_22 ,
1332+ "I_33" : I_33 ,
1333+ "I_12" : I_12 ,
1334+ "I_13" : I_13 ,
1335+ "I_23" : I_23 ,
1336+ "propellant_I_11" : propellant_I_11 ,
1337+ "propellant_I_22" : propellant_I_22 ,
1338+ "propellant_I_33" : propellant_I_33 ,
1339+ "propellant_I_12" : propellant_I_12 ,
1340+ "propellant_I_13" : propellant_I_13 ,
1341+ "propellant_I_23" : propellant_I_23 ,
12861342 }
12871343 )
12881344
@@ -1510,7 +1566,7 @@ def center_of_propellant_mass(self):
15101566 Function
15111567 Function representing the center of mass of the motor.
15121568 """
1513- return self .chamber_position
1569+ return Function ( self .chamber_position ). set_discrete_based_on_model ( self . thrust )
15141570
15151571 @funcify_method ("Time (s)" , "Inertia I_11 (kg m²)" )
15161572 def propellant_I_11 (self ):
@@ -1532,11 +1588,11 @@ def propellant_I_11(self):
15321588 ----------
15331589 https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
15341590 """
1535- return (
1591+ return Function (
15361592 self .propellant_mass
15371593 * (3 * self .chamber_radius ** 2 + self .chamber_height ** 2 )
15381594 / 12
1539- )
1595+ ). set_discrete_based_on_model ( self . thrust )
15401596
15411597 @funcify_method ("Time (s)" , "Inertia I_22 (kg m²)" )
15421598 def propellant_I_22 (self ):
@@ -1580,19 +1636,21 @@ def propellant_I_33(self):
15801636 ----------
15811637 https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
15821638 """
1583- return self .propellant_mass * self .chamber_radius ** 2 / 2
1639+ return Function (
1640+ self .propellant_mass * self .chamber_radius ** 2 / 2
1641+ ).set_discrete_based_on_model (self .thrust )
15841642
15851643 @funcify_method ("Time (s)" , "Inertia I_12 (kg m²)" )
15861644 def propellant_I_12 (self ):
1587- return Function (0 )
1645+ return Function (0 ). set_discrete_based_on_model ( self . thrust )
15881646
15891647 @funcify_method ("Time (s)" , "Inertia I_13 (kg m²)" )
15901648 def propellant_I_13 (self ):
1591- return Function (0 )
1649+ return Function (0 ). set_discrete_based_on_model ( self . thrust )
15921650
15931651 @funcify_method ("Time (s)" , "Inertia I_23 (kg m²)" )
15941652 def propellant_I_23 (self ):
1595- return Function (0 )
1653+ return Function (0 ). set_discrete_based_on_model ( self . thrust )
15961654
15971655 @staticmethod
15981656 def load_from_eng_file (
@@ -1862,8 +1920,8 @@ def all_info(self):
18621920 self .prints .all ()
18631921 self .plots .all ()
18641922
1865- def to_dict (self , include_outputs = False ):
1866- data = super ().to_dict (include_outputs )
1923+ def to_dict (self , ** kwargs ):
1924+ data = super ().to_dict (** kwargs )
18671925 data .update (
18681926 {
18691927 "chamber_radius" : self .chamber_radius ,
0 commit comments