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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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.
  • Bug Fixes

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

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

coderabbitai bot commented Feb 11, 2025

Walkthrough

The changes enhance the Material class and related functions by introducing a new static method overload for constructing materials with molar electron density and mean excitation energy parameters. New private member variables are added to store these values, and the equality operator is updated accordingly. In addition, new constexpr functions calculate molar electron density and approximate mean excitation energy. 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.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant M as Material Class
    participant C as Calculation Functions
    U->>M: Call fromMolarDensity(x0, l0, ar, z, molarRho, molarElectronRho, ?meanExcEnergy)
    alt mean excitation energy provided?
        M->>M: Set m_meanExcitationEnergy with given value
    else
        M->>C: Call approximateMeanExcitationEnergy(z)
        C-->>M: Return default mean excitation energy
    end
    M->>C: Call calculateMolarElectronDensity(z, molarRho)
    C-->>M: Return calculated molar electron density
    M->>U: Return constructed Material object
Loading
sequenceDiagram
    participant U as User
    participant CS as combineSlabs Function
    U->>CS: Call combineSlabs(slab1, slab2)
    alt Either slab has zero thickness?
        CS->>U: Return non-zero slab directly
    else
        CS->>CS: Compute averaged properties, molar electron density, and mean excitation energy
        CS->>U: Return combined MaterialSlab with updated properties
    end
Loading

Suggested labels

automerge

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!
Hmmm, celebrate we must, under starry skies.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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

📊: Physics performance monitoring for bd98e66

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Core Affects the Core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant