-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api changes, version 1.0.0 rebased [publish]
- Loading branch information
1 parent
e38155e
commit 76aadfd
Showing
11 changed files
with
592 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/eigen.h> | ||
#include "definitions.cpp" | ||
|
||
|
||
PYBIND11_MODULE(ModelParameters, module) | ||
{ | ||
module.doc() = "A c++ wrapper class for ModelParameters"; | ||
|
||
pybind11::class_<ModelParameters>(module, "ModelParameters") | ||
|
||
.def_readwrite("nx", &ModelParameters::nx) | ||
.def_readwrite("ny", &ModelParameters::ny) | ||
.def_readwrite("dx", &ModelParameters::dx) | ||
.def_readwrite("dy", &ModelParameters::dy) | ||
.def_readwrite("wavelength", &ModelParameters::wavelength) | ||
.def_readwrite("wavenumber", &ModelParameters::wavenumber) | ||
.def_readwrite("itr_list", &ModelParameters::itr_list_py) | ||
|
||
.def( | ||
pybind11::pickle( | ||
[](ModelParameters& model_parameter) | ||
{ | ||
return model_parameter.get_state(); // dump | ||
}, | ||
[](pybind11::tuple t) | ||
{ | ||
return ModelParameters{ | ||
t[0].cast<double>(), // wavelength | ||
t[1].cast<pybind11::array_t<double>>(), // mesh_gradient_py, | ||
t[2].cast<pybind11::array_t<double>>(), // itr_list_py, | ||
t[3].cast<double>(), // dx | ||
t[4].cast<double>() // dy | ||
}; // load | ||
} | ||
) | ||
|
||
|
||
); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .adiabatic import Adiabatic | ||
|
||
from .index import Index | ||
|
||
from .beating_length import BeatingLength | ||
|
||
from .eigen_value import EigenValue | ||
|
||
from .overlap import Overlap | ||
|
||
from .field import Field | ||
|
||
from .beta import Beta | ||
|
||
from .normalized_coupling import NormalizedCoupling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# #!/usr/bin/env python | ||
# # -*- coding: utf-8 -*- | ||
|
||
import numpy | ||
|
||
from SuPyMode.tools import plot_style | ||
from SuPyMode.representation.base import InheritFromSuperMode, BaseMultiModePlot | ||
|
||
|
||
class Adiabatic(InheritFromSuperMode, BaseMultiModePlot): | ||
def __init__(self, parent_supermode): | ||
self.parent_supermode = parent_supermode | ||
self.plot_style = plot_style.adiabatic | ||
|
||
def get_values(self, other_supermode) -> numpy.ndarray: | ||
""" | ||
Return the array of the modal coupling for the mode | ||
""" | ||
output = self.parent_supermode.binded_supermode.get_adiabatic_with_mode(other_supermode.binded_supermode) | ||
|
||
if not self.parent_supermode.is_computation_compatible(other_supermode): | ||
output *= numpy.inf | ||
|
||
return output | ||
|
||
|
||
# - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# #!/usr/bin/env python | ||
# # -*- coding: utf-8 -*- | ||
|
||
import numpy | ||
from MPSPlots.render2D import SceneList, Axis | ||
|
||
|
||
class BaseMultiModePlot(): | ||
def _render_on_ax_(self, ax: Axis, other_supermode: 'SuperMode' = None): | ||
if other_supermode is None: | ||
other_supermode = self.parent_supermode.parent_set.supermodes | ||
else: | ||
other_supermode = numpy.atleast_1d(other_supermode) | ||
|
||
for mode in other_supermode: | ||
if mode.ID == self.ID or mode.solver_number != self.solver_number: | ||
continue | ||
|
||
ax.add_line( | ||
x=self.itr_list, | ||
y=self.get_values(mode), | ||
label=f'{self.stylized_label} - {mode.stylized_label}' | ||
) | ||
|
||
ax.set_style(**self.plot_style) | ||
|
||
def plot(self, other_supermode=None, row: int = 0, col: int = 0) -> None: | ||
""" | ||
Plotting method for the index. | ||
:param slice_list: Value reprenting the slice where the mode field is evaluated. | ||
:type slice_list: list | ||
:param itr_list: Value of itr value to evaluate the mode field. | ||
:type itr_list: list | ||
:returns: the figure containing all the plots. | ||
:rtype: SceneList | ||
""" | ||
figure = SceneList(unit_size=(10, 4), tight_layout=True) | ||
|
||
ax = figure.append_ax() | ||
|
||
self._render_on_ax_(ax=ax, other_supermode=other_supermode) | ||
|
||
return figure | ||
|
||
|
||
class BaseSingleModePlot(): | ||
def __getitem__(self, idx): | ||
return self._data[idx] | ||
|
||
def _render_on_ax_(self, ax: Axis) -> None: | ||
self._set_axis_(ax) | ||
|
||
ax.set_style(self.plot_style) | ||
|
||
ax.add_line(x=self.itr_list, y=self._data, label=self.stylized_label) | ||
|
||
def plot(self, row: int = 0, col: int = 0) -> None: | ||
""" | ||
Plotting method for the index. | ||
:param slice_list: Value reprenting the slice where the mode field is evaluated. | ||
:type slice_list: list | ||
:param itr_list: Value of itr value to evaluate the mode field. | ||
:type itr_list: list | ||
:returns: the figure containing all the plots. | ||
:rtype: SceneList | ||
""" | ||
figure = SceneList(unit_size=(10, 4), tight_layout=True) | ||
|
||
ax = figure.append_ax() | ||
|
||
self._render_on_ax_(ax) | ||
|
||
return figure | ||
|
||
|
||
class InheritFromSuperMode(): | ||
def _set_axis_(self, ax: Axis): | ||
for element, value in self.plot_style.items(): | ||
setattr(ax, element, value) | ||
|
||
def __getitem__(self, idx): | ||
return self._data[idx] | ||
|
||
@property | ||
def mode_number(self) -> int: | ||
return self.parent_supermode.mode_number | ||
|
||
@property | ||
def solver_number(self) -> int: | ||
return self.parent_supermode.solver_number | ||
|
||
@property | ||
def axes(self): | ||
return self.parent_supermode.axes | ||
|
||
@property | ||
def boundaries(self): | ||
return self.parent_supermode.boundaries | ||
|
||
@property | ||
def itr_list(self): | ||
return self.parent_supermode.itr_list | ||
|
||
@property | ||
def ID(self): | ||
return self.parent_supermode.ID | ||
|
||
@property | ||
def label(self): | ||
return self.parent_supermode.label | ||
|
||
@property | ||
def stylized_label(self): | ||
return self.parent_supermode.stylized_label | ||
|
||
def slice_to_itr(self, slice: list = []): | ||
return self.parent_supermode.parent_set.slice_to_itr(slice) | ||
|
||
def itr_to_slice(self, itr: list = []): | ||
return self.parent_supermode.parent_set.itr_to_slice(itr) | ||
|
||
def _interpret_itr_slice_list_(self, *args, **kwargs): | ||
return self.parent_supermode.parent_set._interpret_itr_slice_list_(*args, **kwargs) | ||
|
||
def _get_symmetrize_vector(self, *args, **kwargs): | ||
return self.parent_supermode._get_symmetrize_vector(*args, **kwargs) | ||
|
||
def _get_axis_vector(self, *args, **kwargs): | ||
return self.parent_supermode._get_axis_vector(*args, **kwargs) | ||
|
||
def get_axis(self, *args, **kwargs): | ||
return self.parent_supermode.get_axis(*args, **kwargs) | ||
|
||
|
||
class NameSpace(): | ||
def __init__(self, **kwargs): | ||
for k, v in kwargs.items(): | ||
setattr(self, k, v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# #!/usr/bin/env python | ||
# # -*- coding: utf-8 -*- | ||
|
||
import numpy | ||
|
||
from SuPyMode.tools import plot_style | ||
from SuPyMode.representation.base import InheritFromSuperMode, BaseMultiModePlot | ||
|
||
|
||
class BeatingLength(InheritFromSuperMode, BaseMultiModePlot): | ||
def __init__(self, parent_supermode): | ||
self.parent_supermode = parent_supermode | ||
self.plot_style = plot_style.beating_length | ||
|
||
def get_values(self, other_supermode) -> numpy.ndarray: | ||
""" | ||
Return the array of the modal coupling for the mode | ||
""" | ||
return self.parent_supermode.binded_supermode.get_beating_length_with_mode(other_supermode.binded_supermode) | ||
|
||
|
||
# - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# #!/usr/bin/env python | ||
# # -*- coding: utf-8 -*- | ||
|
||
import numpy | ||
|
||
from SuPyMode.tools import plot_style | ||
from SuPyMode.representation.base import InheritFromSuperMode, BaseSingleModePlot | ||
|
||
|
||
class Beta(InheritFromSuperMode, BaseSingleModePlot): | ||
def __init__(self, parent_supermode): | ||
self.parent_supermode = parent_supermode | ||
self._data = self.parent_supermode.binded_supermode.get_betas() | ||
self.plot_style = plot_style.beta | ||
|
||
def get_values(self) -> numpy.ndarray: | ||
return self._data | ||
|
||
# - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# #!/usr/bin/env python | ||
# # -*- coding: utf-8 -*- | ||
|
||
import numpy | ||
|
||
from SuPyMode.tools import plot_style | ||
from SuPyMode.representation.base import InheritFromSuperMode, BaseSingleModePlot | ||
|
||
|
||
class EigenValue(InheritFromSuperMode, BaseSingleModePlot): | ||
def __init__(self, parent_supermode): | ||
self.parent_supermode = parent_supermode | ||
self._data = self.parent_supermode.binded_supermode.get_eigen_value() | ||
self.plot_style = plot_style.eigen_value | ||
|
||
def get_values(self) -> numpy.ndarray: | ||
return self._data | ||
# - |
Oops, something went wrong.