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

refactor AU units #5133

Conversation

psychocoderHPC
Copy link
Member

@psychocoderHPC psychocoderHPC commented Sep 23, 2024

  • add conversion au units -> si
  • add conversion au unis -> pic

Please review very carefully!!!!!!

Review

Please check the first commit only. The second commit is changing the access .conv.* to .conv().*. This is required because nvcc is not able to pull the constexpr members correctly into the device code.

@psychocoderHPC psychocoderHPC added component: core in PIConGPU (core application) refactoring code change to improve performance or to unify a concept but does not change public API labels Sep 23, 2024
@psychocoderHPC psychocoderHPC added this to the 0.8.0 / Next stable milestone Sep 23, 2024
@psychocoderHPC psychocoderHPC added the component: user input signals changes in user API such as .param files, .cfg syntax, etc. - changelog! label Sep 23, 2024
@BrianMarre
Copy link
Member

BrianMarre commented Sep 23, 2024

Still in the process of the reviewing the PR, but there is one thing I am already really unhappy with.
This PR only provides conversion methods for Atomic Units instead of treating AtomicUnits as a separate equally valid third unit system.

This in my eyes the wrong approach and leads to combining orthogonal sets of functions elements into one class and a large number of conversion methods.

The root problem seems to be that the PR tries to press both code internal units and AtomicUnits into one class, although AtomicUnits are logically independent of the code internal units and should therefore be represented as a separate class with it's own conversion functions, instead of mashing them into one general set of conversion functions from SI to whatever.

My suggestion would be to define for internalPicUnits and atomicUnits each a class holding only the 4 base quantities and their SI-values.
Namely for internalPicUnits

  • massElectron
  • speedOfLight
  • simulationTimeStepLength
  • electronCharge

And for atomicUnits:

  • atomicUnitEFieldStrength
  • RydbergEnergy
  • AtomicUnitTime
  • (massElectron)

and then based on these define for each an daughter class that defines all the derived units in their respective unit systems, e.g. internalPicUnitEField, ... .

In addition it would be nice to define unit prefixes in one central location to provide generic conversion methods to avoid the magic prefix conversion numbers.

@psychocoderHPC
Copy link
Member Author

Still in the process of the reviewing the PR, but there is one thing I am already really unhappy with. This PR only provides conversion methods for Atomic Units instead of treating AtomicUnits as a separate equally valid third unit system.

I agree with you that the current approach is not very nice. It is fully orientated on the current approach.
Current normalizations are from a time long before constexpr and other helpful features.
This PR is not naming to solve the unit system issue, all the current refactorings have the goal of removing cyclic dependencies or simply removing the *.unitless files.

I opened the issue #5135 for the unit system, but to be fair nobody was interested in this topic until now and without contribution from others I do not see that this will be solved in the next years.

Copy link
Member

@BrianMarre BrianMarre left a comment

Choose a reason for hiding this comment

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

Found No bugs, seems to be function wise correct.

- add conversion au units -> si
- add conversion au unis -> pic

ci: picongpu
nvcc is not possible to pull static constexpr member into the device
code, therefore acessing a function is required.
- add `automicUnit`
- rename `ev` to `eV`
Comment on lines 153 to 154
constexpr float_X eV = static_cast<float_X>(sim.si.conv().joule2eV(
picongpu::sim.unit.mass() * pmacc::math::cPow(picongpu::sim.unit.length(), 2u)));
Copy link
Member

Choose a reason for hiding this comment

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

that's a bug, it should read

constexpr float_X eV = static_cast<float_X>(sim.si.conv().joule2eV(
    picongpu::sim.unit.mass() * pmacc::math::cPow(picongpu::sim.unit.length(), 2u) / pmacc::math::cPow(picongpu::sim.unit.time(), 2u)));

or even shorter

Suggested change
constexpr float_X eV = static_cast<float_X>(sim.si.conv().joule2eV(
picongpu::sim.unit.mass() * pmacc::math::cPow(picongpu::sim.unit.length(), 2u)));
constexpr float_X eV = static_cast<float_X>(picongpu::sim.si.conv().joule2eV(picongpu::sim.unit.energy()));

Copy link
Member Author

@psychocoderHPC psychocoderHPC Sep 26, 2024

Choose a reason for hiding this comment

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

Should it maybe sim.pic.get_eV(); because I assume you would like to have a picongpu eV?

Copy link
Member

Choose a reason for hiding this comment

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

Yes that is even better!

* @{
*/
template<typename T_Type = float_X>
constexpr T_Type eV2Joule(T_Type eV = 1.0) const
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
constexpr T_Type eV2Joule(T_Type eV = 1.0) const
constexpr T_Type eV2picEnergy(T_Type eV = 1.0) const

Copy link
Member

@BrianMarre BrianMarre Sep 25, 2024

Choose a reason for hiding this comment

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

but be careful when using automated search and replace since eV2Joule also exists in the SI namespace.

Copy link
Member

Choose a reason for hiding this comment

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

also needs to be renamed in the other functions

Copy link
Member Author

Choose a reason for hiding this comment

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

offline discussed. Other functions are named equally. I am open that someone refactor it in a sperate PR because this is out of the scope of this PR.

Comment on lines 122 to 123
const float_64 minEnergy_keV = sim.pic.conv().eV2Joule(minEnergy_SI * 1.0e-3);
const float_64 maxEnergy_keV = sim.pic.conv().eV2Joule(maxEnergy_SI * 1.0e-3);
Copy link
Member

Choose a reason for hiding this comment

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

bug

Suggested change
const float_64 minEnergy_keV = sim.pic.conv().eV2Joule(minEnergy_SI * 1.0e-3);
const float_64 maxEnergy_keV = sim.pic.conv().eV2Joule(maxEnergy_SI * 1.0e-3);
const float_64 minEnergy_keV = 1.0e-3 * sim.pic.conv().joule2eV(minEnergy_SI);
const float_64 maxEnergy_keV = 1.0e-3 * sim.pic.conv().joule2eV(maxEnergy_SI);

Copy link
Member Author

Choose a reason for hiding this comment

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

changed it to sim.si.conv()

Comment on lines 304 to 305
const float_64 minEnergy_SI = this->minEnergy * sim.si.conv().eV2Joule(1.0e3);
const float_64 maxEnergy_SI = this->maxEnergy * sim.si.conv().eV2Joule(1.0e3);
Copy link
Member

Choose a reason for hiding this comment

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

bug

Suggested change
const float_64 minEnergy_SI = this->minEnergy * sim.si.conv().eV2Joule(1.0e3);
const float_64 maxEnergy_SI = this->maxEnergy * sim.si.conv().eV2Joule(1.0e3);
const float_64 minEnergy_SI = this->minEnergy * sim.unit.energy();
const float_64 maxEnergy_SI = this->maxEnergy * sim.unit.energy();

Copy link
Member Author

Choose a reason for hiding this comment

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

it conversion to keV, I will add this to the comment

Copy link
Member Author

Choose a reason for hiding this comment

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

changed to

            /* convert keV to joule */
            const float_64 minEnergy_SI = sim.si.conv().eV2Joule(this->minEnergy * 1.0e3);
            const float_64 maxEnergy_SI = sim.si.conv().eV2Joule(this->maxEnergy * 1.0e3);
            /* convert into PIConGPU units */
            this->minEnergy = minEnergy_SI / sim.unit.energy();
            this->maxEnergy = maxEnergy_SI / sim.unit.energy();

Copy link
Member

@BrianMarre BrianMarre left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link
Member

@BrianMarre BrianMarre left a comment

Choose a reason for hiding this comment

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

Nope, the FLYonPIC rate calculation unit test fails.

For reference, check by doing the following

pic-create $PIC_EXAMPLES/../tests/compileAtomicPhysics ./testUnitSystem
git clone [email protected]:ComputationalRadiationPhysics/TestUnitSystemAtomicData.git
cd ./testUnitSystem
cp ../TestUnitSystemAtomicData/* ./
pic-build
./bin/picongpu -g 1 1 1 -d 1 1 1 -s 1 --periodic 1 1 1

In ComputationalRadiationPhysics#5131 we changed rydberg energy from eV to joule but missed to apply
the conversion in the code.
@psychocoderHPC
Copy link
Member Author

fix is applied

@BrianMarre BrianMarre mentioned this pull request Sep 26, 2024
2 tasks
@ikbuibui ikbuibui merged commit 1e1c7b1 into ComputationalRadiationPhysics:dev Sep 27, 2024
10 checks passed
psychocoderHPC added a commit to psychocoderHPC/picongpu that referenced this pull request Sep 27, 2024
The PR ComputationalRadiationPhysics#5133 and ComputationalRadiationPhysics#5142 got merged together with ComputationalRadiationPhysics#4826.
Removed files and renamings for the unit systems collide therefore.
@psychocoderHPC psychocoderHPC deleted the topic-refactorAuUNits branch September 27, 2024 09:20
fabidie pushed a commit to fabidie/picongpu that referenced this pull request Sep 28, 2024
The PR ComputationalRadiationPhysics#5133 and ComputationalRadiationPhysics#5142 got merged together with ComputationalRadiationPhysics#4826.
Removed files and renamings for the unit systems collide therefore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core in PIConGPU (core application) component: user input signals changes in user API such as .param files, .cfg syntax, etc. - changelog! refactoring code change to improve performance or to unify a concept but does not change public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants