diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b109776..a0d97f2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,6 +47,6 @@ repos: - flake8-bugbear==22.1.11 - flake8-isort==4.1.1 - repo: https://github.com/kynan/nbstripout - rev: 0.5.0 + rev: 0.6.1 hooks: - id: nbstripout diff --git a/rocket_twin/notebooks/Visualisation.ipynb b/rocket_twin/notebooks/Visualisation.ipynb deleted file mode 100644 index 2125fd6..0000000 --- a/rocket_twin/notebooks/Visualisation.ipynb +++ /dev/null @@ -1,98 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "8bec8444-0001-4e4a-bb3a-aae9574a5cb6", - "metadata": {}, - "outputs": [], - "source": [ - "from rocket_twin.systems import Ground\n", - "from rocket_twin.systems import Station" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "97e7cc0c-c54d-4dac-9966-ac30c44abe14", - "metadata": {}, - "outputs": [], - "source": [ - "st1 = Station('st1')\n", - "st2 = Station('st2')\n", - "ground = Ground('ground', stations=[st1, st2])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3b5aeda9-94d7-4f2d-a28c-c9e168cb4e69", - "metadata": {}, - "outputs": [], - "source": [ - "ground" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6b46cce2-b0da-44dc-a19d-1f261002608b", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b951bdb0-98eb-405d-9f37-8b0c6bc76568", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ae5b4ea2-e71e-4dc7-ad37-9b47eb0e3daa", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0065a4ad-c135-45bc-a2f5-7b8ec556a547", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d41a129f-04d4-43d3-8aa8-fd234ce0f517", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/rocket_twin/systems/__init__.py b/rocket_twin/systems/__init__.py index ecbd0bd..e5486dd 100644 --- a/rocket_twin/systems/__init__.py +++ b/rocket_twin/systems/__init__.py @@ -4,13 +4,14 @@ from rocket_twin.systems.physics import Dynamics from rocket_twin.systems.tank import Pipe, Tank -from rocket_twin.systems.rocket import Rocket # isort: skip +from rocket_twin.systems.rocket import Stage, Rocket # isort: skip from rocket_twin.systems.station import Station # isort: skip __all__ = [ "Clock", "Engine", "Tank", + "Stage", "Rocket", "Pipe", "Dynamics", diff --git a/rocket_twin/systems/rocket/__init__.py b/rocket_twin/systems/rocket/__init__.py index 900ab5d..a8e3e08 100644 --- a/rocket_twin/systems/rocket/__init__.py +++ b/rocket_twin/systems/rocket/__init__.py @@ -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"] diff --git a/rocket_twin/systems/rocket/stage.py b/rocket_twin/systems/rocket/stage.py new file mode 100644 index 0000000..3f53f13 --- /dev/null +++ b/rocket_twin/systems/rocket/stage.py @@ -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 + ) diff --git a/rocket_twin/tests/test_stages.py b/rocket_twin/tests/test_stages.py new file mode 100644 index 0000000..e8d01cd --- /dev/null +++ b/rocket_twin/tests/test_stages.py @@ -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))