1414 TankGeometry ,
1515)
1616
17+ from fastapi import HTTPException , status
18+
1719from src .models .sub .tanks import TankKinds
1820from src .models .motor import MotorKinds , MotorModel
1921from src .views .motor import MotorSimulation
@@ -35,6 +37,12 @@ def from_motor_model(cls, motor: MotorModel) -> Self:
3537 MotorService containing the rocketpy motor object.
3638 """
3739
40+ reshape_thrust_curve = motor .reshape_thrust_curve
41+ if isinstance (reshape_thrust_curve , bool ):
42+ reshape_thrust_curve = False
43+ elif isinstance (reshape_thrust_curve , list ):
44+ reshape_thrust_curve = tuple (reshape_thrust_curve )
45+
3846 motor_core = {
3947 "thrust_source" : motor .thrust_source ,
4048 "burn_time" : motor .burn_time ,
@@ -44,7 +52,7 @@ def from_motor_model(cls, motor: MotorModel) -> Self:
4452 "center_of_dry_mass_position" : motor .center_of_dry_mass_position ,
4553 "coordinate_system_orientation" : motor .coordinate_system_orientation ,
4654 "interpolation_method" : motor .interpolation_method ,
47- "reshape_thrust_curve" : False or motor . reshape_thrust_curve ,
55+ "reshape_thrust_curve" : reshape_thrust_curve ,
4856 }
4957
5058 match MotorKinds (motor .motor_kind ):
@@ -63,15 +71,36 @@ def from_motor_model(cls, motor: MotorModel) -> Self:
6371 grains_center_of_mass_position = motor .grains_center_of_mass_position ,
6472 )
6573 case MotorKinds .SOLID :
74+ grain_params = {
75+ 'grain_number' : motor .grain_number ,
76+ 'grain_density' : motor .grain_density ,
77+ 'grain_outer_radius' : motor .grain_outer_radius ,
78+ 'grain_initial_inner_radius' : motor .grain_initial_inner_radius ,
79+ 'grain_initial_height' : motor .grain_initial_height ,
80+ 'grain_separation' : motor .grain_separation ,
81+ 'grains_center_of_mass_position' : motor .grains_center_of_mass_position ,
82+ }
83+
84+ missing = [
85+ key for key , value in grain_params .items () if value is None
86+ ]
87+ if missing :
88+ raise HTTPException (
89+ status_code = status .HTTP_422_UNPROCESSABLE_ENTITY ,
90+ detail = (
91+ "Solid motor requires grain configuration: missing "
92+ + ', ' .join (missing )
93+ ),
94+ )
95+
96+ optional_params = {}
97+ if motor .throat_radius is not None :
98+ optional_params ['throat_radius' ] = motor .throat_radius
99+
66100 rocketpy_motor = SolidMotor (
67101 ** motor_core ,
68- grain_number = motor .grain_number ,
69- grain_density = motor .grain_density ,
70- grain_outer_radius = motor .grain_outer_radius ,
71- grain_initial_inner_radius = motor .grain_initial_inner_radius ,
72- grain_initial_height = motor .grain_initial_height ,
73- grains_center_of_mass_position = motor .grains_center_of_mass_position ,
74- grain_separation = motor .grain_separation ,
102+ ** grain_params ,
103+ ** optional_params ,
75104 )
76105 case _:
77106 rocketpy_motor = GenericMotor (
@@ -84,7 +113,7 @@ def from_motor_model(cls, motor: MotorModel) -> Self:
84113 )
85114
86115 if motor .motor_kind not in (MotorKinds .SOLID , MotorKinds .GENERIC ):
87- for tank in motor .tanks :
116+ for tank in motor .tanks or [] :
88117 tank_core = {
89118 "name" : tank .name ,
90119 "geometry" : TankGeometry (
0 commit comments