[Debian-astro-commits] [gyoto] 104/221: Implmented Properties in KerrBL and Yorick
Thibaut Jean-Claude Paumard
thibaut at moszumanska.debian.org
Fri May 22 20:52:37 UTC 2015
This is an automated email from the git hooks/post-receive script.
thibaut pushed a commit to branch master
in repository gyoto.
commit b1f25ac8408bd7c7e4acfa8b038f13c9b96fffb8
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date: Tue Nov 25 15:13:05 2014 +0100
Implmented Properties in KerrBL and Yorick
---
include/GyotoAstrobj.h | 2 +-
include/GyotoKerrBL.h | 6 +----
include/GyotoMetric.h | 4 +--
include/GyotoObject.h | 61 +++++++++++++++++++++++++++++++++++++++++++++
include/GyotoPhoton.h | 2 +-
include/GyotoScenery.h | 2 +-
include/GyotoScreen.h | 2 +-
include/GyotoSpectrometer.h | 2 +-
lib/KerrBL.C | 28 ++++++---------------
lib/Metric.C | 48 ++++++++---------------------------
lib/Object.C | 18 ++++++-------
yorick/gyoto_utils.C | 43 ++++++++++++++++++++++++++++++++
yorick/ygyoto_private.h | 41 ++++++++++++++++++++++++++++++
13 files changed, 178 insertions(+), 81 deletions(-)
diff --git a/include/GyotoAstrobj.h b/include/GyotoAstrobj.h
index 0c0b03f..67ed3a1 100644
--- a/include/GyotoAstrobj.h
+++ b/include/GyotoAstrobj.h
@@ -184,7 +184,7 @@ namespace Gyoto{
*
* See introduction in the Gyoto::Astrobj namespace.
*/
-class Gyoto::Astrobj::Generic : protected Gyoto::SmartPointee {
+class Gyoto::Astrobj::Generic : public Gyoto::SmartPointee {
friend class Gyoto::SmartPointer<Gyoto::Astrobj::Generic>;
diff --git a/include/GyotoKerrBL.h b/include/GyotoKerrBL.h
index b7ab824..053495a 100644
--- a/include/GyotoKerrBL.h
+++ b/include/GyotoKerrBL.h
@@ -69,6 +69,7 @@ class Gyoto::Metric::KerrBL : public Metric::Generic {
// Constructors - Destructor
// -------------------------
public:
+ GYOTO_PROPERTY;
KerrBL(); ///< Default constructor
virtual KerrBL * clone () const ;
@@ -125,11 +126,6 @@ class Gyoto::Metric::KerrBL : public Metric::Generic {
void MakeMomentum(const double coordin[8], const double cst[5], double coordout[8]) const;
///< Transforms from Boyer-Lindquist coordinates [t,r,th,phi,tdot,rdot,thdot,phidot] to [t,r,th,phi,pt,pr,pth,pphi] where pt,pr... are generalized momenta.
- virtual int setParameter(std::string, std::string, std::string);
-#ifdef GYOTO_USE_XERCES
- virtual void fillElement(FactoryMessenger *fmp); ///< called from Factory
-#endif
-
protected:
// outside the API
diff --git a/include/GyotoMetric.h b/include/GyotoMetric.h
index 37c3d34..236b669 100644
--- a/include/GyotoMetric.h
+++ b/include/GyotoMetric.h
@@ -193,9 +193,7 @@ class Gyoto::Metric::Generic
public:
- static Property const * const properties;
- virtual Property const * getProperties() const;
-
+ GYOTO_PROPERTY;
const std::string kind() const; ///< Get kind_
int getRefCount();
diff --git a/include/GyotoObject.h b/include/GyotoObject.h
index 48c4673..9b3fb6f 100644
--- a/include/GyotoObject.h
+++ b/include/GyotoObject.h
@@ -35,6 +35,67 @@ namespace Gyoto {
class FactoryMessenger;
}
+/// Make an NULL-terminated array of ancestors
+/**
+ * Called automatically in GYOTO_PROPERTY_*
+ */
+#define GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor) \
+ Property const * const name##_ancestors[] = {ancestor, NULL}
+
+/// Define a new Property of type Bool
+/*
+ * Declares a static variable named "name". name and namef should not
+ * be quoted.
+ *
+ * \param[in] class name
+ * \param[in] name name of property if true;
+ * \param[in] namef name of property if false;
+ * \param[in] fname name of functions for setting or getting the property
+ * \param[in] ancestor pointer to next Property instance
+ */
+#define GYOTO_PROPERTY_BOOL(class, name, namef, fname, ancestor) \
+ GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
+ Property const name \
+ (#name, \
+ #namef, \
+ (Gyoto::Property::set_bool_t)&class :: fname, \
+ (Gyoto::Property::get_bool_t)&class :: fname, \
+ name##_ancestors)
+
+/// Define a Property of type Double
+#define GYOTO_PROPERTY_DOUBLE(class, name, fname, ancestor) \
+ GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
+ Property const name \
+ (#name, \
+ (Gyoto::Property::set_double_t)&class::fname, \
+ (Gyoto::Property::get_double_t)&class::fname, \
+ name##_ancestors)
+
+/// Define a Property of type Double supporting unit
+#define GYOTO_PROPERTY_DOUBLE_UNIT(class, name, fname, ancestor) \
+ GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
+ Property const name \
+ (#name, \
+ (Gyoto::Property::set_double_t)&class::fname, \
+ (Gyoto::Property::get_double_t)&class::fname, \
+ (Gyoto::Property::set_double_unit_t)&class::fname, \
+ (Gyoto::Property::get_double_unit_t)&class::fname, \
+ name##_ancestors)
+
+/// Define class::properties and class::getProperties()
+#define GYOTO_PROPERTY_FINALIZE(class, property) \
+ Property const * const class::properties = &property; \
+ Property const * class::getProperties() const { \
+ return class::properties; \
+ }
+
+/// Declare class::properties and class::getProperties()
+#define GYOTO_PROPERTY \
+ static Property const * const properties; \
+ virtual Property const * getProperties() const
+
+
+
/**
* \brief Object with properties
*/
diff --git a/include/GyotoPhoton.h b/include/GyotoPhoton.h
index 76a2c59..a439e1c 100644
--- a/include/GyotoPhoton.h
+++ b/include/GyotoPhoton.h
@@ -48,7 +48,7 @@ namespace Gyoto{
*
* This is the central object for ray-tracing.
*/
-class Gyoto::Photon : public Gyoto::Worldline, protected Gyoto::SmartPointee {
+class Gyoto::Photon : public Gyoto::Worldline, public Gyoto::SmartPointee {
friend class Gyoto::SmartPointer<Gyoto::Photon>;
// Data :
// -----
diff --git a/include/GyotoScenery.h b/include/GyotoScenery.h
index 338ad98..9e0c7aa 100644
--- a/include/GyotoScenery.h
+++ b/include/GyotoScenery.h
@@ -158,7 +158,7 @@ namespace Gyoto{
* </Scenery>
* \endcode
*/
-class Gyoto::Scenery : protected Gyoto::SmartPointee {
+class Gyoto::Scenery : public Gyoto::SmartPointee {
friend class Gyoto::SmartPointer<Gyoto::Scenery>;
diff --git a/include/GyotoScreen.h b/include/GyotoScreen.h
index 59bc57e..e60ae83 100644
--- a/include/GyotoScreen.h
+++ b/include/GyotoScreen.h
@@ -162,7 +162,7 @@ namespace Gyoto {
* "`pwd`/".
*
*/
-class Gyoto::Screen : protected Gyoto::SmartPointee {
+class Gyoto::Screen : public Gyoto::SmartPointee {
friend class Gyoto::SmartPointer<Gyoto::Screen>;
private:
diff --git a/include/GyotoSpectrometer.h b/include/GyotoSpectrometer.h
index 1806a59..4b47d55 100644
--- a/include/GyotoSpectrometer.h
+++ b/include/GyotoSpectrometer.h
@@ -169,7 +169,7 @@ namespace Gyoto{
}
class Gyoto::Spectrometer::Generic
-: protected Gyoto::SmartPointee,
+: public Gyoto::SmartPointee,
public Gyoto::Hook::Teller
{
friend class Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>;
diff --git a/lib/KerrBL.C b/lib/KerrBL.C
index c99c0f4..57dcd6c 100644
--- a/lib/KerrBL.C
+++ b/lib/KerrBL.C
@@ -35,6 +35,14 @@ using namespace std ;
using namespace Gyoto ;
using namespace Gyoto::Metric ;
+GYOTO_PROPERTY_DOUBLE(KerrBL, HorizonSecurity, horizonSecurity,
+ Generic::properties);
+GYOTO_PROPERTY_BOOL(KerrBL, GenericIntegrator, SpecificIntegrator,
+ genericIntegrator, &HorizonSecurity);
+GYOTO_PROPERTY_DOUBLE(KerrBL, DiffTol, difftol, &GenericIntegrator);
+GYOTO_PROPERTY_DOUBLE(KerrBL, Spin, spin, &DiffTol);
+GYOTO_PROPERTY_FINALIZE(KerrBL, Spin);
+
/*
NB: points delicats de KerrBL:
- z-axis problems (d'ou interet de KS? a creuser)
@@ -1231,23 +1239,3 @@ void KerrBL::observerTetrad(string const obskind,
}
Generic::observerTetrad(obskind,pos,fourvel,screen1,screen2,screen3);
}
-
-#ifdef GYOTO_USE_XERCES
-void KerrBL::fillElement(Gyoto::FactoryMessenger *fmp) {
- fmp -> setParameter("Spin", spin_);
- Metric::Generic::fillElement(fmp);
- fmp -> setParameter("DiffTol", difftol_);
- fmp->setParameter(generic_integrator_?"GenericIntegrator":"SpecificIntegrator");
- fmp -> setParameter("HorizonSecurity", drhor_);
-}
-#endif
-
-int KerrBL::setParameter(string name, string content, string unit) {
- if (name=="Spin") spin (atof(content.c_str()));
- else if (name=="DiffTol") difftol (atof(content.c_str()));
- else if (name=="GenericIntegrator") genericIntegrator(true);
- else if (name=="SpecificIntegrator") genericIntegrator(false);
- else if (name=="HorizonSecurity") horizonSecurity(atof(content.c_str()));
- else return Generic::setParameter(name, content, unit);
- return 0;
-}
diff --git a/lib/Metric.C b/lib/Metric.C
index 6979165..474c7b8 100644
--- a/lib/Metric.C
+++ b/lib/Metric.C
@@ -35,44 +35,16 @@ Register::Entry* Metric::Register_ = NULL;
//// Gyoto::Object API
// Keplerian/NonKeplerian
-#define GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor) \
- Property const * const name##_ancestors[] = {ancestor, NULL}
-
-#define GYOTO_PROPERTY_BOOL(name, namef, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- #namef, \
- (Property::set_bool_t)&fname, \
- (Property::get_bool_t)&fname, \
- name##_ancestors)
-
-#define GYOTO_PROPERTY_DOUBLE(name, fname, ancestor) \
- GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
- Property const name \
- (#name, \
- (Property::set_double_t)&fname, \
- (Property::get_double_t)&fname, \
- name##_ancestors)
-
-GYOTO_PROPERTY_BOOL(Keplerian, NonKeplerian, Metric::Generic::keplerian, Object::properties);
-GYOTO_PROPERTY_DOUBLE(DeltaMaxOverR, Metric::Generic::deltaMaxOverR, &Keplerian);
-GYOTO_PROPERTY_DOUBLE(DeltaMax, Metric::Generic::deltaMax, &DeltaMaxOverR);
-GYOTO_PROPERTY_DOUBLE(DeltaMin, Metric::Generic::deltaMin, &DeltaMax);
-
-// Mass
-Property const * const _Mass_ancestors[] = {&DeltaMin, NULL};
-Property _Mass(std::string("Mass"),
- (Property::set_double_t)&Metric::Generic::mass,
- (Property::get_double_t)&Metric::Generic::mass,
- (Property::set_double_unit_t)&Metric::Generic::mass,
- (Property::get_double_unit_t)&Metric::Generic::mass,
- _Mass_ancestors);
-Property const * const Metric::Generic::properties = &_Mass;
-
-Property const * Metric::Generic::getProperties() const {
- return Metric::Generic::properties;
-}
+GYOTO_PROPERTY_BOOL(Metric::Generic, Keplerian, NonKeplerian,
+ keplerian, Object::properties);
+GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMaxOverR,
+ deltaMaxOverR, &Keplerian);
+GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMax, deltaMax, &DeltaMaxOverR);
+GYOTO_PROPERTY_DOUBLE(Metric::Generic, DeltaMin, deltaMin, &DeltaMax);
+GYOTO_PROPERTY_DOUBLE_UNIT(Metric::Generic, Mass, mass, &DeltaMin);
+
+GYOTO_PROPERTY_FINALIZE(Metric::Generic, Mass);
+
///
Metric::Generic::Generic(const int coordkind, const std::string &name) :
diff --git a/lib/Object.C b/lib/Object.C
index 4a96d12..6f09348 100644
--- a/lib/Object.C
+++ b/lib/Object.C
@@ -73,7 +73,7 @@ void Object::get(Property const &p, double &val, std::string const &unit) {
if (getu) {
val = (this->*getu)(unit);
} else {
- if (unit == "") throwError("Can't set this Property with unit");
+ if (unit != "") throwError("Can't get this Property with unit");
get(p, val);
}
}
@@ -132,21 +132,19 @@ void Object::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) {
default:
throwError("Unimplemented");
}
+ Property const * const * parent = p.parents;
+ if (parent) {
+ for ( ; *parent; ++parent) {
+ fillProperty(fmp, **parent);
+ }
+ }
}
void Object::fillElement(Gyoto::FactoryMessenger *fmp) {
fmp -> setSelfAttribute("kind", kind_);
Property const * prop = getProperties();
- if (prop) {
- fillProperty(fmp, *prop);
- if (prop->parents) {
- Property const * const * parent;
- for (parent=prop->parents; *parent; ++parent) {
- fillProperty(fmp, **parent);
- }
- }
- }
+ if (prop) fillProperty(fmp, *prop);
}
void Object::setParameters(Gyoto::FactoryMessenger *fmp) {
diff --git a/yorick/gyoto_utils.C b/yorick/gyoto_utils.C
index 236fb5a..4cff883 100644
--- a/yorick/gyoto_utils.C
+++ b/yorick/gyoto_utils.C
@@ -350,3 +350,46 @@ long int __ygyoto_var_idx(long id) {
}
return ids[id];
}
+
+void ypush_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
+ Gyoto::Property const& p, int iarg,
+ std::string name, std::string unit) {
+ switch(p.type) {
+ case Gyoto::Property::bool_t:
+ {
+ bool val;
+ ptr->get(p, val);
+ ypush_long(name==p.name?val:!val);
+ }
+ break;
+ case Gyoto::Property::double_t:
+ {
+ double val;
+ ptr->get(p, val, unit);
+ ypush_double(val);
+ }
+ break;
+ default:
+ y_error("Property type unimplemented in ypush_property()");
+ }
+}
+
+void yget_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
+ Gyoto::Property const& p, int iarg, std::string name,
+ std::string unit) {
+ cerr << "dummy: should get property" << endl;
+ switch(p.type) {
+ case Gyoto::Property::bool_t:
+ {
+ bool val=ygets_l(iarg);
+ if (name != p.name) val = !val;
+ ptr->set(p, val);
+ }
+ break;
+ case Gyoto::Property::double_t:
+ ptr->set(p, ygets_d(iarg), unit);
+ break;
+ default:
+ y_error("Property type unimplemented in yget_property()");
+ }
+}
diff --git a/yorick/ygyoto_private.h b/yorick/ygyoto_private.h
index 59c16ea..374eeee 100644
--- a/yorick/ygyoto_private.h
+++ b/yorick/ygyoto_private.h
@@ -25,6 +25,13 @@
#ifndef __YGYOTO_PRIVATE_H
#define __YGYOTO_PRIVATE_H
+#include "GyotoSmartPointer.h"
+
+void ypush_property(Gyoto::SmartPointer<Gyoto::SmartPointee>,
+ Gyoto::Property const&, int, std::string, std::string);
+void yget_property(Gyoto::SmartPointer<Gyoto::SmartPointee>,
+ Gyoto::Property const&, int, std::string, std::string);
+
/*
The following are to declare a new base (such as Metric or Astrobj)
or independent (such as Photon) class. Seldom used in a Gyoto
@@ -87,6 +94,40 @@ long int __ygyoto_var_idx(long id);
} \
void gyoto_##NAME##_eval(void *obj, int argc); \
void gyoto_##NAME##_closure_eval(void *obj, int argc) { \
+ Property const * prop = ((gyoto_##NAME##_closure*)obj)->smptr \
+ ->property(((gyoto_##NAME##_closure*)obj)->member); \
+ if (prop) { \
+ std::string unit=""; \
+ std::string kwd=""; \
+ int parg=-1; \
+ long kidx=0; \
+ for (int iarg =argc-1; iarg>=0; --iarg) { \
+ if ((kidx=yarg_key(iarg))>=0) { \
+ /* this is a keyword */ \
+ if (strcmp(yfind_name(kidx),"unit")) \
+ y_error("Only the 'unit' keyword is supported"); \
+ unit=ygets_q(--iarg); \
+ } else { \
+ if (parg!=-1) \
+ y_error("Only one positional argument accepted"); \
+ parg=iarg; \
+ } \
+ } \
+ if (yarg_nil(parg)) parg=-1; \
+ if (parg==-1) \
+ ypush_property(((gyoto_##NAME##_closure*)obj)->smptr, \
+ *prop, parg, \
+ ((gyoto_##NAME##_closure*)obj)->member, \
+ unit); \
+ else { \
+ yget_property(((gyoto_##NAME##_closure*)obj)->smptr, \
+ *prop, parg, \
+ ((gyoto_##NAME##_closure*)obj)->member, \
+ unit); \
+ *ypush_##NAME()= ((gyoto_##NAME##_closure*)obj)->smptr; \
+ } \
+ return; \
+ } \
long used_var=0; \
/* we build a yorick statement into ss */ \
stringstream ss; \
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-astro/packages/gyoto.git
More information about the Debian-astro-commits
mailing list