|
ROCK
1.11.5
Relativistic Oscillator Calculation Kit
|
BLAS is less used in electron trajectory calculations. For example, evaluating Lorentz force is the hotspot, whose first step is to calculate the Larmor radius using:
```c const real rl = cc->bv_blt[BV(ib, B_UZ)] * cc->bv_blt[BV(ib, B_AP)] / cc->bv_blt[BV(ib, B_W)] / ((real)(-C_QEME) * c->input.vn_mag_axis[iz]); ``` as well as other operations cannot be expressed in BLAS operations.
prints are not considered for side effects.W_TOTAL and E_TOTAL, that0 <= valid error/warning number <= E_TOTAL0 < a warning < W_TOTALW_TOTAL < an error < E_TOTALSpan=0.2 means ±10% on each side of the reference value. Gaussian distributions are cropped at ±2σ, meaning that span≔4×σ/reference.[0:N] includes 0 but excludes N, like the Python convention.typedef (except the global real type), the Linux kernel lower_case convention is applied for the identifiers except macro which are usually in UPPER_CASE.vn_* arrays. Note that vz_* is intentionally avoided since it is confusing with the velocity $𝑣_𝑧$.sizeof().length forstrlen()*_cs (cs means cos and sin) are normalized complex numbers, which have the form of CPLX(cos(angle), sin(angle)). Since the sincos() calls are so costly, they have to be pre-calculated. Batched pre-calculations can be better vectorized, which further improve the performance. Then in loops the sincos(angle1+angle2) are evaluated by complex multiplications of sincos(angle1) and sincos(angle2).*_omp marks internal functions which contains OpenMP/multithread parallelization, in order to avoid nested multi-threading.cr_*) are OMP by default. Therefore should not contain this suffix.*_offload are the GPU-offloaded variant of functions, whose arguments are host pointers and variables.*_gpu are the GPU functions (not the kernels!), whose arguments are device pointers and variables.cr_*. In order todim_ stands for dimension, which may also cause confusion. This word is used for:d or D, rather than dim.num_ generally indicates discrete numbers (typically integers). Difference to dim_ is that dim_’s are directly related to the data storage.rebuild_ is for refreshing / updating cached (high-dimensional) values, usually follows an update of its dependence.make_ is just a universal word indicating an action (i.e. function / procedure).make_* is more preferable thanget_* since those actions are more complicated than usual getters;calc_* since heavy calculations are not always required.make_* function.tdm_* are related to Tri-Diagonal-Matrix, which consists of dim_z rows.DIM_TDM(dim_z) = 3*ROCK_STRIDE(real,dim_z)opt_* are optional (NULLable) input or output parameters.vn_* are vector(s) of nodes indexed by [iv, in], which has the shape [N, dim_z].vm_* are value(s) of modes indexed by [iv, im], which has the shape [N, dim_m].mvn_* applies.mvn_* is mv_tdm_*, where tdm is the "spatial" coordinate instead of the raw node.mvn_* are applied.To be simple, data are stored in raw 1D vectors, which can be reshaped into multi-dimensional arrays. The following table contains the conventions of the variables which appear as arguments.
| Name | Type | Shape | Description |
|---|---|---|---|
beam_init | real | [DIM_BEAM_INIT] | The statistic initial parameters of beams, see enum ROW_OF_BEAM_INIT. |
bvn_blt_trj | real | [dim_b, DIM_BLT_TRJ, dim_z] | Beamlet trajectory, see enum ROWS_OF_BLT_TRJ |
dim_b | size_t | scalar | Number of beamlets |
dim_bcc | size_t | scalar | Dimension of radial grids for beam coupling coefficients |
dim_m | size_t | scalar | Total number of modes |
dim_z | size_t | scalar | Number of mesh nodes |
mv_tdm_zk | real | [dim_m, DIM_TDM(dim_z)] | FEM matrix operation (Mz-Mk) for each mode |
mvn_env | cplx | [dim_m, dim_z] | State of the envelope |
mvn_losscoef | real | [dim_m, dim_z] | An array for incorporating Ohmic loss in the field equation. Summing over all (i.e., outer and inner) walls results in mvn_losscoef = ∑(mvn_uuload * (wall_radius / sqrt(vn_econd))[None, :]), whose unit = (Ω·m)⁻¹ same as electrical conductivity. |
mvn_mod | real | [dim_m, DIM_MOD, dim_z] | Multi-mode collection of vn_mod |
mvn_src | cplx | [dim_m, dim_z] | Excitation (source) for the envelope equation without FEM-weighting (Unit in TE-mode: V/m^2) |
mvn_uuload | real | [dim_m, dim_z] | "Very" unscaled Ohmic load, unit = (Ω·m)^(-3⁄2)/m. Summing abs(mvn_env)^2 × mvn_uuload over modes results in vn_uload |
num_azi | int16_t | scalar | Azimuth mode number, whose sign represents the co- and counter-rotation |
num_rad | int16_t | scalar | Radial mode number, whose negative sign is reserved for TM-modes |
nvmh_bcc | real | [dim_z, dim_bcc, dim_m, DIM_HARM] | The grid of beamlet coupling coefficients where the v axis is an equidistant grid of radial span |
tdm_c | real | [DIM_TDM(dim_z)] | FEM matrix Mc |
vm_bc | cplx | [DIM_BC, dim_m] | Boundary condition, see enum ROW_OF_BC |
vm_bd | cplx | [DIM_BD, dim_m] | Boundary data, which is dU/dz at left and right boundaries, see enum ROW_OF_BD |
vm_bp | real | [2, dim_m] | Boundary phases, for the transient updating of boundary condition, [0, :] are the left side while [1, :] are the right side |
vm_cf | real | [dim_m] | Carrier frequency in Hz (caution: not omega!) |
vm_cp | real | [dim_m] | Carrier phase in rad |
vm_df | real | [dim_m] | Delta frequency (drift of carrier) in Hz |
vm_num | int16_t | [2, dim_m] | [0, :] = vector of num_azi while [1, :] = vector of num_rad |
vm_rfc | cplx | [dim_m] | (Complex) Resonance Frequency of Cold cavity |
vn_blt_avg | real | [DIM_BLT_AVG, dim_z] | Averaged beamlet data at each node, see enum ROWS_OF_BLT_AVG |
vn_econd | real | [dim_z] | Electrical conductivity along the 𝑧-axis, unit: (Ω·m)⁻¹ |
vn_mod | real | [DIM_MOD, dim_z] | Parameters of a single mode along the 𝑧-discretization |
vn_mrs | real | [dim_z] | Mesh Refinement Score of vn_z, a high value means the mesh is too coarse. The score at vn_mrs[i] indicates the mesh segment between vn_z[i] and vn_z[i+1] |
vn_uload | real | [dim_z] | Unscaled Ohmic load: vn_uload = numpy.sum(abs(mvn_env)**2 × mvn_uuload, aixs=0). Then, vn_uload / sqrt(vn_econd) is the true load. |
vn_z | real | [dim_z] | Nodes of 1D discretization of 𝑧-axis |
IMPORTANT We treat num_azi=0 as having the same effect as a positive num_azi. (This choice is flexible but must be consistent.)
Arguments are sorted in the order (skip the element if not applicable):
dim_mvm_* (excluding mv_tdm_*)dim_zvn_* (or their rows) in the order ofvn_zvn_numvn_modtdm_*mv_tdm_*mvn_*dim_b[in,out] variables (and dimensions)[out] variables (and dimensions)sincos() is not in C standard and therefore not used. Neither is the pair manually calculated by sqrt. The optimization to a sincos() call should rely on the compiler. So, check in the profiler whether sincos() is used instead of individual sin() and cos().I:I or _Complex_I for re+im*Idoes not work on Visual C. Besides, since GCC lacks of _Imaginary_I and uses _Complex_I, INF*I = INF*(0,1) == (NAN,INF) rather than (0,INF).I needs to be involved, use the own-declared II instead of I, see the code docs.CPLX is used instead of CMPLX for the following reasons:CMPLX in GCC's header (as standard in most Linux) is hidden from clang due to the missing of GCC-specific version macro __GNUC_PREREQ.CMPLX is not generalized for CMPLXF and CMPLXL.