feat: integrate AMESim media models and editor UI
This commit is contained in:
1 parent
3e4f466114
commit
e7177ab03e
181 files changed
+7042
-25270
No files matched your search
@@ -6,6 +6,7 @@ from app.simulation.components.experimental.library import LIBRARY
|
||||
from app.simulation.components.amesim.library import LIBRARY as AMESIM_LIBRARY
|
||||
from app.simulation.core.base import AlgebraicComponent
|
||||
from app.simulation.core.catalog import ComponentDisplaySpec, PortDisplaySpec
|
||||
from app.simulation.core.metadata import ParameterDefinition, ParameterOption
|
||||
from app.simulation.core.medium import IdealGasMedium
|
||||
from app.simulation.core.ports import PortDefinition
|
||||
from app.simulation.registry import (
|
||||
@@ -30,6 +31,8 @@ class ComponentRegistryTests(unittest.TestCase):
|
||||
"pipe",
|
||||
"orifice",
|
||||
"tee",
|
||||
"amesim_ideal_air_medium",
|
||||
"amesim_helium_medium",
|
||||
"amesim_pnpl01",
|
||||
"amesim_step0",
|
||||
"amesim_ud00",
|
||||
@@ -62,6 +65,11 @@ class ComponentRegistryTests(unittest.TestCase):
|
||||
|
||||
self.assertIn("amesim", libraries)
|
||||
self.assertEqual(libraries["amesim"], AMESIM_LIBRARY)
|
||||
self.assertEqual(
|
||||
models["amesim_ideal_air_medium"].library.id,
|
||||
"amesim",
|
||||
)
|
||||
self.assertEqual(models["amesim_helium_medium"].library.id, "amesim")
|
||||
self.assertEqual(models["amesim_pnpl01"].library.id, "amesim")
|
||||
self.assertEqual(models["amesim_step0"].library.id, "amesim")
|
||||
self.assertEqual(models["amesim_ud00"].library.id, "amesim")
|
||||
@@ -134,6 +142,97 @@ class ComponentRegistryTests(unittest.TestCase):
|
||||
library=LIBRARY,
|
||||
)
|
||||
|
||||
def test_property_model_parameter_options_are_strictly_validated(self) -> None:
|
||||
def validate_parameter(parameter: ParameterDefinition) -> None:
|
||||
class PropertyModelComponent(AlgebraicComponent):
|
||||
MODEL_TYPE = "property_model_component"
|
||||
MODEL_VERSION = "1.0.0"
|
||||
PORTS = ()
|
||||
PARAMETERS = (parameter,)
|
||||
RESULT_VARIABLES = ()
|
||||
DISPLAY = ComponentDisplaySpec(
|
||||
label="物性模型测试组件",
|
||||
library_id="experimental",
|
||||
category_id="flow",
|
||||
symbol="generic",
|
||||
ports=(),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create(cls, *, name, medium, parameters):
|
||||
del medium, parameters
|
||||
return cls(name)
|
||||
|
||||
validate_component_model_class(
|
||||
PropertyModelComponent,
|
||||
library=LIBRARY,
|
||||
)
|
||||
|
||||
def property_parameter(
|
||||
*,
|
||||
default: float = 0.0,
|
||||
minimum: float | None = None,
|
||||
maximum: float | None = None,
|
||||
options: tuple[ParameterOption, ...] = (),
|
||||
description: object = "",
|
||||
) -> ParameterDefinition:
|
||||
return ParameterDefinition(
|
||||
"property_model",
|
||||
default,
|
||||
label="物性计算模型",
|
||||
quantity="dimensionless",
|
||||
unit="",
|
||||
minimum=minimum,
|
||||
maximum=maximum,
|
||||
editor="amesimGasPropertyModel",
|
||||
options=options,
|
||||
description=description, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "description must be a string"):
|
||||
validate_parameter(property_parameter(description=None))
|
||||
with self.assertRaisesRegex(ValueError, "description must not be blank"):
|
||||
validate_parameter(property_parameter(description=" "))
|
||||
with self.assertRaisesRegex(ValueError, "must declare options"):
|
||||
validate_parameter(property_parameter())
|
||||
with self.assertRaisesRegex(ValueError, "duplicate option values"):
|
||||
validate_parameter(
|
||||
property_parameter(
|
||||
options=(
|
||||
ParameterOption(0, "理想气体"),
|
||||
ParameterOption(0, "重复模型"),
|
||||
)
|
||||
)
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "finite numbers"):
|
||||
validate_parameter(
|
||||
property_parameter(
|
||||
options=(ParameterOption(float("nan"), "非法模型"),)
|
||||
)
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "default value must be one of 0"):
|
||||
validate_parameter(
|
||||
property_parameter(
|
||||
default=1.0,
|
||||
options=(ParameterOption(0, "理想气体"),),
|
||||
)
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "option 1 must be at most 0"):
|
||||
validate_parameter(
|
||||
property_parameter(
|
||||
minimum=0.0,
|
||||
maximum=0.0,
|
||||
options=(ParameterOption(1, "越界模型"),),
|
||||
)
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "option values must be integers"):
|
||||
validate_parameter(
|
||||
property_parameter(
|
||||
default=0.5,
|
||||
options=(ParameterOption(0.5, "非整数模型"),),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user