Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed minor bugs and added functionality. #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion modesolverpy/mode_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ def _write_mode_to_file(self, mode, filename):
e_str = ",".join([str(v) for v in e])
fs.write(e_str + "\n")
return mode

def _write_mode_to_file_details(self, mode, filename):
efieldarray = []
for e, y in zip(mode[::-1], self._structure.y[::-1]):
for a, x in zip(e, self._structure.x[::-1]):
efieldarray.append([x,y,a])
np.savetxt(filename, efieldarray, delimiter=',',fmt='%.4e%+.4ej, %.4e%+.4ej, %.4e%+.4ej')
return mode

def _plot_n_effs(self, filename_n_effs, filename_te_fractions, xlabel, ylabel, title):
args = {
Expand Down Expand Up @@ -545,7 +553,8 @@ def _solve(self, structure, wavelength):

return r

def write_modes_to_file(self, filename="mode.dat", plot=True, analyse=True):
def write_modes_to_file(self, filename="mode.dat", plot=True, analyse=True,
details=False):
"""
Writes the mode fields to a file and optionally plots them.

Expand All @@ -561,6 +570,8 @@ def write_modes_to_file(self, filename="mode.dat", plot=True, analyse=True):
diameter (MFD) and marks it on the output, and it
marks with a cross the maximum E-field value.
Default is `True`.
details (bool): 'True' if you want to save the x, y values in
addition to the electric field amplitudes.

Returns:
dict: A dictionary containing the effective indices
Expand Down Expand Up @@ -606,6 +617,9 @@ def write_modes_to_file(self, filename="mode.dat", plot=True, analyse=True):
self.n_effs[i],
wavelength=self._structure._wl,
)
if details:
self._write_mode_to_file_details( mode, filename)


return self.modes

Expand Down Expand Up @@ -731,6 +745,7 @@ def write_modes_to_file(
filename="mode.dat",
plot=True,
fields_to_write=("Ex", "Ey", "Ez", "Hx", "Hy", "Hz"),
details=False
):
"""
Writes the mode fields to a file and optionally plots them.
Expand All @@ -747,6 +762,8 @@ def write_modes_to_file(
defining what part of the mode should be saved and
plotted. By default, all six components are written
and plotted.
details (bool): 'True' if you want to save the x, y values in
addition to the electric field amplitudes.

Returns:
dict: A dictionary containing the effective indices
Expand Down Expand Up @@ -795,5 +812,8 @@ def write_modes_to_file(
area=area,
wavelength=self._structure._wl,
)
if details:
self._write_mode_to_file_details( mode, filename)


return self.modes
4 changes: 2 additions & 2 deletions modesolverpy/structure_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def x(self):
'''
if None not in (self.x_min, self.x_max, self.x_step) and \
self.x_min != self.x_max:
x = np.arange(self.x_min, self.x_max+self.x_step-self.y_step*0.1, self.x_step)
x = np.arange(self.x_min, self.x_max+self.x_step-self.x_step*0.1, self.x_step)
else:
x = np.array([])
return x
Expand Down Expand Up @@ -369,7 +369,7 @@ def add_slab(self, height, n_background=1., position='top'):
else:
n_back = n_background

height_discretised = self.y_step*((height // self.y_step) + 1)
height_discretised = self.y_step*(height // self.y_step)

y_min = self._next_start
y_max = y_min + height_discretised
Expand Down