iamcalvinlau / PBJ

PBJ stands for Particles By Julia. Hopefully, this grows into a Julia-based particle simulation suite of functions and subroutines to be used for testing various particle-in-cell methods and techniques.
GNU General Public License v3.0
3 stars 0 forks source link

Energy conservation #1

Open aratava opened 1 year ago

aratava commented 1 year ago

Hi Calvin, thanks for the great code. I added a total energy calculation function (kinetic energy plus the electrostatic). I checked the conservation of energy in the example of two-stream instability and it was not very good for the default dt (dt=1.0/omega_theory*0.01). I reduced the dt to (dt=1.0/omega_theory*0.001) and it was much better. But this means dt=0.01 in terms of 1/omega_pe. It is strange if such a small dt is required to keep the energy conserved, so I thought maybe I am doing something wrong. The total energy is calculated as:

        es_energy=0.5*dx*sum((Fields_struct.ion_density.-Fields_struct.electron_density).*Fields_struct.phi)
        total_energy = electrons.total_kinetic_energy+ions.total_kinetic_energy+es_energy

Have you calculated this before? What can be the issue?

Thank you, Arash

iamcalvinlau commented 1 year ago

Hi Arash,

Thanks for your interest! It's been a while since I wrote this code.. years, in fact. I'm going to have to remind myself a bit to see if I can figure out the issue here too, but we have a very, very new newborn right now so I probably won't be able to check it out for a while.

I would suggest playing with the components to see if the problem is in the particle pusher or the calculation of the self consistent fields. So, a simple way to do that is to not update the fields but to use a static field and see if the energy conservation of the particles still requires such a small time step.

Please let know if you find anything interesting there so that I might think other suggestions! --Calvin

On Fri, Jan 20, 2023, 2:59 PM aratava @.***> wrote:

Hi Calvin, thanks for the great code. I added a total energy calculation function (kinetic energy plus the electrostatic). I checked the conservation of energy in the example of two-stream instability and it was not very good for the default dt (dt=1.0/omega_theory0.01). I reduced the dt to (dt=1.0/omega_theory0.001) and it was much better. But this means dt=0.005 in terms of 1/omega_pe. It is strange if such a small dt is required to keep the energy conserved, so I thought maybe I am doing something wrong. The total energy is calculated as:

    es_energy=0.5*dx*sum((Fields_struct.ion_density.-Fields_struct.electron_density).*Fields_struct.phi)
    total_energy = electrons.total_kinetic_energy+ions.total_kinetic_energy+es_energy

Have you calculated this before? What can be the issue?

Thank you, Arash

— Reply to this email directly, view it on GitHub https://github.com/iamcalvinlau/PBJ/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHD4PWDSBQTWNOBZMKQKXM3WTMYHRANCNFSM6AAAAAAUCC7P4M . You are receiving this because you are subscribed to this thread.Message ID: @.***>

aratava commented 1 year ago

I tried to turn off the self-consistent field calculation and the energy conservation was much better. However, because the field calculation is self-consistent, it does not necessarily mean that there is a problem in the field calculation (The reverse would have been more understandable if it had happened.)