From d35b4afc59dde46134532f62a90512018f652f86 Mon Sep 17 00:00:00 2001 From: Lucas <69172945+lucasfourier@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:36:07 -0300 Subject: [PATCH] Motor method 'export_eng' for liquid motors. --- rocketpy/motors/motor.py | 45 ++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/rocketpy/motors/motor.py b/rocketpy/motors/motor.py index 0285a1203..38917dd83 100644 --- a/rocketpy/motors/motor.py +++ b/rocketpy/motors/motor.py @@ -1014,18 +1014,41 @@ def export_eng(self, file_name, motor_name): # Open file file = open(file_name, "w") - # Write first line - file.write( - motor_name - + " {:3.1f} {:3.1f} 0 {:2.3} {:2.3} RocketPy\n".format( - 2000 * self.grain_outer_radius, - 1000 - * self.grain_number - * (self.grain_initial_height + self.grain_separation), - self.propellant_initial_mass, - self.propellant_initial_mass, + if ( + hasattr(self, "grain_outer_radius") + and hasattr(self, "grain_number") + and hasattr(self, "grain_initial_height") + and hasattr(self, "grain_separation") + ): + # Write first line for motors with grains + file.write( + motor_name + + " {:3.1f} {:3.1f} 0 {:2.3} {:2.3} RocketPy\n".format( + 2000 * self.grain_outer_radius, + 1000 + * self.grain_number + * (self.grain_initial_height + self.grain_separation), + self.propellant_initial_mass, + self.propellant_initial_mass, + ) + ) + + else: + # Warn the user that the motor doesn't have at least one grain attribute + warnings.warn( + "The motor object doesn't have some grain-related attributes. Using zeros to write to file." + ) + + # Write first line for motors without grain attributes + # The zeros are here because the first two placeholders + # are grain-related attributes. + file.write( + motor_name + + " 0 0 0 {:2.3} {:2.3} RocketPy\n".format( + self.propellant_initial_mass, + self.propellant_initial_mass, + ) ) - ) # Write thrust curve data points for time, thrust in self.thrust.source[1:-1, :]: