Skip to content

Commit 0cb25a2

Browse files
SebastianM-Cclaude
andcommitted
Add docstrings for the public mass matrix helpers
Also mark __check_dae_adaptivity as public, since it is imported by BoundaryValueDiffEqMIRK and BoundaryValueDiffEqFIRK and the ExplicitImports QA check requires explicit imports to be public, and render all six docstrings on the internal interfaces docs page as required by the API docs QA check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 59428dd commit 0cb25a2

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

docs/src/devdocs/internal_interfaces.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ BoundaryValueDiffEqCore.__FastShortcutNonlinearPolyalg
2222
BoundaryValueDiffEqCore.__Fix3
2323
BoundaryValueDiffEqCore.__add_singular_term!
2424
BoundaryValueDiffEqCore.__any_sparse_ad
25+
BoundaryValueDiffEqCore.__apply_algebraic_constraint!
26+
BoundaryValueDiffEqCore.__apply_algebraic_constraint_oop!
27+
BoundaryValueDiffEqCore.__apply_mass_matrix!
2528
BoundaryValueDiffEqCore.__build_cost
2629
BoundaryValueDiffEqCore.__build_solution
2730
BoundaryValueDiffEqCore.__cache_trait
31+
BoundaryValueDiffEqCore.__check_dae_adaptivity
2832
BoundaryValueDiffEqCore.__concrete_kwargs
2933
BoundaryValueDiffEqCore.__concrete_solve_algorithm
3034
BoundaryValueDiffEqCore.__construct_internal_problem
@@ -36,6 +40,7 @@ BoundaryValueDiffEqCore.__extract_mesh
3640
BoundaryValueDiffEqCore.__extract_problem_details
3741
BoundaryValueDiffEqCore.__extract_u0
3842
BoundaryValueDiffEqCore.__flatten_initial_guess
43+
BoundaryValueDiffEqCore.__get_algebraic_indices
3944
BoundaryValueDiffEqCore.__get_bcresid_prototype
4045
BoundaryValueDiffEqCore.__get_non_sparse_ad
4146
BoundaryValueDiffEqCore.__has_initial_guess
@@ -52,6 +57,7 @@ BoundaryValueDiffEqCore.__needs_diffcache
5257
BoundaryValueDiffEqCore.__resize!
5358
BoundaryValueDiffEqCore.__restructure_sol
5459
BoundaryValueDiffEqCore.__split_kwargs
60+
BoundaryValueDiffEqCore.__subtract_mass_stage!
5561
BoundaryValueDiffEqCore.__tunable_part
5662
BoundaryValueDiffEqCore.__use_both_error_control
5763
BoundaryValueDiffEqCore.__vec

lib/BoundaryValueDiffEqCore/src/BoundaryValueDiffEqCore.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export BVPVerbosity, _process_verbose_param, DEFAULT_VERBOSE
8282
__vec_f, __vec_f!, __vec_so_bc, __vec_so_bc!, _sparse_like,
8383
__apply_mass_matrix!, __get_algebraic_indices, __subtract_mass_stage!,
8484
__apply_algebraic_constraint!, __apply_algebraic_constraint_oop!,
85+
__check_dae_adaptivity,
8586
concrete_jacobian_algorithm, diff!, eval_bc_residual, eval_bc_residual!,
8687
get_dense_ad, interval, nodual_value, recursive_flatten, recursive_flatten!,
8788
recursive_flatten_twopoint!, recursive_unflatten!, safe_similar, _unwrap_val

lib/BoundaryValueDiffEqCore/src/utils.jl

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,18 +940,29 @@ end
940940
return nothing
941941
end
942942

943+
"""
944+
__apply_mass_matrix!(residᵢ, mass_matrix, tmp)
945+
946+
Overwrite `residᵢ` with `mass_matrix * residᵢ` in place, using `tmp` as workspace. Used in
947+
defect estimation so that the defect compares `M * z′` against `f(z)` for mass-matrix
948+
problems. No-op for `UniformScaling` mass matrices, so plain ODEs pay no cost.
949+
"""
943950
@inline function __apply_mass_matrix!(residᵢ, mass_matrix::UniformScaling, tmp)
944-
# Identity matrix - no modification needed
945951
return nothing
946952
end
947953

948954
@inline function __apply_mass_matrix!(residᵢ, mass_matrix::AbstractMatrix, tmp)
949-
# Apply M * residᵢ, using tmp as workspace
950955
mul!(tmp, mass_matrix, residᵢ)
951956
copyto!(residᵢ, tmp)
952957
return nothing
953958
end
954959

960+
"""
961+
__get_algebraic_indices(mass_matrix)
962+
963+
Return the indices of the zero rows of `mass_matrix`, i.e. the algebraic equations of an
964+
index-1 DAE, or `nothing` when there are none (always for `UniformScaling`).
965+
"""
955966
@inline function __get_algebraic_indices(mass_matrix::UniformScaling)
956967
return nothing
957968
end
@@ -961,6 +972,13 @@ end
961972
return isempty(indices) ? nothing : indices
962973
end
963974

975+
"""
976+
__subtract_mass_stage!(res, mass_matrix, K_r, tmp)
977+
978+
Subtract `mass_matrix * K_r` from `res` in place, using `tmp` as workspace. Turns the
979+
collocation stage residual `f(...) - K_r` into `f(...) - M * K_r`, i.e. collocation of
980+
`M * u′ = f(u, p, t)`.
981+
"""
964982
@inline function __subtract_mass_stage!(res, ::UniformScaling, K_r, tmp)
965983
res .-= K_r
966984
return nothing
@@ -972,6 +990,14 @@ end
972990
return nothing
973991
end
974992

993+
"""
994+
__apply_algebraic_constraint!(residᵢ, algebraic_indices, f!, yᵢ₊₁, p, t, tmp)
995+
996+
Overwrite the algebraic rows of the continuity residual `residᵢ` with the DAE constraint
997+
residual evaluated at the right mesh point `yᵢ₊₁`, following the unprojected collocation
998+
approach for index-1 DAEs of Ascher & Spiteri (1994). `f!` is evaluated in place into
999+
`tmp`. No-op when `algebraic_indices === nothing`.
1000+
"""
9751001
@inline function __apply_algebraic_constraint!(
9761002
residᵢ, ::Nothing, f!, yᵢ₊₁, p, t, tmp
9771003
)
@@ -986,6 +1012,11 @@ end
9861012
return nothing
9871013
end
9881014

1015+
"""
1016+
__apply_algebraic_constraint_oop!(residᵢ, algebraic_indices, f, yᵢ₊₁, p, t)
1017+
1018+
Same as [`__apply_algebraic_constraint!`](@ref) for an out-of-place `f`.
1019+
"""
9891020
@inline function __apply_algebraic_constraint_oop!(
9901021
residᵢ, ::Nothing, f, yᵢ₊₁, p, t
9911022
)
@@ -1000,6 +1031,13 @@ end
10001031
return nothing
10011032
end
10021033

1034+
"""
1035+
__check_dae_adaptivity(algebraic_indices, adaptive)
1036+
1037+
Throw an `ArgumentError` when mesh adaptivity is requested for a DAE problem
1038+
(`algebraic_indices !== nothing`): the collocation interpolant is inaccurate for algebraic
1039+
variables, so defect-based mesh refinement cannot converge.
1040+
"""
10031041
@inline __check_dae_adaptivity(::Nothing, adaptive::Bool) = nothing
10041042

10051043
@inline function __check_dae_adaptivity(::Vector{Int}, adaptive::Bool)

0 commit comments

Comments
 (0)