Skip to content

Commit

Permalink
api changes, version 1.0.0 rebased [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPdeS committed Nov 29, 2023
1 parent e38155e commit 76aadfd
Show file tree
Hide file tree
Showing 11 changed files with 592 additions and 0 deletions.
42 changes: 42 additions & 0 deletions SuPyMode/cpp/model_parameters_interface.cpp
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
}
)


);

}

15 changes: 15 additions & 0 deletions SuPyMode/representation/__init__.py
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
27 changes: 27 additions & 0 deletions SuPyMode/representation/adiabatic.py
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


# -
142 changes: 142 additions & 0 deletions SuPyMode/representation/base.py
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)
22 changes: 22 additions & 0 deletions SuPyMode/representation/beating_length.py
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)


# -
19 changes: 19 additions & 0 deletions SuPyMode/representation/beta.py
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

# -
18 changes: 18 additions & 0 deletions SuPyMode/representation/eigen_value.py
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
# -
Loading

0 comments on commit 76aadfd

Please sign in to comment.