ECP-WarpX / WarpX

WarpX is an advanced electromagnetic & electrostatic Particle-In-Cell code.
https://ecp-warpx.github.io
Other
303 stars 191 forks source link

Particle injector and scaling for astrophysical plasma setup #5131

Open n01r opened 2 months ago

n01r commented 2 months ago

Moved discussion from #5077.

User @Tissot11 asked the following questions:

I just want to ask if WarpX also has particle injector available which could be used to simulate astrophysical plasmas. I see in one of your thread (https://github.com/ECP-WarpX/WarpX/issues/4581) you mention about the injector and cathode sources. Are these features already available and missing in the documentation?

For an injector, I need something like a cathode source that can continually inject particles (electron and ions, neutral plasma) into the simulation box from one or two side of a simulation box. This is needed apart from initialising a plasma with a density profile in the simulation box. This simplifies simulating collisionless shocks in PIC simulations.

Since WarpX is a high performance code, it is indeed suitable for astrophysical simulations that require lot more computing power than laser-plasma simulations. I saw the example of a magnetic reconnection using WarpX (PICMI) which is great but having particle injectors/cathode sources in WarpX could make it really versatile for shock related simulations and also other astrophysical scenarios.

In PICMI interface (used in magnetic reconnection example), one can define grid sizes in terms of electron skin-depth etc. However, for WarpX simulations, the domain has be to in physical micrometers which makes sense for laser-plasma interaction scenarios and also quite user friendly to everyone. I am a theoretician who tends to design simulations and interpret results in terms of these physical scales e.g. skip-depth, ion gyro radius etc. Of course, I can assume a plasma density and calculate these lengths to define the domain size. But I was wondering if like PICMI interface, it is also possible to define simulation domain in terms of electron skin-depth, gyro radius etc?

@RevathiJambunathan, do you maybe have experience or guidance given your previous astrophysical WarpX studies?

RemiLehe commented 2 months ago

Thanks for raising this question @Tissot11.

Regarding continuous plasma injection, you can use the "flux injection" (search for NFluxPerCell on this page: https://warpx.readthedocs.io/en/latest/usage/parameters.html). Here is an example that uses it: https://github.com/ECP-WarpX/WarpX/blob/development/Examples/Tests/flux_injection/inputs_3d Also: here is an example that uses this feature within PICMI: https://github.com/ECP-WarpX/WarpX/blob/development/Examples/Physics_applications/spacecraft_charging/PICMI_inputs_rz.py#L188

Regarding your question on defining the simulation domain in terms of physical length (e.g. electron skin depth): there is currently no such feature in PICMI. The natural to do this in PICMI would be (as you mentioned) to pick a density, compute the corresponding skin depth, and then set the simulation domain accordingly.

Tissot11 commented 2 months ago

Thanks for your answer and these links! It does look very promising that I can use this feature to simulate shocks with WarpX. It appears from these examples, that one could define a drifting Maxwellian plasma in WarpX but not in PICMI? The example for PICMI seems to talk about a Gaussian distribution with zero mean velocity. Is the Maxwell-Juettner distribution is used in WarpX? This is essentially to ensure that one can take into relativistic electron temperatures into account.

Regarding the scale-lengths for domain size, I meant this example https://warpx.readthedocs.io/en/latest/usage/examples/ohm_solver_magnetic_reconnection/README.html

where the domain size is defined in ion skin depth using the PICMI interface. I try to look at it carefully again.

Tissot11 commented 2 days ago

I have now started using WarpX for the simulations, I am interested in. I just wanted to clarify few points regarding the injection.

  1. Documentation says do_continuous_injection = 1 for injecting/initialising plasma in moving window and boosted frame simulations. Does it mean that do_continuous_injection = 1 only works for these two simulations? Can one also use it for simulations (without moving window/boosted frame) involving drifting plasmas? Then I do not need to continuously inject particles using NFluxPerCell?
  2. If this is not the case, then I need to use NFluxPerCell but I am interested in injection with a fixed density in a 2D simulation. In your examples, you took flux to be 1. For this calculation, do I need assume some size in missing y direction? Normally, I can just take it be a product of density and drift velocity...

Thanks in advance!

RemiLehe commented 1 day ago

Thanks for the question.

  1. do_continuous_injection should indeed work to inject a drifting plasma in a fixed (i.e. non-moving) box, but for this to work, you will need to turn on the moving window and give it a zero velocity. This is a bit of a quirk but is currently needed because the continuous injection is implemented as part of the moving window module: https://github.com/ECP-WarpX/WarpX/blob/development/Source/Utils/WarpXMovingWindow.cpp#L71

  2. Setting the flux to the product of density by drift velocity should still work for NFluxPerCell in 2D, I think (without having to assume some size in the missing y direction). That being said, I think that solution 1 (i.e. using do_continuous_injection) is probably easier.

Tissot11 commented 8 hours ago

Thanks for your fast answer and the tip! Indeed, it works the way you suggested and it already helps a lot! The additional flexibility provided by NFluxPerCell makes WarpX very attractive option for me to use for my research!

If you won't mind, I have three more clarifications to seek

  1. I defined four diagnostics namely diagField diagPhase diagSpectra diagTracking. In the first, I only dump diagField.fields_to_plot = Ex Ey Ez By Bz rho and in the second diagPhase.Eons.variables = x ux diagPhase.Ions.variables = x ux. The third and fourth are
diagSpectra.particle_fields_species = Eons Ions

diagSpectra.particle_fields_to_plot = u
diagSpectra.particle_fields.u(x,y,z,ux,uy,uz) = sqrt( ux*ux + uy*uy + uz*uz)
diagSpectra.particle_fields.u.filter(x,y,z,ux,uy,uz) = (x>=Lx/2) * (x<0.75*Lx)
diagTracking.Eons.plot_filter_function(t,x,y,z,ux,uy,uz) = (ux>=10) * (x<0.75*Lx) * (x>0.25*Lx)
diagTracking.Eons.random_fraction = 0.1

I was only expecting to see grid fields in the first one, but the remaining three diagnostics also seem to dump E, B, j always. Is this expected?

The last particle diagnostic should be rather light because of the filter condition (based on previous experiences from simulations) but the file size is huge (~15 GB) from the beginning of a small simulation run. This is after turning off diagTracking.write_species = 0 in all diagnostics to reduce file sizes due to checkpoint. I tried to read the documentation carefully but I might have skipped some important aspects. I am using for all diagnostics

<diagName>.format = openpmd
<diagName>.openpmd_encoding = g
<diagName>.openpmd_backend = h5
  1. When I pick for xmin absorbing and thermal for xmax, I got error asking to choose neumann boundary condition instead of PML. Is neumann also for electromagnetic field and not just for electrostatic solver as the documentation says? I am actually interested in reducing the electrostatic field noise at the boundaries.

  2. I found the attribute features quite useful. But I wanted to ask if you have more general usage in mind regarding the functionalities apart from creating and tracking particles by ionization and QED related physics? Could attributes be used to create different populations of a single species to initialise the simulations? I have only seen one or two input files in Tests directory for possible usages.

Again thanks in advance and I am now really looking forward to use WarpX for my research work.

RemiLehe commented 7 hours ago

Thanks for your interest in the code and for the additional questions.

Some of these questions would be easier to answer by having access to your full input script. Would it be possible for you to post the full script here?

Tissot11 commented 7 hours ago

Perhaps, I can send you by email?