Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix combination of material for molar electron density and mean excitation energy #4079

Merged
merged 8 commits into from
Mar 5, 2025

Conversation

andiwand
Copy link
Contributor

@andiwand andiwand commented Feb 11, 2025

During working on dense propagation I discovered that our material combination does not work for the molar electron density and the mean excitation energy. To fix this I have put these quantities into new variables which are averaged correctly and derived if not provided by the user.

In the future we may want to think about expanding the material param vector to include these quantities.

Summary by CodeRabbit

  • New Features

    • Expanded material configuration options now allow users to specify detailed electron density and excitation energy parameters for more precise material properties.
    • New methods for calculating molar electron density and mean excitation energy have been introduced.
  • Bug Fixes

    • Improved the material combination logic by handling edge conditions to prevent potential calculation errors.
  • Documentation

    • Updated hash values for specific test files to ensure consistency and accuracy in testing.

@andiwand andiwand added this to the next milestone Feb 11, 2025
Copy link

coderabbitai bot commented Feb 11, 2025

Walkthrough

Enhance the Material class and related functions, these changes do. A new static method overload for constructing materials with molar electron density and mean excitation energy parameters introduced, it is. New private member variables added to store these values, and the equality operator updated accordingly, it has been. New constexpr functions for calculating molar electron density and approximate mean excitation energy also added. The combineSlabs function now includes checks for zero thickness and returns materials with updated property calculations.

Changes

Files Change Summary
Core/include/…/Material.hpp
Core/src/Material/Material.cpp
Introduced a new static method overload fromMolarDensity with additional parameters (molar electron density, mean excitation energy). Added member variables m_molarElectronRho and m_meanExcitationEnergy, updated the equality operator, and added constexpr calculation functions. The output stream operator now prints the new properties.
Core/src/Material/AverageMaterials.cpp Updated combineSlabs to include zero thickness checks and to compute and return averaged material properties along with molar electron density and mean excitation energy.
Examples/Python/tests/root_file_hashes.txt Updated hash values for two root files due to changes in their content.

Possibly related PRs

  • refactor!: Accumulated material changes #4077: The changes in the main PR are related to the modifications in the Material class, specifically the addition of the fromMolarDensity method and updates to member variables, which align with the refactoring of material handling in the retrieved PR that also involves renaming methods and enhancing material representation.

Suggested reviewers

  • andiwand

Poem

New methods rise, they do,
In materials deep, secrets anew.
Electron flows and energies combine,
Calculations crisp as a Jedi's mind.
Code marches forward with checks so wise,
May the force of updates ever arise!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2aecc4a and 885666f.

📒 Files selected for processing (1)
  • Examples/Python/tests/root_file_hashes.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Examples/Python/tests/root_file_hashes.txt
⏰ Context from checks skipped due to timeout of 90000ms (21)
  • GitHub Check: CI Bridge / lcg_106a: [alma9, clang16]
  • GitHub Check: CI Bridge / build_gnn_tensorrt
  • GitHub Check: CI Bridge / lcg_106a: [alma9, gcc14]
  • GitHub Check: CI Bridge / lcg_105: [alma9, clang16]
  • GitHub Check: CI Bridge / lcg_106a: [alma9, gcc13]
  • GitHub Check: CI Bridge / lcg_105: [alma9, gcc13]
  • GitHub Check: CI Bridge / linux_ubuntu_2204_clang
  • GitHub Check: CI Bridge / linux_ubuntu_2204
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: CI Bridge / build_exatrkx_cpu
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: unused_files
  • GitHub Check: macos
  • GitHub Check: missing_includes
  • GitHub Check: linux_ubuntu_extra (ubuntu2204, 20, clang++)
  • GitHub Check: linux_ubuntu_extra (ubuntu2204, 20, g++)
  • GitHub Check: linux_ubuntu
  • GitHub Check: docs
  • GitHub Check: build_debug

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the Component - Core Affects the Core module label Feb 11, 2025
@andiwand andiwand changed the title fix: Fix combination of material for molar electron density and mean excitation energy fix: Fix combination of material for molar electron density and mean excitation energy Feb 11, 2025
Copy link

github-actions bot commented Feb 11, 2025

📊: Physics performance monitoring for 885666f

Full contents

physmon summary

@andiwand andiwand marked this pull request as ready for review February 11, 2025 10:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
Core/include/Acts/Material/Material.hpp (2)

132-133: Documentation for new members, improve we should!

Missing documentation comments for these new members, I sense. Help future padawans understand their purpose, we must.

Add documentation like this, you should:

+  /// Molar electron density in mol/length³
   float m_molarElectronRho = 0.0f;
+  /// Mean excitation energy in native energy units
   float m_meanExcitationEnergy = 0.0f;

144-150: Floating-point comparisons, tricky they are!

Direct equality comparison for floating-point values, dangerous it can be. Consider epsilon-based comparison for floating-point members, we should.

Consider implementing like this:

-           (lhs.m_molarElectronRho == rhs.m_molarElectronRho) &&
-           (lhs.m_meanExcitationEnergy == rhs.m_meanExcitationEnergy);
+           (std::abs(lhs.m_molarElectronRho - rhs.m_molarElectronRho) < epsilon) &&
+           (std::abs(lhs.m_meanExcitationEnergy - rhs.m_meanExcitationEnergy) < epsilon);
Core/src/Material/AverageMaterials.cpp (1)

130-146: Complex calculations, handle with care we must!

Exponential averaging for mean excitation energy, complex it is. Consider adding comments explaining the physics behind this approach, we should.

Add explanatory comments like this:

+  // For mean excitation energy, we use geometric averaging when both values are positive
+  // as it better represents the physics of energy loss in combined materials.
+  // For zero or negative values, we fall back to arithmetic averaging.
   float meanExcitationEnergy = 0.f;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e46a352 and bd98e66.

📒 Files selected for processing (3)
  • Core/include/Acts/Material/Material.hpp (7 hunks)
  • Core/src/Material/AverageMaterials.cpp (2 hunks)
  • Core/src/Material/Material.cpp (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_debug
🔇 Additional comments (4)
Core/src/Material/Material.cpp (3)

30-39: Approve these functions, I do!

Well implemented, these constexpr functions are. Efficient at compile-time, they shall be. Clear and focused, their purpose is.


58-60: Careful with precision loss, we must be!

From double to float, the conversion goes. In calculations where high precision matters, impact this might have.

Consider if double precision throughout the calculation chain, needed it is.


70-82: Wise implementation, this is!

Good use of optional parameters and clear parameter handling, I see. Strong with the Force, this implementation is.

Core/src/Material/AverageMaterials.cpp (1)

35-40: Handle zero thickness wisely, you do!

Prevent division by zero, these checks do. Return early pattern, clean it is.

@asalzburger asalzburger self-requested a review February 27, 2025 13:11
asalzburger
asalzburger previously approved these changes Feb 27, 2025
Copy link
Contributor

@asalzburger asalzburger left a comment

Choose a reason for hiding this comment

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

Let's go ahead with this.

@asalzburger
Copy link
Contributor

There's some conflicts, but also CI failures, can you check @andiwand ?

@github-actions github-actions bot added Component - Examples Affects the Examples module Changes Performance labels Feb 28, 2025
@andiwand andiwand requested a review from asalzburger March 3, 2025 10:33
@kodiakhq kodiakhq bot merged commit f48292a into acts-project:main Mar 5, 2025
45 checks passed
@github-actions github-actions bot removed the automerge label Mar 5, 2025
@andiwand andiwand deleted the fix-material-average branch March 5, 2025 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changes Performance Component - Core Affects the Core module Component - Examples Affects the Examples module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants