ROCK 1.9.1
Relativistic Oscillator Calculation Kit
Loading...
Searching...
No Matches
crock.h File Reference

CROCK API. More...

#include "types.h"
#include <stddef.h>
#include <stdint.h>
Include dependency graph for crock.h:

Go to the source code of this file.

Data Structures

struct  cr_cache
 Read the detailed description! More...

Macros

#define CROCK_API
#define ROCK_MALLOC
#define ROCK_PURE
#define ROCK_CONST
#define ROCK_NODISCARD
#define ROCK_UNUSED
#define ROCK_MASK_BLT_VAR_UZ
 Beamlet option: consider variable axial velocity.
#define ROCK_MASK_BLT_TAYLOR
 Beamlet option: consider 2nd term of Taylor expansion.
#define ROCK_MASK_BLT_CALI_CYC_PHASE
#define ROCK_MASK_BLT_CALI_GC_AZI
#define ROCK_MASK_BLT_CALI_GC_R
#define ROCK_MASK_BLT_DOPPLER
#define ROCK_MASK_BLT_SRC_MONOHARM
#define ROCK_MASK_BLT_MONOGC
#define ROCK_MASK_BLT_DEBUG
#define ROCK_MASK_BLT_ALL_FEATURES
 Beamlet option: All features except MONOGC and SRC_MONOHARM. Slowest option.
#define ROCK_FOREACH(X)
#define ROCK_FOREACH_1(X)
 Unified commonly used FOREACH, but stating from 1 instead of 0.
#define ROCK_IF_RETURN(IF_VAL, RET_VAL)
 Trick the coverage test for handling errors.
#define CR_NUMA_BLESS(type, buf, ...)

Functions

CROCK_API int cr_numa_bless (void *restrict buf, size_t sizeof_type, size_t dim_shape, const size_t *restrict shape)
 Set the data of buf to zero.
CROCK_API ROCK_CONST ROCK_NODISCARD int cr_version_major (void)
CROCK_API ROCK_CONST ROCK_NODISCARD int cr_version_minor (void)
CROCK_API ROCK_CONST ROCK_NODISCARD int cr_version_patch (void)
CROCK_API ROCK_PURE ROCK_NODISCARD const char * cr_errmsg (int err)
CROCK_API ROCK_PURE ROCK_NODISCARD size_t cr_stride_real (size_t dim)
 Calculate stride including padding.
CROCK_API ROCK_PURE ROCK_NODISCARD size_t cr_stride_cplx (size_t dim)
 Calculate stride including padding.
CROCK_API int cr_make_mode_holl (size_t dim_m, const int16_t *restrict vm_num, size_t dim_z, const real *restrict vn_geo_rout, real *restrict mvn_mod)
CROCK_API int cr_make_mode_coax (size_t dim_m, const int16_t *restrict vm_num, size_t dim_z, const real *restrict vn_geo_rout, const real *restrict vn_geo_rin, real *restrict mvn_mod)
CROCK_API int cr_make_mode_corr_ins (size_t dim_m, const int16_t *restrict vm_num, size_t dim_z, const real *restrict vn_geo_rout, const real *restrict vn_geo_rin, const real *restrict vn_geo_rel_w, const real *restrict vn_geo_depth, real *restrict mvn_mod)
CROCK_API int cr_make_mode_corr_holl_imp (size_t dim_m, const int16_t *restrict vm_num, size_t dim_z, const real *restrict vn_geo_rout, const real *restrict vn_geo_rel_w, const real *restrict vn_geo_depth, real *restrict mvn_mod)
CROCK_API int cr_deprecated_search_cold_resonance (const real *restrict opt_ptr_ref_z, size_t dim_m, size_t dim_z, const real *restrict vn_z, const real *restrict mvn_mod, cplx *restrict vm_freq)
CROCK_API int cr_find_cold_resonance (size_t dim_m, const real *restrict opt_vm_freq_init, size_t dim_z, size_t opt_iz_min_fcut, const real *restrict vn_z, const real *restrict mvn_mod, const real *restrict tdm_c, const real *restrict mv_tdm_zk, cplx *restrict vm_cfreq)
CROCK_API int cr_find_all_cold_resonances (size_t dim_z, size_t opt_iz_min_fcut, const real *restrict vn_z, const real *restrict vn_mod, const real *restrict tdm_c, const real *restrict tdm_zk, size_t dim_freq, size_t *restrict out_dim_freq, cplx *restrict out_cfreq)
CROCK_API int cr_make_cold_envelope (size_t dim_m, const cplx *restrict vm_rfc, size_t dim_z, const real *restrict vn_z, const real *restrict mvn_mod, cplx *restrict mvn_env)
CROCK_API ROCK_PURE ROCK_NODISCARD size_t cr_guess_dim_cold_spectrum (size_t dim_z, const real *restrict vn_z, const real *restrict vn_mod)
CROCK_API int cr_deprecated_make_cold_spectrum (size_t dim_z, const real *restrict vn_z, const real *restrict vn_mod, size_t dim_freq, real *restrict freq, real *restrict ampl)
CROCK_API int cr_make_cold_spectrum (int max_iter, size_t dim_z, const real *restrict vn_z, const real *restrict vn_mod, const real *restrict tdm_c, const real *restrict tdm_zk, size_t dim_freq, real *restrict freq, real *restrict ampl)
CROCK_API int cr_make_fem (size_t dim_m, size_t dim_z, const real *restrict vn_z, const real *restrict mvn_mod, real *restrict tdm_c, real *restrict mv_tdm_zk)
CROCK_API int cr_step_field (real dt, size_t dim_m, const real *restrict vm_cf, const cplx *restrict vm_bc, size_t dim_z, const real *restrict tdm_c, const real *restrict mv_tdm_zk, const cplx *restrict mvn_src, cplx *restrict vm_bd, cplx *restrict mvn_env, real *restrict opt_vm_cp, real *restrict opt_vm_df, struct cr_cache *restrict *restrict opt_pp_cache)
CROCK_API void cr_make_bc_simple (size_t dim_m, const real *restrict vm_freq, size_t dim_z, const real *restrict mvn_mod, cplx *restrict vm_bc)
CROCK_API void cr_init_bp (size_t dim_m, size_t dim_z, const cplx *restrict mvn_env, real *restrict vm_bp)
CROCK_API void cr_update_bc_simple (real dt, size_t dim_m, const real *restrict vm_cf, size_t dim_z, const real *restrict mvn_mod, const cplx *restrict mvn_env, real *restrict vm_bp, cplx *restrict vm_bc)
CROCK_API void cr_init_bd (size_t dim_m, const cplx *restrict vm_bc, size_t dim_z, const cplx *restrict mvn_env, cplx *restrict vm_bd)
CROCK_API ROCK_MALLOC void * cr_malloc (size_t size)
CROCK_API void cr_free (void *ptr)
CROCK_API void cr_make_potential (real pot_outer, real opt_pot_inner, const real *restrict beam_init, size_t dim_z, const real *restrict vn_mag_axis, const real *restrict vn_rhocd, const real *restrict vn_r_outer, const real *restrict opt_vn_r_inner, real *restrict vn_pot)
CROCK_API int cr_make_bcc (real r_center, real r_span, size_t dim_m, const int16_t *restrict vm_num, size_t dim_z, const real *restrict vn_mag_axis, const real *restrict mvn_mod, size_t dim_bcc, real *restrict nvmh_bcc)
CROCK_API int cr_shoot_beamlet (uint32_t options, const real *restrict beam_init, size_t dim_m, const int16_t *restrict vm_num, const real *restrict vm_cf, const real *restrict vm_cp, size_t dim_z, const real *restrict vn_z, const real *restrict vn_pot, const real *restrict vn_mag_axis, const real *restrict mvn_mod, const cplx *restrict mvn_env, size_t dim_b, size_t dim_bcc, real bcc_r_center, real bcc_r_span, const real *restrict nvmh_bcc, uint32_t *seed, real *restrict vn_rhocd, cplx *restrict mvn_src, real *restrict opt_vn_mrs, real *restrict opt_vn_blt_avg, real *restrict opt_bvn_blt_trj, struct cr_cache *restrict *restrict opt_pp_cache)
CROCK_API void cr_make_power_out (size_t dim_m, const real *restrict vm_cf, size_t dim_z, const real *restrict mvn_mod, const cplx *restrict mvn_env, real *restrict opt_vm_pout_left, real *restrict opt_vm_pout_right)
CROCK_API real cr_make_chi_TE_corr_ins (real r, real d, real w, int16_t num_azi, int16_t num_rad, real *restrict opt_array_chi)
CROCK_API real cr_make_chi_TE_corr_holl_imp (real d, real w, int16_t num_azi, int16_t num_rad, real *restrict opt_array_chi)
CROCK_API void cr_make_uload (size_t dim_m, size_t dim_z, const cplx *restrict mvn_env, const real *restrict mvn_uuload, real *restrict vn_uload)
CROCK_API void cr_make_uuload (size_t dim_m, const int16_t *restrict vm_num, const real *restrict vm_freq, size_t dim_z, const real *restrict vn_radius, const real *restrict mvn_mod, real *restrict mvn_uuload)
CROCK_API int cr_tdm_solve (size_t systems, size_t rows, const cplx *restrict multi_mat, const cplx *restrict multi_vec, cplx *restrict multi_x)
CROCK_API void cr_make_df (real elapsed_time, size_t dim_m, size_t dim_z, const cplx *restrict mvn_new_env, real *restrict mvn_old_env_phase, real *restrict vm_df)
CROCK_API int cr_refine_z (real weight, size_t dim_z, const real *restrict vn_z, const real *restrict vn_mrs, size_t dim_z_new, real *restrict vn_z_new)
 Remap vn_z into vn_z_ne considering the mesh refinement score.
CROCK_API int cr_tdm_solve_offload (size_t systems, size_t rows, const cplx *restrict multi_mat, const cplx *restrict multi_vec, cplx *restrict multi_x)
CROCK_API int cr_step_field_gpu (real dt, size_t dim_m, const real *restrict vm_cf, const cplx *restrict vm_bc, size_t dim_z, const real *restrict tdm_c, const real *restrict mv_tdm_zk, const cplx *restrict mvn_src, cplx *restrict vm_bd, cplx *restrict mvn_env, real *restrict opt_vm_cp, real *restrict opt_vm_df, struct cr_cache *restrict *restrict opt_pp_cache)
 Doc see the CPU version.
CROCK_API int cr_step_field_offload (real dt, size_t dim_m, const real *restrict vm_cf, const cplx *restrict vm_bc, size_t dim_z, const real *restrict tdm_c, const real *restrict mv_tdm_zk, const cplx *restrict mvn_src, cplx *restrict vm_bd, cplx *restrict mvn_env, real *restrict opt_vm_cp, real *restrict opt_vm_df, struct cr_cache *restrict *restrict opt_pp_cache)
 Doc see the CPU version.

Detailed Description

CROCK API.

While the core functions are pure, the crock interface has side effects and is not thread-safe.

Macro Definition Documentation

◆ CR_NUMA_BLESS

#define CR_NUMA_BLESS ( type,
buf,
... )
Returns
Error code

◆ CROCK_API

#define CROCK_API

◆ ROCK_CONST

#define ROCK_CONST

◆ ROCK_FOREACH

#define ROCK_FOREACH ( X)

Unified commonly used FOREACH.

Use this wherever possible, in order to

  • prevent typo bugs
  • facilitate refactoring

Caveat: ROCK_FOREACH() in GPU offloading does not like dim_XXX=0

◆ ROCK_FOREACH_1

#define ROCK_FOREACH_1 ( X)

Unified commonly used FOREACH, but stating from 1 instead of 0.

◆ ROCK_IF_RETURN

#define ROCK_IF_RETURN ( IF_VAL,
RET_VAL )

Trick the coverage test for handling errors.

◆ ROCK_MALLOC

#define ROCK_MALLOC

◆ ROCK_MASK_BLT_ALL_FEATURES

#define ROCK_MASK_BLT_ALL_FEATURES

Beamlet option: All features except MONOGC and SRC_MONOHARM. Slowest option.

◆ ROCK_MASK_BLT_CALI_CYC_PHASE

#define ROCK_MASK_BLT_CALI_CYC_PHASE

Beamlet option: consider calibration of cyclotron phase, reduce performance due to atan2()

◆ ROCK_MASK_BLT_CALI_GC_AZI

#define ROCK_MASK_BLT_CALI_GC_AZI

Beamlet option: consider azimuthal motion (drift, oscillation etc.) of guiding center caused by RF field, reduce performance due to atan2()

◆ ROCK_MASK_BLT_CALI_GC_R

#define ROCK_MASK_BLT_CALI_GC_R

Beamlet option: consider radial motion (drift, oscillation etc.) of guiding center caused by RF field.

◆ ROCK_MASK_BLT_DEBUG

#define ROCK_MASK_BLT_DEBUG

The name ROCK_MASK_BLT_DEBUG will be deprecated and will be removed in future versions, use ROCK_MASK_BLT_MONOGC instead.

◆ ROCK_MASK_BLT_DOPPLER

#define ROCK_MASK_BLT_DOPPLER

Beamlet option: consider further Doppler effect caused by the transversal RF B field

◆ ROCK_MASK_BLT_MONOGC

#define ROCK_MASK_BLT_MONOGC

Beamlet option: Disable all spreads and randomizations, set all guiding centers to 0 degree

◆ ROCK_MASK_BLT_SRC_MONOHARM

#define ROCK_MASK_BLT_SRC_MONOHARM

Beamlet option: Instead of summing all harmonical contributions, guess the harmonic numbers and apply only one harmonic for the source calculation. Enabling this causes less accurate exciation, but we get only the main frequency band of the field spectrum.

◆ ROCK_MASK_BLT_TAYLOR

#define ROCK_MASK_BLT_TAYLOR

Beamlet option: consider 2nd term of Taylor expansion.

◆ ROCK_MASK_BLT_VAR_UZ

#define ROCK_MASK_BLT_VAR_UZ

Beamlet option: consider variable axial velocity.

◆ ROCK_NODISCARD

#define ROCK_NODISCARD

◆ ROCK_PURE

#define ROCK_PURE

◆ ROCK_UNUSED

#define ROCK_UNUSED

Function Documentation

◆ cr_deprecated_make_cold_spectrum()

CROCK_API int cr_deprecated_make_cold_spectrum ( size_t dim_z,
const real *restrict vn_z,
const real *restrict vn_mod,
size_t dim_freq,
real *restrict freq,
real *restrict ampl )

Generate a spectrum of the cold resonance

Parameters
[out]freqis a 1D array with dimension [dim_freq]
[out]amplis a 1D array with dimension [dim_freq].
Returns
Error code

◆ cr_deprecated_search_cold_resonance()

CROCK_API int cr_deprecated_search_cold_resonance ( const real *restrict opt_ptr_ref_z,
size_t dim_m,
size_t dim_z,
const real *restrict vn_z,
const real *restrict mvn_mod,
cplx *restrict vm_freq )

Search resonance frequency for cold cavity

Warning
Since cold cavity is non-essential for interaction simulation, this API is just a temporary solution and will be changed in future.
Parameters
[in]opt_ptr_ref_zAn optional z-coordinate whose cut-off frequency will become the minimum frequency of the searching range. This is designed for gyrotron cavity simulation including up-taper, where the low-frequency resonances with profile maximum within the up-taper can be skipped. If NULL, the minimum cutoff of the whole geometry is the lower boundary of frequency range.
[out]vm_freqThe scalar complex resonance frequency (in Hz).
Returns
Error code

◆ cr_errmsg()

CROCK_API ROCK_PURE ROCK_NODISCARD const char * cr_errmsg ( int err)
Returns
The error message

◆ cr_find_all_cold_resonances()

CROCK_API int cr_find_all_cold_resonances ( size_t dim_z,
size_t opt_iz_min_fcut,
const real *restrict vn_z,
const real *restrict vn_mod,
const real *restrict tdm_c,
const real *restrict tdm_zk,
size_t dim_freq,
size_t *restrict out_dim_freq,
cplx *restrict out_cfreq )
Parameters
dim_freqThe maximum dim_freq allocated for the buffer
out_dim_freqThe number of actual resonance points
out_cfreqResonance frequencies, whose total dimension should be dim_freq, however, only contains *out_dim_freq number of valid resonances.
opt_iz_min_fcutThe index of grid node, whose cutoff frequency becomes lowest boundary of search interval. Ignored if opt_iz_min_fcut >= dim_z.
Returns
Error code

◆ cr_find_cold_resonance()

CROCK_API int cr_find_cold_resonance ( size_t dim_m,
const real *restrict opt_vm_freq_init,
size_t dim_z,
size_t opt_iz_min_fcut,
const real *restrict vn_z,
const real *restrict mvn_mod,
const real *restrict tdm_c,
const real *restrict mv_tdm_zk,
cplx *restrict vm_cfreq )
Parameters
[in]opt_vm_freq_initThe initial frequencies for the searching. If opt_vm_freq_init == NULL or opt_vm_freq_init[im] <= 0, the resonances with the highest Q are searched; otherwise, for each mode, a resonance close to the given frequency is to be found.
[in]tdm_cThe matrix Mc
[in]mv_tdm_zkThe TDM (Mz-Mk) per mode
opt_iz_min_fcutThe index of grid node, whose cutoff frequency becomes lowest boundary of search interval. Ignored if opt_iz_min_fcut >= dim_z. opt_vm_freq_init overrides this parameter, if both are provided.
Returns
Error code

◆ cr_free()

CROCK_API void cr_free ( void * ptr)

◆ cr_guess_dim_cold_spectrum()

CROCK_API ROCK_PURE ROCK_NODISCARD size_t cr_guess_dim_cold_spectrum ( size_t dim_z,
const real *restrict vn_z,
const real *restrict vn_mod )
Returns
Suggested minimum number of frequency points in the spectrum, zero if error occurs

◆ cr_init_bd()

CROCK_API void cr_init_bd ( size_t dim_m,
const cplx *restrict vm_bc,
size_t dim_z,
const cplx *restrict mvn_env,
cplx *restrict vm_bd )

Initialize boundary data.

It assumes a stationary state a priori to the start of the simulation.

Since this function is used in all system simulations, instead of letting user manually initialize the vm_bd every time, CROCK provides a thin wrap of the process.

Parameters
[in]vm_bcBoundary conditions
[in]mvn_envEnvelopes
[out]vm_bdInitialized boundary data

◆ cr_init_bp()

CROCK_API void cr_init_bp ( size_t dim_m,
size_t dim_z,
const cplx *restrict mvn_env,
real *restrict vm_bp )
Parameters
[out]vm_bpPrevious boundary phase, has shape (2, dim_m).

◆ cr_make_bc_simple()

CROCK_API void cr_make_bc_simple ( size_t dim_m,
const real *restrict vm_freq,
size_t dim_z,
const real *restrict mvn_mod,
cplx *restrict vm_bc )

Single frequency boundary condition

Parameters
[in]vm_freqThe frequency at which the boundary is perfectly matched

◆ cr_make_bcc()

CROCK_API int cr_make_bcc ( real r_center,
real r_span,
size_t dim_m,
const int16_t *restrict vm_num,
size_t dim_z,
const real *restrict vn_mag_axis,
const real *restrict mvn_mod,
size_t dim_bcc,
real *restrict nvmh_bcc )

Make grid for Beam Coupling Coefficient (BCC)

The coupling coeffient is independent of frequency. This frequency is used to determine the harmonic number.

This is not an equi-flux grid, but equidistant grid, in order to make dim_bcc=1 at r_center rather than flux_center

Parameters
r_centerThe center radius (in meter) of BCC grid, at the entrance of the cavity. Typically one can choose the radius of the norminal beam guiding center.
r_spanThe relative span, should be larger than the beam radius span, otherwise the range of BCC grid will be cropped.
Returns
Error code

◆ cr_make_chi_TE_corr_holl_imp()

CROCK_API real cr_make_chi_TE_corr_holl_imp ( real d,
real w,
int16_t num_azi,
int16_t num_rad,
real *restrict opt_array_chi )

List eigenvalues from TE(m,1) to TE(m,n) of hollow modes with corrugated outer wall.

Warning
Impedance model is used!
Parameters
dRatio corrugation_depth / r_out
wRatio of (corrugation width) / (width of a period)
num_aziAzimuthal number (i.e. the m)
num_radThe maximum order of solution (i.e. the n)
opt_array_chiThe vector output, dimension = num_rad, whose zeroth element is the TE(m,1) mode. Ignored if NULL.
Returns
The last eigenvalue, NAN if input parameter is invalid

◆ cr_make_chi_TE_corr_ins()

CROCK_API real cr_make_chi_TE_corr_ins ( real r,
real d,
real w,
int16_t num_azi,
int16_t num_rad,
real *restrict opt_array_chi )

List eigenvalues of coaxial modes with corrugated insert from TE(m,1) to TE(m,n).

Parameters
rRatio r_in / r_out
dRatio corrugation_depth / r_out
wRatio of (corrugation width) / (width of a period)
num_aziAzimuthal number (i.e. the m)
num_radThe maximum order of solution (i.e. the n)
opt_array_chiThe vector output, dimension = num_rad, whose zeroth element is the TE(m,1) mode. Ignored if NULL.
Returns
The last eigenvalue, NAN if input parameter is invalid

◆ cr_make_cold_envelope()

CROCK_API int cr_make_cold_envelope ( size_t dim_m,
const cplx *restrict vm_rfc,
size_t dim_z,
const real *restrict vn_z,
const real *restrict mvn_mod,
cplx *restrict mvn_env )

Reconstruct profile for cold cavity

This function integrates the cold cavity wave equation once to obtain the field profile. It does not search resonance. Parameters see cr_search_cold_resonance().

Parameters
[in]vm_rfcThe complex resonance frequency for cold cavity
[out]mvn_envThe normalized complex envelope profile
Returns
Error code

◆ cr_make_cold_spectrum()

CROCK_API int cr_make_cold_spectrum ( int max_iter,
size_t dim_z,
const real *restrict vn_z,
const real *restrict vn_mod,
const real *restrict tdm_c,
const real *restrict tdm_zk,
size_t dim_freq,
real *restrict freq,
real *restrict ampl )

Generate a spectrum of the cold resonance

Parameters
[in]max_iter0 if no refinement is required, otherwise a positive number to get more accurate spectrum.
[out]freqis a 1D array with dimension [dim_freq]
[out]amplis a 1D array with dimension [dim_freq].
Returns
Error code

◆ cr_make_df()

CROCK_API void cr_make_df ( real elapsed_time,
size_t dim_m,
size_t dim_z,
const cplx *restrict mvn_new_env,
real *restrict mvn_old_env_phase,
real *restrict vm_df )

Calculate delta frequency

Parameters
[in,out]mvn_old_env_phasecarg(mvn_new_env) will be stored into mvn_old_env_phase.
[out]vm_dfThe frequency drift: new_freq = old_freq + df

◆ cr_make_fem()

CROCK_API int cr_make_fem ( size_t dim_m,
size_t dim_z,
const real *restrict vn_z,
const real *restrict mvn_mod,
real *restrict tdm_c,
real *restrict mv_tdm_zk )

Create matrices for FEM

Parameters
[out]tdm_cThe matrix Mc
[out]mv_tdm_zkThe TDM (Mz-Mk) per mode
Returns
Error code

◆ cr_make_mode_coax()

CROCK_API int cr_make_mode_coax ( size_t dim_m,
const int16_t *restrict vm_num,
size_t dim_z,
const real *restrict vn_geo_rout,
const real *restrict vn_geo_rin,
real *restrict mvn_mod )

Eigenvalue solver for coaxial waveguide (without corrugation)

Parameters
[in]vn_geo_routWaveguide outer radius
[in]vn_geo_rinWaveguide inner radius
Returns
Error code

◆ cr_make_mode_corr_holl_imp()

CROCK_API int cr_make_mode_corr_holl_imp ( size_t dim_m,
const int16_t *restrict vm_num,
size_t dim_z,
const real *restrict vn_geo_rout,
const real *restrict vn_geo_rel_w,
const real *restrict vn_geo_depth,
real *restrict mvn_mod )
Parameters
[in]vn_geo_routWaveguide outer radius in meter
[in]vn_geo_rel_wCarved width divided by width period
[in]vn_geo_depthCorrugation depth in meter
Returns
Error code

◆ cr_make_mode_corr_ins()

CROCK_API int cr_make_mode_corr_ins ( size_t dim_m,
const int16_t *restrict vm_num,
size_t dim_z,
const real *restrict vn_geo_rout,
const real *restrict vn_geo_rin,
const real *restrict vn_geo_rel_w,
const real *restrict vn_geo_depth,
real *restrict mvn_mod )
Parameters
[in]vn_geo_routWaveguide outer radius in meter
[in]vn_geo_rinWaveguide outer radius in meter
[in]vn_geo_rel_wCarved width divided by width period
[in]vn_geo_depthCorrugation depth in meter
Returns
Error code

◆ cr_make_mode_holl()

CROCK_API int cr_make_mode_holl ( size_t dim_m,
const int16_t *restrict vm_num,
size_t dim_z,
const real *restrict vn_geo_rout,
real *restrict mvn_mod )
Parameters
[in]vn_geo_routWaveguide outer radius
Returns
Error code

◆ cr_make_potential()

CROCK_API void cr_make_potential ( real pot_outer,
real opt_pot_inner,
const real *restrict beam_init,
size_t dim_z,
const real *restrict vn_mag_axis,
const real *restrict vn_rhocd,
const real *restrict vn_r_outer,
const real *restrict opt_vn_r_inner,
real *restrict vn_pot )

Make depression voltage from charge density and geometry

Parameters
pot_outerPotential of outer boundary
opt_pot_innerPotential of coaxial insert (unused for hollow cavity)
[in]beam_initFrom which the initial guiding center is extracted
[in]vn_mag_axis$B$ field on the axis
[in]vn_rhocdCharge density (which has negative values)
[in]vn_r_outerRadius of outer boundary
[in]opt_vn_r_innerRadius of coaxial insert (NULL for hollow cavity)
[out]vn_potElectric potential

◆ cr_make_power_out()

CROCK_API void cr_make_power_out ( size_t dim_m,
const real *restrict vm_cf,
size_t dim_z,
const real *restrict mvn_mod,
const cplx *restrict mvn_env,
real *restrict opt_vm_pout_left,
real *restrict opt_vm_pout_right )

Calculate output power of each mode on each boundary, assuming zero reflection at frequency vm_cf.

Parameters
[out]opt_vm_pout_leftIf not NULL, the vector in shape [dim_m] will store the output power
[out]opt_vm_pout_rightIf not NULL, the vector in shape [dim_m] will store the output power

◆ cr_make_uload()

CROCK_API void cr_make_uload ( size_t dim_m,
size_t dim_z,
const cplx *restrict mvn_env,
const real *restrict mvn_uuload,
real *restrict vn_uload )

Apply the field of each mode and sum the unscaled ohmic load. The final load is vn_uload / sigma at each node.

Parameters
[out]vn_uloadThe unscaled load

◆ cr_make_uuload()

CROCK_API void cr_make_uuload ( size_t dim_m,
const int16_t *restrict vm_num,
const real *restrict vm_freq,
size_t dim_z,
const real *restrict vn_radius,
const real *restrict mvn_mod,
real *restrict mvn_uuload )

Make unscaled ohmic load per mode

Parameters
vm_freqThe frequency where the ohmic load is evaluated at
vn_radiusThe radius where the ohmic load is evaluated at, for example, the profile of outer wall or coaxial insert
[out]mvn_uuloadThe very unscaled load

◆ cr_malloc()

CROCK_API ROCK_MALLOC void * cr_malloc ( size_t size)

◆ cr_numa_bless()

CROCK_API int cr_numa_bless ( void *restrict buf,
size_t sizeof_type,
size_t dim_shape,
const size_t *restrict shape )

Set the data of buf to zero.

It performs the NUMA first-touch onto shape[0] static parallel nodes, but does not assert the alignment of page boundaries on shape[0].

Returns
Error code

◆ cr_refine_z()

CROCK_API int cr_refine_z ( real weight,
size_t dim_z,
const real *restrict vn_z,
const real *restrict vn_mrs,
size_t dim_z_new,
real *restrict vn_z_new )

Remap vn_z into vn_z_ne considering the mesh refinement score.

Parameters
weightweight=0 means not using vn_mrs while keeping the original density; weight=1 is a moderate value which does not make the coarse segments too much coarser; weight=infinite means only weighted by vn_mrs.
Returns
Error code

◆ cr_shoot_beamlet()

CROCK_API int cr_shoot_beamlet ( uint32_t options,
const real *restrict beam_init,
size_t dim_m,
const int16_t *restrict vm_num,
const real *restrict vm_cf,
const real *restrict vm_cp,
size_t dim_z,
const real *restrict vn_z,
const real *restrict vn_pot,
const real *restrict vn_mag_axis,
const real *restrict mvn_mod,
const cplx *restrict mvn_env,
size_t dim_b,
size_t dim_bcc,
real bcc_r_center,
real bcc_r_span,
const real *restrict nvmh_bcc,
uint32_t * seed,
real *restrict vn_rhocd,
cplx *restrict mvn_src,
real *restrict opt_vn_mrs,
real *restrict opt_vn_blt_avg,
real *restrict opt_bvn_blt_trj,
struct cr_cache *restrict *restrict opt_pp_cache )

Simple beamlet model

Stochastic inputs are generated in GPU to save transfer of huge beam arrays

Assume:

  • Homogeneous distribution of guiding center radius
  • Homogeneous distribution of guiding center azimuthal angle
  • Homogeneous distribution of initial phase
  • Bz of guiding center is approached by Bz of axis
  • Br is calculated from numerical derivative of Bz
Parameters
optionsBit pattern consists of ROCK_MASK_BLT_*
beam_initBeam initial data See enum BEAM_INIT.
bcc_r_centerThe same parameter used in cr_make_bcc()
bcc_r_spanThe same parameter used in cr_make_bcc()
[in,out]seedRandom seed
[in]vn_potRelative electrical potential at guiding center. Since only its numerical derivative is needed, an arbitrary offset can be applied.
[out]vn_rhocdCharge density (of this MPI node) which will be used to calculate vn_pot for the next iteration.
[out]mvn_srcExcitations (of this MPI node), which should be weighted by FEM matrix Mc
[out]opt_vn_mrsMesh refinement score. The i'th index designates the mesh segment between i'th and (i+1)'th node, i.e., a new node should be added in the middle of this segment for refinement.
[out]opt_vn_blt_avgOptional averaged data, NULL if not required, see enum ROW_OF_BLT_AVG.
Returns
Error code

◆ cr_step_field()

CROCK_API int cr_step_field ( real dt,
size_t dim_m,
const real *restrict vm_cf,
const cplx *restrict vm_bc,
size_t dim_z,
const real *restrict tdm_c,
const real *restrict mv_tdm_zk,
const cplx *restrict mvn_src,
cplx *restrict vm_bd,
cplx *restrict mvn_env,
real *restrict opt_vm_cp,
real *restrict opt_vm_df,
struct cr_cache *restrict *restrict opt_pp_cache )

Step the field envelope profile

Parameters
[in]vm_cfCarrier frequency in Hz
[in]vm_bcBoundary condition
[in]mvn_srcNon-weighted excitation per mode (unit: V/m^2)
[in,out]vm_bdBoundary data
[in,out]mvn_envEnvelope profile
[in,out]opt_vm_cpCarrier phase, can be NULL
[out]opt_vm_dfFrequency shift for vm_cf[:] += opt_vm_df[:]. Set to NULL to save computational efforts..
Returns
Error code

◆ cr_step_field_gpu()

CROCK_API int cr_step_field_gpu ( real dt,
size_t dim_m,
const real *restrict vm_cf,
const cplx *restrict vm_bc,
size_t dim_z,
const real *restrict tdm_c,
const real *restrict mv_tdm_zk,
const cplx *restrict mvn_src,
cplx *restrict vm_bd,
cplx *restrict mvn_env,
real *restrict opt_vm_cp,
real *restrict opt_vm_df,
struct cr_cache *restrict *restrict opt_pp_cache )

Doc see the CPU version.

◆ cr_step_field_offload()

CROCK_API int cr_step_field_offload ( real dt,
size_t dim_m,
const real *restrict vm_cf,
const cplx *restrict vm_bc,
size_t dim_z,
const real *restrict tdm_c,
const real *restrict mv_tdm_zk,
const cplx *restrict mvn_src,
cplx *restrict vm_bd,
cplx *restrict mvn_env,
real *restrict opt_vm_cp,
real *restrict opt_vm_df,
struct cr_cache *restrict *restrict opt_pp_cache )

Doc see the CPU version.

◆ cr_stride_cplx()

CROCK_API ROCK_PURE ROCK_NODISCARD size_t cr_stride_cplx ( size_t dim)

Calculate stride including padding.

Parameters
dimData dimension without padding
Returns
Stride

◆ cr_stride_real()

CROCK_API ROCK_PURE ROCK_NODISCARD size_t cr_stride_real ( size_t dim)

Calculate stride including padding.

Parameters
dimData dimension without padding
Returns
Stride

◆ cr_tdm_solve()

CROCK_API int cr_tdm_solve ( size_t systems,
size_t rows,
const cplx *restrict multi_mat,
const cplx *restrict multi_vec,
cplx *restrict multi_x )

Solve x from mat*x == vec

Returns
Error code

◆ cr_tdm_solve_offload()

CROCK_API int cr_tdm_solve_offload ( size_t systems,
size_t rows,
const cplx *restrict multi_mat,
const cplx *restrict multi_vec,
cplx *restrict multi_x )

Solve x from mat*x == vec

Returns
Error code

◆ cr_update_bc_simple()

CROCK_API void cr_update_bc_simple ( real dt,
size_t dim_m,
const real *restrict vm_cf,
size_t dim_z,
const real *restrict mvn_mod,
const cplx *restrict mvn_env,
real *restrict vm_bp,
cplx *restrict vm_bc )
Parameters
[in,out]vm_bpPrevious boundary phase, has shape (2, dim_m). initialized by cr_init_bp()
[out]vm_bcUpdated boundary condition

◆ cr_version_major()

CROCK_API ROCK_CONST ROCK_NODISCARD int cr_version_major ( void )

◆ cr_version_minor()

CROCK_API ROCK_CONST ROCK_NODISCARD int cr_version_minor ( void )

◆ cr_version_patch()

CROCK_API ROCK_CONST ROCK_NODISCARD int cr_version_patch ( void )