优化雅可比矩阵计算;端口转发情况下仿真结果传输方式优化
This commit is contained in:
1 parent
3bc4be3c06
commit
aa4951b14e
28 files changed
+8038
-23
No files matched your search
@@ -13,6 +13,7 @@ from app.simulation.core.metadata import ResultVariableMetadata
|
||||
from app.simulation.systems.network import SimulationNetwork
|
||||
from .contracts import SUPPORTED_TYPES, SUPPORTED_VERSIONS
|
||||
from .tolerances import state_absolute_tolerance
|
||||
from .jacobian import JacobianStructure
|
||||
|
||||
|
||||
class NativeCapabilityError(ValueError):
|
||||
@@ -35,6 +36,7 @@ class NativeProgram:
|
||||
variables: tuple[ResultVariableMetadata, ...]
|
||||
component_types: tuple[str, ...]
|
||||
evaluation_schedule: dict | None = None
|
||||
jacobian_structure: dict | None = None
|
||||
|
||||
def manifest(self) -> dict:
|
||||
return {
|
||||
@@ -42,7 +44,8 @@ class NativeProgram:
|
||||
"variables": [v.as_dict() for v in self.variables],
|
||||
"componentTypes": self.component_types,
|
||||
"componentVersions": {name: SUPPORTED_VERSIONS[name] for name in self.component_types},
|
||||
"jacobianPolicy": "CVODE default; no custom Jacobian",
|
||||
"jacobianPolicy": (self.jacobian_structure or {}).get("policy", "CVODE default; no custom Jacobian"),
|
||||
"jacobianStructure": self.jacobian_structure,
|
||||
"evaluationSchedule": self.evaluation_schedule or {"strategy": "storage-anchored", "cyclicBlockCount": 0},
|
||||
}
|
||||
|
||||
@@ -362,6 +365,7 @@ def _compile_storage_anchored_program(network: SimulationNetwork) -> NativeProgr
|
||||
next_event.append(f"if (t < {_number(c.time)}) result = fmin(result, {_number(c.time)});")
|
||||
else:
|
||||
next_event.append(f"result = fmin(result, native_signal_break(t, end, {_number(c.tstart)}, {c.nstages}, {int(c.iscyclic)}, signal_{index}));")
|
||||
jacobian = JacobianStructure.dense(len(state_keys), 'Compact storage-anchored lowering retains default differences')
|
||||
source = '\n'.join([
|
||||
'#include "model.h"', '#include <math.h>', *declarations,
|
||||
f"const NativeStop model_stops[{max(1,len(stops))}] = {{{stop_c}}};",
|
||||
@@ -387,9 +391,10 @@ def _compile_storage_anchored_program(network: SimulationNetwork) -> NativeProgr
|
||||
extern const NativeStop model_stops[{max(1,len(stops))}];
|
||||
extern const double model_atol[NSTATES];
|
||||
extern const char *const model_output_keys[NOUTPUTS];
|
||||
{chr(10).join(jacobian.header_lines())}
|
||||
int model_init(double *y);
|
||||
int model_eval(double t, const double *y, double *dy, double *w);
|
||||
double model_next_break(double t, double end);
|
||||
#endif
|
||||
'''
|
||||
return NativeProgram(source, header, tuple(state_keys), variables, tuple(sorted({c.model_type for c in components})))
|
||||
return NativeProgram(source, header, tuple(state_keys), variables, tuple(sorted({c.model_type for c in components})),jacobian_structure=jacobian.manifest())
|
||||
Reference in new issue
Block a user