Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/condor/implementations/sgm_trajectory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from functools import cached_property

import numpy as np

Expand Down Expand Up @@ -134,13 +135,6 @@ def construct(
model.dot, self.simulation_signature, subs=control_sub_expression
)

self.state_jacobian_expr = jacobian(state_equation_func.expr, self.x)
self.state_dot_jac_func = expression_to_operator(
self.simulation_signature,
self.state_jacobian_expr,
f"{ode_model.__name__}_state_jacobian",
)

self.e_exprs = []
self.h_exprs = []

Expand Down Expand Up @@ -307,7 +301,7 @@ class Terminate(ode_model.Event):
dim_state=model.state._count,
initial_state=self.state0,
dot=state_equation_func,
jac=self.state_dot_jac_func,
jac=None if solver is not self.Solver.CVODE else self.state_jac_func,
time_generator=sgm.TimeGeneratorFromSlices(at_time_slices),
events=expression_to_operator(
self.simulation_signature,
Expand Down Expand Up @@ -338,6 +332,16 @@ class Terminate(ode_model.Event):
jacobian_of=None,
)

@cached_property
def state_jac_func(self):
state_jacobian_expr = jacobian(self.state_equation_func.expr, self.x)
state_dot_jac_func = expression_to_operator(
self.simulation_signature,
state_jacobian_expr,
f"{self.ode_model.__name__}_state_jacobian",
)
return state_dot_jac_func

def generate_sgm_jacobian(self, jacobian_of):
state_equation_func = self.state_equation_func
# lamda_jac = self.state_jacobian_expr.T
Expand Down Expand Up @@ -524,7 +528,7 @@ def generate_sgm_jacobian(self, jacobian_of):
trajectory_analysis=self.trajectory_analysis_nom,
dte_dxs=self.dte_dxs,
dh_dxs=self.dh_dxs,
state_jac=self.state_dot_jac_func,
state_jac=self.state_jac_func,
p_x0_p_params=p_state0_p_p,
p_dots_p_params=param_dot_jac_func,
dh_dps=self.dh_dps,
Expand Down
Loading