Compile a user-defined Fortran source file to a shared library at runtime
and call its ic_udf subroutine to fill the initial state.
The source file must contain exactly one subroutine with the interface:
subroutine ic_udf(n, x, rho, rho_u, E) bind(C, name="ic_udf") use iso_c_binding, only: c_int, c_double integer(c_int), value, intent(in) :: n real(c_double), intent(in) :: x(n) ! grid-point coordinates [m] real(c_double), intent(out) :: rho(n) ! density [kg/m^3] real(c_double), intent(out) :: rho_u(n) ! momentum [kg/m^2/s] real(c_double), intent(out) :: E(n) ! total energy [J/m^3] end subroutine
bind(C) requires C-interoperable argument types: use c_int / c_double
from iso_c_binding regardless of the solver's wp kind parameter.
See example/udf_sod.f90 for a complete working example.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(solver_state_t), | intent(inout) | :: | state |
Solver state (must have ub allocated, schemes bound) |
||
| type(config_t), | intent(in) | :: | cfg |
Runtime configuration (uses cfg%ic_udf_src) |