## 1 Introduction  
Synchrotrons and free electron lasers (FELs) are constructed for the production of bright beams of electromagnetic radiation, which is essential for a detailed exploration of surrounding matter [1]. This radiation is efficiently induced by bending the trajectories of highly relativistic electrons within a static magnetic field. One of the crucial parts of such synchrotrons is undulators. An extensive overview of the various solutions for undulators has been performed by [PERSON] [2]. The most common solution is the straightforward planar undulator design [3], where each girder comprises a single row of magnetic arrays. The wavelength of the emitted light can be modified by adjusting the position of the girders with respect to the beam axis. There are also more advanced undulator designs based on the above solution that can be found in so-called Apple-type undulators [4], which utilize four magnetic arrays. Here, by moving the opposing arrays in an appropriate sequence along the beam axis, it becomes possible to switch the polarization of the emitted light from linear to circular. As the requirements for beam quality have increased, further modifications have been developed. Currently, several configurations exist that contain four rows of magnets, adapted to specific scientific needs. These include Apple II [5] and Apple III [6; 7], Delta [8], and Apple X [9], with differences primarily in their cross-section and orientations of the magnets. A spatially periodic magnetic field is generated between two parallel arrays of magnets. This magnetic setup, known as the Halbach array, was originally invented in 1980 by [PERSON] to control the beam in particle accelerators and free electron lasers [10; 11; 12]. The objective of this configuration is to strengthen the magnetic field between the arrays, where the electrons are passing, in order to control their trajectory, while simultaneously weakening the magnetic field on the opposite side. Permanent magnets or electromagnets are used to generate a magnetic field based on the specific field parameters required. There are only several families of permanent magnetic materials suitable for these applications [13]. The most frequently used alloys include neodymium magnets (NdFeB--neodymium, iron, and boron) [14], SmCo (samarium, cobalt), and PrFeB magnets (praseodymium, iron, and boron) [15]. These magnets vary in terms of grade, magnetic remanence, coercivity, radiation resistance, and maximum operating temperature. The common feature of all high-strength permanent magnets is their brittleness, which makes them susceptible to chipping and cracking. This inconvenience should be taken into account in designing magnet holders and during the choice of the maximum load applied to the magnet. A large cross-section of the emitted THz beam requires a wide aperture, across which a sufficient field must be achieved. That leads to a high remanence requirement for the NdFeB blocks. The interaction of the electron beam with a constant magnetic field induces electron oscillations, which subsequently lead to the emission of radiation with a frequency and intensity governed by the field period and a tunable amplitude. This underscores the key importance of magnet quality and the precision of its positioning for the brightness and coherence of the light source, as well as for the further propagation of the electrons. In linear accelerator-driven light sources, the radiation frequency can be controlled by independently tuning both the electron energy \(E_{e}\) and the undulator field amplitude \(B_{0}\). Light of the desired frequency can be emitted for various \(E_{e}\), \(B_{0}\) couples. An appropriate selection of parameters allows one to choose the integrated flux or the brightness maximization, alternatively. The useful information related to the design and optimization of undulators as well as useful analytical formulations can be found in References [16; 17]. The applied period of the magnetic array is determined through the optimization procedure.