Gyoto
GyotoPython.h
Go to the documentation of this file.
1/*
2 Copyright 2015-2016 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>
94#include <GyotoThinDisk.h>
95#include <Python.h>
96
97namespace 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() ;
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
293{
295 protected:
296
303 PyObject * pCall_;
304
308 PyObject * pIntegrate_;
309
328
329 public:
332
333 Python();
334
335 Python(const Python&);
336
337 virtual Python * clone() const;
338
339 ~Python();
340
341 // For some reason we need to implement the bunch although only one
342 // is non-trivial
343 virtual std::string module() const ;
344 virtual void module(const std::string&);
345 virtual std::string inlineModule() const ;
346 virtual void inlineModule(const std::string&);
347 virtual std::string klass() const ;
348 virtual void klass(const std::string&);
349 virtual std::vector<double> parameters() const;
350 virtual void parameters(const std::vector<double>&);
351
352 virtual double operator()(double nu) const;
353 virtual double operator()(double nu, double opacity, double ds) const;
354
355 virtual double integrate(double nu1, double nu2) ;
356
357};
358
359
378{
380
381 private:
382 // Variables to cache Python objects:
386 PyObject * pGmunu_;
387
391 PyObject * pChristoffel_;
392
393 public:
396 Python();
397 Python(const Python&);
398 ~Python();
399 virtual Python* clone() const ;
400
401 // Accessors for the Gyoto::Property members:
402 // Those are mere wrappers arround Generic::coordKind(), useful for
403 // declaring a boolen property using the macro GYOTO_PROPERTY_BOOL:
404 void spherical(bool);
405 bool spherical() const;
406 virtual std::string module() const ;
407 virtual void module(const std::string&);
408 virtual std::string inlineModule() const ;
409 virtual void inlineModule(const std::string&);
410 virtual std::string klass() const ;
411 virtual void klass(const std::string&);
412 virtual std::vector<double> parameters() const;
413 virtual void parameters(const std::vector<double>&);
415 virtual void mass(double m);
416
417 // The minimal Gyoto::Metric API:
418 void gmunu(double g[4][4], const double * x) const ;
419 int christoffel(double dst[4][4][4], const double * x) const ;
420
421};
422
435{
437
438 private:
439 PyObject *pEmission_, *pIntegrateEmission_, *pTransmission_, *pCall_,
440 *pGetVelocity_, *pGiveDelta_;
441 bool pEmission_overloaded_, pIntegrateEmission_overloaded_;
442
443 public:
446
447 /* Birth and Death*/
448 Standard();
449 Standard(const Standard&);
451 Standard* clone() const;
452
453 /* Astrobj::Generic API */
454 virtual double emission(double nu_em, double dsem, state_t const &coord_ph,
455 double const coord_obj[8]=NULL) const ;
456
457 virtual void emission(double Inu[], double const nu_em[], size_t nbnu,
458 double dsem, state_t const &coord_ph,
459 double const coord_obj[8]=NULL) const ;
460
461 virtual double integrateEmission(double nu1, double nu2, double dsem,
462 state_t const &c_ph, double const c_obj[8]=NULL) const;
463
464 virtual void integrateEmission(double * I, double const * boundaries,
465 size_t const * chaninds, size_t nbnu,
466 double dsem, state_t const &cph, double const *co) const;
467
468 virtual double transmission(double nuem, double dsem, state_t const &cph, double const *co) const ;
469
470 /* Astrobj::Standard API */
471 virtual double operator()(double const coord[4]) ;
472 virtual void getVelocity(double const pos[4], double vel[4]) ;
473 virtual double giveDelta(double coord[8]);
474
475 /* Python::Base */
476 virtual std::string module() const ;
477 virtual void module(const std::string&);
478 virtual std::string inlineModule() const ;
479 virtual void inlineModule(const std::string&);
480 virtual std::string klass() const ;
481 virtual void klass(const std::string&);
482 virtual std::vector<double> parameters() const;
483 virtual void parameters(const std::vector<double>&);
484 virtual double criticalValue() const ;
485 virtual void criticalValue(double) ;
486
487};
488
501{
503
504 private:
505 PyObject *pEmission_, *pIntegrateEmission_, *pTransmission_, *pCall_,
506 *pGetVelocity_, *pGiveDelta_;
507 bool pEmission_overloaded_, pIntegrateEmission_overloaded_;
508
509 public:
512
513 /* Birth and Death*/
514 ThinDisk();
515 ThinDisk(const ThinDisk&);
517 ThinDisk* clone() const;
518
519 /* Astrobj::Generic API */
520 virtual double emission(double nu_em, double dsem, state_t const &coord_ph,
521 double const coord_obj[8]=NULL) const ;
522
523 virtual void emission(double Inu[], double const nu_em[], size_t nbnu,
524 double dsem, state_t const &coord_ph,
525 double const coord_obj[8]=NULL) const ;
526
527 virtual double integrateEmission(double nu1, double nu2, double dsem,
528 state_t const &c_ph, double const c_obj[8]=NULL) const;
529
530 virtual void integrateEmission(double * I, double const * boundaries,
531 size_t const * chaninds, size_t nbnu,
532 double dsem, state_t const &cph, double const *co) const;
533
534 virtual double transmission(double nuem, double dsem, state_t const &cph ,double const *co) const ;
535
536 /* Astrobj::ThinDisk API */
537 virtual double operator()(double const coord[4]) ;
538 virtual void getVelocity(double const pos[4], double vel[4]) ;
539
540 /* Python::Base */
541 virtual std::string module() const ;
542 virtual void module(const std::string&);
543 virtual std::string inlineModule() const ;
544 virtual void inlineModule(const std::string&);
545 virtual std::string klass() const ;
546 virtual void klass(const std::string&);
547 virtual std::vector<double> parameters() const;
548 virtual void parameters(const std::vector<double>&);
549
550};
551
552
553#endif
Base class for metric description.
#define GYOTO_OBJECT_THREAD_SAFETY
Declare virtual bool isThreadSafe() const.
Definition: GyotoObject.h:99
#define GYOTO_OBJECT
Declare class::properties and class::getProperties()
Definition: GyotoObject.h:84
Spectrum of a simple object (e.g. Star)
Astronomical objects defined bya a potential/distance.
Geometrically thin disks and rings.
Coding a Gyoto::Astrobj::Standard in Python.
Definition: GyotoPython.h:435
Coding a Gyoto::Astrobj::ThinDisk in Python.
Definition: GyotoPython.h:501
Astronomical objects defined bya a potential/distance.
Definition: GyotoStandardAstrobj.h:87
Geometrically thin disks and rings.
Definition: GyotoThinDisk.h:71
Base class for metrics.
Definition: GyotoMetric.h:162
double mass() const
Get mass used in unitLength()
Metric coded in Python.
Definition: GyotoPython.h:378
Base class for classes in the Python plug-in.
Definition: GyotoPython.h:175
virtual void inlineModule(const std::string &)
Set inline_module_ and import the Python module.
virtual void module(const std::string &)
Set module_ and import the Python module.
std::string class_
Name of the Python class that we want to expose.
Definition: GyotoPython.h:196
virtual std::string inlineModule() const
Return inline_module_.
std::string module_
Name of the Python module that holds the class.
Definition: GyotoPython.h:183
virtual std::string klass() const
Retrieve class_.
virtual std::string module() const
Return module_.
std::vector< double > parameters_
Parameters that this class needs.
Definition: GyotoPython.h:205
PyObject * pInstance_
Reference to the python instance once it has been instantiated.
Definition: GyotoPython.h:215
virtual void klass(const std::string &c)
Set class_ and instantiate the Python class.
virtual void parameters(const std::vector< double > &)
Set parameters_ and send them to pInstance_.
std::string inline_module_
Python source code for module that holds the class.
Definition: GyotoPython.h:189
virtual std::vector< double > parameters() const
Retrieve parameters_.
PyObject * pModule_
Reference to the python module once it has been loaded.
Definition: GyotoPython.h:210
Pointers performing reference counting.
Definition: GyotoSmartPointer.h:135
Spectrum emitted by an Astrobj.
Definition: GyotoSpectrum.h:137
Loader for Python classes implementing the Spectrum interface.
Definition: GyotoPython.h:293
PyObject * pCall_
Reference to ___call__.
Definition: GyotoPython.h:303
virtual std::string inlineModule() const
Return inline_module_.
bool pCall_overloaded_
Whether call is overloaded.
Definition: GyotoPython.h:327
virtual Python * clone() const
Cloner.
virtual std::vector< double > parameters() const
Retrieve parameters_.
virtual std::string klass() const
Retrieve class_.
virtual std::string module() const
Return module_.
virtual double integrate(double nu1, double nu2)
Integrate optically thick I_nu.
PyObject * pIntegrate_
Reference to the (optional) integrate method.
Definition: GyotoPython.h:308
PyObject * pGyotoThinDisk()
Get reference to the ThinDisk constructor in the gyoto Python extension.
PyObject * pGyotoSpectrum()
Get reference to the Spectrum constructor in the gyoto Python extension.
PyObject * PyImport_Gyoto()
Return refernce to the gyoto module, or NULL.
PyObject * PyInstance_GetMethod(PyObject *pInstance, const char *name)
Return new reference to method, or NULL if method not found.
PyObject * PyModule_NewFromPythonCode(const char *code)
Create module from Python source code in a C string.
PyObject * pGyotoMetric()
Get reference to the Metric constructor in the gyoto Python extension.
void PyInstance_SetThis(PyObject *pInstance, PyObject *pNew, void *ptr)
Set "this" attribute in instance.
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.
Namespace for the Gyoto library.
Definition: GyotoAstrobj.h:43