How does the Max Modulation tool calculate the maximum modulation of two electric fields? I am asking since it is not described in the manual and it also does not appear in any of the tutorials.
Based on the this post, the tool is based on the formula derived in the Grossman et al., 2017 paper which is the following:
I applied this formula and the results I got were not correct when post-processing the two electric fields in Python, outside of Sim4Life. The above formula is for the |E_1| > |E_2| area. The code that I am using in Python is:
import numpy as np import scipy.io as io base_data = io.loadmat('Directory of extracted mat file for the simulation 1') delta_data = io.loadmat('Directory of extracted mat file for the simulation 2') e_field_1 = np.nan_to_num(base_data['EM_E_x_y_z_f0_Snapshot0']) e_field_2 = np.nan_to_num(delta_data['EM_E_x_y_z_f0_Snapshot0']) # Calculate the subtraction and addtion of the vectors E_plus = np.add(e_field_1, e_field_2) # Create the sum of the E fields E_minus = np.subtract(e_field_1, e_field_2) # Create the difference of the E fields # Calculate the angles between the two fields for each vector # Assuming that E_a is the difference of the vectors dot_angle = np.einsum('ij,ij->i', e_field_1, E_minus) cross_angle = np.linalg.norm(np.cross(e_field_1, E_minus), axis=1) angles = np.arctan2(cross_angle, dot_angle) # Condition to have two times the E2 field amplitude max_condition = np.linalg.norm(e_field_2, axis=1) < np.linalg.norm(e_field_1, axis=1)*np.cos(angles) e1_gr_e2 = np.where(np.linalg.norm(e_field_1, axis=1) > np.linalg.norm(e_field_2, axis=1), max_condition, False) # Calculate the maximum envelope envelope = np.where(e1_gr_e2, 2.0*np.linalg.norm(e_field_2, axis=1), envelope) # Find the other points where the condition is not true tmp = np.logical_xor(e1_gr_e2, np.linalg.norm(e_field_1, axis=1) > np.linalg.norm(e_field_2, axis=1)) envelope = np.where(tmp, 2.0*(np.linalg.norm(np.cross(e_field_2, E_minus), axis=1)/np.linalg.norm(E_minus, axis=1)), envelope) np.nan_to_num(envelope)
The resulting graphs can be seen in the figure below, with the calculations from the above code shown on the left-most image, results from Sim4Life shown in the middle and the common points between Sim4Life and Python calculations shown in the right-most image.
I have tried many variations of the code, setting the amplitudes of electric field on and two to double the value for all points and trying to find the common points and also tried different variations with the indices in the cross product formula. Still with all the variations I could not get all the points filled in the common points plot. The image with all calculated common points is shown below. The correct simulation image is also shown below.