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

Implementation of Maxwell Juettner distribution #4826

Conversation

SergeyKonstantinErmakov
Copy link
Contributor

@SergeyKonstantinErmakov SergeyKonstantinErmakov commented Feb 22, 2024

Closes #4814

[added by @PrometheusPi]

Velocity distribution for highly relativistic particle temperatures. For this see MaxwellJuettner.hpp and MaxwellJuetner.def.

For verification, a temperature of 10MeV was used.
MaxwellJuettner

@PrometheusPi
Copy link
Member

PrometheusPi commented Feb 23, 2024

For some reason, the CI files with some python style issue - code that you did not touch.
I will retrigger the CI.

@steindev steindev requested a review from BrianMarre February 23, 2024 10:52
@BrianMarre
Copy link
Member

@SergeyKonstantinErmakov the CI complains because you are using an old dev as the base for your pull request(PR) and that is what the CI checks.
Please rebase your PR to the current dev.

u = (-1._X) * theta * math::log(x1 * x2 * x3);

x4 = uniformNoZeroRng();
nu = (-1._X) * theta * log(x1 * x2 * x3 * x4);
Copy link
Member

Choose a reason for hiding this comment

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

bug!!: must be math::log else C function can be used which can have strong side effects

Copy link
Member

Choose a reason for hiding this comment

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

Maybe for performance reasons it is better to write

foo = -1._X * theta;
bar = math::log(x1*x2*x3);
u = foo * bar;
nu = fo * (bar + log(x4);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you very much for the suggestions! Will be implemented.

Copy link
Member

Choose a reason for hiding this comment

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

@psychocoderHPC That still calls log twice, thus no performance gain.

Copy link
Member

Choose a reason for hiding this comment

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

stays the same

@psychocoderHPC psychocoderHPC added the component: core in PIConGPU (core application) label Feb 29, 2024
@psychocoderHPC psychocoderHPC added this to the 0.8.0 / Next stable milestone Feb 29, 2024
@psychocoderHPC psychocoderHPC added the changelog PR's marked with this label will be added to the changelog label Feb 29, 2024
@PrometheusPi
Copy link
Member

@SergeyKonstantinErmakov This pull request failed with a formatting issue, but I do not see in the logs why clang format changed.

@PrometheusPi
Copy link
Member

For me this error looks like a CI issue and not a common clang format error (which gives the not code style conform code lines). Could you have a look @psychocoderHPC and @chillenzer ?

@chillenzer
Copy link
Contributor

Nope, that's a real formatting issue. Following steps will give you a passing CI (see https://picongpu.readthedocs.io/en/latest/dev/docs/COMMIT.html for details):

# install pre-commit if not yet done
cd /path/to/repo
git checkout add_MaxwellJuettner
pre-commit install
pre-commit run --all-files
git add -u
git commit -m "Fix formatting issues"
git push

@chillenzer
Copy link
Contributor

PS: As an explanation, clang-format is run within pre-commit since #4817. Which would "report" the necessary changes by editing the files themselves (just like a local run of clang-format would do). In the CI these local changes are wiped out immediately afterwards, so that is not particularly helpful, I agree. pre-commit has better ways to handle this that we currently do not leverage because they are not quite aligned with how we handle CI.

@psychocoderHPC
Copy link
Member

PS: As an explanation, clang-format is run within pre-commit since #4817. Which would "report" the necessary changes by editing the files themselves (just like a local run of clang-format would do). In the CI these local changes are wiped out immediately afterwards, so that is not particularly helpful, I agree. pre-commit has better ways to handle this that we currently do not leverage because they are not quite aligned with how we handle CI.

@chillenzer can we run git diff in the CI in case a test fails? To show the broken lines?

@chillenzer chillenzer mentioned this pull request Mar 1, 2024
@SergeyKonstantinErmakov
Copy link
Contributor Author

Thanks to everyone for suggestions and comments! These will be implemented ASAP.

@PrometheusPi
Copy link
Member

Hi @SergeyKonstantinErmakov, in case you forgot about this pull request: The clang format issue is still open.

@PrometheusPi
Copy link
Member

Hi @SergeyKonstantinErmakov, what's the status of this pull request?

@psychocoderHPC psychocoderHPC force-pushed the add_MaxwellJuettner branch from bb4b648 to 6f3c12b Compare May 7, 2024 15:32
@psychocoderHPC
Copy link
Member

@SergeyKonstantinErmakov I removed all files that should not be part of this PR, rebased, formatted the code, and squashed all into a single commit.
I committed all under your credentials.

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.

in general @SergeyKonstantinErmakov could you rerun the your tests/provide your test scripts to verify the distribution of the current version?

Also the distribution seems to deviate for low energies, do we know why? No Accusation just a a honest question

Comment on lines 42 to 48
* @tparam T_ValueFunctor pmacc::math::operation::*, binary functor type to
* add a new momentum to an old one
*/
/** @tparam T_ValueFunctor pmacc::math::operation::*, binary functor type to
* add a new momentum to an old one
* @{
*/
Copy link
Member

Choose a reason for hiding this comment

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

this seems to be doubled up

Copy link
Member

Choose a reason for hiding this comment

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

was fixed

Comment on lines 50 to 55
/** Version with fixed temperature given via parameter struct
*
* @tparam T_ParamClass configuration parameter, follows requirements of param::MaxwellJuettnerCfg
*/
/** USE THIS IN THE SAME WAY AS Temperature.hpp JUST REPLACE Temperature with MaxwellJuettner FOR
* ALL FUNCTOR AND TEMPLATE NAMES**/
Copy link
Member

Choose a reason for hiding this comment

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

both comment blocks claim to be documentation of something following them, I think you intended them to be one block.

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 50 to 63
/** Version with fixed temperature given via parameter struct
*
* @tparam T_ParamClass configuration parameter, follows requirements of param::MaxwellJuettnerCfg
*/
/** USE THIS IN THE SAME WAY AS Temperature.hpp JUST REPLACE Temperature with MaxwellJuettner FOR
* ALL FUNCTOR AND TEMPLATE NAMES**/
template<typename T_ParamClass, typename T_ValueFunctor>
struct MaxwellJuettner;

/** Version with user-provided temperature functor
*
* @tparam T_MaxwellJuettnerFunctor temperature functor, follows requirements of
* param::MaxwellJuettnerFunctor
*/
template<typename T_Functor, typename T_ValueFunctor>
struct FreeMaxwellJuettner;
Copy link
Member

Choose a reason for hiding this comment

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

we should in general think about unifying this param class structure with the existing temperature functor, it does not make that much sense to have tow completely separate temperature param class definitions that are one to one copies.

Copy link
Member

Choose a reason for hiding this comment

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

I agree but let us bring this in and in a separate PR unify it. The user should not see the unification.

@SergeyKonstantinErmakov
Copy link
Contributor Author

in general @SergeyKonstantinErmakov could you rerun the your tests/provide your test scripts to verify the distribution of the current version?

Also the distribution seems to deviate for low energies, do we know why? No Accusation just a a honest question

Great Question!
You can find the answer in the paper which I used as a basis for this implementation
https://doi.org/10.1063/1.4919383
under Sobols Method. They explicitly state bad convergence for small energies which essentially comes from one of the approximations for the distribution which they have made (for details see paper), which only agrees for large values. Since Maxwell Juettner is used for high temperatures only, this is not an issue.
I determined that the convergence becomes significantly worse below 10 keV energies. For energies below this level, I suggest using Maxwell Boltzmann.
Maybe this is something which I should document, thanks for pointing that out!

PS: push will follow next thursday :)

@BrianMarre
Copy link
Member

@SergeyKonstantinErmakov ping!, gentle reminder ;)

@PrometheusPi
Copy link
Member

@SergeyKonstantinErmakov Could we finish this pull request this week together?

@PrometheusPi PrometheusPi force-pushed the add_MaxwellJuettner branch 3 times, most recently from 5680c3d to 8897c96 Compare June 24, 2024 07:35
PrometheusPi
PrometheusPi previously approved these changes Jun 26, 2024
@steindev
Copy link
Member

steindev commented Aug 6, 2024

ping @PrometheusPi

@steindev
Copy link
Member

steindev commented Sep 3, 2024

ping again @PrometheusPi

@psychocoderHPC
Copy link
Member

@PrometheusPi If this should be part of the next release we need asap a rebase and update of this PR

@steindev
Copy link
Member

☝️ @PrometheusPi

@PrometheusPi PrometheusPi dismissed stale reviews from psychocoderHPC and themself via 916a8f4 September 24, 2024 12:19
@PrometheusPi
Copy link
Member

@steindev please review then I can squash

@PrometheusPi
Copy link
Member

@steindev fixed author and squashed - ready for review and merge

@PrometheusPi PrometheusPi force-pushed the add_MaxwellJuettner branch 2 times, most recently from 5a07728 to 49a9c7e Compare September 24, 2024 15:45
steindev
steindev previously approved these changes Sep 24, 2024
@PrometheusPi
Copy link
Member

@steindev No code changes with the last force push, only linked @SergeyKonstantinErmakov now correctly via his email

@psychocoderHPC
Copy link
Member

@PrometheusPi you should wait to fix the CI issues until #5133 is merged.
#5133 will have priority because it is more difficulty to rebase it because it is touching the full code base.

@PrometheusPi
Copy link
Member

@steindev The CI discovered a real clang-format issue. This is fixed now. Please review again and merge.

@psychocoderHPC
Copy link
Member

you can already rebase against #5133 and fix the issues locally

@psychocoderHPC
Copy link
Member

I chacked the code changes looks like this PR is not affected by #5133

@PrometheusPi PrometheusPi changed the title Implementation of Maxwell Juettner distribution, Implementation of Maxwell Juettner distribution Sep 26, 2024
@steindev steindev merged commit 591e4b6 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.
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
changelog PR's marked with this label will be added to the changelog component: core in PIConGPU (core application)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The initialization with temperature is non-relativistic
6 participants