Warwick-Plasma / epoch

Particle-in-cell code for plasma physics simulations
https://epochpic.github.io
GNU General Public License v3.0
184 stars 58 forks source link

How to compile the code with ID and Per_Particle_CHARGE_MASS #702

Closed DanRRRR closed 2 months ago

DanRRRR commented 2 months ago

What I am missing if I unlock in Makefile these two lines

DEFINES += $(D)PARTICLE_ID DEFINES += $(D)PER_PARTICLE_CHARGE_MASS

and not adding anything else to the default EPOCH source files try to compile the EPOCH code? I get compilation errors, see below. Shouldn't the EPOCH compile fine in this case?

Of course i can manually add these structures in the DIAGNOSTICS subroutine but i need to check if some annoying run time errors I get sometimes with no reason appear not because of my own additions (to subr DIAGNOSTICS ) but due to these two options. Without these two options the code runs OK



 2522 |           part_mc = c * current%mass
      |                                    1
Error: ‘mass’ at (1) is not a member of the ‘particle’ structure
src/io/diagnostics.F90:2576:36:

 2576 |           part_mc = c * current%mass
      |                                    1
Error: ‘mass’ at (1) is not a member of the ‘particle’ structure
src/io/diagnostics.F90:2608:32:

 2608 |       part_mc = c * current%mass
      |                                1
Error: ‘mass’ at (1) is not a member of the ‘particle’ structure
src/io/diagnostics.F90:2713:25:

 2713 |       IF (current%charge < sub%restriction(n)) &
      |                         1
Error: ‘charge’ at (1) is not a member of the ‘particle’ structure
src/io/diagnostics.F90:2719:25:

 2719 |       IF (current%charge > sub%restriction(n)) &
      |                         1
Error: ‘charge’ at (1) is not a member of the ‘particle’ structure
src/io/diagnostics.F90:2725:23:

 2725 |       IF (current%mass < sub%restriction(n)) &
      |                       1
Error: ‘mass’ at (1) is not a member of the ‘particle’ structure
src/io/diagnostics.F90:2731:23:

 2731 |       IF (current%mass > sub%restriction(n)) &
      |                       1
Error: ‘mass’ at (1) is not a member of the ‘particle’ structure
src/io/diagnostics.F90:2738:21:

 2738 |       IF (current%id < sub%restriction(n)) &
      |                     1
Error: ‘id’ at (1) is not a member of the ‘particle’ structure
src/io/diagnostics.F90:2744:21:

 2744 |       IF (current%id > sub%restriction(n)) &
      |                     1
Error: ‘id’ at (1) is not a member of the ‘particle’ structure
make[1]: *** [Makefile:385: diagnostics.o] Error 1
Status-Mirror commented 2 months ago

Hi Dan,

I'm guessing this is a version of the code you've been editing? I'm able to compile the current version on the main branch with these precompiler options. Can you try again with a clean git clone?

It's also worth mentioning that we'd advise users to avoid $(D)PER_PARTICLE_CHARGE_MASS. Here, mass and charge become particle variables which must be passed through MPI boundaries. This offers no benefit to the code, and only slows it down.

Cheers, Stuart

DanRRRR commented 2 months ago

Thanks for response Stuart. I'd be glad not to use this PER_PARTICLE_CHARGE_MASS (it definitely has problems with moving frame, so in this case to run i indeed do not change the defaults in Makefile) but if i stop using it for other cases then besides mass (for which you gave me a hint how to add it few weeks ago) i am losing also charge defined in subr Diagnostics as element of linked list current%charge. Any hints how to fix that?

Also i still manically afraid that downloading clean git clone will somehow by mistake overwrite my older one with all my so painfully made workarounds :(((((. Nothing actually to worry about ? :)

Status-Mirror commented 2 months ago

Hi Dan,

I remember the mass workaround I suggested. The charge variable should have an equivalent treatment, which is best demonstrated in io/iterators.F90. The function it_output_real contains lines like:

charge = current_species%charge
CALL start_particle_list(current_species, current_list, cur)
DO WHILE (ASSOCIATED(cur) .AND. (part_count < npoint_it))
    part_count = part_count + 1
#ifdef PER_PARTICLE_CHARGE_MASS
    array(part_count) = cur%charge
#else
    array(part_count) = charge
#endif
    cur => cur%next
END DO

This script is a heavily cut-down version of the real it_output_real function, but it demonstrates how you might fill an array with charges, whether you use -DPER_PARTICLE_CHARGE_MASS or not.

Hope this helps, Stuart

DanRRRR commented 2 months ago

Thanks for the hint, will try to implement it