1use crate::math::{
2 Derivative, Differentiate, Quantity, Tensor, TensorVec,
3 integrate::{IntegrationError, Times},
4 optimize::{
5 EqualityConstraint, FirstOrderOptimization, FirstOrderRootFinding, SecondOrderOptimization,
6 ZerothOrderRootFinding,
7 },
8 sparse::SparseSolver,
9};
10use crate::units::Time;
11
12pub(super) mod explicit;
13pub trait ExplicitDaeZerothOrderRoot<G, Y, Z, U, V, W, T = Time>
17where
18 Y: Differentiate<T> + Tensor,
19 Z: Tensor,
20 U: TensorVec<Item = Y>,
21 V: TensorVec<Item = Z>,
22 W: TensorVec<Item = Derivative<Y, T>>,
23{
24 fn integrate(
25 &self,
26 evolution: impl FnMut(Quantity<T>, &Y, &Z) -> Result<Derivative<Y, T>, String>,
27 function: impl FnMut(Quantity<T>, &Y, &Z) -> Result<G, String>,
28 solver: impl ZerothOrderRootFinding<G, Z>,
29 time: &[Quantity<T>],
30 initial_condition: (Y, Z),
31 equality_constraint: impl FnMut(Quantity<T>) -> EqualityConstraint,
32 ) -> Result<(Times<T>, U, W, V), IntegrationError>;
33}
34
35pub trait ExplicitDaeFirstOrderRoot<F, J, Y, Z, U, V, W, T = Time>
37where
38 Y: Differentiate<T> + Tensor,
39 Z: Tensor,
40 U: TensorVec<Item = Y>,
41 V: TensorVec<Item = Z>,
42 W: TensorVec<Item = Derivative<Y, T>>,
43{
44 #[allow(clippy::too_many_arguments)]
45 fn integrate(
46 &self,
47 evolution: impl FnMut(Quantity<T>, &Y, &Z) -> Result<Derivative<Y, T>, String>,
48 function: impl FnMut(Quantity<T>, &Y, &Z) -> Result<F, String>,
49 jacobian: impl FnMut(Quantity<T>, &Y, &Z) -> Result<J, String>,
50 solver: impl FirstOrderRootFinding<F, J, Z>,
51 time: &[Quantity<T>],
52 initial_condition: (Y, Z),
53 equality_constraint: impl FnMut(Quantity<T>) -> EqualityConstraint,
54 ) -> Result<(Times<T>, U, W, V), IntegrationError>;
55}
56
57pub trait ExplicitDaeFirstOrderMinimize<F, G, Y, Z, U, V, W, T = Time>
59where
60 Y: Differentiate<T> + Tensor,
61 Z: Tensor,
62 U: TensorVec<Item = Y>,
63 V: TensorVec<Item = Z>,
64 W: TensorVec<Item = Derivative<Y, T>>,
65{
66 #[allow(clippy::too_many_arguments)]
67 fn integrate(
68 &self,
69 evolution: impl FnMut(Quantity<T>, &Y, &Z) -> Result<Derivative<Y, T>, String>,
70 function: impl FnMut(Quantity<T>, &Y, &Z) -> Result<F, String>,
71 jacobian: impl FnMut(Quantity<T>, &Y, &Z) -> Result<G, String>,
72 solver: impl FirstOrderOptimization<F, G, Z>,
73 time: &[Quantity<T>],
74 initial_condition: (Y, Z),
75 equality_constraint: impl FnMut(Quantity<T>) -> EqualityConstraint,
76 ) -> Result<(Times<T>, U, W, V), IntegrationError>;
77}
78
79pub trait ExplicitDaeSecondOrderMinimize<F, J, H, Y, Z, U, V, W, T = Time>
81where
82 Y: Differentiate<T> + Tensor,
83 Z: Tensor,
84 U: TensorVec<Item = Y>,
85 V: TensorVec<Item = Z>,
86 W: TensorVec<Item = Derivative<Y, T>>,
87{
88 #[allow(clippy::too_many_arguments)]
89 fn integrate(
90 &self,
91 evolution: impl FnMut(Quantity<T>, &Y, &Z) -> Result<Derivative<Y, T>, String>,
92 function: impl FnMut(Quantity<T>, &Y, &Z) -> Result<F, String>,
93 jacobian: impl FnMut(Quantity<T>, &Y, &Z) -> Result<J, String>,
94 hessian: impl FnMut(Quantity<T>, &Y, &Z) -> Result<H, String>,
95 solver: impl SecondOrderOptimization<F, J, H, Z>,
96 time: &[Quantity<T>],
97 initial_condition: (Y, Z),
98 equality_constraint: impl FnMut(Quantity<T>) -> EqualityConstraint,
99 sparse: Option<SparseSolver>,
100 ) -> Result<(Times<T>, U, W, V), IntegrationError>;
101}
102
103pub trait ImplicitDaeZerothOrderRoot<G, Y, U, V, T = Time>
105where
106 Y: Differentiate<T> + Tensor,
107 U: TensorVec<Item = Y>,
108 V: TensorVec<Item = Derivative<Y, T>>,
109{
110 fn integrate(
111 &self,
112 function: impl FnMut(Quantity<T>, &Y, &Derivative<Y, T>) -> Result<G, String>,
113 solver: impl ZerothOrderRootFinding<G, Derivative<Y, T>>,
114 time: &[Quantity<T>],
115 initial_condition: Y,
116 equality_constraint: impl FnMut(Quantity<T>) -> EqualityConstraint,
117 ) -> Result<(Times<T>, U, V), IntegrationError>;
118}
119
120pub trait ImplicitDaeFirstOrderRoot<F, J, Y, U, V, T = Time>
122where
123 Y: Differentiate<T> + Tensor,
124 U: TensorVec<Item = Y>,
125 V: TensorVec<Item = Derivative<Y, T>>,
126{
127 fn integrate(
128 &self,
129 function: impl FnMut(Quantity<T>, &Y, &Derivative<Y, T>) -> Result<F, String>,
130 jacobian: impl FnMut(Quantity<T>, &Y, &Derivative<Y, T>) -> Result<J, String>,
131 solver: impl FirstOrderRootFinding<F, J, Derivative<Y, T>>,
132 time: &[Quantity<T>],
133 initial_condition: Y,
134 equality_constraint: impl FnMut(Quantity<T>) -> EqualityConstraint,
135 ) -> Result<(Times<T>, U, V), IntegrationError>;
136}
137
138pub trait ImplicitDaeFirstOrderMinimize<F, G, Y, U, V, T = Time>
140where
141 Y: Differentiate<T> + Tensor,
142 U: TensorVec<Item = Y>,
143 V: TensorVec<Item = Derivative<Y, T>>,
144{
145 #[allow(clippy::too_many_arguments)]
146 fn integrate(
147 &self,
148 function: impl FnMut(Quantity<T>, &Y, &Derivative<Y, T>) -> Result<F, String>,
149 jacobian: impl FnMut(Quantity<T>, &Y, &Derivative<Y, T>) -> Result<G, String>,
150 solver: impl FirstOrderOptimization<F, G, Derivative<Y, T>>,
151 time: &[Quantity<T>],
152 initial_condition: Y,
153 equality_constraint: impl FnMut(Quantity<T>) -> EqualityConstraint,
154 ) -> Result<(Times<T>, U, V), IntegrationError>;
155}
156
157pub trait ImplicitDaeSecondOrderMinimize<F, J, H, Y, U, V, T = Time>
159where
160 Y: Differentiate<T> + Tensor,
161 U: TensorVec<Item = Y>,
162 V: TensorVec<Item = Derivative<Y, T>>,
163{
164 #[allow(clippy::too_many_arguments)]
165 fn integrate(
166 &self,
167 function: impl FnMut(Quantity<T>, &Y, &Derivative<Y, T>) -> Result<F, String>,
168 jacobian: impl FnMut(Quantity<T>, &Y, &Derivative<Y, T>) -> Result<J, String>,
169 hessian: impl FnMut(Quantity<T>, &Y, &Derivative<Y, T>) -> Result<H, String>,
170 solver: impl SecondOrderOptimization<F, J, H, Derivative<Y, T>>,
171 time: &[Quantity<T>],
172 initial_condition: Y,
173 equality_constraint: impl FnMut(Quantity<T>) -> EqualityConstraint,
174 sparse: Option<SparseSolver>,
175 ) -> Result<(Times<T>, U, V), IntegrationError>;
176}