-
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.
- Loading branch information
Showing
6 changed files
with
56 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from rocket_twin.systems.control.clock import Clock | ||
|
||
__all__ = ['Clock'] | ||
__all__ = ["Clock"] |
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,13 +1,24 @@ | ||
from cosapp.base import System | ||
|
||
|
||
class Clock(System): | ||
"""A system that measures the elapsed time. | ||
Inputs | ||
------ | ||
Outputs | ||
------ | ||
time_var: float, | ||
the time since the beginning of the simulation | ||
""" | ||
|
||
def setup(self): | ||
|
||
#Transient to ensure the system is visited in every time step | ||
self.add_transient('x', der='1') | ||
self.add_outward('time_var', 0., desc="Command time") | ||
# Transient to ensure the system is visited in every time step | ||
self.add_transient("x", der="1") | ||
self.add_outward("time_var", 0.0, desc="Command time") | ||
|
||
def compute(self): | ||
|
||
self.time_var = self.time | ||
self.time_var = self.time |
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,14 +1,14 @@ | ||
import numpy as np | ||
from rocket_twin.systems import Clock | ||
from cosapp.drivers import RungeKutta | ||
|
||
class TestClock: | ||
from rocket_twin.systems import Clock | ||
|
||
|
||
class TestClock: | ||
def test_time(self): | ||
|
||
sys = Clock('sys') | ||
sys.add_driver(RungeKutta(order=4,time_interval=[0, 15], dt=1.)) | ||
sys = Clock("sys") | ||
sys.add_driver(RungeKutta(order=4, time_interval=[0, 15], dt=1.0)) | ||
sys.run_drivers() | ||
|
||
np.testing.assert_allclose(sys.time_var, 15., atol=10**(-4)) | ||
|
||
np.testing.assert_allclose(sys.time_var, 15.0, atol=10 ** (-4)) |
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,26 +1,28 @@ | ||
import numpy as np | ||
from rocket_twin.systems import Station | ||
from cosapp.drivers import RungeKutta | ||
from cosapp.recorders import DataFrameRecorder | ||
|
||
class TestSequencesFMU: | ||
from rocket_twin.systems import Station | ||
|
||
|
||
class TestSequencesFMU: | ||
def test_sequence_fmu(self): | ||
|
||
sys = Station('sys', fmu_path="rocket_twin/systems/control/controller.fmu") | ||
driver = sys.add_driver(RungeKutta(order=4,time_interval=[0, 15], dt=0.01)) | ||
init = {'g_tank.weight_p' : 10., | ||
'rocket.tank.weight_p' : 0.} | ||
values = {'g_tank.w_out_max' : 1., | ||
'rocket.tank.w_out_max' : 0.5, | ||
'rocket.engine.force_max' : 100.} | ||
sys = Station("sys", fmu_path="rocket_twin/systems/control/controller.fmu") | ||
driver = sys.add_driver(RungeKutta(order=4, time_interval=[0, 15], dt=0.01)) | ||
init = {"g_tank.weight_p": 10.0, "rocket.tank.weight_p": 0.0} | ||
values = { | ||
"g_tank.w_out_max": 1.0, | ||
"rocket.tank.w_out_max": 0.5, | ||
"rocket.engine.force_max": 100.0, | ||
} | ||
driver.set_scenario(init=init, values=values) | ||
driver.add_recorder(DataFrameRecorder(includes=['rocket.dyn.a']), period=1.) | ||
driver.add_recorder(DataFrameRecorder(includes=["rocket.dyn.a"]), period=1.0) | ||
sys.run_drivers() | ||
|
||
data=driver.recorder.export_data() | ||
data = driver.recorder.export_data() | ||
print(data) | ||
|
||
np.testing.assert_allclose(sys.rocket.dyn.a, 40., atol=10**(-1)) | ||
np.testing.assert_allclose(sys.g_tank.weight_p, 5., atol=10**(-2)) | ||
np.testing.assert_allclose(sys.rocket.tank.weight_p, 0., atol=10**(-2)) | ||
np.testing.assert_allclose(sys.rocket.dyn.a, 40.0, atol=10 ** (-1)) | ||
np.testing.assert_allclose(sys.g_tank.weight_p, 5.0, atol=10 ** (-2)) | ||
np.testing.assert_allclose(sys.rocket.tank.weight_p, 0.0, atol=10 ** (-2)) |