## 2 Materials and Methods
### Ray Launching Technique
The algorithm beamforming strategy is based on the instantaneous mapping of each defined beam in the considered scenario. At this step, all possible cases of angular variation can be considered by simulation (both in the base station and in the UE). Then, once all simulations are performed, in a postprocessing algorithm step, flexible beamforming takes place. By considering all the simulation-based cases, the beamforming can be defined and analyzed depending on the wireless system operating conditions under analysis. It is worth noting that the algorithm is not influenced by the type of beamforming strategy considered for the wireless system, exhibiting, in principle, no limitation in this sense. This is given by the fact that, considering the selected beamforming strategy, the corresponding sequence of simulations to be performed is scheduled. Once these simulations have been performed, in the simulation postprocessing step, the different 3D spatial planes can be overlapped, obtaining the final results. The algorithm principle is the following: when a ray hits an obstacle, reflected and refracted rays are created, and when a ray hits an edge, a new family of diffracted rays is created. These new rays are created according to the material properties of all the obstacles within the environment for the operation frequency of the system under analysis. The electric field \(E\) created by GO and the diffracted electric field created by UTD are calculated by [44]  
\[E_{\rm GO}=\sqrt{\frac{P_{\rm rad}D_{\rm t}(\theta_{\rm t},\ \varnothing_{\rm t})\eta_{0}}{2 \Pi}}\ \frac{e^{-\rm j\beta\sigma}}{\bf r}\ {\rm X}^{\perp\parallel}L^{\perp\parallel} \tag{1}\]  
\[E_{\rm UTD}=e_{0}\frac{e^{-\rm j\kappa_{1}}}{s_{1}}D^{s,h}\sqrt{\frac{s_{1}}{s _{2}(s_{1}+s_{2})}}e^{-\rm j\kappa_{2}} \tag{2}\]  
where \(\beta_{0}=2\pi f_{\rm c}\sqrt{\epsilon_{0}\mu_{0}}\), \(\epsilon_{0}\)= 8.854 \(\times\) 10\({}^{-12}\) F/m, \(\mu_{0}=4\pi\)\(\times\) 10\({}^{-7}\) H/m and \(\eta_{0}=\) 120 \(\pi\)\(\Omega\). \(P_{\rm rad}\) is the radiated power of the transmitter antenna. \(D_{\rm t}(\theta_{\rm t},\ \varnothing_{\rm t})\) is the directivity of the beam radiation pattern where rays are launched, as defined in the spherical coordinate system at an elevation angle \(\theta_{\rm t}\) and an azimuth angle \(\varnothing_{\rm t}\). For each polarization, \({\rm X}^{\perp\parallel}\) and \(L^{\perp\parallel}\) are the polarization ratio and path loss coefficients, \(r\) is the distance in the free space and \(f_{\rm c}\) is the transmission frequency. In the diffracted electric field created by UTD, \(D^{s,h}\) are the diffraction coefficients for soft and hard polarization determined by considering the edge-fixed incidence plane, \(e_{0}\) is the free-space field strength, \(k\) is the propagation constant and \(s_{1}\) and \(s_{2}\) are the distances from the source to the edge and from the edge to the receiver point [44; 45]. The diffraction phenomena can be activated or disactivated by the user, as one of the simulation software parameters. The complete scenario is divided in a predetermined 3D mesh, and the total electric field is calculated with the sum of the reflected, refracted, diffracted and incident electric vector fields at an instantaneous time inside each cuboid of the defined mesh. From these results, the incident power density can be calculated as the modulus of the complex Poynting vector [46]:  
\[S_{inc}=\left|\mathbf{E}\times\mathbf{H}^{*}\right| \tag{3}\]  
where \(\mathbf{E}\) is the E-field in volts per m (V/m), and \(\mathbf{H}^{*}\) is the complex conjugate of the magnetic field in amperes per m (A/m). In the case of the far field, the incident power density is derived as  
\[S_{inc}=\frac{\left|\mathbf{E}^{2}\right|}{Z_{0}}=Z_{0}\left|\mathbf{H}^{2}\right| \tag{4}\]  
where \(Z_{0}\) is the characteristic impedance of free space (i.e., 120 \(\pi\)\(\Omega\)).