Skip to content

Commit

Permalink
Motor method 'export_eng' for liquid motors.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfourier committed Feb 20, 2024
1 parent e7b17de commit d35b4af
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions rocketpy/motors/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 1038 in rocketpy/motors/motor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/motor.py#L1038

Added line #L1038 was not covered by tests
"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(

Check warning on line 1045 in rocketpy/motors/motor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/motor.py#L1045

Added line #L1045 was not covered by tests
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, :]:
Expand Down

0 comments on commit d35b4af

Please sign in to comment.