Gyoto
GyotoPython.h
Go to the documentation of this file.
1 /*
2  Copyright 20015 Thibaut Paumard
3 
4  This file is part of Gyoto.
5 
6  Gyoto is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Gyoto is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
89 #ifndef __GyotoPython_H_
90 #define __GyotoPython_H_
91 #include <GyotoSpectrum.h>
92 #include <GyotoMetric.h>
93 #include <GyotoStandardAstrobj.h>
94 #include <GyotoThinDisk.h>
95 #include <Python.h>
96 
97 namespace Gyoto {
103  namespace Python {
104  class Base;
105 
107  PyObject * PyInstance_GetMethod(PyObject* pInstance, const char *name);
108 
110  PyObject * PyImport_Gyoto();
111 
113  void PyInstance_SetThis(PyObject * pInstance,
114  PyObject * pNew,
115  void * ptr);
116 
118  bool PyCallable_HasVarArg(PyObject * pMethod);
119 
121  PyObject * PyModule_NewFromPythonCode(const char * code);
122 
124  PyObject * pGyotoSpectrum() ;
126  PyObject * pGyotoMetric() ;
128  PyObject * pGyotoStandardAstrobj() ;
130  PyObject * pGyotoThinDisk() ;
131  }
132  namespace Spectrum {
133  class Python;
134  }
135  namespace Metric {
136  class Python;
137  }
138  namespace Astrobj {
143  namespace Python {
144  class Standard;
145  class ThinDisk;
146  }
147  }
148 }
149 
176  protected:
183  std::string module_;
184 
189  std::string inline_module_;
190 
196  std::string class_;
197 
205  std::vector<double> parameters_;
206 
210  PyObject * pModule_;
211 
215  PyObject * pInstance_;
216 
217  public:
218  Base();
219  Base(const Base&);
220  ~Base();
221 
222  virtual std::string module() const ;
223  virtual std::string inlineModule() const ;
224 
233  virtual void module(const std::string&);
234 
243  virtual void inlineModule(const std::string&);
244 
246  virtual std::string klass() const ;
247 
261  virtual void klass(const std::string& c);
262 
264  virtual std::vector<double> parameters() const;
271  virtual void parameters(const std::vector<double>&);
272 
273 };
274 
275 
276 
291 : public Gyoto::Spectrum::Generic,
292  public Gyoto::Python::Base
293 {
294  friend class Gyoto::SmartPointer<Gyoto::Spectrum::Python>;
295  protected:
296 
303  PyObject * pCall_;
304 
308  PyObject * pIntegrate_;
309 
327  bool pCall_overloaded_;
328 
329  public:
330  GYOTO_OBJECT;
331 
332  Python();
333 
334  Python(const Python&);
335 
336  virtual Python * clone() const;
337 
338  ~Python();
339 
340  // For some reason we need to implement the bunch although only one
341  // is non-trivial
342  virtual std::string module() const ;
343  virtual void module(const std::string&);
344  virtual std::string inlineModule() const ;
345  virtual void inlineModule(const std::string&);
346  virtual std::string klass() const ;
347  virtual void klass(const std::string&);
348  virtual std::vector<double> parameters() const;
349  virtual void parameters(const std::vector<double>&);
350 
351  virtual double operator()(double nu) const;
352  virtual double operator()(double nu, double opacity, double ds) const;
353 
354  virtual double integrate(double nu1, double nu2) ;
355 
356 };
357 
358 
375 : public Gyoto::Metric::Generic,
376  public Gyoto::Python::Base
377 {
378  friend class Gyoto::SmartPointer<Gyoto::Metric::Python>;
379 
380  private:
381  // Variables to cache Python objects:
385  PyObject * pGmunu_;
386 
390  PyObject * pChristoffel_;
391 
392  public:
393  GYOTO_OBJECT;
394  Python();
395  Python(const Python&);
396  ~Python();
397  virtual Python* clone() const ;
398 
399  // Accessors for the Gyoto::Property members:
400  // Those are mere wrappers arround Generic::coordKind(), useful for
401  // declaring a boolen property using the macro GYOTO_PROPERTY_BOOL:
402  void spherical(bool);
403  bool spherical() const;
404  virtual std::string module() const ;
405  virtual void module(const std::string&);
406  virtual std::string inlineModule() const ;
407  virtual void inlineModule(const std::string&);
408  virtual std::string klass() const ;
409  virtual void klass(const std::string&);
410  virtual std::vector<double> parameters() const;
411  virtual void parameters(const std::vector<double>&);
413  virtual void mass(double m);
414 
415  // The minimal Gyoto::Metric API:
416  void gmunu(double g[4][4], const double * x) const ;
417  int christoffel(double dst[4][4][4], const double * x) const ;
418 
419 };
420 
431 : public Gyoto::Astrobj::Standard,
432  public Gyoto::Python::Base
433 {
434  friend class Gyoto::SmartPointer<Gyoto::Astrobj::Python::Standard>;
435 
436  private:
437  PyObject *pEmission_, *pIntegrateEmission_, *pTransmission_, *pCall_,
438  *pGetVelocity_, *pGiveDelta_;
439  bool pEmission_overloaded_, pIntegrateEmission_overloaded_;
440 
441  public:
442  GYOTO_OBJECT;
443 
444  /* Birth and Death*/
445  Standard();
446  Standard(const Standard&);
447  ~Standard();
448  Standard* clone() const;
449 
450  /* Astrobj::Generic API */
451  virtual double emission(double nu_em, double dsem, double coord_ph[8],
452  double coord_obj[8]=NULL) const ;
453 
454  virtual void emission(double Inu[], double nu_em[], size_t nbnu,
455  double dsem, double coord_ph[8],
456  double coord_obj[8]=NULL) const ;
457 
458  virtual double integrateEmission(double nu1, double nu2, double dsem,
459  double c_ph[8], double c_obj[8]=NULL) const;
460 
461  virtual void integrateEmission(double * I, double const * boundaries,
462  size_t const * chaninds, size_t nbnu,
463  double dsem, double *cph, double *co) const;
464 
465  virtual double transmission(double nuem, double dsem, double coord[8]) const ;
466 
467  /* Astrobj::Standard API */
468  virtual double operator()(double const coord[4]) ;
469  virtual void getVelocity(double const pos[4], double vel[4]) ;
470  virtual double giveDelta(double coord[8]);
471 
472  /* Python::Base */
473  virtual std::string module() const ;
474  virtual void module(const std::string&);
475  virtual std::string inlineModule() const ;
476  virtual void inlineModule(const std::string&);
477  virtual std::string klass() const ;
478  virtual void klass(const std::string&);
479  virtual std::vector<double> parameters() const;
480  virtual void parameters(const std::vector<double>&);
481  virtual double criticalValue() const ;
482  virtual void criticalValue(double) ;
483 
484 };
485 
496 : public Gyoto::Astrobj::ThinDisk,
497  public Gyoto::Python::Base
498 {
499  friend class Gyoto::SmartPointer<Gyoto::Astrobj::Python::ThinDisk>;
500 
501  private:
502  PyObject *pEmission_, *pIntegrateEmission_, *pTransmission_, *pCall_,
503  *pGetVelocity_, *pGiveDelta_;
504  bool pEmission_overloaded_, pIntegrateEmission_overloaded_;
505 
506  public:
507  GYOTO_OBJECT;
508 
509  /* Birth and Death*/
510  ThinDisk();
511  ThinDisk(const ThinDisk&);
512  ~ThinDisk();
513  ThinDisk* clone() const;
514 
515  /* Astrobj::Generic API */
516  virtual double emission(double nu_em, double dsem, double coord_ph[8],
517  double coord_obj[8]=NULL) const ;
518 
519  virtual void emission(double Inu[], double nu_em[], size_t nbnu,
520  double dsem, double coord_ph[8],
521  double coord_obj[8]=NULL) const ;
522 
523  virtual double integrateEmission(double nu1, double nu2, double dsem,
524  double c_ph[8], double c_obj[8]=NULL) const;
525 
526  virtual void integrateEmission(double * I, double const * boundaries,
527  size_t const * chaninds, size_t nbnu,
528  double dsem, double *cph, double *co) const;
529 
530  virtual double transmission(double nuem, double dsem, double coord[8]) const ;
531 
532  /* Astrobj::ThinDisk API */
533  virtual double operator()(double const coord[4]) ;
534  virtual void getVelocity(double const pos[4], double vel[4]) ;
535 
536  /* Python::Base */
537  virtual std::string module() const ;
538  virtual void module(const std::string&);
539  virtual std::string inlineModule() const ;
540  virtual void inlineModule(const std::string&);
541  virtual std::string klass() const ;
542  virtual void klass(const std::string&);
543  virtual std::vector<double> parameters() const;
544  virtual void parameters(const std::vector<double>&);
545 
546 };
547 
548 
549 #endif
PyObject * pGyotoMetric()
Get reference to the Metric constructor in the gyoto Python extension.
#define GYOTO_OBJECT
Declare class::properties and class::getProperties()
Definition: GyotoObject.h:83
double mass() const
Get mass used in unitLength()
PyObject * pModule_
Reference to the python module once it has been loaded.
Definition: GyotoPython.h:210
std::string class_
Name of the Python class that we want to expose.
Definition: GyotoPython.h:196
PyObject * pGyotoThinDisk()
Get reference to the ThinDisk constructor in the gyoto Python extension.
void PyInstance_SetThis(PyObject *pInstance, PyObject *pNew, void *ptr)
Set "this" attribute in instance.
Base class for metrics.
Definition: GyotoMetric.h:148
PyObject * pInstance_
Reference to the python instance once it has been instanciated.
Definition: GyotoPython.h:215
PyObject * pGyotoSpectrum()
Get reference to the Spectrum constructor in the gyoto Python extension.
std::string module_
Name of the Python module that holds the class.
Definition: GyotoPython.h:183
Astronomical objects defined bya a potential/distance.
std::string inline_module_
Python source code for module that holds the class.
Definition: GyotoPython.h:189
PyObject * PyImport_Gyoto()
Return refernce to the gyoto module, or NULL.
Base class for metric description.
Geometrically thin disks and rings.
Definition: GyotoThinDisk.h:68
Metric coded in Python.
Definition: GyotoPython.h:374
Coding a Gyoto::Astrobj::Standard in Python.
Definition: GyotoPython.h:430
Geometrically thin disks and rings.
Spectrum of a simple object (e.g. Star)
Namespace for the Gyoto library.
Definition: GyotoAstrobj.h:43
PyObject * PyInstance_GetMethod(PyObject *pInstance, const char *name)
Return new reference to method, or NULL if method not found.
Pointers performing reference counting.
Definition: GyotoProperty.h:41
Coding a Gyoto::Astrobj::ThinDisk in Python.
Definition: GyotoPython.h:495
Spectrum emitted by an Astrobj.
Definition: GyotoSpectrum.h:126
Loader for Python classes implementing the Spectrum interface.
Definition: GyotoPython.h:290
Astronomical objects defined bya a potential/distance.
Definition: GyotoStandardAstrobj.h:84
Base class for classes in the Python plug-in.
Definition: GyotoPython.h:175
PyObject * pGyotoStandardAstrobj()
Get reference to the StandardAstrobj constructor in the gyoto Python extension.
bool PyCallable_HasVarArg(PyObject *pMethod)
Check whether method accepts the varargs argument.
PyObject * PyModule_NewFromPythonCode(const char *code)
Create module from Python source code in a C string.
std::vector< double > parameters_
Parameters that this class needs.
Definition: GyotoPython.h:205