diff --git a/Base/Axis/Scale.cpp b/Base/Axis/Scale.cpp index fd39ade02076d2b43f9eaccb8e373ea6e7c49330..a2836c71d33e00cba5d24f6cd1efc3aec5c12fa0 100644 --- a/Base/Axis/Scale.cpp +++ b/Base/Axis/Scale.cpp @@ -16,6 +16,7 @@ #include "Base/Const/Units.h" #include "Base/Util/Assert.h" #include "Base/Util/StringUtil.h" +#include <cmath> #include <iomanip> #include <iostream> #include <numbers> @@ -243,3 +244,41 @@ Scale Scale::transformedScale(const Coordinate& coord, const trafo_t& axTrafo) c } return {coord, outvector}; } + +Scale Scale::alpha_f_Scale(double lambda, double alpha_i) const +{ + if (m_coord->unit() == "1/nm") { + return transformedScale(Coordinate("alpha_f", "rad").label(), [lambda, alpha_i](double qz) { + return std::asin(qz * lambda / 2 / pi - std::sin(alpha_i)); + }); + } + return {m_coord->label(), m_bins}; +} + +Scale Scale::phi_f_Scale(double lambda) const +{ + if (m_coord->unit() == "1/nm") { + return transformedScale(Coordinate("phi_f", "rad").label(), + [lambda](double qy) { return std::asin(qy * lambda / 2 / pi); }); + } + return {m_coord->label(), m_bins}; +} + +Scale Scale::qz_Scale(double lambda, double alpha_i) const +{ + if (m_coord->unit() == "rad") + return transformedScale( + Coordinate("qz", "1/nm").label(), [lambda, alpha_i](double alpha_f) { + return 2 * pi / lambda * (std::sin(alpha_i) + std::sin(alpha_f)); + }); + return {m_coord->label(), m_bins}; +} + +Scale Scale::qy_Scale(double lambda) const +{ + if (m_coord->unit() == "rad") + return transformedScale(Coordinate("qy", "1/nm").label(), [lambda](double phi_f) { + return 2 * pi / lambda * std::sin(phi_f); + }); + return {m_coord->label(), m_bins}; +} diff --git a/Base/Axis/Scale.h b/Base/Axis/Scale.h index e434429e43140461b0fa6ffb697f5a4b30d62a18..2516940455aab15479cc5372a3f7ca295968851d 100644 --- a/Base/Axis/Scale.h +++ b/Base/Axis/Scale.h @@ -86,6 +86,12 @@ public: Scale plottableScale() const; Scale transformedScale(const Coordinate& coord, const trafo_t& axTrafo) const; + Scale alpha_f_Scale(double lambda, double alpha_i) const; + Scale phi_f_Scale(double lambda) const; + + Scale qz_Scale(double lambda, double alpha_i) const; + Scale qy_Scale(double lambda) const; + protected: std::vector<Bin1D> m_bins; std::unique_ptr<Coordinate> m_coord; diff --git a/auto/Wrap/libBornAgainBase.py b/auto/Wrap/libBornAgainBase.py index 685a616f9b03b6011d869d5020a70037ea148438..6591da4a468f9a1009d8fd7297a0771555f2356f 100644 --- a/auto/Wrap/libBornAgainBase.py +++ b/auto/Wrap/libBornAgainBase.py @@ -1879,6 +1879,22 @@ class Scale(object): def transformedScale(self, coord, axTrafo): r"""transformedScale(Scale self, Coordinate const & coord, trafo_t const & axTrafo) -> Scale""" return _libBornAgainBase.Scale_transformedScale(self, coord, axTrafo) + + def alpha_f_Scale(self, _lambda, alpha_i): + r"""alpha_f_Scale(Scale self, double _lambda, double alpha_i) -> Scale""" + return _libBornAgainBase.Scale_alpha_f_Scale(self, _lambda, alpha_i) + + def phi_f_Scale(self, _lambda): + r"""phi_f_Scale(Scale self, double _lambda) -> Scale""" + return _libBornAgainBase.Scale_phi_f_Scale(self, _lambda) + + def qz_Scale(self, _lambda, alpha_i): + r"""qz_Scale(Scale self, double _lambda, double alpha_i) -> Scale""" + return _libBornAgainBase.Scale_qz_Scale(self, _lambda, alpha_i) + + def qy_Scale(self, _lambda): + r"""qy_Scale(Scale self, double _lambda) -> Scale""" + return _libBornAgainBase.Scale_qy_Scale(self, _lambda) __swig_destroy__ = _libBornAgainBase.delete_Scale # Register Scale in _libBornAgainBase: diff --git a/auto/Wrap/libBornAgainBase_wrap.cpp b/auto/Wrap/libBornAgainBase_wrap.cpp index 81f282a2ad04d72d9a04efea0f341e0d38b059bd..583894e19883a6c7aef6f79e37571df70cb21851 100644 --- a/auto/Wrap/libBornAgainBase_wrap.cpp +++ b/auto/Wrap/libBornAgainBase_wrap.cpp @@ -26682,6 +26682,186 @@ fail: } +SWIGINTERN PyObject *_wrap_Scale_alpha_f_Scale(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + Scale *arg1 = (Scale *) 0 ; + double arg2 ; + double arg3 ; + void *argp1 = 0 ; + int res1 = 0 ; + double val2 ; + int ecode2 = 0 ; + double val3 ; + int ecode3 = 0 ; + PyObject *swig_obj[3] ; + SwigValueWrapper< Scale > result; + + (void)self; + if (!SWIG_Python_UnpackTuple(args, "Scale_alpha_f_Scale", 3, 3, swig_obj)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Scale, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Scale_alpha_f_Scale" "', argument " "1"" of type '" "Scale const *""'"); + } + arg1 = reinterpret_cast< Scale * >(argp1); + ecode2 = SWIG_AsVal_double(swig_obj[1], &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Scale_alpha_f_Scale" "', argument " "2"" of type '" "double""'"); + } + arg2 = static_cast< double >(val2); + ecode3 = SWIG_AsVal_double(swig_obj[2], &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Scale_alpha_f_Scale" "', argument " "3"" of type '" "double""'"); + } + arg3 = static_cast< double >(val3); + { + try { + result = ((Scale const *)arg1)->alpha_f_Scale(arg2,arg3); + } catch (const std::exception& ex) { + // message shown in the Python interpreter + const std::string msg { + "BornAgain C++ Exception: " + std::string(ex.what()) + }; + SWIG_exception(SWIG_RuntimeError, msg.c_str()); + } + } + resultobj = SWIG_NewPointerObj((new Scale(result)), SWIGTYPE_p_Scale, SWIG_POINTER_OWN | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Scale_phi_f_Scale(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + Scale *arg1 = (Scale *) 0 ; + double arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + double val2 ; + int ecode2 = 0 ; + PyObject *swig_obj[2] ; + SwigValueWrapper< Scale > result; + + (void)self; + if (!SWIG_Python_UnpackTuple(args, "Scale_phi_f_Scale", 2, 2, swig_obj)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Scale, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Scale_phi_f_Scale" "', argument " "1"" of type '" "Scale const *""'"); + } + arg1 = reinterpret_cast< Scale * >(argp1); + ecode2 = SWIG_AsVal_double(swig_obj[1], &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Scale_phi_f_Scale" "', argument " "2"" of type '" "double""'"); + } + arg2 = static_cast< double >(val2); + { + try { + result = ((Scale const *)arg1)->phi_f_Scale(arg2); + } catch (const std::exception& ex) { + // message shown in the Python interpreter + const std::string msg { + "BornAgain C++ Exception: " + std::string(ex.what()) + }; + SWIG_exception(SWIG_RuntimeError, msg.c_str()); + } + } + resultobj = SWIG_NewPointerObj((new Scale(result)), SWIGTYPE_p_Scale, SWIG_POINTER_OWN | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Scale_qz_Scale(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + Scale *arg1 = (Scale *) 0 ; + double arg2 ; + double arg3 ; + void *argp1 = 0 ; + int res1 = 0 ; + double val2 ; + int ecode2 = 0 ; + double val3 ; + int ecode3 = 0 ; + PyObject *swig_obj[3] ; + SwigValueWrapper< Scale > result; + + (void)self; + if (!SWIG_Python_UnpackTuple(args, "Scale_qz_Scale", 3, 3, swig_obj)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Scale, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Scale_qz_Scale" "', argument " "1"" of type '" "Scale const *""'"); + } + arg1 = reinterpret_cast< Scale * >(argp1); + ecode2 = SWIG_AsVal_double(swig_obj[1], &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Scale_qz_Scale" "', argument " "2"" of type '" "double""'"); + } + arg2 = static_cast< double >(val2); + ecode3 = SWIG_AsVal_double(swig_obj[2], &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Scale_qz_Scale" "', argument " "3"" of type '" "double""'"); + } + arg3 = static_cast< double >(val3); + { + try { + result = ((Scale const *)arg1)->qz_Scale(arg2,arg3); + } catch (const std::exception& ex) { + // message shown in the Python interpreter + const std::string msg { + "BornAgain C++ Exception: " + std::string(ex.what()) + }; + SWIG_exception(SWIG_RuntimeError, msg.c_str()); + } + } + resultobj = SWIG_NewPointerObj((new Scale(result)), SWIGTYPE_p_Scale, SWIG_POINTER_OWN | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Scale_qy_Scale(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + Scale *arg1 = (Scale *) 0 ; + double arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + double val2 ; + int ecode2 = 0 ; + PyObject *swig_obj[2] ; + SwigValueWrapper< Scale > result; + + (void)self; + if (!SWIG_Python_UnpackTuple(args, "Scale_qy_Scale", 2, 2, swig_obj)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Scale, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Scale_qy_Scale" "', argument " "1"" of type '" "Scale const *""'"); + } + arg1 = reinterpret_cast< Scale * >(argp1); + ecode2 = SWIG_AsVal_double(swig_obj[1], &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Scale_qy_Scale" "', argument " "2"" of type '" "double""'"); + } + arg2 = static_cast< double >(val2); + { + try { + result = ((Scale const *)arg1)->qy_Scale(arg2); + } catch (const std::exception& ex) { + // message shown in the Python interpreter + const std::string msg { + "BornAgain C++ Exception: " + std::string(ex.what()) + }; + SWIG_exception(SWIG_RuntimeError, msg.c_str()); + } + } + resultobj = SWIG_NewPointerObj((new Scale(result)), SWIGTYPE_p_Scale, SWIG_POINTER_OWN | 0 ); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_delete_Scale(PyObject *self, PyObject *args) { PyObject *resultobj = 0; Scale *arg1 = (Scale *) 0 ; @@ -30285,6 +30465,10 @@ static PyMethodDef SwigMethods[] = { { "Scale_unit", _wrap_Scale_unit, METH_O, "Scale_unit(Scale self) -> std::string"}, { "Scale_plottableScale", _wrap_Scale_plottableScale, METH_O, "Scale_plottableScale(Scale self) -> Scale"}, { "Scale_transformedScale", _wrap_Scale_transformedScale, METH_VARARGS, "Scale_transformedScale(Scale self, Coordinate const & coord, trafo_t const & axTrafo) -> Scale"}, + { "Scale_alpha_f_Scale", _wrap_Scale_alpha_f_Scale, METH_VARARGS, "Scale_alpha_f_Scale(Scale self, double _lambda, double alpha_i) -> Scale"}, + { "Scale_phi_f_Scale", _wrap_Scale_phi_f_Scale, METH_VARARGS, "Scale_phi_f_Scale(Scale self, double _lambda) -> Scale"}, + { "Scale_qz_Scale", _wrap_Scale_qz_Scale, METH_VARARGS, "Scale_qz_Scale(Scale self, double _lambda, double alpha_i) -> Scale"}, + { "Scale_qy_Scale", _wrap_Scale_qy_Scale, METH_VARARGS, "Scale_qy_Scale(Scale self, double _lambda) -> Scale"}, { "delete_Scale", _wrap_delete_Scale, METH_O, "delete_Scale(Scale self)"}, { "Scale_swigregister", Scale_swigregister, METH_O, NULL}, { "Scale_swiginit", Scale_swiginit, METH_VARARGS, NULL},