113 lines
4.9 KiB
Python
113 lines
4.9 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from app.simulation.reporting.amesim_results import load_test_mql_amesim_results
|
|
from app.simulation.reporting.test_mql_chamber_observations import (
|
|
build_test_mql_chamber_observation_catalog,
|
|
)
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
TEST_MQL_AME = REPO_ROOT / "AmesimModels" / "test_mql.ame"
|
|
|
|
|
|
class TestMqlChamberObservationCatalogTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls) -> None:
|
|
cls.amesim_results = load_test_mql_amesim_results(TEST_MQL_AME)
|
|
cls.catalog = build_test_mql_chamber_observation_catalog(cls.amesim_results)
|
|
|
|
def test_builds_expected_chamber_observation_bindings(self) -> None:
|
|
self.assertEqual(len(self.catalog.bindings), 12)
|
|
self.assertEqual(self.catalog.fixed_count, 4)
|
|
self.assertEqual(self.catalog.variable_count, 8)
|
|
|
|
fixed = self.catalog.by_alias("pn_general_chamber")
|
|
variable = self.catalog.by_alias("pn_c1_8")
|
|
|
|
self.assertEqual(fixed.submodel, "PNCH023")
|
|
self.assertFalse(fixed.is_variable)
|
|
self.assertEqual(fixed.pressure_path, "press@pn_general_chamber")
|
|
self.assertEqual(fixed.temperature_path, "temp@pn_general_chamber")
|
|
self.assertEqual(fixed.gas_mass_path, "mgas@pn_general_chamber")
|
|
self.assertEqual(fixed.pressure_duplicate_paths, ("press2@pn_general_chamber",))
|
|
self.assertEqual(fixed.temperature_duplicate_paths, ("temp2@pn_general_chamber",))
|
|
self.assertIsNone(fixed.volume_path)
|
|
self.assertEqual(variable.submodel, "PNCH012")
|
|
self.assertTrue(variable.is_variable)
|
|
self.assertEqual(variable.pressure_path, "press@pn_c1_8")
|
|
self.assertEqual(variable.temperature_path, "temp@pn_c1_8")
|
|
self.assertEqual(variable.gas_mass_path, "mgas1@pn_c1_8")
|
|
self.assertEqual(
|
|
variable.pressure_duplicate_paths,
|
|
("press3@pn_c1_8", "press2@pn_c1_8", "press4@pn_c1_8"),
|
|
)
|
|
self.assertEqual(
|
|
variable.temperature_duplicate_paths,
|
|
("temp3@pn_c1_8", "temp2@pn_c1_8", "temp4@pn_c1_8"),
|
|
)
|
|
self.assertEqual(variable.volume_path, "vol@pn_c1_8")
|
|
|
|
def test_fixed_chamber_observation_matches_amesim_samples(self) -> None:
|
|
observation = self.catalog.by_alias("pn_general_chamber").observation_at(
|
|
self.amesim_results,
|
|
-1,
|
|
)
|
|
|
|
self.assertAlmostEqual(observation.time, self.amesim_results.times[-1])
|
|
self.assertAlmostEqual(observation.pressure_pa, 4310273.332655074)
|
|
self.assertAlmostEqual(observation.temperature_k, 179.646447269399)
|
|
self.assertAlmostEqual(observation.gas_mass_g, 666.3851161956942)
|
|
self.assertIsNone(observation.volume_cm3)
|
|
|
|
def test_variable_chamber_observation_matches_amesim_samples(self) -> None:
|
|
observation = self.catalog.by_alias("pn_c1_8").observation_at(
|
|
self.amesim_results,
|
|
-1,
|
|
)
|
|
|
|
self.assertAlmostEqual(observation.pressure_pa, 4310310.457796034)
|
|
self.assertAlmostEqual(observation.temperature_k, 293.1143259012449)
|
|
self.assertAlmostEqual(observation.gas_mass_g, 353.6887889918552)
|
|
self.assertAlmostEqual(observation.volume_cm3, 49242.54636512914)
|
|
|
|
def test_initial_pressure_conventions_are_preserved(self) -> None:
|
|
fixed = self.catalog.by_alias("pn_general_chamber").observation_at(
|
|
self.amesim_results,
|
|
0,
|
|
)
|
|
variable = self.catalog.by_alias("pn_c1_8").observation_at(
|
|
self.amesim_results,
|
|
0,
|
|
)
|
|
|
|
self.assertAlmostEqual(fixed.pressure_pa, 15198699.999999998)
|
|
self.assertAlmostEqual(variable.pressure_pa, -1299.99999999999)
|
|
self.assertAlmostEqual(fixed.temperature_k, 293.15)
|
|
self.assertAlmostEqual(variable.temperature_k, 293.15)
|
|
self.assertAlmostEqual(variable.volume_cm3, 15000.0)
|
|
|
|
def test_duplicate_pressure_and_temperature_paths_match_primary_series(self) -> None:
|
|
for binding in self.catalog.bindings:
|
|
pressure = self.amesim_results.series(binding.pressure_path)
|
|
temperature = self.amesim_results.series(binding.temperature_path)
|
|
with self.subTest(alias=binding.alias):
|
|
for duplicate_path in binding.pressure_duplicate_paths:
|
|
duplicate = self.amesim_results.series(duplicate_path)
|
|
self.assertLess(
|
|
max(abs(a - b) for a, b in zip(pressure, duplicate)),
|
|
1.0e-12,
|
|
)
|
|
for duplicate_path in binding.temperature_duplicate_paths:
|
|
duplicate = self.amesim_results.series(duplicate_path)
|
|
self.assertLess(
|
|
max(abs(a - b) for a, b in zip(temperature, duplicate)),
|
|
1.0e-12,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|