I'm currently trying to analyze the reflection characteristics of different 3D shapes using OpenEMS in python interface. In the following, let's consider a simple sphere as the shape (I am aware of the trivial solution. This is just a simple choice to demonstrate my problem).

The structure of the simulation is very similar to calculating the RCS as it is described in the RCS_sphere.py tutorial (https://github.com/thliebig/openEMS/blo ... _Sphere.py), and my code is inspired by it, with the simple difference that here I rotate the source and the Farfield position around the shape and catch the normalized reflection values.

Code: Select all

```
### Import Libraries
import os, tempfile
from math import *
import CSXCAD
from openEMS import openEMS
from openEMS.physical_constants import *
from openEMS.ports import UI_data
import numpy as np
import matplotlib.pyplot as plt
from numpy import linalg as LA
def dihedral_reflector(inc_angle, getFrequencies):
### Setup the simulation
Sim_Path = os.path.join(tempfile.gettempdir(), os.path.basename(__file__)[:-3])
unit = 1e-3 # all length in mm
# size of the simulation box
SimBox = 1550
PW_Box = 1200
# Setup FDTD parameters & excitation function
FDTD = openEMS(EndCriteria=1e-5)
f_start = 50e6 # start frequency
f_stop = 1010e6 # stop frequency
f0 = 500e6
FDTD.SetGaussExcite(0.5 * (f_start + f_stop), 0.5 * (f_stop - f_start))
FDTD.SetBoundaryCond(['PML_8', 'PML_8', 'PML_8', 'PML_8', 'PML_8', 'PML_8'])
# Setup Geometry & Mesh
CSX = CSXCAD.ContinuousStructure()
FDTD.SetCSX(CSX)
mesh = CSX.GetGrid()
mesh.SetDeltaUnit(unit)
# create mesh
mesh.SetLines('x', [-SimBox / 2, 0, SimBox / 2])
mesh.SmoothMeshLines('x', C0 / f_stop / unit / 20) # cell size: lambda/20
mesh.SetLines('y', mesh.GetLines('x'))
mesh.SetLines('z', mesh.GetLines('x'))
### Create a metal sphere and plane wave source
sphere_metal = CSX.AddMetal('sphere') # create a perfect electric conductor (PEC)
sphere_metal.AddSphere(priority=10, center=[0, 0, 0], radius=200)
# plane wave excitation beginning from theta = 0 degree
k_dir = [0, -cos(np.deg2rad(inc_angle)), -sin(np.deg2rad(inc_angle))]
E_dir = [1, 0, 0] # plane wave polarization --> E_z
pw_exc = CSX.AddExcitation('plane_wave', exc_type=10, exc_val=E_dir)
pw_exc.SetPropagationDir(k_dir)
pw_exc.SetFrequency(f0)
start = np.array([-PW_Box / 2, -PW_Box / 2, -PW_Box / 2])
stop = -start
pw_exc.AddBox(start, stop)
# nf2ff calc
nf2ff = FDTD.CreateNF2FFBox()
CSX_file = os.path.join(Sim_Path, 'sphere.xml')
if not os.path.exists(Sim_Path):
os.mkdir(Sim_Path)
CSX.Write2XML(CSX_file)
# Run the simulation
FDTD.Run(Sim_Path, verbose=3, cleanup=True)
get_data_at_f0_and_phi0 = UI_data('et', Sim_Path, freq=getFrequencies)
Pin = 0.5 * LA.norm(E_dir) ** 2 / Z0 * abs(np.array(get_data_at_f0_and_phi0.ui_f_val[0])) ** 2 # Et = ui_f_val[0]
far_data_at_f0_phi0 = nf2ff.CalcNF2FF(Sim_Path, getFrequencies, 90 - inc_angle, 90)
powerRCS_at_f0_phi0 = np.array([4*pi/Pin[fn]*far_data_at_f0_phi0.P_rad[fn][0][0] for fn in range(len(getFrequencies))])
return np.rad2deg(far_data_at_f0_phi0.theta)%360, powerRCS_at_f0_phi0
if __name__ == '__main__':
# number of points in [0,360) range of angles
npts = 6
angles = np.arange(npts) / npts * 360
# Analyse the reflection on this frequency
getFrequencies = np.array([1000e6])
nfreqs = len(getFrequencies)
# Define arrays to plot later
Theta = np.zeros((npts, nfreqs))
powerRCS_at_f_phi = np.zeros((npts, nfreqs))
# calculating the normalized reflection for different angles
for n in range(npts):
print('\x1b[6;30;42m' + "Angle of incidence: {:.4f} [rad] or {:.4f} [degree]"
.format(np.deg2rad(angles[n]), angles[n]) + '\x1b[0m')
print("Starting the simulation...")
Theta[n], powerRCS_at_f_phi[n] = dihedral_reflector(angles[n], getFrequencies)
# Post plotting and saving
fig1 = plt.subplot(111, projection='polar')
fig1.set_theta_zero_location("N")
fig1.set_theta_direction(-1)
for x, y in zip(np.deg2rad(Theta[:]), powerRCS_at_f_phi[:]):
plt.polar(x, y, 'ro', color='b')
fig1.set_ylim([0, np.amax(powerRCS_at_f_phi[:, :]) * 5 / 4])
plt.show()
```

Code: Select all

`f_stop = 20e9`

Code: Select all

`getFrequencies = np.array([18e9]) `

Do you know any trick to reduce the required amount of RAM, and also speeding up the simulation? Intuitively, a single frequency source would help, but does such a thing exist in OpenEMS python interface? Additionally, considering symmetries would speed up the simulation, however, I'm not sure how I can use symmetries into my code (please have a look at the script)

Also considering the RCS_sphere tutorial, It is not clear to me why we use both

Code: Select all

`FDTD.SetGaussExcite(0.5 * (f_start + f_stop), 0.5 * (f_stop - f_start)) `

Code: Select all

```
pw_exc = CSX.AddExcitation('plane_wave', exc_type=10, exc_val=E_dir)
pw_exc.SetPropagationDir(k_dir)
pw_exc.SetFrequency(f0)
```