Skip to content

Generalize the temperature scalar type for forward-mode AD - #35

Open
Samm-Py wants to merge 7 commits into
ORNL-MDF:mainfrom
Samm-Py:scalar-template-ad
Open

Generalize the temperature scalar type for forward-mode AD#35
Samm-Py wants to merge 7 commits into
ORNL-MDF:mainfrom
Samm-Py:scalar-template-ad

Conversation

@Samm-Py

@Samm-Py Samm-Py commented Aug 5, 2026

Copy link
Copy Markdown

Summary

  • Make the temperature field scalar configurable in Grid, Boundary,
    Layer, and SolidificationData, while retaining double as the default.
  • Derive the solver scalar from its temperature view and add scalar-valued
    material/source properties plus ADL-based math and value customization
    points. Finch core remains independent of any AD library.
  • Add an optional finch_sensitivity application using cpp_oti_lib to
    compute first-order sensitivities for six material and source parameters in
    one solve and compare them with central finite differences.

Compatibility

  • Existing callers continue to use double without source changes.
  • Mesh geometry, phase-change thresholds, and downstream solidification-event
    storage remain double.
  • The sensitivity application is built only when cpp_oti_lib is found; the
    standard Finch build has no new dependency.

Validation

  • clang-format 14.0.6 check passed for every changed C++ file.
  • GCC 9.4 Release builds passed with -Wall -Wextra -pedantic -Werror, both
    with and without cpp_oti_lib available.
  • The single_line temperature outputs are bit-for-bit identical to upstream
    main; solidification records are identical (their parallel emission order
    is nondeterministic).
  • The sensitivity application completed on one and four MPI ranks. OTI values
    matched the ordinary double solve, and all six derivatives were validated
    against central finite differences using FINCH_FD_STEP=1e-8.

Finch's field type was fixed to double. This threads a Scalar template
parameter (defaulting to double) through Grid, Boundary, Solver, Layer and
SolidificationData, so the temperature field can carry a user-supplied
arithmetic type. With double the generated code and temperature fields are
unchanged; verified bit-identical temperature output and identical
solidification records on the single_line case.

The differentiated material and source inputs move into a MaterialProperties
struct so a caller can supply values of the field scalar type rather than plain
doubles read from the input deck. Quantities that only select a branch
(solidus, liquidus) and all mesh geometry stay double.

Finch_Scalar.hpp adds exp/fmin/fmax dispatch: arithmetic types forward to
Kokkos as before, anything else resolves by ADL into the scalar type's own
namespace. Finch therefore carries no dependency on any AD library.

The optional finch_sensitivity application demonstrates the result with
cpp_oti_lib, obtaining d(QoI)/dp for six material and source parameters from a
single solve and validating each against central finite differences.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PNkQTS2g7P6dNDybhWRkwz
@Samm-Py

Samm-Py commented Aug 5, 2026

Copy link
Copy Markdown
Author

@Rombur The PR is open and ready for review.

Comment thread applications/Finch_OTI.hpp Outdated
Comment thread applications/CMakeLists.txt Outdated
Comment thread applications/SingleLayer_Sensitivity.cpp
Comment thread applications/Finch_OTI.hpp Outdated
Comment thread applications/CMakeLists.txt Outdated
Comment thread applications/Finch_OTI.hpp Outdated
Comment thread applications/Finch_OTI.hpp Outdated
Comment thread integrations/sparrow/Finch_Sparrow.hpp
Comment thread applications/Sensitivity.cpp Outdated
Comment thread applications/SingleLayer_Sensitivity.cpp
Comment thread applications/Sensitivity.cpp Outdated
Comment thread src/Finch_Grid.hpp Outdated
Comment thread src/Finch_Solver.hpp Outdated
Samm-Py and others added 2 commits August 7, 2026 11:22
Co-authored-by: Bruno Turcksin <bruno.turcksin@gmail.com>
Co-authored-by: Bruno Turcksin <bruno.turcksin@gmail.com>
@Samm-Py
Samm-Py requested review from Rombur and streeve August 7, 2026 19:22
@Samm-Py Samm-Py mentioned this pull request Aug 7, 2026
Comment thread .gitignore Outdated
Comment thread examples/single_line_sensitivity/inputs_mpi.json Outdated
Comment thread OTI_INTEGRATION_NOTES.md Outdated
Replace the ad hoc spike run directories with an example under
examples/single_line_sensitivity, laid out like the existing single_line
example. run_example.sh performs the reference double solve and then four
sensitivity configurations: the default finite difference step, a refined
step, latent heat removed, and four MPI ranks.

The four rank stage now reuses inputs.json

Drop the spike specific .gitignore entries, which belong in a local exclude
file rather than in the repository.
@Samm-Py
Samm-Py force-pushed the scalar-template-ad branch from fe75f43 to aaca526 Compare August 10, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants