LMMC
Lamina Mathematic core
Toggle main menu visibility
载入中...
搜索中...
未找到
ode_jacobian.c
浏览该文件的文档.
1
#include "
ode_internal.h
"
2
3
static
int
lmmc_ode_jacobian_buffers_valid(
const
lmmc_ode_jacobian_request_t
* s) {
4
return
s->
jacobian_data
!= NULL && s->
base_rhs_work
!= NULL &&
5
s->
y_perturbed
!= NULL && s->
rhs_perturbed
!= NULL;
6
}
7
8
static
int
lmmc_ode_jacobian_request_valid(
9
const
lmmc_ode_jacobian_request_t
* s,
size_t
* count
10
) {
11
if
(s->
rhs
== NULL || s->
y
== NULL || !lmmc_ode_jacobian_buffers_valid(s)) {
return
0; }
12
if
(s->
io_rhs_evals
== NULL || s->
out_callback_failed
== NULL || s->
dim
== 0) {
return
0; }
13
return
lmmc_safe_mul_size(s->
dim
, s->
dim
, count);
14
}
15
16
lmmc_status_t
lmmc_ode_jacobian_eval
(
const
lmmc_ode_jacobian_request_t
* s) {
17
const
lmmc_real_t
* base = s->
base_rhs
;
18
size_t
i, j;
19
size_t
jacobian_count;
20
lmmc_status_t
st;
21
22
if
(!lmmc_ode_jacobian_request_valid(s, &jacobian_count)) {
23
return
LMMC_STATUS_INVALID_ARGUMENT
;
24
}
25
*s->
out_callback_failed
= 0;
26
if
(s->
jacobian
!= NULL) {
27
st = s->
jacobian
(s->
t
, s->
y
, s->
jacobian_data
, s->
dim
, s->
user_data
);
28
if
(st !=
LMMC_STATUS_OK
) {
return
st; }
29
return
lmmc_ode_values_are_finite
(s->
jacobian_data
, jacobian_count);
30
}
31
32
if
(base == NULL) {
33
st =
lmmc_ode_rhs_eval
(s->
rhs
, s->
t
, s->
y
, s->
base_rhs_work
, s->
dim
, s->
user_data
,
34
s->
io_rhs_evals
, s->
out_callback_failed
);
35
if
(st !=
LMMC_STATUS_OK
) {
return
st; }
36
base = s->
base_rhs_work
;
37
}
38
39
for
(j = 0; j < s->
dim
; ++j) {
40
const
lmmc_real_t
delta =
41
sqrt(
LMMC_REAL_EPSILON
) * fmax(1.0, fabs(s->
y
[j]));
42
memcpy(s->
y_perturbed
, s->
y
, s->
dim
*
sizeof
(*s->
y
));
43
s->
y_perturbed
[j] += delta;
44
st =
lmmc_ode_rhs_eval
(s->
rhs
, s->
t
, s->
y_perturbed
, s->
rhs_perturbed
, s->
dim
,
45
s->
user_data
, s->
io_rhs_evals
, s->
out_callback_failed
);
46
if
(st !=
LMMC_STATUS_OK
) {
return
st; }
47
for
(i = 0; i < s->
dim
; ++i) {
48
s->
jacobian_data
[i * s->
dim
+ j] =
49
(s->
rhs_perturbed
[i] - base[i]) / delta;
50
}
51
}
52
return
lmmc_ode_values_are_finite
(s->
jacobian_data
, jacobian_count);
53
}
lmmc_real_t
double lmmc_real_t
Public and internal LMMC real type.
定义
config.h:28
LMMC_REAL_EPSILON
#define LMMC_REAL_EPSILON
既有算法的经验近似阈值,非机器 epsilon。
定义
config.h:85
ode_internal.h
ODE 求解器共享的内部辅助函数。
lmmc_ode_jacobian_request_t::y_perturbed
lmmc_real_t * y_perturbed
定义
ode_internal.h:28
lmmc_ode_rhs_eval
lmmc_status_t lmmc_ode_rhs_eval(lmmc_ode_rhs_t rhs, lmmc_real_t t, const lmmc_real_t *y, lmmc_real_t *y_prime, size_t dim, void *user_data, size_t *io_eval_count, int *out_callback_failed)
定义
ode_support.c:78
lmmc_ode_jacobian_eval
lmmc_status_t lmmc_ode_jacobian_eval(const lmmc_ode_jacobian_request_t *request)
定义
ode_jacobian.c:16
lmmc_ode_values_are_finite
lmmc_status_t lmmc_ode_values_are_finite(const lmmc_real_t *values, size_t count)
定义
ode_support.c:188
lmmc_ode_jacobian_request_t::out_callback_failed
int * out_callback_failed
定义
ode_internal.h:31
lmmc_ode_jacobian_request_t::dim
size_t dim
定义
ode_internal.h:25
lmmc_ode_jacobian_request_t::io_rhs_evals
size_t * io_rhs_evals
定义
ode_internal.h:30
lmmc_ode_jacobian_request_t::y
const lmmc_real_t * y
定义
ode_internal.h:23
lmmc_ode_jacobian_request_t::jacobian
lmmc_ode_jac_t jacobian
定义
ode_internal.h:20
lmmc_ode_jacobian_request_t::base_rhs_work
lmmc_real_t * base_rhs_work
定义
ode_internal.h:27
lmmc_ode_jacobian_request_t::jacobian_data
lmmc_real_t * jacobian_data
定义
ode_internal.h:26
lmmc_ode_jacobian_request_t::rhs_perturbed
lmmc_real_t * rhs_perturbed
定义
ode_internal.h:29
lmmc_ode_jacobian_request_t::rhs
lmmc_ode_rhs_t rhs
定义
ode_internal.h:19
lmmc_ode_jacobian_request_t::user_data
void * user_data
定义
ode_internal.h:21
lmmc_ode_jacobian_request_t::t
lmmc_real_t t
定义
ode_internal.h:22
lmmc_ode_jacobian_request_t::base_rhs
const lmmc_real_t * base_rhs
定义
ode_internal.h:24
lmmc_ode_jacobian_request_t
定义
ode_internal.h:18
lmmc_status_t
lmmc_status_t
LMMC 库统一返回的状态码.
定义
status.h:22
LMMC_STATUS_OK
@ LMMC_STATUS_OK
定义
status.h:23
LMMC_STATUS_INVALID_ARGUMENT
@ LMMC_STATUS_INVALID_ARGUMENT
定义
status.h:24
src
ode_jacobian.c
生成于
, 为 LMMC使用
1.18.0