Skip to content

Commit e63333a

Browse files
[docs] Document API of C interfaces
1 parent f2f283c commit e63333a

File tree

5 files changed

+109
-7
lines changed

5 files changed

+109
-7
lines changed

docs/source/api/api-c/linsolve.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
linsolve
22
========
33

4+
.. doxygenfile:: oif/interfaces/linsolve.h
45

docs/source/api/api-c/qeq.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
qeq
22
===
3+
4+
.. doxygenfile:: oif/interfaces/qeq.h

oif/interfaces/c/include/oif/interfaces/ivp.h

+62-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* @file
3+
* @brief Interface for solving initial-value problems (IVP) for ordinary differential equations (ODE).
4+
*
5+
* This interface defines the interface for solving initial-value problems
6+
* for ordinary differential equations:
7+
* \f[
8+
* \frac{dy}{dt} = f(t, y), \quad y(t_0) = y_0,
9+
* \f]
10+
* where \f$y\f$ is the state vector, \f$t\f$ is the time,
11+
* \f$f\f$ is the right-hand side (RHS) function.
12+
*/
113
#pragma once
214

315
#ifdef __cplusplus
@@ -6,49 +18,93 @@ extern "C" {
618

719
#include <oif/api.h>
820

9-
typedef int (*oif_ivp_rhs_fn_t)(double, OIFArrayF64 *y, OIFArrayF64 *ydot, void *user_data);
21+
/**
22+
* User-provided right-hand side function for the system of ODEs.
23+
*
24+
* @param[in] t Current time
25+
* @param[in] y State vector at time `t`
26+
* @param[out] ydot Derivative of the state vector, which must be computed during the function call
27+
* @param[in] user_data User data (additional context) required by the right-hand side function
28+
*/
29+
typedef int (*oif_ivp_rhs_fn_t)(double t, OIFArrayF64 *y, OIFArrayF64 *ydot, void *user_data);
1030

1131
/**
12-
* Set right hand side of the system of ordinary differential equations.
32+
* Set right-hand side of the system of ordinary differential equations.
33+
*
34+
* @param[in] implh Implementation handle
35+
* @param[in] rhs Right-hand side callback function
1336
*/
1437
int
1538
oif_ivp_set_rhs_fn(ImplHandle implh, oif_ivp_rhs_fn_t rhs);
1639

1740
/**
18-
* Set initial value y(t0) = y0.
41+
* Set initial value :math:`y(t0) = y0`.
42+
*
43+
* @param[in] implh Implementation handle
44+
* @param[in] y0 Initial value
45+
* @param[in] t0 Initial time
1946
*/
2047
int
2148
oif_ivp_set_initial_value(ImplHandle implh, OIFArrayF64 *y0, double t0);
2249

2350
/**
24-
* Set user data that can be used to pass additional information
51+
* Set user data (additional context) to pass additional information
2552
* to the right-hand side function.
53+
*
54+
* User data can be any object that is needed by the right-hand side function.
55+
* For example, if only a scalar value is required as an additional parameter,
56+
* then `user_data` can be just the pointer to that value.
57+
* If multiple values are required, then `user_data` can be a pointer to a
58+
* structure defined by the user, and the it is the user's responsibility
59+
* to cast the pointer to the correct type in the right-hand side function.
60+
*
61+
* @param[in] implh Implementation handle
62+
* @param[in] user_data User data (pointer to a user-defined object)
2663
*/
2764
int
2865
oif_ivp_set_user_data(ImplHandle implh, void *user_data);
2966

3067
/**
3168
* Set tolerances for adaptive time integration.
32-
* @param rtol Relative tolerance
33-
* @param atol Absolute tolerance
69+
*
70+
* @param[in] implh Implementation handle
71+
* @param[in] rtol Relative tolerance
72+
* @param[in] atol Absolute tolerance
3473
*/
3574
int
3675
oif_ivp_set_tolerances(ImplHandle implh, double rtol, double atol);
3776

3877
/**
3978
* Integrate to time `t` and write the solution to `y`.
79+
*
80+
* @param[in] implh Implementation handle
81+
* @param[in] t Time at which we want the solution
82+
* @param[out] y Array to which the solution at time `t` will be written
4083
*/
4184
int
4285
oif_ivp_integrate(ImplHandle implh, double t, OIFArrayF64 *y);
4386

4487
/**
4588
* Set integrator and optionally its parameters.
89+
*
90+
* Many implementations of ODE solvers contain multiple integrators,
91+
* with each integrator having specific options.
92+
* Hence, this function allows the user to set these options for a particular
93+
* integrator.
94+
* The integrator name and the options must be checked in the documentation
95+
* of a particular implementation.
96+
*
97+
* @param[in] implh Implementation handle
98+
* @param[in] integrator_name Name of the integrator
99+
* @param[in] config Configuration dictionary for the integrator
46100
*/
47101
int
48102
oif_ivp_set_integrator(ImplHandle implh, char *integrator_name, OIFConfigDict *config);
49103

50104
/**
51105
* Print statistics about integration.
106+
*
107+
* @param[in] implh Implementation handle
52108
*/
53109
int
54110
oif_ivp_print_stats(ImplHandle implh);

oif/interfaces/c/include/oif/interfaces/linsolve.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* @file
3+
* This module defines the interface for solving linear systems of equations.
4+
*
5+
* Problems to be solved are of the form:
6+
*
7+
* \f[
8+
* A x = b,
9+
* \f]
10+
* where \f$A\f$ is a square matrix and \f$b\f$ is a vector.
11+
*/
112
#pragma once
213

314
#ifdef __cplusplus
@@ -7,7 +18,12 @@ extern "C" {
718
#include <oif/api.h>
819

920
/**
10-
* Solve system of linear equations Ax = b via LU factorization.
21+
* Solve the linear system of equations \f$A x = b\f$.
22+
23+
* @param[in] implh Implementation handle
24+
* @param[in] A Coefficient matrix with shape `(n, n)`
25+
* @param[in] b Right-hand side vector with shape `(n,)`
26+
* @param[out] x Solution vector with shape `(n,)`
1127
*/
1228
int
1329
oif_solve_linear_system(ImplHandle implh, OIFArrayF64 *A, OIFArrayF64 *b, OIFArrayF64 *x);

oif/interfaces/c/include/oif/interfaces/qeq.h

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/**
2+
* @file
3+
* This module defines the interface for solving a quadratic equation.
4+
*
5+
* The quadratic equation is of the form:
6+
* \f[
7+
* a x^2 + b x + c = 0,
8+
* \f]
9+
* where \f$a\f$, \f$b\f$, and \f$c\f$ are the coefficients of the equation.
10+
*
11+
* Of course, this is not very useful in scientific context to invoke
12+
* such a solver.
13+
*
14+
* It was developed as a prototype to ensure that the envisioned architecture
15+
* of Open Interfaces is feasible.
16+
* It is used as a simple text case as well.
17+
*
18+
*/
119
#pragma once
220

321
#ifdef __cplusplus
@@ -6,6 +24,15 @@ extern "C" {
624

725
#include <oif/api.h>
826

27+
/**
28+
* Solve the quadratic equation \f$a x^2 + b x + c = 0\f$.
29+
*
30+
* @param[in] implh Implementation handle
31+
* @param[in] a Coefficient of the quadratic term
32+
* @param[in] b Coefficient of the linear term
33+
* @param[in] c Constant term
34+
* @param[out] roots Roots of the quadratic equation
35+
*/
936
int
1037
oif_solve_qeq(ImplHandle implh, double a, double b, double c, OIFArrayF64 *roots);
1138

0 commit comments

Comments
 (0)