-
Notifications
You must be signed in to change notification settings - Fork 176
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes enhance the Changes
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
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
Suggested labels
Poem
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
molar electron density
and mean excitation energy
There was a problem hiding this 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
📒 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.
|
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
Bug Fixes