Skip to content

Add ThrustCalculator#1229

Draft
efaulhaber wants to merge 11 commits into
mainfrom
ef/thrust-calculator
Draft

Add ThrustCalculator#1229
efaulhaber wants to merge 11 commits into
mainfrom
ef/thrust-calculator

Conversation

@efaulhaber

Copy link
Copy Markdown
Member

Based on #1228.

@efaulhaber efaulhaber self-assigned this Jun 1, 2026
@efaulhaber efaulhaber added the enhancement New feature or request label Jun 1, 2026
@efaulhaber efaulhaber force-pushed the ef/thrust-calculator branch from 189c13b to 5aa80fe Compare June 1, 2026 13:04
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.66667% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.86%. Comparing base (6bb102a) to head (5aa80fe).

Files with missing lines Patch % Lines
src/general/mechanical_work_calculator.jl 76.13% 21 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (6bb102a) and HEAD (5aa80fe). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (6bb102a) HEAD (5aa80fe)
total 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1229       +/-   ##
===========================================
- Coverage   90.05%   70.86%   -19.19%     
===========================================
  Files         136      136               
  Lines       10594    10596        +2     
===========================================
- Hits         9540     7509     -2031     
- Misses       1054     3087     +2033     
Flag Coverage Δ
total ?
unit 70.86% <76.66%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@efaulhaber efaulhaber force-pushed the ef/thrust-calculator branch from 5aa80fe to fc31569 Compare June 1, 2026 13:47
efaulhaber

This comment was marked as duplicate.

@efaulhaber efaulhaber left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review

This is an AI-generated code review. Please verify the findings and summary before acting on them.

Summary

  • Adds MechanicalWorkCalculator as a general custom quantity for PostprocessCallback and removes the old callback include.
  • Adds ThrustCalculator and calculated_thrust for projected hydrodynamic force calculations.
  • Updates exports, documentation, and tests/examples to use the new calculator-based postprocessing flow.

Comment thread test/callbacks/mechanical_work_calculator.jl
end

# This should dispatch on `TotalLagrangianSPHSystem`, but this name is not yet defined
# due to the include order.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: direction_ = SVector(Tuple(direction)) preserves the input vector element type instead of converting it to the system element type. For Float32 systems with default Float64 literals, this leaves calculator.direction as Float64, contradicting the updated test expectation and causing type instability. Convert the direction to ELTYPE before normalization, e.g. build an SVector{ndims(system), ELTYPE}.

@efaulhaber efaulhaber left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review

This is an AI-generated code review. Please verify the findings and summary before acting on them.

Summary

  • Adds MechanicalWorkCalculator as a custom quantity for PostprocessCallback and removes the old callback include.
  • Adds ThrustCalculator and calculated_thrust to compute projected hydrodynamic force.
  • Exports the new calculator APIs and documents mechanical work calculator autodocs.
  • Updates mechanical work and example tests to use PostprocessCallback.

Comment thread test/callbacks/mechanical_work_calculator.jl
Get the latest projected hydrodynamic force from a [`ThrustCalculator`](@ref).
"""
function calculated_thrust(calculator::ThrustCalculator)
return calculator.thrust

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO: calculated_thrust is exported public API, but its docstring lacks the required # Arguments section. Add an arguments section documenting calculator, matching the package docstring convention for public functions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the legacy MechanicalWorkCalculatorCallback with a PostprocessCallback-compatible custom quantity (MechanicalWorkCalculator) and introduces a new ThrustCalculator custom quantity for projected hydrodynamic force on structures.

Changes:

  • Added MechanicalWorkCalculator and ThrustCalculator functors (custom quantities) and exported the new APIs.
  • Removed MechanicalWorkCalculatorCallback callback implementation and updated tests/examples to use PostprocessCallback.
  • Updated documentation to include the new calculators via autodocs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/examples/examples.jl Migrates example smoke tests from MechanicalWorkCalculatorCallback to MechanicalWorkCalculator + PostprocessCallback, and adds a thrust sanity check.
test/callbacks/mechanical_work_calculator.jl Updates unit tests for the new MechanicalWorkCalculator API and adds tests for ThrustCalculator.
src/TrixiParticles.jl Updates exports to expose MechanicalWorkCalculator/ThrustCalculator and their accessors.
src/general/mechanical_work_calculator.jl Adds implementations of MechanicalWorkCalculator and ThrustCalculator plus supporting helpers.
src/general/general.jl Includes the new general/mechanical_work_calculator.jl module file.
src/callbacks/mechanical_work_calculator.jl Removes the old callback-based mechanical work calculator implementation.
src/callbacks/callbacks.jl Drops the include of the removed callback file.
docs/src/callbacks.md Adds autodocs section for the new calculator implementations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/general/mechanical_work_calculator.jl
Comment on lines +267 to +276
# Check vector length before converting to `SVector` to avoid extremely long
# compile times when accidentally passing large vectors.
if length(direction) != ndims(system)
throw(ArgumentError("length of `direction` must match the number of dimensions"))
end
direction_ = SVector(Tuple(direction))
if iszero(direction_)
throw(ArgumentError("`direction` must not be zero"))
end
direction_ = normalize(direction_)
Comment thread docs/src/callbacks.md
Comment on lines +18 to +22
# Mechanical Work Calculator

The `MechanicalWorkCalculator` is a special custom quantity to be used with the
[`PostprocessCallback`](@ref).

Comment thread test/examples/examples.jl
Comment thread test/examples/examples.jl

@efaulhaber efaulhaber left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review

This is an AI-generated code review. Please verify the findings and summary before acting on them.

The PR replaces the previous mechanical work callback with a postprocess custom quantity and adds thrust calculation, but it removes the exported callback API without a compatibility path. Existing user code relying on the public callback constructor will break.

Comment thread src/general/mechanical_work_calculator.jl
Comment thread src/TrixiParticles.jl

Functor that accumulates the work done by a set of particles in a
[`TotalLagrangianSPHSystem`](@ref) by integrating the instantaneous power over time.
It can be passed as a custom quantity to [`PostprocessCallback`](@ref), which controls

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: MechanicalWorkCalculator integrates work only when PostprocessCallback invokes it, so the callback interval is also the Euler integration step rather than only an output sampling interval. Document this accuracy tradeoff and point users to write_file_interval when they only want less frequent file output.

Comment thread src/TrixiParticles.jl
PostprocessCallback, StepsizeCallback, UpdateCallback, SteadyStateReachedCallback,
SplitIntegrationCallback, MechanicalWorkCalculatorCallback,
calculated_mechanical_work,
SplitIntegrationCallback, MechanicalWorkCalculator, calculated_mechanical_work,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: MechanicalWorkCalculator and ThrustCalculator are new exported user-facing quantities, but the PR does not add compact and rich Base.show methods required for types shown in callback summaries. Add display methods using summary_header, summary_line, and summary_footer.

Comment thread docs/src/callbacks.md
Pages = ["general/custom_quantities.jl"]
```

# Mechanical Work Calculator

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO: This autodocs block now includes ThrustCalculator, but the section title and intro only mention mechanical work. Rename or expand the section so users can find thrust documentation under an accurate heading.

@efaulhaber

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 669482115e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

true,
dv, v_ode, u_ode, semi, 0.0,
dt3)
work1 = TrixiParticles.update_mechanical_work!(work1, system, eachparticle,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fix the renamed work helper call

This test now calls TrixiParticles.update_mechanical_work!, but the helper introduced in this commit is named update_mechanical_work (without !). Since test/callbacks/callbacks.jl includes this file, the callbacks test suite will throw UndefVarError as soon as it reaches this testset instead of validating the calculator; use the actual function name or restore a compatibility alias.

Useful? React with 👍 / 👎.

if length(direction) != ndims(system)
throw(ArgumentError("length of `direction` must match the number of dimensions"))
end
direction_ = SVector(Tuple(direction))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cast thrust direction to the system eltype

When a Float32 system is constructed with a usual Float64 tuple direction, this line preserves a Float64 direction instead of the calculator/system element type; the added constructor test for system32 therefore fails, and later thrust projections promote to Float64 before being narrowed back into thrust::Float32. Convert the direction entries to ELTYPE before building or normalizing the SVector.

Useful? React with 👍 / 👎.

Comment on lines +134 to +138
if !calculator.initialized
calculator.t = t
calculator.work = zero(calculator.work)
calculator.initialized = true
return calculator.work

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset accumulated work between solves

If the same MechanicalWorkCalculator object is reused for another solve or a restarted run, initialized remains true from the previous run, so the first postprocess call at the new initial time computes dt = t - calculator.t using the old final time and carries the old accumulated work forward. The previous callback reset t and work during callback initialization; this functor needs an equivalent reset path when PostprocessCallback starts a solve.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants