AddingBeam - adda-team/adda GitHub Wiki

All places in the code, where something should be added, are commented. These comments start with TO ADD NEW BEAM and contain detailed description; the text below is less detailed. Added code should be analogous to beam types already present. The procedure is the following:

  • Add new beam descriptor in the file const.h. Starting descriptor name with B_ is recommended, as well as adding a descriptive comment.
  • Add information about the new beam type in the file param.c. It should be a new row in the constant array beam_opt. This line should contain: the beam name (it will be used in a command line), usage string (the description of possible input parameters), help string (it will be shown when -h option is used), possible number of parameters (real values), beam descriptor. If this beam type can accept variable number of parameters use UNDEF instead of a number and then check the number of parameters explicitly in function PARSE_FUNC(beam) (below in the same file). If beam type accepts a single parameter with a file name, use FNAME_ARG instead.
  • Add initialization of the new beam type as a new case in the long switch in the function InitBeam in the file GenerateB.c. This initialization should save all parameters from the array beam_pars to local variables, which should be declared in the beginning of the file (the place for that is shown by a comment). Then test all input parameters for consistency (for that you are encouraged to use functions from param.h since they would automatically produce informative output in case of error). If the shape breaks any symmetry, corresponding variables should be set to false. However, asymmetry due to location of beam center is handled automatically. Then initialize the following variables: 1) beam_descr – descriptive string that would be shown in the log; 2) vorticity - (only for vortex beam) integer value, how many turns the phase experience, when one makes a full turn around the beam axis; 3) all other auxiliary variables that are used in beam generation (below). If the new beam type is incompatible with -surf, add an explicit exception. If you need temporary local variables (which are used only in this part of the code) declare them in the beginning of InitBeam function or inside a specific case. In the latter variant, surround the whole case with braces.
  • Add definition of the new beam type as a new case in the long switch in the function GenerateB in the file GenerateB.c. This definition should set complex vector b, describing the incident field in the particle reference frame. It is set inside the cycle for each dipole of the particle and is calculated using 1) DipoleCoord – array of dipole coordinates; 2) prop – propagation direction of the incident field; 3) ex – direction of incident polarization; 4) ey – complementary unity vector of polarization (orthogonal to both prop and ex); 5) beam_center – beam center in the particle reference frame (automatically calculated from beam_center_0 defined by -beam_center command line option). If the new beam type is compatible with '-surf', include here the corresponding code. For that you will need the variables, related to surface, defined in vars.c. In that case you also need to define inc_scale. If you need temporary local variables (which are used only in this part of the code), either use t1t8 or declare your own (with more informative names) in the beginning of GenerateB function.
  • Take a look at function ExtCross in file crosssec.c. Used formulae for non-plane beams assume that the amplitude of the beam is unity at the focal point. So either make sure that the new beam type satisfies this condition or add other formulae to this function.

Please refer to section Incident Beam of the manual for description of the above-mentioned variables and for general overview of how the incident beam is treated inside ADDA.

If you add a new predefined beam type to ADDA according to the described procedure, please consider contributing your code to be incorporated in future releases.