Replace Python numerical kernels with native C execution
This commit is contained in:
1 parent
48da6be21c
commit
3b38f73fe0
227 files changed
+16801
-75499
No files matched your search
@@ -10,8 +10,6 @@ from app.main import (
|
||||
compile_system_xml_network,
|
||||
run_system_xml_simulation,
|
||||
)
|
||||
from app.simulation.solvers.solver import SolveIVPConfig
|
||||
from app.simulation.systems.generic import GenericFluidSystem
|
||||
from app.system_xml import validate_system_xml_document
|
||||
from tests.test_amesim_pnvo001_signal_xml import signal_edge, signal_port
|
||||
from tests.test_generic_system_xml_simulation import component_node, physical_edge
|
||||
@@ -293,149 +291,10 @@ def force_node_mass_project(right_port_count: int = 8) -> ReactFlowProjectPayloa
|
||||
|
||||
|
||||
class AmesimMechanicalXmlTests(unittest.TestCase):
|
||||
def test_mechanical_states_use_machine_scale_absolute_tolerances(self) -> None:
|
||||
system = GenericFluidSystem(
|
||||
compile_reactflow_network(zero_force_mass_project())
|
||||
)
|
||||
|
||||
tolerances = system.mechanical_state_reducer.absolute_tolerances(1.0e-8)
|
||||
|
||||
self.assertEqual(tolerances, [1.0e-12, 1.0e-12])
|
||||
self.assertEqual(len(tolerances), len(system.initial_state_vector()))
|
||||
|
||||
def test_self_loop_contact_does_not_relax_mass_velocity(self) -> None:
|
||||
contact_parameters = {**LSTP00A_DEFAULTS, "rcont": 1.0e11}
|
||||
project = ReactFlowProjectPayload(
|
||||
projectSchemaVersion=1,
|
||||
name="amesim-mechanical-self-contact",
|
||||
nodes=[
|
||||
component_node(
|
||||
"mass_1",
|
||||
"amesim_mecmas21",
|
||||
[
|
||||
mechanical_port("port_1", "left"),
|
||||
mechanical_port("port_2", "right"),
|
||||
],
|
||||
MECMAS21_DEFAULTS,
|
||||
),
|
||||
component_node(
|
||||
"contact_1",
|
||||
"amesim_lstp00a",
|
||||
[
|
||||
mechanical_port("port_1", "left"),
|
||||
mechanical_port("port_2", "right"),
|
||||
],
|
||||
contact_parameters,
|
||||
),
|
||||
],
|
||||
edges=[
|
||||
physical_edge(
|
||||
"edge-1",
|
||||
"mass_1",
|
||||
"port_1",
|
||||
"contact_1",
|
||||
"port_1",
|
||||
),
|
||||
physical_edge(
|
||||
"edge-2",
|
||||
"mass_1",
|
||||
"port_2",
|
||||
"contact_1",
|
||||
"port_2",
|
||||
),
|
||||
],
|
||||
simulation={
|
||||
"t_start": 0.0,
|
||||
"t_stop": 0.02,
|
||||
"step": 0.01,
|
||||
"max_step": 0.005,
|
||||
"method": "BDF",
|
||||
},
|
||||
)
|
||||
system = GenericFluidSystem(compile_reactflow_network(project))
|
||||
|
||||
plan = system.mechanical_state_reducer.absolute_tolerance_plan(
|
||||
1.0e-8,
|
||||
mode="contact-aware-v1",
|
||||
)
|
||||
|
||||
self.assertEqual(plan.values, (1.0e-12, 1.0e-12))
|
||||
self.assertEqual(plan.groups[0].contacts, ())
|
||||
self.assertFalse(plan.groups[0].eligible)
|
||||
self.assertEqual(plan.groups[0].reason, "noFlexibleContact")
|
||||
|
||||
def test_weak_contact_damping_does_not_relax_velocity(self) -> None:
|
||||
project = elastic_contact_project()
|
||||
project.nodes[2].data.parameters["rcont"] = 1.0e-300
|
||||
system = GenericFluidSystem(compile_reactflow_network(project))
|
||||
|
||||
plan = system.mechanical_state_reducer.absolute_tolerance_plan(
|
||||
1.0e-8,
|
||||
mode="contact-aware-v1",
|
||||
)
|
||||
|
||||
self.assertTrue(plan.groups)
|
||||
self.assertTrue(all(not group.eligible for group in plan.groups))
|
||||
self.assertTrue(
|
||||
all(group.reason == "weakContactDamping" for group in plan.groups)
|
||||
)
|
||||
self.assertTrue(
|
||||
all(
|
||||
group.velocity_atol == 1.0e-12
|
||||
and group.position_atol == 1.0e-12
|
||||
for group in plan.groups
|
||||
)
|
||||
)
|
||||
|
||||
def test_legacy_tolerance_ignores_extreme_contact_scales(self) -> None:
|
||||
project = elastic_contact_project()
|
||||
project.nodes[2].data.parameters.update(
|
||||
{"kcont": 5.0e-324, "Pdis": 5.0e-324, "rcont": 1.0}
|
||||
)
|
||||
system = GenericFluidSystem(compile_reactflow_network(project))
|
||||
|
||||
legacy = system.mechanical_state_reducer.absolute_tolerance_plan(
|
||||
1.0e-8,
|
||||
mode="legacy",
|
||||
)
|
||||
contact_aware = (
|
||||
system.mechanical_state_reducer.absolute_tolerance_plan(
|
||||
1.0e-8,
|
||||
mode="contact-aware-v1",
|
||||
)
|
||||
)
|
||||
|
||||
self.assertTrue(all(value == 1.0e-12 for value in legacy.values))
|
||||
self.assertTrue(
|
||||
all(group.reason == "legacyMode" for group in legacy.groups)
|
||||
)
|
||||
self.assertTrue(
|
||||
all(
|
||||
group.reason == "invalidContactScale"
|
||||
for group in contact_aware.groups
|
||||
)
|
||||
)
|
||||
|
||||
def test_contact_aware_tolerance_is_limited_to_bdf(self) -> None:
|
||||
system = GenericFluidSystem(
|
||||
compile_reactflow_network(zero_force_mass_project())
|
||||
)
|
||||
|
||||
result = system.simulate(
|
||||
SolveIVPConfig(
|
||||
t_start=0.0,
|
||||
t_stop=0.001,
|
||||
method="RK45",
|
||||
max_step=0.001,
|
||||
),
|
||||
sample_step=0.001,
|
||||
)
|
||||
|
||||
self.assertTrue(result.success)
|
||||
tolerance = result.diagnostics["integration"][
|
||||
"mechanicalAbsoluteTolerance"
|
||||
]
|
||||
self.assertEqual(tolerance["mode"], "legacy")
|
||||
|
||||
|
||||
def test_sparse_reactflow_mecmas_parameters_use_registered_defaults(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user