1 Introduction

The most important part of laser application is about the interaction between the laser beams and the irradiated substances, such as laser cleaning [1, 2], laser marking [3, 4] and laser engraving [5], etc. Generally, the light intensity in the cross-section perpendicular to the propagation direction of the beam follows a Gaussian distribution. In the case, the light energy is excessively concentrated in the beam center, and the laser crystal, the optical element or the object to be processed could be easily damaged. Therefore, we need to convert a Gaussian beam into a flat-top one in fields of laser cleaning, laser medicine, optical information storage and optical information processing.

There are lot of shaping tools that can turn Gaussian beam into flat-top one, for example, phase diffractive optical elements [6, 7], refractive or reflective elements [8, 9], hollow polygonal light pipes [10], micro-optical components [11], phase holograms [12, 13], liquid crystal spatial light modulators [14], and so on. In these shaping tools, refractive beam-shaping elements have become the most commonly used one for its high energy conversion efficiency and simple structure [15].

Geometrical optics is generally used for the design of refractive beam-shaping elements with the condition of energy conservation. First, the coordinate mapping between ray intersections at the input and output planes is established. Second, the differential equation describing the shape at corresponding points is constructed according to the mapping relation and Snell’s law. Then, by means of a reasonable approximation, the derivative of the sag with respect to the height of the surface can be obtained and solved. This method was first presented by Frieden [16]. Kreuzer applied patent for the method in 1969 [17], and it is still widely used today. Rhodes [18] and Hoffnagle [19, 20] further researched and developed this technique for establishing a mapping between the output and input rays. The later researches contributed to the simplification of practical design [21] and more optimized design steps [22]. Cheng-Mu Tsai et al. [23,24,25] designed aspheric shaping lens systems using a genetic algorithm, the designed shaping system can convert laser beams into beams with a variety of different spot shapes. When the spot diameter is reduced from 3 to 1.07 mm, the light intensity uniformity is 88%; the spot diameter increase from 3 to 5.273 mm, and the light intensity uniformity is 90%. Compared with differential equation methods, the optimization algorithm does not need to solve differential equations. Structural parameters that represent all the characteristics of a beam shaping system are sought through the optimization processes. The global optimization method of the commercial software ZEMAX includes the genetic algorithm. However, the most commonly used method in Zemax is the damped least square method which is heavily dependent on the choice of initial structure, the solution obtained by this method is usually a local minimum of the merit function, and it is usually one lying near to the starting point. Design results are heavily dependent on initial structures, and designers’ experience still plays a vital role in the design process.

The particle swarm optimization algorithm, just like the genetic algorithm, is also a global optimization algorithm. Since its advent in 1995 [26], this algorithm has not been applied in the design of beam shaping lens in the published literature. Therefore, it is a useful attempt to apply the PSO algorithm to design beam shaping lenses, which can not only enrich the design methods of beam shaping system, also promote the development of PSO itself. In comparison to Zemax, the PSO method does not require the initial datum of structural variables, therefore, the PSO method is more intelligent, and depends less on the experience of the designer.

Two-element beam shapers and single-element beam shapers have been designed for testing the effectiveness of this method. The designed shapers can not only transform Gaussian beams into flat-top beams but also re-collimate output beams.

In the second section, according to the conservation of energy and constant optical path length, we derive an expression for the output ray coordinate as a function of the input ray coordinate when a plane wave Gaussian beam is transformed into a plane wave flat-top beam. A beam shaping merit function is defined based on the coordinate expression of ray–plane intersection, and a brief description on the PSO optimization methods that will be used to design laser beam shapers is given. The lens shape and spacing parameters are used as optimization variables, and the optimum parameter combination gives the smallest value of the merit function. In the third part of this paper, several detailed design examples are included to illustrate this approach, and design results are also discussed. The fourth section is the conclusion.

2 Design method

In this part, we describe in detail the new method for designing a beam shaping lens that can convert a Gaussian beam into a flat-top one, and give the merit function in line with this transformation. According to the energy conservation of specific areas before and after conversion, the relationship between the output ray coordinate and the input ray coordinate is derived. The PSO algorithm used to search for the minimum value of merit function is discussed in brief.

2.1 Energy conservation in a beam shaping lens

Figure 1 is a schematic diagram illustrating the conversion of a Gaussian beam to a flat-top beam. A laser beam shaper is rotationally symmetric about the optical axis. The Gaussian intensity profile of input beam is described by \(I\left( r \right)={I_{\text{0}}}\exp \left( {{{ - 2{r^2}} \mathord{\left/ {\vphantom {{ - 2{r^2}} {r_{0}^{2}}}} \right. \kern-0pt} {r_{0}^{2}}}} \right)\), here I0 is the intensity at the center of the beam, r is defined as the radial distance from the center of the beam, rmax is the corresponding maximum distance, and r0 is the spot radius at which the light intensity is 1/e2 of its value at the beam center. The output beam is a flat-top beam with a uniform light intensity Iout, 2Rmax is the maximum irradiated width in the radial direction. Obviously, the input energy within a circle of radial distance r from beam center is

$$A=\int\limits_{0}^{r} {{I_0}{e^ - }^{{\frac{{2{r^2}}}{{r_{0}^{2}}}}}} 2\pi r{\text{d}}r=\frac{{\pi {I_0}r_{0}^{2}}}{2}\left[ {1 - {e^{ - 2{r^2}/r_{0}^{2}}}} \right],$$
(1)
Fig. 1
figure 1

The schematic diagram of transformation of a Gaussian beam into a flat-top one

The output beam energy at output plane within a circle of radius R is

$$B=\int_{0}^{R} {{I_{{\text{out}}}}2\pi R{\text{d}}R} =\pi {I_{{\text{out}}}}{R^2}.$$
(2)

Without considering reflection and absorption losses by lenses, then, the energy of the input beam is equal to that of the output beam, A = B, namely

$$\frac{{\pi {I_0}r_{0}^{2}}}{2}\left[ {1 - \exp ( - 2{r^2}/r_{0}^{2})} \right]=\pi {I_{{\text{out}}}}{R^2},$$
(3)
$${R^2}=\frac{{{I_0}r_{0}^{2}}}{{2{I_{{\text{out}}}}}}\left[ {1 - \exp \left( { - 2{r^2}/r_{0}^{2}} \right)} \right].$$
(4)

Moreover, the total output energy equals the total input energy

$$\frac{{\pi {I_0}r_{0}^{2}}}{2}\left[ {1 - \exp \left( { - \frac{{2r_{{{max} }}^{2}}}{{r_{0}^{2}}}} \right)} \right]=\pi {I_{{\text{out}}}}R_{{{max} }}^{2},$$
(5)
$${I_{{\text{out}}}}=\frac{{{I_0}r_{0}^{2}}}{{2R_{{{max} }}^{2}}}\left[ {1 - \exp \left( { - \frac{{2r_{{{max} }}^{2}}}{{r_{0}^{2}}}} \right)} \right].$$
(6)

Substituting the above expression into Eq. (4), we can get

$$R(r)={\left[ {\frac{{1 - \exp \left( { - \frac{{2r_{{}}^{2}}}{{r_{0}^{2}}}} \right)}}{{1 - \exp \left( { - \frac{{2r_{{\hbox{max} }}^{2}}}{{r_{0}^{2}}}} \right)}}} \right]^{\frac{1}{2}}}{R_{{max} }}.$$
(7)

The above expression provides a theoretical value of ray intersection coordinate at the output plane for a given incident ray of radius r at the input plane. Such a coordinate conversion between input and output rays following the above expression will turn Gaussian beams into flat-tops. Equation (7) will be used to define the merit function of a beam shaping lens.

2.2 Merit function

Suppose there are N rays incident on a beam shaping lens, the radial coordinate of the ith incident ray at the input plane is ri, taking

$${r_i}=(i - 1)\frac{{{r_{\hbox{max} }} - {r_{{min} }}}}{{N - 1}},$$
(8)

where \({r_{{max} }}\) and \({r_{{min} }}\) are the maximum and minimum radial distances at the input plane, respectively.

Suppose that the actual radial coordinate of the ith light ray at the output plane after a beam shaping lens is Ria, and the corresponding theoretical coordinate is \({R_{i{\text{t}}}}\), therefore, the merit function of a beam shaping lens is defined as

$$F=\sum\limits_{{i=1}}^{N} {\left| {{R_{i{\text{a}}}} - {R_{i{\text{t}}}}} \right|} .$$
(9)

If each ray is given a weighting factor wi based on its coordinate position, then the merit function can be rewritten as

$$F=\sum\limits_{{i=1}}^{N} {{w_i}\left| {{R_{i{\text{a}}}} - {R_{i{\text{t}}}}} \right|} ,$$
(10)

where Rit is calculated using Eq. (7), and Ria can be obtained using the ray tracing technique.

As shown in Fig. 2, let shaping lenses be rotational symmetry about the x-axis (optical axis), also it is assumed that the input Gaussian beam has been collimated along the x-axis. \({\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\rightharpoonup}$}} {Q} _{ii}}({\alpha _{ii}},0,0)\) is the unit vector along the direction of the input beam, the coordinate of a point on an incident ray be Pii(xi, yi, zi), the unit vector and the coordinate of the corresponding output light ray at the output plane are \({\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\rightharpoonup}$}} {Q} _{i{\text{o}}}}({\alpha _{i{\text{o}}}},{\beta _{i{\text{o}}}},{\gamma _{i{\text{o}}}})\) and \({P_{i{\text{o}}}}({X_i},{Y_i},{Z_i})\).

Fig. 2
figure 2

The schematic diagram of ray tracing process

$$r_{i}^{2}=y_{i}^{2}+z_{i}^{2},$$
(11)
$$R_{{i{\text{a}}}}^{2}=Y_{i}^{2}+Z_{i}^{2}.$$
(12)

Giving Pii and \({\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\rightharpoonup}$}} {Q} _{ii}}\), \({P_{i{\text{o}}}}\) and \({\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\rightharpoonup}$}} {Q} _{i{\text{o}}}}\) can be calculated from the law of refraction and a surface equation.

To make the conventional optical element easy to operate, such as the zooming element or the focused element, a flat-top beam with a long working distance is often necessary. Therefore, the output beam needs to be re-collimated. For this reason, add a new term to the merit function Eq. (10)

$${F_\alpha }=\sqrt {\sum\limits_{{i=1}}^{N} {{w_{i\alpha }}\left( {1 - {\alpha _{i{\text{o}}}}} \right)} ,}$$
(13)

where \({\alpha _{i{\text{o}}}}\) is the direction cosine of the ith light ray at the output plane in the x direction, and can be calculated by tracing rays; \({w_{i\alpha }}\) is the weight factor of the ith light ray. \({F_\alpha }\) can be called the merit function of collimation. Add \({F_\alpha }\) to Eq. (10) and Eq. (10) becomes Eq. (14)

$$F=\sum\limits_{{i=1}}^{N} {{w_i}\left| {{R_{i{\text{a}}}} - {R_{i{\text{t}}}}} \right|} +\sqrt {\sum\limits_{{i=1}}^{N} {{w_{i\alpha }}\left( {1 - {\alpha _{i{\text{o}}}}} \right)} } .$$
(14)

This merit function will be minimized during the optimization process for the design of beam shaping lenses.

If \({\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\rightharpoonup}$}} {Q} _{ii}}\)and Pii are given, the merit function F is only the function of structure parameters of a shaping lens. That is to say, as long as these structure parameters are appropriately selected, the merit function of a shaping lens can have the minimum value.

2.3 The particle swarm optimization algorithm applied to design of a shaping lens system

The PSO algorithm has been successfully applied to the design of imaging optical systems [27], and this paper again proposes a new application of the PSO algorithm in the field of non-imaging optical systems. It can be used to perform global searches [28], and also can be used to perform local searches [29]. In shaping lens systems, the best system we define is one having the smallest merit function value. To find the best variable parameters in a system’s structure space, we organize the corresponding PSO program in Matlab, and the merit function is used as a fitness function in the PSO algorithm. It is worth mentioning that although the PSO algorithm is a kind of global optimization algorithm, there is no guarantee that the structure parameters which minimize the merit function must be found. To ensure global optimization, scientists are constantly exploring the methods for jumping out of the local minimum. On the other hand, for optical design, as long as the structure parameters with a local minimal merit function meets our actual requirements, even if the global minimum is not found, the search is also thought to be successful. In general, we can always find the most suitable one from multiple running results of the program.

Characteristics of the PSO algorithm applied to the design of a beam shaping lens are described as follows:

  1. 1.

    A swarm consists of a number of particles which have velocity and position, but no mass. The ith particle’s position vector Xi = (xi1, xi2,…, xiD) corresponds to the ith candidate solution of the considered optimization problem, which is represented by a fitness value, where D means the dimension of the solution space. For a beam shaping lens system, the fitness value is the merit function value of a shaping system, and can be calculated from Eq. (14). The ith particle’s velocity vector is expressed as Vi = (υi1, υi1,…,υiD).

The velocities and positions of the particles are iteratively updated by the best fitness value Gbest in a swarm’s history and the best fitness value Pbest in an individual particle’s history, until a stopping criterion is met. The particle’s position corresponding to Gbest after all iterations is the structure parameters of a beam shaper we are looking for. Please refer to [30] for the update process.

  1. 2.

    The dimension of each particle’s position vector or velocity vector is the number of structural parameter variables characterizing a shaping lens system, the value ranges of each dimension variable of the position vector are reasonably chosen according to the characteristics of system structure parameters.

  2. 3.

    It is worth mentioning that there is no concrete functional form between the merit function and system structure parameters, the relationship between them is only an invisible function, and this kind of indirect relationship has been given in Sects. 2.1 and 2.2.

  3. 4.

    The optimization process of the PSO algorithm, in fact, is the process of searching for a specific merit function value (maximum, minimum, or a certain value), namely, is the process of looking for a beam shaping system whose merit function meets our requirements, this is the design of a beam shaping system.

  4. 5.

    There are standard PSO and its different variants, and we can choose an algorithm most suitable for the design of a beam shaping lens by experiment. In this paper, we use the standard PSO to design the beam shaping lenses.

3 Design examples

To evaluate the performance of the PSO optimization approach for the design of laser beam shapers, we first design two beam shapers consisting of two plano-aspheric lenses using this method, then test the correctness of the design results by simulations in ZEMAX software. These beam shapers can transform a rotationally symmetric Gaussian laser beam into a uniform irradiance output beam. The input Gaussian profile beam has a radius of 8 mm, which equals the radius of the entrance pupil, and a wavelength of 589 nm. 589 nm laser can effectively cure cutaneous hemangiomas, port wine stains and retinal detachment, because hemoglobin has high absorption rates for lasers with wavelengths between 589 and 593 nm. The shaping of a 589-nm Gaussian beam into a flat-top beam can be more powerful in promoting its therapeutic applications.

The lens material is chosen to be CaF2, and the size of a lens is measured in millimeters. The aspherical lens surface is a rotationally symmetric aspheric surface described by the following even aspheric equation:

$$x=\frac{{C{h^2}}}{{1+\sqrt {1 - {h^2}{C^2}(1+{a_2})} }}+\sum\limits_{{j=2}}^{4} {{a_{2j}}{h^{2j}}} ,$$
(15)

where \(h=\sqrt {{y^2}+{z^2}}\) is a vertical distance from a point on an aspheric surface to the optical axis, C is the curvature of the aspheric surface, \({a_2}\) is the constant of the cone, and \({a_{2j}}\) denotes the coefficient of aspheric surface deformation. Therefore, the structure variables for applying the PSO method are C, \({a_2}\), \({a_{2j}}\), the lens thickness and the separation for two lenses. Therefore, there are seven variables altogether in this analysis, which denotes that the dimension of each particle’s position vector is seven in the PSO algorithm. The distance from the last surface of the 2nd lens to the output plane is 25 mm for both designs.

3.1 Two plano-aspheric lenses beam shaper

The beam shaping system will convert the input Gaussian profile beam of 8 mm radius to an uniform profile output beam of 12 mm radius, the entrance pupil diameter is 16 mm, therefore r0 and Rmax in Eq. (7) are respectively equal to 8 mm and 12 mm, rmax = r0. Therefore, Eq. (7) can be specifically written as

$$R(r)=12{\left[ {\frac{{1 - \exp \left( { - \frac{{r_{{}}^{2}}}{{32}}} \right)}}{{1 - \exp ( - 2)}}} \right]^{\frac{1}{2}}}.$$
(16)

R in the above equation is Rit in Eq. (14). Substitute Eq. (16) into Eq. (14) and let \({w_i}=w{}_{{i\alpha }}=1\), N = 41. Taking Eq. (14) as a fitness function in the PSO algorithm and searching for a particle with the minimal fitness function value, then the component of position vector of this particle is structure parameters of a beam shaper to be designed.

Table 1 lists the value ranges of structure parameters when we use the PSO algorithm to design a beam shaping lens. The number of particles and the iteration times are chosen as 30 and 2000, respectively. The program compiled by ourselves runs for about 30 min on the PC. Figure 3 shows the convergence curve of fitness value versus the number of iterations, and the smallest fitness value is 0.8889.

Table 1 The value ranges of the parameters of aspheric equation
Fig. 3
figure 3

Evolution of fitness function with the number of iterations

Table 2 lists the system parameters of the designed two-lens shaping systems using the beam shaping merit function and PSO optimization procedures described in this paper. Put the parameters of design example 1 into the Zemax lens data editor, as shown in Fig. 4. Figure 5a, b shows 2D optical layouts plotted by Zemax for the designed two-lens beam shapers, respectively. Both figures show that an input beam with Gaussian intensity distribution has been redistributed to form a uniform irradiance of the output beam with good collimation along the optical axis. The one-dimensional scans of relative illumination on the output plane for both design examples are shown in Fig. 6, which confirm that the input Gaussian beam has been transformed to a more uniform output beam in both x and y directions. Therefore, the design method for laser beam shaper described in Sect. 2 has been successively applied to the design of the two plano-aspheric lenses beam shaper.

Table 2 The design of two-plano-aspheric-lens laser beam shapers
Fig. 4
figure 4

The aspheric parameters of design example 1 in Table 2 were put into the ZEMAX Lens Data Editor

Fig. 5
figure 5

The 2D optical layouts of the designed two-plano-aspheric-lens beam shapers

Fig. 6
figure 6

The x-scan and y-scan plots of relative illumination on the output plane of the designed two-lens Gaussian beam shapers (a) design example 1; (b) design example 2

On locating the optimum observation plane, the flat-top quality is evaluated by beam uniformity and steepness as follows [31]:

Uniformity:

$$U=\frac{{{I_{{max} }} - {I_{{min} {\text{valley}}}}}}{{{I_{{max} }}}},$$

where \({I_{{max} }}\) is the peak intensity, \({I_{{min} {\text{valley}}}}\) is the intensity at the bottom of the valley in the flat-top region.

Steepness:

$$K=\frac{{{r_2}@90\% \;{\text{of peak intensity}}}}{{{r_2}@10\% \;{\text{of peak intensity}}}},$$

where r2 is the radial distance to the shaped beam center at the observation plane. For relative illumination diagrams of both design examples shown in Fig. 6, we have U = 5.5% and 6.9%, and K = 0.84 and 0.82, respectively.

Uniformity values from Fig. 6a and b do not agree with the visual inspection of Fig. 6a and b. In our opinion, a possible reason for this inconsistency is the difference in tracing ray number. In fact, Fig. 6a has been plotted with the help of 1 million rays, and Fig. 6b with the help of 10 million rays.

Figure 7 presents the 3D simulations of relative illumination (RI) on the output plane of the designed two-lens Gaussian beam shapers, which are plotted in Matlab programs compiled by ourselves, it also shows the consistency of relative illumination in Figs. 6 and 7. It can be seen more comprehensively from Fig. 7 that a Gaussian input beam has indeed been converted to a uniform flat-top beam, which also prove that the method to design a beam shaping lens with the PSO algorithm is feasible and effective.

Fig. 7
figure 7

The 3D simulations of relative illumination on the output plane of the designed two-lens Gaussian beam shapers (a) design example 1; (b) design example 2

3.2 Single lens beam shaper

Although a two-lens laser beam shaper is widely used, a single-lens beam shaper which can do the same job will be much preferred. In this chapter, a single-piece aspheric lens will be designed using the method described in Sect. 2, the front and back surfaces of the lens are both rotationally symmetric aspheric surface. The input Gaussian beam, the output beam, the entrance pupil diameter and lens material are all the same as Sect. 3.1.

Table 3 shows the searching ranges of aspheric parameters for the front and back surfaces of a lens when we use the PSO algorithm to design a single lens beam shaper. Table 4 lists the parameter values of a better particle with fitness value of 2.8542, and these values are imported into the Zemax lens data editor as in Fig. 8. Figure 9 shows the schematic optical layout of a single-lens beam shaper plotted by Zemax, which displays that a laser beam having a gaussian density distribution has indeed been transformed into a uniform density beam, and re-collimated. Figure 10 confirms that the input Gaussian beam has been converted to a uniform flat-top profile. Figure 11 is the 3D simulations of relative illumination corresponding to Fig. 10.

Table 3 The value ranges of aspheric parameters for the front and back surfaces of the lens
Table 4 The aspheric parameters obtained by PSO algorithm-based MATLAB programs
Fig. 8
figure 8

The aspheric parameters in Table 4 have been imported into the ZEMAX Lens Data Editor

Fig. 9
figure 9

The 2D optical layouts of the designed single-lens beam shaper

Fig. 10
figure 10

The x-scan plot of relative illumination on the output plane of the designed single-lens Gaussian beam shaper

Fig. 11
figure 11

The 3D simulations of relative illumination on the output plane of the designed single-lens Gaussian beam shaper

4 Conclusions

For position coordinates of given incident light rays, coordinates of output ray intersections at the output plane are theoretically calculated from the law of energy conservation. A beam shaping lens system’s merit function is constructed from absolute values of the differences between theoretical coordinates and real coordinates obtained by the ray tracing method. Taking this merit function as the fitness function of the PSO algorithm, seeking structure variables minimizing the fitness function by self-compiled Matlab program, and two-lens beam shapers and the single-lens beam shaper have been designed. It can be known from the ray tracing analysis that the designed laser beam shapers can transform Gaussian beams into flat-top beams. The design examples demonstrate that the proposed approach can be considered to be feasible and effective; it has the potential to be a useful tool for designing laser beam shaping lenses.