优化压力流量求解并达到四路性能门槛
This commit is contained in:
1 parent
6572defaa4
commit
6a064892e2
20 files changed
+711
-175
No files matched your search
@@ -160,7 +160,7 @@ def simulation_preparation_issues(
|
||||
for component in network.components.values()
|
||||
if any(
|
||||
definition.kind == "physical"
|
||||
for definition in component.port_definitions
|
||||
for definition in component.active_port_definitions
|
||||
)
|
||||
}
|
||||
adjacency = {name: set() for name in physical_component_names}
|
||||
@@ -449,6 +449,22 @@ class GenericFluidSystem:
|
||||
self._jacobian_sparsity = self._build_jacobian_sparsity()
|
||||
return self._jacobian_sparsity
|
||||
|
||||
def jacobian_sparsity_diagnostics(self) -> dict[str, float | int]:
|
||||
from scipy.optimize._numdiff import group_columns
|
||||
|
||||
sparsity = self.jacobian_sparsity()
|
||||
group_count = int(group_columns(sparsity).max(initial=-1)) + 1
|
||||
state_count = int(sparsity.shape[0])
|
||||
return {
|
||||
"nonzeroCount": int(sparsity.nnz),
|
||||
"density": (
|
||||
float(sparsity.nnz) / float(state_count * state_count)
|
||||
if state_count
|
||||
else 0.0
|
||||
),
|
||||
"colorGroupCount": group_count,
|
||||
}
|
||||
|
||||
def _close_current_state(self, time: float) -> dict[str, dict[str, float]]:
|
||||
signal = self.signal_resolver.solve(time)
|
||||
self.signal_propagation_count += signal.propagated
|
||||
@@ -471,7 +487,7 @@ class GenericFluidSystem:
|
||||
physical_ports = tuple(
|
||||
port
|
||||
for component in self.network.components.values()
|
||||
for definition in component.port_definitions
|
||||
for definition in component.active_port_definitions
|
||||
if definition.kind == "physical"
|
||||
for port in (component.get_port(definition.name),)
|
||||
)
|
||||
@@ -655,6 +671,54 @@ class GenericFluidSystem:
|
||||
)
|
||||
report_progress(postprocess_progress, "postprocessing", force=True)
|
||||
times = [float(value) for value in solution.t]
|
||||
if isinstance(solution, ODESolution):
|
||||
solver_segment_diagnostics = [
|
||||
segment.as_dict() for segment in solution.solver_segments
|
||||
]
|
||||
else:
|
||||
solver_segment_diagnostics = [
|
||||
{
|
||||
"startTime": float(config.t_start),
|
||||
"requestedStopTime": float(config.t_stop),
|
||||
"simulatedUntil": times[-1] if times else float(config.t_start),
|
||||
"nfev": int(getattr(solution, "nfev", 0)),
|
||||
"njev": int(getattr(solution, "njev", 0)),
|
||||
"nlu": int(getattr(solution, "nlu", 0)),
|
||||
"acceptedStepCount": 0,
|
||||
"solverStartCount": 1,
|
||||
"stateTransitionCount": 0,
|
||||
"recoverableRetryCount": 0,
|
||||
}
|
||||
]
|
||||
solver_total_keys = (
|
||||
"nfev",
|
||||
"njev",
|
||||
"nlu",
|
||||
"acceptedStepCount",
|
||||
"solverStartCount",
|
||||
"stateTransitionCount",
|
||||
"recoverableRetryCount",
|
||||
)
|
||||
solver_totals = {
|
||||
key: sum(int(segment[key]) for segment in solver_segment_diagnostics)
|
||||
for key in solver_total_keys
|
||||
}
|
||||
jacobian_diagnostics = (
|
||||
self.jacobian_sparsity_diagnostics()
|
||||
if integration_config.method in {"BDF", "Radau"}
|
||||
else None
|
||||
)
|
||||
if jacobian_diagnostics is not None:
|
||||
color_group_count = int(jacobian_diagnostics["colorGroupCount"])
|
||||
for segment in solver_segment_diagnostics:
|
||||
segment["finiteDifferenceRhsEstimate"] = (
|
||||
int(segment["njev"]) * color_group_count
|
||||
)
|
||||
solver_totals["finiteDifferenceRhsEstimate"] = sum(
|
||||
int(segment["finiteDifferenceRhsEstimate"])
|
||||
for segment in solver_segment_diagnostics
|
||||
)
|
||||
|
||||
series: dict[str, list[float]] = {"time": []}
|
||||
postprocessing_error: Exception | None = None
|
||||
self.mechanical_state_reducer.reset_constraint_modes()
|
||||
@@ -693,6 +757,13 @@ class GenericFluidSystem:
|
||||
if key != "time" and values
|
||||
}
|
||||
diagnostics = {
|
||||
"integration": {
|
||||
"method": integration_config.method,
|
||||
"jacobianSparsity": jacobian_diagnostics,
|
||||
"segmentCount": len(solver_segment_diagnostics),
|
||||
"segments": solver_segment_diagnostics,
|
||||
"totals": solver_totals,
|
||||
},
|
||||
"pressureFlow": {
|
||||
"solveCount": self.algebraic_solve_count,
|
||||
"maxScaledResidual": self.max_algebraic_residual,
|
||||
|
||||
Reference in new issue
Block a user