From ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Zrounba?= <6691770+clement-z@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:06:01 +0200 Subject: Initial release --- src/devices/generic_transmission_device.h | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/devices/generic_transmission_device.h (limited to 'src/devices/generic_transmission_device.h') diff --git a/src/devices/generic_transmission_device.h b/src/devices/generic_transmission_device.h new file mode 100644 index 0000000..bfd110b --- /dev/null +++ b/src/devices/generic_transmission_device.h @@ -0,0 +1,94 @@ +#pragma once + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include +#include +#include +#include "devices/spx_module.h" +#include "optical_signal.h" +#include "optical_output_port.h" + +using std::vector; +using std::valarray; +using std::string; +using std::cout; +using std::endl; +using std::cerr; + +class TransmissionMatrix { +public: + typedef TransmissionMatrix this_type; + typedef double wavelength_type; + typedef double param_type; + typedef valarray taylor_series_type; + typedef valarray matrix_type; + typedef struct{ double alpha, phi, tau; } paramset_type; + + size_t N; // Number of ports (= Nrow = Ncol) in the matrix + // Arrays of matrices describing alpha, phi and the group delay via their taylor coefficients (starting from alpha0) + matrix_type Malpha; + matrix_type Mphi; + matrix_type Mtau; + valarray Mactive; + wavelength_type lambda0; // Wavelength at which the taylor coefficients were calculated + + paramset_type operator()(const size_t &i, const size_t &j, const wavelength_type &lambda, const size_t max_order=2) const; + inline bool isActive(const size_t &i, const size_t &j) const + { return Mactive[i * N + j]; } + inline bool isInputActive(const size_t &i) const + { + bool ret = false; + for (size_t j = 0; j < N; ++j) + ret |= Mactive[i * N + j]; + return ret; + } + + void clear() + { + N = 0; + lambda0 = 0; + Malpha.resize(0); + Mphi.resize(0); + Mtau.resize(0); + Mactive.resize(0); + } + + void resize(size_t nports) + { + N = nports; + Malpha.resize(nports*nports, {0}); + Mphi.resize(nports*nports, {0}); + Mtau.resize(nports*nports, {0}); + Mactive.resize(nports*nports, false); + } +}; + +class GenericTransmissionDevice : public spx_module { +public: + typedef GenericTransmissionDevice this_type; + + /* ------------------------ */ + size_t nports; + vector> ports_in; + vector> ports_out; + vector> ports_out_writers; + TransmissionMatrix TM; + + /* ------------------------ */ + virtual void pre_init(); + virtual void init(); + virtual string describe() const; + virtual void prepareTM() = 0; + + // Process input on i + void input_on_i(size_t i); + void input_on_i_output_on_j(size_t i, size_t j); + + GenericTransmissionDevice(sc_module_name name, size_t N = 1) + : spx_module(name) + , nports(N) + { + pre_init(); + } +}; \ No newline at end of file -- cgit v1.2.3