|
LMMC
Lamina Mathematic core
|
显式 ODE 求解器:Euler,RK45(Cash-Karp 嵌入对)与 RK4. 更多...
#include <math.h>#include "memory_bridge.h"#include "internal.h"#include "ode_internal.h"#include "lmmc/ode.h"结构体 | |
| struct | ode_explicit_state_t |
函数 | |
| lmmc_status_t | lmmc_ode_euler_solve (lmmc_ode_rhs_t rhs, void *user_data, size_t dim, lmmc_real_t t_start, lmmc_real_t t_end, lmmc_real_t *y, const lmmc_ode_config_t *cfg, lmmc_ode_result_t *out_result) |
| 显式 Euler 法求解常微分方程初值问题 \(y' = f(t,y)\) 。 | |
| lmmc_status_t | lmmc_ode_rk45_solve (lmmc_ode_rhs_t rhs, void *user_data, size_t dim, lmmc_real_t t_start, lmmc_real_t t_end, lmmc_real_t *y, const lmmc_ode_config_t *cfg, lmmc_ode_result_t *out_result) |
| 自适应 Runge-Kutta-Fehlberg (RK45) 求解器。 | |
| lmmc_status_t | lmmc_ode_rk4_solve (lmmc_ode_rhs_t rhs, void *user_data, size_t dim, lmmc_real_t t_start, lmmc_real_t t_end, lmmc_real_t *y, const lmmc_ode_config_t *cfg, lmmc_ode_result_t *out_result) |
| 经典四阶 Runge-Kutta 法求解 \(y' = f(t,y)\) (固定步长)。 | |
显式 ODE 求解器:Euler,RK45(Cash-Karp 嵌入对)与 RK4.
在文件 ode_explicit.c 中定义.
| struct ode_explicit_state_t |
在文件 ode_explicit.c 第 12 行定义.
| 成员变量 | ||
|---|---|---|
| lmmc_ode_rhs_t | rhs | |
| void * | user_data | |
| size_t | dim | |
| size_t | work_bytes | |
| lmmc_real_t * | y | |
| lmmc_ode_config_t | local_cfg | |
| lmmc_ode_result_t * | out_result | |
| lmmc_real_t | t | |
| lmmc_real_t | h | |
| lmmc_real_t * | k[6] | |
| lmmc_real_t * | y_tmp | |
| lmmc_status_t lmmc_ode_euler_solve | ( | lmmc_ode_rhs_t | rhs, |
| void * | user_data, | ||
| size_t | dim, | ||
| lmmc_real_t | t_start, | ||
| lmmc_real_t | t_end, | ||
| lmmc_real_t * | y, | ||
| const lmmc_ode_config_t * | cfg, | ||
| lmmc_ode_result_t * | out_result ) |
显式 Euler 法求解常微分方程初值问题 \(y' = f(t,y)\) 。
使用固定步长(由 cfg->initial_step 决定)逐步推进,一阶精度。 适用于快速原型验证,不建议用于高精度需求。
| [in] | rhs | 右端函数回调。 |
| [in] | user_data | 传递给 rhs 的用户上下文指针。 |
| [in] | dim | 状态向量维度(>= 1)。 |
| [in] | t_start | 积分起始时间。 |
| [in] | t_end | 积分终止时间。 |
| [in,out] | y | 输入初始条件,输出终态向量,长度 dim 。 |
| [in] | cfg | 求解配置(步长、容差等)。 |
| [out] | out_result | 求解统计信息(步数、RHS 求值次数、收敛状态等)。 |
y 数组为终态值。rhs 被调用 num_steps 次(每步一次)。在文件 ode_explicit.c 第 116 行定义.
引用了 ode_explicit_state_t::dim, lmmc_ode_result_t::failure_reason, ode_explicit_state_t::h, lmmc_ode_config_t::initial_step, ode_explicit_state_t::k, lmmc_memory_alloc(), lmmc_memory_free(), lmmc_ode_do_log(), lmmc_ode_euler_solve(), LMMC_ODE_FAILURE_NUMERICAL_ISSUE, LMMC_REAL_SUB, LMMC_STATUS_ALLOCATION_FAILED, LMMC_STATUS_OK, ode_explicit_state_t::local_cfg, lmmc_ode_config_t::max_step, lmmc_ode_config_t::min_step, ode_explicit_state_t::out_result, ode_explicit_state_t::rhs, ode_explicit_state_t::t, ode_explicit_state_t::user_data, validate_and_init_ode_config(), ode_explicit_state_t::work_bytes , 以及 ode_explicit_state_t::y.
被这些函数引用 lmmc_ode_euler_solve().
| lmmc_status_t lmmc_ode_rk45_solve | ( | lmmc_ode_rhs_t | rhs, |
| void * | user_data, | ||
| size_t | dim, | ||
| lmmc_real_t | t_start, | ||
| lmmc_real_t | t_end, | ||
| lmmc_real_t * | y, | ||
| const lmmc_ode_config_t * | cfg, | ||
| lmmc_ode_result_t * | out_result ) |
自适应 Runge-Kutta-Fehlberg (RK45) 求解器。
使用嵌入式 4(5) 阶公式进行局部误差估计,自动调整步长以满足 cfg->abs_tol 和 cfg->rel_tol 指定的精度要求。每步需要 6 次 RHS 求值。 适用于大多数非刚性问题。
| [in] | rhs | 右端函数回调。 |
| [in] | user_data | 传递给 rhs 的用户上下文指针。 |
| [in] | dim | 状态向量维度(>= 1)。 |
| [in] | t_start | 积分起始时间。 |
| [in] | t_end | 积分终止时间。 |
| [in,out] | y | 输入初始条件,输出终态向量,长度 dim 。 |
| [in] | cfg | 求解配置(步长范围、容差、最大步数等)。 |
| [out] | out_result | 求解统计信息。 |
y 数组为终态值。rhs 被调用约 6 × num_steps 次(被拒绝的步也会消耗求值次数)。在文件 ode_explicit.c 第 335 行定义.
引用了 ode_explicit_state_t::dim, ode_explicit_state_t::h, lmmc_ode_config_t::initial_step, lmmc_ode_do_log(), lmmc_ode_rk45_solve(), LMMC_REAL_SUB, LMMC_STATUS_OK, ode_explicit_state_t::local_cfg, lmmc_ode_config_t::max_step, lmmc_ode_config_t::min_step, ode_explicit_state_t::out_result, ode_explicit_state_t::rhs, ode_explicit_state_t::t, ode_explicit_state_t::user_data, validate_and_init_ode_config(), ode_explicit_state_t::work_bytes , 以及 ode_explicit_state_t::y.
被这些函数引用 lmmc_ode_rk45_solve().
| lmmc_status_t lmmc_ode_rk4_solve | ( | lmmc_ode_rhs_t | rhs, |
| void * | user_data, | ||
| size_t | dim, | ||
| lmmc_real_t | t_start, | ||
| lmmc_real_t | t_end, | ||
| lmmc_real_t * | y, | ||
| const lmmc_ode_config_t * | cfg, | ||
| lmmc_ode_result_t * | out_result ) |
经典四阶 Runge-Kutta 法求解 \(y' = f(t,y)\) (固定步长)。
使用固定步长(由 cfg->initial_step 决定),四阶精度。 每步需要 4 次 RHS 求值。
| [in] | rhs | 右端函数回调。 |
| [in] | user_data | 传递给 rhs 的用户上下文指针。 |
| [in] | dim | 状态向量维度(>= 1)。 |
| [in] | t_start | 积分起始时间。 |
| [in] | t_end | 积分终止时间。 |
| [in,out] | y | 输入初始条件,输出终态向量,长度 dim 。 |
| [in] | cfg | 求解配置(步长、容差等)。 |
| [out] | out_result | 求解统计信息。 |
y 数组为终态值。rhs 被调用 4 × num_steps 次。在文件 ode_explicit.c 第 448 行定义.
引用了 ode_explicit_state_t::dim, ode_explicit_state_t::h, lmmc_ode_config_t::initial_step, lmmc_ode_do_log(), lmmc_ode_rk4_solve(), LMMC_REAL_SUB, LMMC_STATUS_OK, ode_explicit_state_t::local_cfg, lmmc_ode_config_t::max_step, lmmc_ode_config_t::min_step, ode_explicit_state_t::out_result, ode_explicit_state_t::rhs, ode_explicit_state_t::t, ode_explicit_state_t::user_data, validate_and_init_ode_config(), ode_explicit_state_t::work_bytes , 以及 ode_explicit_state_t::y.
被这些函数引用 lmmc_ode_rk4_solve().