-
Notifications
You must be signed in to change notification settings - Fork 45
Add helpers for array type, precision, and quantity conversion #2223
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
base: develop
Are you sure you want to change the base?
Changes from all commits
a155cee
95df594
0a87eb9
d38c08e
a34fb8b
3541a25
05f5d60
7ea63aa
4009f79
472a1d0
8c89d6c
262eee9
f3aebe6
b2337f9
559f024
e3b47c5
bc87762
3f4a067
7291409
90f3db3
ac22663
45a4fec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,10 @@ | |
|
|
||
| #include "corecel/Types.hh" | ||
| #include "corecel/cont/Array.hh" | ||
| #include "corecel/math/ArrayUtils.hh" | ||
| #include "corecel/math/ArrayQuantity.hh" | ||
| #include "geocel/GeantGeoUtils.hh" | ||
| #include "geocel/g4/Convert.hh" | ||
| #include "celeritas/Types.hh" | ||
| #include "celeritas/ext/GeantUnits.hh" | ||
| #include "celeritas/UnitTypes.hh" | ||
| #include "celeritas/field/CartMapField.hh" | ||
| #include "celeritas/field/CartMapFieldInput.hh" | ||
| #include "celeritas/field/CartMapFieldParams.hh" | ||
|
|
@@ -40,16 +39,18 @@ MakeCartMapFieldInput(G4Field const& field, | |
| CartMapFieldParams::Input field_input; | ||
|
|
||
| // Convert from Geant4 units to native units | ||
| field_input.x.min = convert_from_geant(params.x.min, clhep_length); | ||
| field_input.x.max = convert_from_geant(params.x.max, clhep_length); | ||
| // (NOTE: params currently use real_type not double) | ||
| using ClhepLength = Quantity<units::Millimeter, real_type>; | ||
| field_input.x.min = native_value_from(ClhepLength{params.x.min}); | ||
| field_input.x.max = native_value_from(ClhepLength{params.x.max}); | ||
| field_input.x.num = params.x.num; | ||
|
|
||
| field_input.y.min = convert_from_geant(params.y.min, clhep_length); | ||
| field_input.y.max = convert_from_geant(params.y.max, clhep_length); | ||
| field_input.y.min = native_value_from(ClhepLength{params.y.min}); | ||
| field_input.y.max = native_value_from(ClhepLength{params.y.max}); | ||
| field_input.y.num = params.y.num; | ||
|
|
||
| field_input.z.min = convert_from_geant(params.z.min, clhep_length); | ||
| field_input.z.max = convert_from_geant(params.z.max, clhep_length); | ||
| field_input.z.min = native_value_from(ClhepLength{params.z.min}); | ||
| field_input.z.max = native_value_from(ClhepLength{params.z.max}); | ||
| field_input.z.num = params.z.num; | ||
|
|
||
| // Prepare field data storage | ||
|
|
@@ -67,7 +68,7 @@ MakeCartMapFieldInput(G4Field const& field, | |
| G4double const dy = (params.y.max - params.y.min) / (params.y.num - 1); | ||
| G4double const dz = (params.z.max - params.z.min) / (params.z.num - 1); | ||
|
|
||
| // Position calculator for Cartesian grid | ||
| // Position calculator for Cartesian grid (G4 coords) | ||
| auto position_calculator = [&](size_type ix, size_type iy, size_type iz) { | ||
| G4double x = params.x.min + ix * dx; | ||
| G4double y = params.y.min + iy * dy; | ||
|
|
@@ -79,7 +80,9 @@ MakeCartMapFieldInput(G4Field const& field, | |
| auto field_converter = [](Array<G4double, 3> const& bfield, | ||
| Array<G4double, 4> const&, | ||
| real_type cur_bfield[3]) { | ||
| auto bfield_native = convert_from_geant(bfield.data(), clhep_field); | ||
| using ClhepField = Quantity<units::ClhepUnitBField, double>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not the same: real_type vs Geant4 value (double ).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ones in Quantities are double too, were they meant to be real_type? |
||
| auto bfield_native | ||
| = native_value_from(make_quantity_array<ClhepField>(bfield)); | ||
| std::copy(bfield_native.cbegin(), bfield_native.cend(), cur_bfield); | ||
| }; | ||
|
|
||
|
|
||
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.
Maybe the former should also be
native_value_from(just to make it clearer to developers that it's converting units) even though we know the energy units are both MeV.