-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added stage class * pre-commit * Added unit test * pre-commit * CI test * pre-commit update * CI test
- Loading branch information
Showing
6 changed files
with
65 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from rocket_twin.systems.rocket.rocket import Rocket | ||
from rocket_twin.systems.rocket.stage import Stage | ||
|
||
__all__ = ["Rocket"] | ||
__all__ = ["Stage", "Rocket"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from cosapp.base import System | ||
|
||
from rocket_twin.systems import ControllerCoSApp, Engine, Tank | ||
|
||
|
||
class Stage(System): | ||
"""Model of a rocket stage. | ||
Inputs | ||
------ | ||
Outputs | ||
------ | ||
force [N]: float, | ||
thrust force | ||
weight [kg]: float, | ||
weight | ||
cg [m]: float, | ||
center of gravity | ||
""" | ||
|
||
def setup(self): | ||
|
||
self.add_child(ControllerCoSApp("controller")) | ||
self.add_child(Tank("tank"), pulling=["w_in", "weight_max", "weight_p"]) | ||
self.add_child(Engine("engine")) | ||
|
||
self.connect(self.controller.outwards, self.tank.inwards, {"w": "w_command"}) | ||
self.connect(self.tank.outwards, self.engine.inwards, {"w_out": "w_out"}) | ||
|
||
self.add_outward("weight", 1.0, desc="Weight", unit="kg") | ||
self.add_outward("cg", 1.0, desc="Center of gravity", unit="m") | ||
|
||
def compute(self): | ||
|
||
self.weight = self.tank.weight + self.engine.weight | ||
self.cg = (self.tank.cg * self.tank.weight + self.engine.cg * self.engine.weight) / ( | ||
self.weight | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import numpy as np | ||
from cosapp.drivers import RungeKutta | ||
|
||
from rocket_twin.systems import Stage | ||
|
||
|
||
class TestStage: | ||
def test_single_stage(self): | ||
|
||
sys = Stage("sys") | ||
init = {"tank.weight_p": "tank.weight_max"} | ||
values = {"controller.w_temp": 1.0, "tank.w_out_max": 1.0} | ||
stop = "tank.weight_p == 0." | ||
|
||
driver = sys.add_driver(RungeKutta(order=4, dt=0.1)) | ||
driver.time_interval = (0, 10) | ||
driver.set_scenario(init=init, values=values, stop=stop) | ||
sys.run_drivers() | ||
|
||
np.testing.assert_allclose(sys.weight, 2.0, atol=10 ** (-2)) | ||
np.testing.assert_allclose(sys.cg, 1.0, atol=10 ** (-2)) |