[Debian-astro-commits] [gyoto] 111/221: Convert Astrobj::Generic to Object/Property paradigm
Thibaut Jean-Claude Paumard
thibaut at moszumanska.debian.org
Fri May 22 20:52:38 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 714d24bb9bbb90be2e875be2c9b3579654564ce0
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date: Wed Nov 26 23:02:51 2014 +0100
Convert Astrobj::Generic to Object/Property paradigm
---
include/GyotoAstrobj.h | 99 +++++++++++++-----------------------------------
include/GyotoFixedStar.h | 2 +
include/GyotoObject.h | 7 +++-
include/GyotoStar.h | 1 -
lib/Astrobj.C | 84 +++++++++++++++++-----------------------
lib/FixedStar.C | 6 ++-
lib/Object.C | 4 +-
lib/Star.C | 13 +------
lib/Torus.C | 4 +-
9 files changed, 79 insertions(+), 141 deletions(-)
diff --git a/include/GyotoAstrobj.h b/include/GyotoAstrobj.h
index 67ed3a1..0d16bfa 100644
--- a/include/GyotoAstrobj.h
+++ b/include/GyotoAstrobj.h
@@ -200,54 +200,36 @@ class Gyoto::Astrobj::Generic : public Gyoto::SmartPointee {
/**
* Maximum distance from the center of the coordinate system at
- * which a photon may hit the object. Child classes may choose to
- * update rMax at all time or to use it to cache the value, for
- * instance when rMax() is called. External classes (Photons in
- * particular) must use rMax() to access this information.
- *
- * #rmax_set_==1 means that #rmax_ was set using rMax() or the
- * constructor. In this case, rMax() must always return this
- * value, not recompute it.
+ * which a photon may hit the object. Child classes may compute a
+ * decent value for #rmax_ at any time if #rmax_ is
+ * DBL_MAX. External classes (Photons in particular) must use rMax()
+ * to access this information.
*
* #rmax_ is in geometrical units.
*/
double rmax_; ///< Maximum distance to the center of the coordinate system [geometrical units]
- /**
- * #rmax_set_==1 means that #rmax_ was set using rMax(double r) or the
- * constructor. In this case, rMax() must always return this
- * value, not recompute it.
- *
- * Use unsetRmax() to reset rmax_set_ to 0.
- *
- */
- int rmax_set_; ///< Never recompute rmax: it was externally set
-
- /**
- * The kind should match the name of the class, e.g. "Star" for a
- * Gyoto::Star.
- */
- std::string kind_; ///< Kind of object (e.g. "Star"...)
-
- int flag_radtransf_; ///< 1 if radiative transfer inside Astrobj, else 0
+ bool flag_radtransf_; ///< 1 if radiative transfer inside Astrobj, else 0
int radiativeq_; ///< 1 to use the new radiativeQ function (under dvp)
int noredshift_; ///< 1 to impose redshift factor g = 1
// Constructors - Destructor
// -------------------------
public:
+ GYOTO_OBJECT;
+
/**
- * #kind_ = "Default", #rmax_ = 0., #rmax_set_ = 0.
+ * #kind_ = "Default", #rmax_ = DBL_MAX
*/
Generic(); ///< Default constructor.
/**
- * #kind_ = "Default", #rmax_ = radmax, #rmax_set_ = 1.
+ * #kind_ = "Default", #rmax_ = radmax
*/
Generic(double radmax); ///< Set rmax in constructor.
/**
- * #kind_ = kind, #rmax_ = 0., #rmax_set_ = 0.
+ * #kind_ = kind, #rmax_ = DBL_MAX
*/
Generic(std::string kind); ///< Set kind in constructor.
@@ -293,14 +275,15 @@ class Gyoto::Astrobj::Generic : public Gyoto::SmartPointee {
* Get maximal distance from center of coordinate system at which a
* Photon may hit the object.
*
- * Child classes may use the rmax_ member to cache this value.
+ * Child classes may use the #rmax_ member to cache this value, if
+ * its current value is DBL_MAX.
*
- * It can also be set using rmax(). If rmax has been used
- * to set rmax_, rMax() must not recompute it.
+ * It can also be set using rMax().
*
* \return rmax_ in geometrical units
*/
virtual double rMax(); ///< Get maximal distance from center of coordinate system
+ virtual double rMax() const; ///< Get maximal distance from center of coordinate system
/**
* Call rMax() and convert result to unit.
@@ -308,7 +291,8 @@ class Gyoto::Astrobj::Generic : public Gyoto::SmartPointee {
* \param unit string
* \return double rmax converted to unit
*/
- virtual double rMax(std::string unit); ///< Get rmax_ is specified unit
+ virtual double rMax(std::string const &unit); ///< Get rmax_ is specified unit
+ virtual double rMax(std::string const &unit) const; ///< Get rmax_ is specified unit
/// Get max step constraint for adaptive integration
/**
@@ -323,7 +307,6 @@ class Gyoto::Astrobj::Generic : public Gyoto::SmartPointee {
* Set maximal distance from center of coordinate system at which a
* Photon may hit the object.
*
- * Side effect: set #rmax_set_ to 1.
* \param val new #rmax_ in geometrical units.
*/
virtual void rMax(double val); ///< Set maximal distance from center of coordinate system
@@ -335,28 +318,27 @@ class Gyoto::Astrobj::Generic : public Gyoto::SmartPointee {
* \param val #rmax_ expressed in unit "unit";
* \param unit string...
*/
- virtual void rMax(double val, std::string unit); ///< Set maximal distance from center of coordinate system
-
- /**
- * rmax() will then be free to recompute rmax_. Astrobjs
- * which cache rmax_ may need to update it when unrmax() is
- * called.
- */
- virtual void unsetRmax() ; ///< Set rmax_set_ to 0.
+ virtual void rMax(double val, std::string const &unit); ///< Set maximal distance from center of coordinate system
/**
* Set flag indicating that radiative transfer should be integrated,
* i.e. the object is to be considered optically thin.
* \param flag: 1 if optically thin, 0 if optically thick.
*/
- void opticallyThin(int flag);
+ void opticallyThin(bool flag);
///< Set whether the object is optically thin.
/**
- * See opticallyThin(int flag).
+ * See opticallyThin(bool flag).
*/
- int opticallyThin() const ;
+ bool opticallyThin() const ;
///< Query whether object is optically thin.
+ void radiativeQ(bool flag);
+ bool radiativeQ() const ;
+
+ void redshift(bool flag);
+ bool redshift() const ;
+
/**
* Return a Gyoto::Quantity_t suitable as input to
* Gyoto::Scenery::setRequestedQuantities() to set de default
@@ -368,35 +350,6 @@ class Gyoto::Astrobj::Generic : public Gyoto::SmartPointee {
//XML I/O
public:
- /**
- * \brief Set parameter by name
- *
- * Assume MyKind is a subclass of Astrobj::Generic which has two
- * members (a string StringMember and a double DoubleMember):
- * \code
- * int MyKind::setParameter(std::string name,
- * std::string content,
- * std::string unit) {
- * if (name=="StringMember") setStringMember(content);
- * else if (name=="DoubleMember") setDoubleMember(atof(content.c_str()),
- * unit);
- * else return Generic::setParameter(name, content, unit);
- * return 0;
- * }
- * \endcode
- * If MyKind is not a direct subclass of Generic but is a subclass
- * of e.g. Standard, UniformSphere of ThinDisk, it should call the
- * corresponding setParameter() implementation instead of
- * Generic::setParameter().
- *
- * \param name XML name of the parameter
- * \param content string representation of the value
- * \param unit string representation of the unit
- * \return 0 if this parameter is known, 1 if it is not.
- */
- virtual int setParameter(std::string name,
- std::string content,
- std::string unit) ;
#ifdef GYOTO_USE_XERCES
/**
diff --git a/include/GyotoFixedStar.h b/include/GyotoFixedStar.h
index 6a1262b..0a60dc6 100644
--- a/include/GyotoFixedStar.h
+++ b/include/GyotoFixedStar.h
@@ -81,6 +81,8 @@ class Gyoto::Astrobj::FixedStar : public Astrobj::UniformSphere {
double const * getPos() const; ///< Get const pointer to pos_
void getPos(double* dst) const; ///< Get a copy of the pos_ array
+ double rMax();
+
bool rotating() const ;
void rotating(bool) ;
diff --git a/include/GyotoObject.h b/include/GyotoObject.h
index 2f1b4bb..7d7ab15 100644
--- a/include/GyotoObject.h
+++ b/include/GyotoObject.h
@@ -122,6 +122,9 @@ namespace Gyoto {
static Property const * const properties; \
virtual Property const * getProperties() const
+#define GYOTO_OBJECT \
+ static Property const * const properties; \
+ virtual Property const * getProperties() const
/**
@@ -153,7 +156,7 @@ class Gyoto::Object
virtual Property const * getProperties() const;
#ifdef GYOTO_USE_XERCES
- void fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) ;
+ void fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const ;
/// Called from Factory
/**
@@ -161,7 +164,7 @@ class Gyoto::Object
* parameters to XML and call the Metric::fillElement(fmp) for the
* shared properties
*/
- virtual void fillElement(Gyoto::FactoryMessenger *fmp) ;
+ virtual void fillElement(Gyoto::FactoryMessenger *fmp) const ;
/**
* \brief Main loop in Subcontractor_t function
diff --git a/include/GyotoStar.h b/include/GyotoStar.h
index d9b765d..8d0a150 100644
--- a/include/GyotoStar.h
+++ b/include/GyotoStar.h
@@ -143,7 +143,6 @@ class Gyoto::Astrobj::Star :
public:
using UniformSphere::rMax;
virtual double rMax() ;
- virtual void unsetRmax();
// void setCoordSys(int); ///< Get coordinate system for integration
// int getCoordSys(); ///< Set coordinate system for integration
virtual void setInitialCondition(double coord[8]); ///< Same as Worldline::setInitialCondition(gg, coord, sys,1)
diff --git a/lib/Astrobj.C b/lib/Astrobj.C
index fe23119..2cdeb22 100644
--- a/lib/Astrobj.C
+++ b/lib/Astrobj.C
@@ -41,9 +41,18 @@ using namespace Gyoto::Astrobj;
Register::Entry* Gyoto::Astrobj::Register_ = NULL;
-Generic::Generic(string kin) :
+GYOTO_PROPERTY_BOOL(Generic, OpticallyThin, OpticallyThick,
+ opticallyThin, Object::properties);
+GYOTO_PROPERTY_BOOL(Generic, RadiativeQ, NoRadiativeQ,
+ radiativeQ, &OpticallyThin);
+GYOTO_PROPERTY_BOOL(Generic, Redshift, NoRedshift,
+ redshift, &RadiativeQ);
+GYOTO_PROPERTY_DOUBLE_UNIT(Generic, RMax, rMax, &Redshift);
+GYOTO_PROPERTY_FINALIZE(Astrobj::Generic, RMax);
+
- gg_(NULL), rmax_(DBL_MAX), rmax_set_(0), kind_(kin), flag_radtransf_(0),
+Generic::Generic(string kin) :
+ SmartPointee(kin), gg_(NULL), rmax_(DBL_MAX), flag_radtransf_(0),
radiativeq_(0), noredshift_(0)
{
#if GYOTO_DEBUG_ENABLED
@@ -53,7 +62,7 @@ Generic::Generic(string kin) :
Generic::Generic() :
- gg_(NULL), rmax_(DBL_MAX), rmax_set_(0), kind_("Default"), flag_radtransf_(0),
+ SmartPointee("Default"), gg_(NULL), rmax_(DBL_MAX), flag_radtransf_(0),
radiativeq_(0), noredshift_(0)
{
#if GYOTO_DEBUG_ENABLED
@@ -62,7 +71,7 @@ Generic::Generic() :
}
Generic::Generic(double radmax) :
- gg_(NULL), rmax_(radmax), rmax_set_(1), kind_("Default"), flag_radtransf_(0),
+ SmartPointee("Default"), gg_(NULL), rmax_(radmax), flag_radtransf_(0),
radiativeq_(0), noredshift_(0)
{
#if GYOTO_DEBUG_ENABLED
@@ -72,7 +81,7 @@ Generic::Generic(double radmax) :
Generic::Generic(const Generic& orig) :
SmartPointee(orig), gg_(NULL),
- rmax_(orig.rmax_), rmax_set_(orig.rmax_set_), kind_(orig.kind_),
+ rmax_(orig.rmax_),
flag_radtransf_(orig.flag_radtransf_), radiativeq_(orig.radiativeq_),
noredshift_(orig.noredshift_)
{
@@ -99,64 +108,39 @@ Generic::~Generic() {
SmartPointer<Metric::Generic> Generic::metric() const { return gg_; }
void Generic::metric(SmartPointer<Metric::Generic> gg) {gg_=gg;}
-double Generic::rMax() {
- return rmax_;
-}
-
-double Generic::rMax(string unit) {
- return Units::FromGeometrical(rMax(), unit, gg_);
-}
-
-const string Generic::kind() const {
- return kind_;
-}
-
-void Generic::rMax(double val) {
- rmax_set_=1;
- rmax_=val;
-}
-
-void Generic::rMax(double val, string unit) {
- rMax(Units::ToGeometrical(val, unit, gg_));
-}
+const string Generic::kind() const { return kind_; }
-void Generic::unsetRmax() {
- rmax_set_=0;
-}
+double Generic::rMax() { return rmax_; }
+double Generic::rMax() const { return rmax_; }
+double Generic::rMax(string const &unit) {
+ return Units::FromGeometrical(rMax(), unit, gg_); }
+double Generic::rMax(string const &unit) const {
+ return Units::FromGeometrical(rMax(), unit, gg_); }
+void Generic::rMax(double val) { rmax_=val; }
+void Generic::rMax(double val, string const &unit) {
+ rMax(Units::ToGeometrical(val, unit, gg_)); }
#ifdef GYOTO_USE_XERCES
void Generic::fillElement(FactoryMessenger *fmp) const {
- if (rmax_set_) fmp -> setParameter ( "RMax", rmax_ ) ;
fmp -> metric(gg_);
- fmp -> setSelfAttribute("kind", kind_);
- fmp -> setParameter ( flag_radtransf_? "OpticallyThin" : "OpticallyThick");
+ Object::fillElement(fmp);
}
void Generic::setParameters(FactoryMessenger *fmp) {
- string name="", content="", unit="";
- if (fmp) {
- metric(fmp->metric());
- while (fmp->getNextParameter(&name, &content, &unit))
- setParameter(name, content, unit);
- }
+ if (fmp) metric(fmp->metric());
+ Object::setParameters(fmp);
}
#endif
-void Generic::opticallyThin(int flag) {flag_radtransf_=flag;}
-int Generic::opticallyThin() const {return flag_radtransf_;}
+void Generic::opticallyThin(bool flag) {flag_radtransf_=flag;}
+bool Generic::opticallyThin() const {return flag_radtransf_;}
-int Generic::setParameter(string name, string content, string unit) {
- char* tc = const_cast<char*>(content.c_str());
- if (name=="Flag_radtransf") flag_radtransf_= atoi(tc);
- else if (name=="OpticallyThin") flag_radtransf_= 1;
- else if (name=="OpticallyThick") flag_radtransf_= 0;
- else if (name=="RMax") rMax(atof(tc), unit);
- else if (name=="RadiativeQ") radiativeq_=1;
- else if (name=="NoRedshift") noredshift_=1;
- else return 1;
- return 0;
-}
+void Generic::radiativeQ(bool flag) {radiativeq_=flag;}
+bool Generic::radiativeQ() const {return radiativeq_;}
+
+void Generic::redshift(bool flag) {noredshift_=!flag;}
+bool Generic::redshift() const {return !noredshift_;}
void Generic::processHitQuantities(Photon* ph, double* coord_ph_hit,
double* coord_obj_hit, double dt,
diff --git a/lib/FixedStar.C b/lib/FixedStar.C
index 1501bad..2370cf8 100644
--- a/lib/FixedStar.C
+++ b/lib/FixedStar.C
@@ -146,7 +146,10 @@ void FixedStar::radius(double r) {
# endif
return;
}
- if (!rmax_set_) {
+}
+
+double FixedStar::rMax() {
+ if (rmax_==DBL_MAX) {
switch (gg_ -> coordKind()) {
case GYOTO_COORDKIND_SPHERICAL:
rmax_=3.*(pos_[0]+radius_);
@@ -158,6 +161,7 @@ void FixedStar::radius(double r) {
throwError("unimplemented coordinate system in FixedStar");
}
}
+ return rmax_;
}
void FixedStar::setPos(const double p[3])
diff --git a/lib/Object.C b/lib/Object.C
index 454de64..b9f9b76 100644
--- a/lib/Object.C
+++ b/lib/Object.C
@@ -137,7 +137,7 @@ Property const * Object::getProperties() const {
#ifdef GYOTO_USE_XERCES
-void Object::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) {
+void Object::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const {
string name=p.name;
switch (p.type) {
case Property::bool_t:
@@ -180,7 +180,7 @@ void Object::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) {
}
}
-void Object::fillElement(Gyoto::FactoryMessenger *fmp) {
+void Object::fillElement(Gyoto::FactoryMessenger *fmp) const {
fmp -> setSelfAttribute("kind", kind_);
Property const * prop = getProperties();
diff --git a/lib/Star.C b/lib/Star.C
index be41b75..9f22787 100644
--- a/lib/Star.C
+++ b/lib/Star.C
@@ -109,23 +109,14 @@ void Star::getCartesian(double const * const t,
double Star::rMax() {
- // rmax may not be up to date. Assume it's OK if it's non-0 warning:
- // if line is extended, need to either update rmax or reset it to 0
- // if (debug()) cerr << "DEBUG: Star::rMax(): rmax_set_=="
- // << rmax_set_ << endl;
- if (!rmax_set_ && !rmax_) {
+ if (rmax_==DBL_MAX) {
size_t i;
for (i=imin_;i<=imax_;++i) if (x1_[i]>rmax_) rmax_=x1_[i];
- rmax_*=3.;
+ rmax_ *= 3.;
}
return rmax_;
}
-void Star::unsetRmax() {
- rmax_set_=0;
- rmax_=DBL_MAX;
-}
-
int Star::setParameter(string name, string content, string unit) {
if (!UniformSphere::setParameter(name, content, unit)) ; // if found
else if (!Worldline ::setParameter(name, content, unit)) ; // do nothing
diff --git a/lib/Torus.C b/lib/Torus.C
index 33f657b..96eea8d 100644
--- a/lib/Torus.C
+++ b/lib/Torus.C
@@ -84,7 +84,9 @@ SmartPointer<Spectrum::Generic> Torus::opacity() const { return opacity_; }
void Torus::opacity(SmartPointer<Spectrum::Generic> sp) {opacity_=sp;}
double Torus::rMax() {
- if (!rmax_set_ && rmax_==DBL_MAX) { rmax_ = 3.*(c_+sqrt(critical_value_)); }
+ if (rmax_==DBL_MAX) {
+ rmax_ = 3.*(c_+sqrt(critical_value_));
+ }
return rmax_ ;
}
--
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