校准第二支路热流体能量与管路摩擦

This commit is contained in:
huojiarong committed 2026-08-11 12:13:09 +00:00
1 parent 0f73d5b568
commit caca32a513
12 files changed
+336 -42

No files matched your search

+25 -8
View File
@@ -60,6 +60,20 @@ class MechanicalConstraintGroup:
def _boundary_tolerance(bound: float) -> float:
return 1.0e-12 * max(abs(bound), 1.0)
@staticmethod
def _velocity_tolerance(velocity: float) -> float:
"""Treat only floating-point-scale motion as stationary at a stop.
Implicit solvers perturb every state while constructing a numerical
Jacobian. Around an ideal endstop those perturbations must not switch
the unilateral constraint on and off; doing so turns a zero constrained
acceleration into the full outward-force acceleration across a
machine-scale velocity delta. The tolerance is deliberately far below
MECMAS21's physical ``dvel`` threshold so real release motion is kept.
"""
return 1.0e-12 * max(abs(velocity), 1.0)
def reset_mode(self) -> None:
self.mode = "uninitialized"
@@ -131,6 +145,7 @@ class MechanicalConstraintGroup:
def _static_endstop_side(self, total_force: float) -> str | None:
position = self.representative.x
velocity = self.representative.v
velocity_tolerance = self._velocity_tolerance(velocity)
lower = self.lower_bound
upper = self.upper_bound
# MECMAS21's dvel is the friction stick threshold. Its discrete
@@ -138,14 +153,14 @@ class MechanicalConstraintGroup:
if (
lower is not None
and position <= lower + self._boundary_tolerance(lower)
and velocity <= 0.0
and velocity <= velocity_tolerance
and total_force <= 0.0
):
return "lower"
if (
upper is not None
and position >= upper - self._boundary_tolerance(upper)
and velocity >= 0.0
and velocity >= -velocity_tolerance
and total_force >= 0.0
):
return "upper"
@@ -489,6 +504,8 @@ class MechanicalStateReducer:
position_index = velocity_index + 1
previous_velocity = float(previous_state[velocity_index])
current_velocity = float(current_state[velocity_index])
previous_velocity_tolerance = group._velocity_tolerance(previous_velocity)
current_velocity_tolerance = group._velocity_tolerance(current_velocity)
previous_position = float(previous_state[position_index])
current_position = float(current_state[position_index])
lower = group.lower_bound
@@ -496,7 +513,7 @@ class MechanicalStateReducer:
if (
lower is not None
and previous_position <= lower + group._boundary_tolerance(lower)
and previous_velocity < 0.0
and previous_velocity < -previous_velocity_tolerance
):
candidates.append((previous_time, group, "lower", lower))
elif (
@@ -522,8 +539,8 @@ class MechanicalStateReducer:
elif (
lower is not None
and previous_position <= lower
and previous_velocity > 0.0
and current_velocity < 0.0
and previous_velocity > previous_velocity_tolerance
and current_velocity < -current_velocity_tolerance
and current_position <= lower
):
turnaround_time = self._locate_turnaround(
@@ -551,7 +568,7 @@ class MechanicalStateReducer:
if (
upper is not None
and previous_position >= upper - group._boundary_tolerance(upper)
and previous_velocity > 0.0
and previous_velocity > previous_velocity_tolerance
):
candidates.append((previous_time, group, "upper", upper))
elif (
@@ -577,8 +594,8 @@ class MechanicalStateReducer:
elif (
upper is not None
and previous_position >= upper
and previous_velocity < 0.0
and current_velocity > 0.0
and previous_velocity < -previous_velocity_tolerance
and current_velocity > current_velocity_tolerance
and current_position >= upper
):
turnaround_time = self._locate_turnaround(