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

Support native CLHEP unit system #1085

Merged
merged 21 commits into from
Feb 1, 2024
Merged

Conversation

sethrj
Copy link
Member

@sethrj sethrj commented Jan 18, 2024

This allows users to configure Celeritas to process "native" values in a different unit system. Having multiple unit systems supported by the code in CI provides a valuable check for correctness of units in physics code, unit tests, and translation layers.

Following on to #1076 as a holiday/vacation project, this fixes several unit system scaling issues in Celeritas and fixes (or disables) issues with missing system of units in the unit tests.

  • Add missing scaling units to event writer
  • Replace hardcoded CLHEP::cm with a variable clhep_length which translates from CLHEP to the native unit system
  • Add units to ImportData so that we can convert in place after importing
  • Add runtime enumeration for doing unit conversions on import quantities
  • Activate VecGeom unit system scaling routines

Things to note:

  • All data is converted to native unit system as soon as possible, and it's always exported in the native unit system
  • VecGeom hardcodes "bump" values as fixed-precision values (rather than specific to a length scale), so we cannot get exactly the same results when using different scale factors.
  • CGS doesn't work for JSON ORANGE problems at present because the scales are embedded into the preprocessed data (this will obviously change when we create geometries on the fly)
  • Single-precision runtime arithmetic messes with the imported values because the unit system, like the constants, are stored as "real_type" rather than double. (This is to avoid accidentally introducing floating point arithmetic at runtime).

Changes split into separate PRs:

@sethrj sethrj added enhancement New feature or request physics Particles, processes, and stepping algorithms labels Jan 18, 2024
@sethrj sethrj changed the title Support native CLHEP unit system Support native CLHEP and SI unit systems Jan 25, 2024
@sethrj sethrj marked this pull request as ready for review January 25, 2024 18:53
@stognini
Copy link
Member

Thanks Seth! Looks great.

Copy link
Contributor

@amandalund amandalund left a comment

Choose a reason for hiding this comment

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

Cool, this is great @sethrj!

Are the tests expected to pass in all unit systems now? I'm still seeing a handful failing with SI and CLHEP (looks like device tests).

src/celeritas/io/ImportUnits.cc Outdated Show resolved Hide resolved
src/celeritas/ext/detail/GeantMicroXsCalculator.cc Outdated Show resolved Hide resolved
test/celeritas/em/RelativisticBrem.test.cc Show resolved Hide resolved
test/celeritas/optical/Cerenkov.test.cc Outdated Show resolved Hide resolved
@@ -157,6 +164,11 @@ TEST_F(MaterialTest, params)

TEST_F(MaterialTest, material_view)
{
if (CELERITAS_UNITS != CELERITAS_UNITS_CGS)
{
GTEST_SKIP() << "Test needs updating to include units";
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you already updated part of this test... were you planning on updating the rest?

Copy link
Member Author

Choose a reason for hiding this comment

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

I got lazy at some point... I just wanted enough to show that the code essentially works, and later (next Christmas?) polish everything to a shine.

@amandalund
Copy link
Contributor

Tests are passing now with CLHEP, but I'm still seeing the following failures with SI:

	 88 - celeritas/Constants (Failed)
	 96 - celeritas/em/LivermorePE (Failed)
	103 - celeritas/em/UrbanMsc (Failed)
	111 - celeritas/ext/GeantGeo (Failed)
	113 - celeritas/ext/GeantImporter:FourSteelSlabs* (Failed)
	115 - celeritas/ext/GeantImporter:OneSteelSphere.* (Failed)
	124 - celeritas/field/LinearPropagator (Failed)
	136 - celeritas/global/AlongStep:SimpleCmsRZFieldAlongStepTest.msc_rzfield (Failed)
	166 - celeritas/phys/Physics (Failed)
	186 - celeritas/track/TrackSort (Failed)
	208 - app/demo-rasterizer (Failed)

@sethrj
Copy link
Member Author

sethrj commented Jan 31, 2024

Ah I never even tested the whole thing with SI (only tested the units/constants). How about I change the title and fix SI in a subsequent PR? :)

@sethrj sethrj changed the title Support native CLHEP and SI unit systems Support native CLHEP unit system Jan 31, 2024
Copy link
Contributor

@amandalund amandalund left a comment

Choose a reason for hiding this comment

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

Haha, sure that works. Thanks!

@sethrj sethrj merged commit 8f5849a into celeritas-project:develop Feb 1, 2024
21 checks passed
@sethrj sethrj deleted the fix-units branch February 1, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request physics Particles, processes, and stepping algorithms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants