Menu

NGSpy and boost::bessel

2016-12-29
2017-01-03
  • Sofi Esterhazy

    Sofi Esterhazy - 2016-12-29

    Hey there!!

    I would be very much interested to export the bessel function from boost into NGSpy!!

    I was hoping this could be done by adapting the ExportStdMathFunction to ExportSplMathFunction which accepts two arguments the order of the bessel function v and the postion x.

    So something like that in <python_fem.cpp>:</python_fem.cpp>

    #include <boost/math/special_functions/bessel.hpp>
    
    template <typename FUNC> **// adapt for two arguments ??**
    void ExportSplMathFunction(string name)
    {
      bp::def (name.c_str(), FunctionPointer
               ([] (bp::object x) -> bp::object
                {
                  FUNC func;
                  if (bp::extract<SPCF>(x).check())
                    {
                      auto coef = bp::extract<SPCF>(x)();
                      return bp::object(UnaryOpCF(coef, func, func, FUNC::Name()));
                    }
                  bp::extract<double> ed(x);
                  if (ed.check()) return bp::object(func(ed(),ed()));  **// <- two arguments !?**
                  // if (bp::extract<Complex> (x).check())
                  //   return bp::object(func(ed(),bp::extract<Complex> (x)()));  **// <- two arguments !?**
                  throw Exception ("can't compute math-function");
                }));
    }
    

    So that I can use:

    struct GenericBessel_J {
      template <typename T> T operator() (T v, T x) const { return cyl_bessel_j(v,x); } // from boost
      static string Name() { return "Bessel_J"; }
    

    for

    ExportSplMathFunction<GenericBessel_J>("Bessel_J");
    

    Thank you very much!!

    CheerS

     

    Last edit: Sofi Esterhazy 2016-12-29
  • Joachim Schoeberl

    Hi Sofi,

    you can do it like the atan2, which also uses 2 arguments,

    Joachim

     
  • Joachim Schoeberl

    Hi Sofi,

    you can now export unary functions (binary functions may come soon) from a separate module, without changing the NGSolve code. It is explained in our brand-new NGSolve-Blog:
    https://ngsolve.sourceforge.io/index.php/blog/ngsolve/9-exporting-mathematical-functions

    Joachim

     

Anonymous
Anonymous

Add attachments
Cancel