Skip to content

Commit

Permalink
MNT: renames z_coordinate_com_to_cdm to com_to_cdm_function
Browse files Browse the repository at this point in the history
  • Loading branch information
Gui-FernandesBR committed May 16, 2024
1 parent 1b038d5 commit 61ebbc7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions rocketpy/rocket/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Rocket:
for more information
regarding the coordinate system.
Expressed in meters as a function of time.
Rocket.z_coordinate_com_to_cdm : Function
Rocket.com_to_cdm_function : Function
Function of time expressing the z-coordinate of the center of mass
relative to the center of dry mass.
Rocket.reduced_mass : Function
Expand Down Expand Up @@ -780,24 +780,24 @@ def evaluate_nozzle_gyration_tensor(self):
)
return self.nozzle_gyration_tensor

def evaluate_z_coordinate_com_to_cdm(self):
def evaluate_com_to_cdm_function(self):
"""Evaluates the z-coordinate of the center of mass (COM) relative to
the center of dry mass (CDM).
Notes
-----
1. The `z_coordinate_com_to_cdm` plus `center_of_mass` should be equal
1. The `com_to_cdm_function` plus `center_of_mass` should be equal
to `center_of_dry_mass_position` at every time step.
2. The `z_coordinate_com_to_cdm` is a function of time and will usually
2. The `com_to_cdm_function` is a function of time and will usually
already be discretized.
Returns
-------
self.z_coordinate_com_to_cdm : Function
self.com_to_cdm_function : Function
Function of time expressing the z-coordinate of the center of mass
relative to the center of dry mass.
"""
self.z_coordinate_com_to_cdm = (
self.com_to_cdm_function = (
-1
* (
(self.center_of_propellant_position - self.center_of_dry_mass_position)
Expand All @@ -806,10 +806,10 @@ def evaluate_z_coordinate_com_to_cdm(self):
* self.motor.propellant_mass
/ self.total_mass
)
self.z_coordinate_com_to_cdm.set_inputs("Time (s)")
self.z_coordinate_com_to_cdm.set_outputs("Z Coordinate COM to CDM (m)")
self.z_coordinate_com_to_cdm.set_title("Z Coordinate COM to CDM")
return self.z_coordinate_com_to_cdm
self.com_to_cdm_function.set_inputs("Time (s)")
self.com_to_cdm_function.set_outputs("Z Coordinate COM to CDM (m)")
self.com_to_cdm_function.set_title("Z Coordinate COM to CDM")
return self.com_to_cdm_function

def get_inertia_tensor_at_time(self, t):
"""Returns a Matrix representing the inertia tensor of the rocket with
Expand Down Expand Up @@ -921,7 +921,7 @@ def add_motor(self, motor, position):
self.evaluate_center_of_pressure()
self.evaluate_stability_margin()
self.evaluate_static_margin()
self.evaluate_z_coordinate_com_to_cdm()
self.evaluate_com_to_cdm_function()
self.evaluate_nozzle_gyration_tensor()

def add_surfaces(self, surfaces, positions):
Expand Down
4 changes: 2 additions & 2 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ def u_dot(self, t, u, post_processing=False):
* self.rocket._csys
)
c = self.rocket.nozzle_to_cdm
a = self.rocket.z_coordinate_com_to_cdm.get_value_opt(t)
a = self.rocket.com_to_cdm_function.get_value_opt(t)

Check warning on line 1345 in rocketpy/simulation/flight.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/simulation/flight.py#L1344-L1345

Added lines #L1344 - L1345 were not covered by tests
rN = self.rocket.motor.nozzle_radius
# Prepare transformation matrix
a11 = 1 - 2 * (e2**2 + e3**2)
Expand Down Expand Up @@ -1571,7 +1571,7 @@ def u_dot_generalized(self, t, u, post_processing=False):
total_mass_dot = self.rocket.total_mass_flow_rate.get_value_opt(t)
total_mass_ddot = self.rocket.total_mass_flow_rate.differentiate_complex_step(t)
## CM position vector and time derivatives relative to CDM in body frame
r_CM_z = self.rocket.z_coordinate_com_to_cdm
r_CM_z = self.rocket.com_to_cdm_function
r_CM_t = r_CM_z.get_value_opt(t)
r_CM = Vector([0, 0, r_CM_t])
r_CM_dot = Vector([0, 0, r_CM_z.differentiate_complex_step(t)])
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ def test_evaluate_nozzle_gyration_tensor(calisto):
assert np.allclose(expected_gyration_tensor, np.array(res), atol=atol)


def test_evaluate_z_coordinate_com_to_cdm(calisto):
def test_evaluate_com_to_cdm_function(calisto):
atol = 1e-3 # Equivalent to 1mm
assert np.allclose(
(calisto.center_of_dry_mass_position - calisto.center_of_mass).source,
calisto.z_coordinate_com_to_cdm.source,
calisto.com_to_cdm_function.source,
atol=atol,
)

Expand Down

0 comments on commit 61ebbc7

Please sign in to comment.