Skip to content

Commit

Permalink
Merge branch 'coll_rel_red_diags' of github.com:aeriforme/WarpX into …
Browse files Browse the repository at this point in the history
…coll_rel_red_diags
  • Loading branch information
aeriforme committed Aug 5, 2023
2 parents 3627e6e + f05e61e commit ed71e13
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
19 changes: 8 additions & 11 deletions Examples/Tests/collider_relevant_diags/analysis_beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import numpy as np
from numpy import exp, sqrt
import openpmd_api as io
import pandas as pd
from scipy.constants import alpha, c
from scipy.constants import e as q_e
from scipy.constants import hbar, m_e, physical_constants, pi
import pandas as pd

r_e = physical_constants["classical electron radius"][0]

Expand Down Expand Up @@ -193,7 +193,7 @@ def disruption():
### LUMINOSITY ###
##################
dL_dt_cr = df[[col for col in df.columns if 'dL_dt' in col]].to_numpy()
times = df[[col for col in df.columns if 'time' in col]].to_numpy()
times = df[[col for col in df.columns if 'time' in col]].to_numpy()
L_cr = np.trapz(dL_dt_cr, times)
coll_timestep = np.argmax(dL_dt_cr)
coll_time = times[coll_timestep]
Expand All @@ -210,7 +210,7 @@ def disruption():
L_theory = N**2 / (4*pi*sigmax*sigmay)

# from guinea-pig: lumi_fine
L_gp = 7.95485e+30
L_gp = 7.95485e+30

assert np.isclose(L_cr, L_theory, rtol=0.02, atol=0.)
assert np.isclose(L_cr, L_gp, rtol=0.003, atol=0,)
Expand Down Expand Up @@ -359,7 +359,7 @@ def disruption():
ax[2].set_title('dL/dt')

for a in ax.reshape(-1):
a.legend()
a.legend()
a.axvline(x=times[coll_timestep], color='black')
a.axvline(x=times[ref_timestep], color='magenta')

Expand All @@ -384,11 +384,11 @@ def disruption():


for a in ax.reshape(-1):
a.legend()
a.legend()
a.axvline(x=times[coll_timestep], color='black')
a.axvline(x=times[ref_timestep], color='magenta')

fig.savefig('y.png', dpi=300.)
fig.savefig('y.png', dpi=300.)
plt.close()


Expand Down Expand Up @@ -419,11 +419,11 @@ def disruption():


for a in ax.reshape(-1):
a.legend()
a.legend()
a.axvline(x=times[coll_timestep], color='black')
a.axvline(x=times[ref_timestep], color='magenta')

fig.savefig('z.png', dpi=300.)
fig.savefig('z.png', dpi=300.)
plt.show()


Expand Down Expand Up @@ -504,6 +504,3 @@ def disruption():
#ax[3].plot(times, yave_ele, label='ave')
#ax[3].plot(times, ystd_ele, label='std')
#ax[3].set_title('y')



4 changes: 2 additions & 2 deletions Examples/Tests/collider_relevant_diags/inputs_3d_beams
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ diag1.diag_type = Full
diag1.write_species = 1
diag1.fields_to_plot = Ex Ey Ez Bx By Bz rho_beam_e rho_beam_p rho
diag1.species = beam_e beam_p
diag1.beam_e.variables = w ux uy
diag1.beam_p.variables = w ux uy
diag1.beam_e.variables = w ux uy
diag1.beam_p.variables = w ux uy
diag1.format = openpmd
diag1.openpmd_backend = bp
diag1.dump_last_timestep = 1
Expand Down
32 changes: 16 additions & 16 deletions Source/Diagnostics/ReducedDiags/ColliderRelevant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ColliderRelevant::ColliderRelevant (std::string rd_name)
add_diag("thetax_ave_"+species_names[i_s], "thetax_ave_"+species_names[i_s]+"(rad)");
add_diag("thetay_ave_"+species_names[i_s], "thetay_ave_"+species_names[i_s]+"(rad)");
add_diag("thetax_std_"+species_names[i_s], "thetax_std_"+species_names[i_s]+"(rad)");
add_diag("thetay_std_"+species_names[i_s], "thetay_std_"+species_names[i_s]+"(rad)");
add_diag("thetay_std_"+species_names[i_s], "thetay_std_"+species_names[i_s]+"(rad)");
add_diag("thetax_min_"+species_names[i_s], "thetax_min_"+species_names[i_s]+"(rad)");
add_diag("thetay_min_"+species_names[i_s], "thetay_min_"+species_names[i_s]+"(rad)");
add_diag("thetax_max_"+species_names[i_s], "thetax_max_"+species_names[i_s]+"(rad)");
Expand Down Expand Up @@ -224,9 +224,9 @@ void ColliderRelevant::ComputeDiags (int step)
ParallelDescriptor::ReduceRealSum(wtot, ParallelDescriptor::IOProcessorNumber());

#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
// thetax_min, thetax_max
Real thetax_min = 0.0_rt;
Real thetax_max = 0.0_rt;
// thetax_min, thetax_max
Real thetax_min = 0.0_rt;
Real thetax_max = 0.0_rt;

amrex::ReduceOps<ReduceOpMin, ReduceOpMax> reduce_ops_minmax;
auto r_minmax = amrex::ParticleReduce<amrex::ReduceData<Real, Real>>(
Expand All @@ -243,8 +243,8 @@ void ColliderRelevant::ComputeDiags (int step)
thetax_max = amrex::get<1>(r_minmax);
ParallelDescriptor::ReduceRealMin(thetax_min, ParallelDescriptor::IOProcessorNumber());
ParallelDescriptor::ReduceRealMax(thetax_max, ParallelDescriptor::IOProcessorNumber());
// x_ave, thetax_ave

// x_ave, thetax_ave
Real x_ave = 0.0_rt;
Real thetax_ave = 0.0_rt;

Expand All @@ -267,7 +267,7 @@ void ColliderRelevant::ComputeDiags (int step)
x_ave = x_ave / wtot;
thetax_ave = thetax_ave / wtot;

// x_std, y_std, thetax_std, thetay_std
// x_std, y_std, thetax_std, thetay_std
Real x_std = 0.0_rt;
Real thetax_std = 0.0_rt;

Expand Down Expand Up @@ -300,11 +300,11 @@ void ColliderRelevant::ComputeDiags (int step)
m_data[get_idx("thetax_std_"+species_names[i_s])] = thetax_std;

#elif defined(WARPX_DIM_3D)
// thetax_min, thetax_max, thetay_min, thetay_max
Real thetax_min = 0.0_rt;
Real thetax_max = 0.0_rt;
Real thetay_min = 0.0_rt;
Real thetay_max = 0.0_rt;
// thetax_min, thetax_max, thetay_min, thetay_max
Real thetax_min = 0.0_rt;
Real thetax_max = 0.0_rt;
Real thetay_min = 0.0_rt;
Real thetay_max = 0.0_rt;

amrex::ReduceOps<ReduceOpMin, ReduceOpMax, ReduceOpMin, ReduceOpMax> reduce_ops_minmax;
auto r_minmax = amrex::ParticleReduce<amrex::ReduceData<Real, Real, Real, Real>>(
Expand All @@ -325,8 +325,8 @@ void ColliderRelevant::ComputeDiags (int step)
thetay_max = amrex::get<3>(r_minmax);
ParallelDescriptor::ReduceRealMin({thetax_min, thetay_min}, ParallelDescriptor::IOProcessorNumber());
ParallelDescriptor::ReduceRealMax({thetax_max, thetay_max}, ParallelDescriptor::IOProcessorNumber());
// x_ave, y_ave, thetax_ave, thetay_ave

// x_ave, y_ave, thetax_ave, thetay_ave
Real x_ave = 0.0_rt;
Real y_ave = 0.0_rt;
Real thetax_ave = 0.0_rt;
Expand Down Expand Up @@ -358,7 +358,7 @@ void ColliderRelevant::ComputeDiags (int step)
thetax_ave = thetax_ave / wtot;
thetay_ave = thetay_ave / wtot;

// x_std, y_std, thetax_std, thetay_std
// x_std, y_std, thetax_std, thetay_std
Real x_std = 0.0_rt;
Real y_std = 0.0_rt;
Real thetax_std = 0.0_rt;
Expand Down Expand Up @@ -553,4 +553,4 @@ void ColliderRelevant::ComputeDiags (int step)
auto const lumi = 2. * PhysConst::c * n1_dot_n2 * dV;
m_data[get_idx("dL_dt")] = lumi;
}
// end void ColliderRelevant::ComputeDiags
// end void ColliderRelevant::ComputeDiags

0 comments on commit ed71e13

Please sign in to comment.