Skip to content

Commit

Permalink
Corrected pipe design, added sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
luca7084 committed Jun 27, 2023
1 parent ba09e08 commit 4b271ba
Show file tree
Hide file tree
Showing 17 changed files with 570 additions and 106 deletions.
5 changes: 2 additions & 3 deletions rocket_twin/drivers/fuelling_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ def __init__(self, name: str, flux, dt, owner: Optional["System"] = None, **kwar

init = {
"rocket.dyn.switch": False,
"rocket.tank.p_out": 0.0,
"rocket.tank.flux": 0.0,
"g_tank.p_in": 0.0,
"pipe.pi_in": flux,
"pipe.pi_out": flux,
"g_tank.flux": flux,
}

stop = "rocket.tank.w_p >= rocket.tank.w_max"
Expand Down
5 changes: 2 additions & 3 deletions rocket_twin/drivers/vertical_flying_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ def __init__(self, name: str, flux, dt, owner: Optional["System"] = None, **kwar
init = {
"rocket.dyn.switch": True,
"g_tank.p_in": 0.0,
"pipe.pi_in": 0.0,
"pipe.pi_out": 0.0,
"rocket.tank.p_out": flux,
"g_tank.flux": 0.0,
"rocket.tank.flux": flux,
}

stop = "rocket.tank.w_p <= 0."
Expand Down
99 changes: 23 additions & 76 deletions rocket_twin/notebooks/Visualisation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"metadata": {},
"outputs": [],
"source": [
"from rocket_twin import Rocket"
"from rocket_twin.systems import Ground"
]
},
{
Expand All @@ -17,7 +17,7 @@
"metadata": {},
"outputs": [],
"source": [
"rocket = Rocket('rocket')"
"ground = Ground('ground')"
]
},
{
Expand All @@ -33,7 +33,7 @@
" <iframe\n",
" width=\"810px\"\n",
" height=\"650px\"\n",
" src=\"rocket.html\"\n",
" src=\"ground.html\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" \n",
Expand All @@ -44,36 +44,12 @@
"\n",
"### Child components\n",
"\n",
"- `engine`: Engine\n",
"- `reserv`: Reservatory\n",
"- `geom`: RocketGeom\n",
"- `dyn`: Dynamics\n",
"\n",
"### Inputs\n",
"\n",
"- `inwards`: ExtensiblePort\n",
"\n",
"<div class='cosapp-port-table' style='margin-left: 25px; margin-top: -12px'><style type='text/css'>.cosapp-port-table >table >thead{display: none}.cosapp-port-table tbody tr{background: rgba(255, 255, 255, 0)!important}.cosapp-port-table tbody tr:hover{background: #e1f5fe!important}.cosapp-port-table >table {margin-left: unset; margin-right: unset}</style>\n",
"\n",
"| | |\n",
"---|---\n",
" **p_in** &#128274;&#128274; : 0 kg/s | Fuel income rate\n",
"</div>\n",
"\n",
"### Outputs\n",
"\n",
"- `outwards`: ExtensiblePort\n",
"\n",
"<div class='cosapp-port-table' style='margin-left: 25px; margin-top: -12px'><style type='text/css'>.cosapp-port-table >table >thead{display: none}.cosapp-port-table tbody tr{background: rgba(255, 255, 255, 0)!important}.cosapp-port-table tbody tr:hover{background: #e1f5fe!important}.cosapp-port-table >table {margin-left: unset; margin-right: unset}</style>\n",
"\n",
"| | |\n",
"---|---\n",
" **center**: 1 m | Center of gravity\n",
" **a**: 1 m/s**2 | Acceleration\n",
"</div>"
"- `pipe`: Pipe\n",
"- `g_tank`: Tank\n",
"- `rocket`: Rocket"
],
"text/plain": [
"rocket - Rocket"
"ground - Ground"
]
},
"execution_count": 3,
Expand All @@ -82,69 +58,32 @@
}
],
"source": [
"rocket"
"ground"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "6b46cce2-b0da-44dc-a19d-1f261002608b",
"metadata": {},
"outputs": [],
"source": [
"from ground import Ground"
]
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "b951bdb0-98eb-405d-9f37-8b0c6bc76568",
"metadata": {},
"outputs": [],
"source": [
"ground = Ground('ground')"
]
"source": []
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "ae5b4ea2-e71e-4dc7-ad37-9b47eb0e3daa",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"810px\"\n",
" height=\"650px\"\n",
" src=\"ground.html\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" \n",
" ></iframe>\n",
" "
],
"text/markdown": [
"\n",
"### Child components\n",
"\n",
"- `rocket`: Rocket\n",
"- `pipe`: Pipe\n",
"- `g_res`: GroundReservatory"
],
"text/plain": [
"ground - Ground"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ground"
]
"outputs": [],
"source": []
},
{
"cell_type": "code",
Expand All @@ -153,6 +92,14 @@
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d41a129f-04d4-43d3-8aa8-fd234ce0f517",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
163 changes: 163 additions & 0 deletions rocket_twin/notebooks/test_design_method.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "312c249e-eb51-4474-b794-d130e6f6c2bd",
"metadata": {},
"outputs": [],
"source": [
"from cosapp.base import System\n",
"from cosapp.drivers import RunSingleCase, NonLinearSolver, RungeKutta\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "2d1ffcfa-ad28-4f46-b757-2cc91e033b72",
"metadata": {},
"outputs": [],
"source": [
"class Ball2(System):\n",
"\n",
" def setup(self):\n",
"\n",
" self.add_inward('b', 1.)\n",
" self.add_transient('a', der='b')\n",
"\n",
" dm = self.add_design_method('test_1')\n",
" dm.add_unknown('a')\n",
" dm.add_equation('b == 3')\n",
"\n",
" def compute(self):\n",
"\n",
" self.b = 2*self.a"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "08720b0e-5e11-42b1-9ed3-6d8d1e327abf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.5\n"
]
}
],
"source": [
"ball2 = Ball2('ball2')\n",
"solver = ball2.add_driver(NonLinearSolver('solver', tol=1e-12))\n",
"case = solver.add_child(RunSingleCase('case'))\n",
"\n",
"case.design.extend(ball2.design_methods['test_1'])\n",
"\n",
"ball2.run_drivers()\n",
"\n",
"print(ball2.a)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "de43078b-8360-4913-991f-31aa805fa427",
"metadata": {},
"outputs": [],
"source": [
"class Ball(System):\n",
"\n",
" def setup(self):\n",
"\n",
" self.add_inward('v', 1., unit='m/s')\n",
" self.add_transient('x', der='v')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "e9b2a14e-018d-4502-8fde-a789b4dad1a1",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"`ball.inwards`: ExtensiblePort\n",
"<div class='cosapp-port-table' style='margin-left: 25px; margin-top: -12px'><style type='text/css'>.cosapp-port-table >table >thead{display: none}.cosapp-port-table tbody tr{background: rgba(255, 255, 255, 0)!important}.cosapp-port-table tbody tr:hover{background: #e1f5fe!important}.cosapp-port-table >table {margin-left: unset; margin-right: unset}</style>\n",
"\n",
"| | |\n",
"---|---\n",
" **v** &#128274;&#128274; : 4 m/s |\n",
" **x** &#128274;&#128274; : 16 | Transient variable defined as d(x)/dt = v\n",
"</div>\n"
],
"text/plain": [
"ExtensiblePort: {'v': 4.000000000000002, 'x': 15.99999999999997}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ball = Ball('ball')\n",
"solver = ball.add_driver(NonLinearSolver('solver', factor=0.9, tol=1e-5))\n",
"target = solver.add_child(RunSingleCase('target'))\n",
"driver = target.add_child(RungeKutta('rk', order=4))\n",
"\n",
"driver.time_interval = (0, 4)\n",
"driver.dt = 0.1\n",
"init = {'x' : 0.}\n",
"driver.set_scenario(init = init)\n",
"\n",
"target.design.add_unknown('v')\n",
"target.design.add_equation('x == 16.')\n",
"\n",
"ball.run_drivers()\n",
"\n",
"ball.inwards"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40a151fe-6547-47d1-bb80-8d5bc8bb82cd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4e00fcd-aecf-495c-87ba-aa179c187eef",
"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
}
Loading

0 comments on commit 4b271ba

Please sign in to comment.