89#ifndef __GyotoPython_H_
90#define __GyotoPython_H_
109 template <
class O>
class Object;
293 virtual void klass(
const std::string& c);
305 virtual bool hasPythonProperty(std::string
const &key)
const ;
306 virtual void setPythonProperty(std::string
const &key,
Value val);
307 virtual Value getPythonProperty(std::string
const &key)
const;
308 virtual int pythonPropertyType(std::string
const &key)
const;
329 virtual void set(std::string
const &key,
Value val) {
332 if (hasPythonProperty(key)) {
333 GYOTO_DEBUG <<
"Python key " << key <<
" exists" << std::endl;
334 setPythonProperty(key, val);
336 GYOTO_DEBUG <<
"Python key " << key <<
" does not exist" << std::endl;
342 std::string key=p.
name;
344 if (!hasPythonProperty(key)) {
345 GYOTO_DEBUG <<
"calling Generic::set" << std::endl;
349 setPythonProperty(key, val);
352 virtual void set(
Property const &p,
Value val, std::string
const &unit) {
354 if (hasPythonProperty(p.
name)) {
356 if (unit!=
"")
GYOTO_ERROR(
"units not implemented");
357 setPythonProperty(p.
name, val);
359 GYOTO_DEBUG <<
"Python key " << p.
name <<
" does not exist" << std::endl;
360 O::set(p, val, unit);
366 virtual Value get(std::string
const &key)
const {
368 if (!hasPythonProperty(key)) {
369 GYOTO_DEBUG <<
"calling Generic::get" << std::endl;
372 return getPythonProperty(key);
376 std::string
const &unit)
const {
377 if (!hasPythonProperty(p.
name)) {
378 GYOTO_DEBUG <<
"calling Generic::get" << std::endl;
379 return O::get(p, unit);
381 return getPythonProperty(p.
name);
385 if (!hasPythonProperty(p.
name)) {
386 GYOTO_DEBUG <<
"calling Generic::get" << std::endl;
389 return getPythonProperty(p.
name);
392 using O::setParameter;
394 virtual int setParameter(std::string name, std::string content, std::string unit) {
398 if (hasPythonProperty(name)) {
401 p.
type=pythonPropertyType(name);
402 GYOTO_DEBUG <<
"Calling setParameter(p, name, content, unit)" << std::endl;
403 setParameter(p, name, content, unit);
406 return O::setParameter(name, content, unit);
413 PyObject *pKey, *pVal;
415 std::string key=PyUnicode_AsUTF8(pKey);
416 std::string stype=PyUnicode_AsUTF8(pVal);
419 this->fillProperty(fmp, p);
426 std::string name=
"", content=
"", unit=
"";
430 GYOTO_DEBUG <<
"Setting '" << name <<
"' to '" << content
431 <<
"' (unit='"<<unit<<
"')" << std::endl;
433 bool need_delete=
false;
434 if (hasPythonProperty(name)) {
436 prop =
new Property(name, pythonPropertyType(name));
439 prop = this->property(name);
442 GYOTO_DEBUG <<
"'" << name <<
"' not found, calling setParameter()"
446 setParameter(name, content, unit);
448 GYOTO_DEBUG <<
"'" << name <<
"' found "<< std::endl;
449 std::vector<std::string> plugins;
450 switch (prop->
type) {
452 set(*prop, fmp->
metric());
458 set(*prop, fmp->
screen());
461 content = fmp -> getAttribute(
"kind");
462 child = fmp -> getChild();
463 plugins =
Gyoto::split(fmp -> getAttribute(
"plugin"),
",");
468 content = fmp -> getAttribute(
"kind");
469 child = fmp -> getChild();
470 plugins =
Gyoto::split(fmp -> getAttribute(
"plugin"),
",");
478 setParameter(*prop, name, content, unit);
482 if (need_delete)
delete prop;
484 GYOTO_DEBUG <<
"Done processing parameters" << std::endl;
558 virtual void
klass(const std::string&);
562 virtual double operator()(double nu) const;
563 virtual double operator()(double nu, double opacity, double ds) const;
603 PyObject * pChristoffel_;
618 PyObject * pGetSpecificAngularMomentum_;
623 PyObject * pGetPotential_;
628 PyObject * pIsStopCondition_;
633 PyObject * pCircularVelocity_;
646 void spherical(bool);
647 bool spherical() const;
648 virtual std::string module() const ;
649 virtual void module(const std::string&);
650 virtual std::string inlineModule() const ;
651 virtual void inlineModule(const std::string&);
652 virtual std::string klass() const ;
653 virtual void klass(const std::string&);
654 virtual std::vector<double> parameters() const;
655 virtual void parameters(const std::vector<double>&);
657 virtual void mass(double m);
660 void gmunu(double g[4][4], const double * x) const ;
661 int christoffel(double dst[4][4][4], const double * x) const ;
664 double getRmb() const;
665 double getRms() const;
666 double getSpecificAngularMomentum(double rr) const;
667 double getPotential(double const pos[4], double l_cst) const;
668 int isStopCondition(double const coord[8]) const;
669 void circularVelocity(double const pos[4], double vel[4],
670 double dir=1.) const ;
689 PyObject *pEmission_, *pIntegrateEmission_, *pTransmission_, *pCall_,
690 *pGetVelocity_, *pGiveDelta_;
691 bool pEmission_overloaded_, pIntegrateEmission_overloaded_;
704 virtual double emission(double nu_em, double dsem, state_t const &coord_ph,
705 double const coord_obj[8]=NULL) const ;
707 virtual void emission(double Inu[], double const nu_em[], size_t nbnu,
708 double dsem, state_t const &coord_ph,
709 double const coord_obj[8]=NULL) const ;
711 virtual double integrateEmission(double nu1, double nu2, double dsem,
712 state_t const &c_ph, double const c_obj[8]=NULL) const;
714 virtual void integrateEmission(double * I, double const * boundaries,
715 size_t const * chaninds, size_t nbnu,
716 double dsem, state_t const &cph, double const *co) const;
718 virtual double transmission(double nuem, double dsem, state_t const &cph, double const *co) const ;
721 virtual double operator()(double const coord[4]) ;
722 virtual void getVelocity(double const pos[4], double vel[4]) ;
723 virtual double giveDelta(double coord[8]);
726 virtual std::string module() const ;
727 virtual void module(const std::string&);
728 virtual std::string inlineModule() const ;
729 virtual void inlineModule(const std::string&);
730 virtual std::string klass() const ;
731 virtual void klass(const std::string&);
732 virtual std::vector<double> parameters() const;
733 virtual void parameters(const std::vector<double>&);
734 virtual double criticalValue() const ;
735 virtual void criticalValue(double) ;
754 PyObject *pEmission_, *pIntegrateEmission_, *pTransmission_, *pCall_,
755 *pGetVelocity_, *pGiveDelta_;
756 bool pEmission_overloaded_, pIntegrateEmission_overloaded_;
769 virtual double emission(double nu_em, double dsem, state_t const &coord_ph,
770 double const coord_obj[8]=NULL) const ;
772 virtual void emission(double Inu[], double const nu_em[], size_t nbnu,
773 double dsem, state_t const &coord_ph,
774 double const coord_obj[8]=NULL) const ;
776 virtual double integrateEmission(double nu1, double nu2, double dsem,
777 state_t const &c_ph, double const c_obj[8]=NULL) const;
779 virtual void integrateEmission(double * I, double const * boundaries,
780 size_t const * chaninds, size_t nbnu,
781 double dsem, state_t const &cph, double const *co) const;
783 virtual double transmission(double nuem, double dsem, state_t const &cph ,double const *co) const ;
786 virtual double operator()(double const coord[4]) ;
787 virtual void getVelocity(double const pos[4], double vel[4]) ;
790 virtual std::string module() const ;
791 virtual void module(const std::string&);
792 virtual std::string inlineModule() const ;
793 virtual void inlineModule(const std::string&);
794 virtual std::string klass() const ;
795 virtual void klass(const std::string&);
796 virtual std::vector<double> parameters() const;
797 virtual void parameters(const std::vector<double>&);
#define GYOTO_DEBUG
Display debug message (in debug mode)
Definition GyotoDefs.h:341
#define GYOTO_DEBUG_EXPR(a)
Output expression value in debug mode.
Definition GyotoDefs.h:280
#define GYOTO_ERROR(msg)
Throw a Gyoto::Error nicely.
Definition GyotoError.h:196
Factory / SmartPointee::Subcontractor_t interface.
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
Introspectable properties.
Description of the observer screen.
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:685
Coding a Gyoto::Astrobj::ThinDisk in Python.
Definition GyotoPython.h:750
Factory / SmartPointee::Subcontractor_t interface.
Definition GyotoFactoryMessenger.h:92
std::string fullPath(std::string relpath)
Transform path into full path specification.
SmartPointer< Astrobj::Generic > astrobj()
Build and get the Astrobj described in this XML file.
int getNextParameter(std::string *name, std::string *content, std::string *unit=NULL)
Get name and value of next parameter.
SmartPointer< Metric::Generic > metric()
Build and get the Metric described in this XML file.
SmartPointer< Screen > screen()
Build and get the Screen described in this XML file.
double mass() const
Get mass used in unitLength()
Metric coded in Python.
Definition GyotoPython.h:590
Property that can be set and got using standard methods.
Definition GyotoProperty.h:608
static type_e typeFromString(std::string stype)
Get Property::type_e value from name.
type_e
Possible type of a Property instance.
Definition GyotoProperty.h:616
@ metric_t
Type is Gyoto::SmartPointer<Gyoto::Metric::Generic>
Definition GyotoProperty.h:644
@ astrobj_t
Type is Gyoto::SmartPointer<Gyoto::Astrobj::Generic>
Definition GyotoProperty.h:648
@ filename_t
Type is std::string and holds a file name.
Definition GyotoProperty.h:638
@ spectrometer_t
Type is Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>
Definition GyotoProperty.h:652
@ spectrum_t
Type is Gyoto::SmartPointer<Gyoto::Spectrum::Generic>
Definition GyotoProperty.h:650
@ screen_t
Type is Gyoto::SmartPointer<Gyoto::Screen::Generic>
Definition GyotoProperty.h:646
std::string name
Name of this instance.
Definition GyotoProperty.h:663
int type
Type of this instance.
Definition GyotoProperty.h:670
Base class for classes in the Python plug-in.
Definition GyotoPython.h:192
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:213
PyObject * pGet_
Reference to the (optional) Get method.
Definition GyotoPython.h:247
virtual std::string inlineModule() const
Return inline_module_.
PyObject * pProperties_
Reference to the properties member.
Definition GyotoPython.h:237
std::string module_
Name of the Python module that holds the class.
Definition GyotoPython.h:200
virtual std::string klass() const
Retrieve class_.
PyObject * pSet_
Reference to the (optional) Set method.
Definition GyotoPython.h:242
virtual std::string module() const
Return module_.
std::vector< double > parameters_
Parameters that this class needs.
Definition GyotoPython.h:222
PyObject * pInstance_
Reference to the python instance once it has been instantiated.
Definition GyotoPython.h:232
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:206
virtual std::vector< double > parameters() const
Retrieve parameters_.
PyObject * pModule_
Reference to the python module once it has been loaded.
Definition GyotoPython.h:227
Class template to implement parts of the Gyoto::Object API.
Definition GyotoPython.h:321
Pointers performing reference counting.
Definition GyotoSmartPointer.h:135
Loader for Python classes implementing the Spectrum interface.
Definition GyotoPython.h:503
PyObject * pCall_
Reference to ___call__.
Definition GyotoPython.h:513
virtual std::string inlineModule() const
Return inline_module_.
bool pCall_overloaded_
Whether call is overloaded.
Definition GyotoPython.h:537
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:518
Container for the value of a Property.
Definition GyotoValue.h:60
int type
Type of this instance.
Definition GyotoValue.h:72
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 * PyObject_FromGyotoValue(const Gyoto::Value &)
Convert Gyoto Value to Python Object.
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.
Gyoto::Spectrometer::Subcontractor_t * getSubcontractor(std::string name, std::vector< std::string > &plugins, int errmode=0)
Query the Spectrometer register.
Gyoto::Spectrum::Subcontractor_t * getSubcontractor(std::string name, std::vector< std::string > &plugins, int errmode=0)
Query the Spectrum register.
Namespace for the Gyoto library.
Definition GyotoAstrobj.h:44
std::vector< std::string > split(std::string const &src, std::string const &delim)
Split string.