[Debian-astro-commits] [gyoto] 118/221: * New Value/Property type: spectrum; * Converted UniformSphere to Object/Property metaphor
Thibaut Jean-Claude Paumard
thibaut at moszumanska.debian.org
Fri May 22 20:52:39 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 f5659d915d3f4b462b286dbe4b24cfe2109a517c
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date: Thu Nov 27 18:42:00 2014 +0100
* New Value/Property type: spectrum;
* Converted UniformSphere to Object/Property metaphor
---
include/GyotoProperty.h | 24 ++++++++-
include/GyotoUniformSphere.h | 38 ++++----------
include/GyotoValue.h | 5 ++
lib/Object.C | 16 ++++++
lib/Property.C | 9 ++++
lib/UniformSphere.C | 115 +++++++++++++------------------------------
lib/Value.C | 9 +++-
yorick/gyoto_utils.C | 6 +++
8 files changed, 112 insertions(+), 110 deletions(-)
diff --git a/include/GyotoProperty.h b/include/GyotoProperty.h
index ca99499..723be57 100644
--- a/include/GyotoProperty.h
+++ b/include/GyotoProperty.h
@@ -34,6 +34,7 @@ namespace Gyoto {
class Object;
class Property;
namespace Metric { class Generic; }
+ namespace Spectrum { class Generic; }
template <class T> class SmartPointer;
}
@@ -120,6 +121,15 @@ namespace Gyoto {
(Gyoto::Property::get_metric_t)&class::fname, \
name##_ancestors)
+/// Define a Property of type Gyoto::Spectrum::Generic
+#define GYOTO_PROPERTY_SPECTRUM(class, name, fname, ancestor) \
+ GYOTO_PROPERTY_MAKE_ANCESTORS(name, ancestor); \
+ Property const name \
+ (#name, \
+ (Gyoto::Property::set_spectrum_t)&class::fname, \
+ (Gyoto::Property::get_spectrum_t)&class::fname, \
+ name##_ancestors)
+
/// Define class::properties and class::getProperties()
#define GYOTO_PROPERTY_FINALIZE(class, ancestor) \
Property const * const class::properties = ancestor; \
@@ -136,7 +146,7 @@ class Gyoto::Property
public:
enum type_e {double_t, long_t, bool_t, string_t, filename_t,
- vector_double_t, metric_t};
+ vector_double_t, metric_t, spectrum_t};
std::string name;
std::string name_false;
int type;
@@ -161,6 +171,11 @@ class Gyoto::Property
typedef Gyoto::SmartPointer<Gyoto::Metric::Generic>
(Object::* get_metric_t)() const;
+ typedef void (Object::* set_spectrum_t)
+ (Gyoto::SmartPointer<Gyoto::Spectrum::Generic>);
+ typedef Gyoto::SmartPointer<Gyoto::Spectrum::Generic>
+ (Object::* get_spectrum_t)() const;
+
union setter_t {
set_double_t set_double;
set_long_t set_long;
@@ -168,6 +183,7 @@ class Gyoto::Property
set_string_t set_string;
set_vector_double_t set_vdouble;
set_metric_t set_metric;
+ set_spectrum_t set_spectrum;
};
union getter_t {
get_double_t get_double;
@@ -176,6 +192,7 @@ class Gyoto::Property
get_string_t get_string;
get_vector_double_t get_vdouble;
get_metric_t get_metric;
+ get_spectrum_t get_spectrum;
};
union setter_unit_t {set_double_unit_t set_double;};
union getter_unit_t {get_double_unit_t get_double;};
@@ -219,6 +236,11 @@ class Gyoto::Property
get_metric_t get_metric,
Property const * const * ancestors);
+ Property(std::string name,
+ set_spectrum_t set_spectrum,
+ get_spectrum_t get_spectrum,
+ Property const * const * ancestors);
+
Property const * find(std::string name) const;
};
diff --git a/include/GyotoUniformSphere.h b/include/GyotoUniformSphere.h
index e782529..ac20a0c 100644
--- a/include/GyotoUniformSphere.h
+++ b/include/GyotoUniformSphere.h
@@ -94,7 +94,7 @@ class Gyoto::Astrobj::UniformSphere :
// -----
protected:
double radius_ ; ///< sphere radius [geometrical units]
- int isotropic_; ///< if 1, then emission just returns 1
+ bool isotropic_; ///< if 1, then emission just returns 1
double alpha_; ///< such that nu*I_nu = nu^alpha_; note that Xray photon
///< index Gamma is: alpha_ = 2-Gamma
SmartPointer<Spectrum::Generic> spectrum_; ///< sphere emission law
@@ -105,6 +105,8 @@ class Gyoto::Astrobj::UniformSphere :
// Constructors - Destructor
// -------------------------
public:
+ GYOTO_OBJECT;
+
/**
* Create UniformSphere object.
* \param kind: specifi kind (e.g. "Star" or "FixedStar")
@@ -146,38 +148,18 @@ class Gyoto::Astrobj::UniformSphere :
double radius(std::string) const ; ///< Get radius_ in specified unit
virtual void radius(double, std::string); ///< Set radius_ in specified unit
- double deltaMaxOverRadius(); ///< Get dltmor_
+ double deltaMaxOverRadius() const ; ///< Get dltmor_
virtual void deltaMaxOverRadius(double f); ///< Set dltmor_
- double deltaMaxOverDistance(); ///< Get dltmod_
+ double deltaMaxOverDistance() const ; ///< Get dltmod_
virtual void deltaMaxOverDistance(double f); ///< Set dltmod_
- public:
- virtual int setParameter(std::string name,
- std::string content,
- std::string unit) ;
+ bool isotropic() const;
+ void isotropic(bool);
+ double alpha() const ;
+ void alpha(double);
-#ifdef GYOTO_USE_XERCES
- /**
- * The sub-classes implementations of the
- * Astrobj::Generic::fillElement() method should call
- * Astrobj::UniformSphere::fillElement() to fill the common bits.
- */
- virtual void fillElement(FactoryMessenger *fmp) const ;
- ///< Fill the generic XML bits
- /**
- * The sub-classes subcontractor function (see
- * Astrobj::Subcontractor_t) should call this after creating the
- * object to interpret the common bits (Spectrum, Opacity, Radius):
-\code
- SmartPointer<MyObject> object = new MyObject (.....);
- fmp -> reset();
- object -> setParameters(fmp);
-\endcode
- */
- virtual void setParameters(FactoryMessenger *fmp) ;
- ///< Interpret common XML sections
-#endif
+ public:
virtual double operator()(double const coord[4]) ;
///< Square distance to the center of the sphere
diff --git a/include/GyotoValue.h b/include/GyotoValue.h
index d81ea6e..5a311a7 100644
--- a/include/GyotoValue.h
+++ b/include/GyotoValue.h
@@ -33,6 +33,7 @@
namespace Gyoto {
namespace Metric {class Generic;}
+ namespace Spectrum {class Generic;}
}
class Gyoto::Value {
@@ -65,6 +66,10 @@ class Gyoto::Value {
Gyoto::SmartPointer<Gyoto::Metric::Generic> Metric;
Value(Gyoto::SmartPointer<Gyoto::Metric::Generic>);
operator Gyoto::SmartPointer<Gyoto::Metric::Generic>();
+
+ Gyoto::SmartPointer<Gyoto::Spectrum::Generic> Spectrum;
+ Value(Gyoto::SmartPointer<Gyoto::Spectrum::Generic>);
+ operator Gyoto::SmartPointer<Gyoto::Spectrum::Generic>();
};
#endif
diff --git a/lib/Object.C b/lib/Object.C
index 2090b79..3673e4f 100644
--- a/lib/Object.C
+++ b/lib/Object.C
@@ -4,6 +4,7 @@
#include "GyotoError.h"
#include "GyotoFactoryMessenger.h"
#include "GyotoMetric.h"
+#include "GyotoSpectrum.h"
#include <iostream>
@@ -65,6 +66,7 @@ void Object::set(Property const &p, Value val) {
}
break;
___local_case(metric);
+ ___local_case(spectrum);
default:
throwError("Unimplemented Property type in Object::set");
}
@@ -112,6 +114,7 @@ Value Object::get(Property const &p) const {
}
break;
___local_case(metric);
+ ___local_case(spectrum);
default:
throwError("Unimplemented Property type in Object::get");
}
@@ -125,6 +128,7 @@ Property const * Object::property(std::string const pname) const {
#ifdef GYOTO_USE_XERCES
void Object::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const {
+ FactoryMessenger * childfmp=NULL;
string name=p.name;
switch (p.type) {
case Property::bool_t:
@@ -143,6 +147,11 @@ void Object::fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const
case Property::metric_t:
fmp->metric(get(p));
break;
+ case Property::spectrum_t:
+ childfmp = fmp -> makeChild ( name );
+ get(p).Spectrum -> fillElement(childfmp);
+ delete childfmp;
+ break;
default:
throwError("Property type unimplemented in Object::fillProperty()");
}
@@ -163,6 +172,7 @@ void Object::fillElement(Gyoto::FactoryMessenger *fmp) const {
void Object::setParameters(Gyoto::FactoryMessenger *fmp) {
string name="", content="", unit="";
+ FactoryMessenger * child = NULL;
if (fmp)
while (fmp->getNextParameter(&name, &content, &unit)) {
GYOTO_DEBUG << "Setting '" << name << "' to '" << content
@@ -177,6 +187,12 @@ void Object::setParameters(Gyoto::FactoryMessenger *fmp) {
case Property::metric_t:
set(*prop, fmp->metric());
break;
+ case Property::spectrum_t:
+ content = fmp -> getAttribute("kind");
+ child = fmp -> getChild();
+ set(*prop, (*Spectrum::getSubcontractor(content))(child) );
+ delete child;
+ break;
case Property::filename_t:
content = fmp->fullPath(content);
// no 'break;' here, we need to proceed
diff --git a/lib/Property.C b/lib/Property.C
index a4b54b3..683b138 100644
--- a/lib/Property.C
+++ b/lib/Property.C
@@ -55,6 +55,15 @@ Property::Property(string n,
getter.get_metric=get;
}
+Property::Property(string n,
+ set_spectrum_t set,
+ get_spectrum_t get,
+ Property const * const * ancestors)
+ : name(n), type(spectrum_t), parents(ancestors) {
+ setter.set_spectrum=set;
+ getter.get_spectrum=get;
+}
+
Property const * Property::find(std::string n) const {
if (this == NULL) return NULL;
if (name == n || (type == bool_t && name_false == n)) return this;
diff --git a/lib/UniformSphere.C b/lib/UniformSphere.C
index b1061c6..a492c3f 100644
--- a/lib/UniformSphere.C
+++ b/lib/UniformSphere.C
@@ -24,6 +24,7 @@
#include "GyotoBlackBodySpectrum.h"
#include "GyotoFactoryMessenger.h"
#include "GyotoConverters.h"
+#include "GyotoProperty.h"
#include <iostream>
#include <cmath>
@@ -37,6 +38,24 @@ using namespace std;
using namespace Gyoto;
using namespace Gyoto::Astrobj;
+GYOTO_PROPERTY_DOUBLE(UniformSphere, Radius, radius, Standard::properties);
+GYOTO_PROPERTY_DOUBLE(UniformSphere, Alpha, alpha, &Radius);
+GYOTO_PROPERTY_DOUBLE(UniformSphere,
+ DeltaMaxOverRadius, deltaMaxOverRadius, &Alpha);
+GYOTO_PROPERTY_DOUBLE(UniformSphere,
+ DeltaMaxOverDistance, deltaMaxOverDistance,
+ &DeltaMaxOverRadius);
+GYOTO_PROPERTY_BOOL(UniformSphere,
+ IsotropicEmittedIntensity,
+ TrueEmittedIntensity,
+ isotropic, &DeltaMaxOverDistance);
+GYOTO_PROPERTY_SPECTRUM(UniformSphere,
+ Opacity, opacity, &IsotropicEmittedIntensity);
+GYOTO_PROPERTY_SPECTRUM(UniformSphere,
+ Spectrum, spectrum, &Opacity);
+GYOTO_PROPERTY_FINALIZE(UniformSphere, &::Spectrum);
+
+
#define GYOTO_USPH_DELTAMAX_OVER_RAD 0.1
#define GYOTO_USPH_DELTAMAX_OVER_DST 0.1
@@ -57,8 +76,9 @@ UniformSphere::UniformSphere(string kin) :
// also initial safety_value_ etc.
radius(0.);
- spectrum_ = new Spectrum::BlackBody();
- opacity_ = new Spectrum::PowerLaw(0., 1.);
+ spectrum(new Spectrum::BlackBody());
+ opacity(new Spectrum::PowerLaw(0., 1.));
+ opticallyThin(false);
}
UniformSphere::UniformSphere(string kin,
@@ -74,9 +94,9 @@ UniformSphere::UniformSphere(string kin,
// also initialize safety_value_ etc.
radius(rad);
- spectrum_ = new Spectrum::BlackBody();
- opacity_ = new Spectrum::PowerLaw(0., 1.);
-
+ spectrum(new Spectrum::BlackBody());
+ opacity(new Spectrum::PowerLaw(0., 1.));
+ opticallyThin(false);
gg_=met;
}
@@ -111,7 +131,10 @@ SmartPointer<Spectrum::Generic> UniformSphere::spectrum() const { return spectru
void UniformSphere::spectrum(SmartPointer<Spectrum::Generic> sp) {spectrum_=sp;}
SmartPointer<Spectrum::Generic> UniformSphere::opacity() const { return opacity_; }
-void UniformSphere::opacity(SmartPointer<Spectrum::Generic> sp) {opacity_=sp;}
+void UniformSphere::opacity(SmartPointer<Spectrum::Generic> sp) {
+ opticallyThin(sp);
+ opacity_=sp;
+}
double UniformSphere::operator()(double const coord[4]) {
@@ -241,82 +264,14 @@ void UniformSphere::radius(double r, std::string unit) {
radius(Units::ToGeometrical(r, unit, gg_));
}
-double UniformSphere::deltaMaxOverRadius() {return dltmor_;}
+double UniformSphere::deltaMaxOverRadius() const {return dltmor_;}
void UniformSphere::deltaMaxOverRadius(double f) {dltmor_=f;}
-double UniformSphere::deltaMaxOverDistance() {return dltmod_;}
+double UniformSphere::deltaMaxOverDistance() const {return dltmod_;}
void UniformSphere::deltaMaxOverDistance(double f) {dltmod_=f;}
-int UniformSphere::setParameter(string name, string content, string unit) {
- if (name=="Radius") radius(atof(content.c_str()), unit);
- else if (name=="IsotropicEmittedIntensity") isotropic_=1;
- else if (name=="Alpha") alpha_=atof(content.c_str());
- else if (name=="DeltaMaxOverRadius") deltaMaxOverRadius(atof(content.c_str()));
- else if (name=="DeltaMaxOverDistance") deltaMaxOverDistance(atof(content.c_str()));
- else return Standard::setParameter(name, content, unit);
- return 0;
-}
-
-#ifdef GYOTO_USE_XERCES
-void UniformSphere::fillElement(FactoryMessenger *fmp) const {
- FactoryMessenger * childfmp=NULL;
-
- fmp -> metric (metric()) ;
- fmp -> setParameter ("Radius", radius());
-
- childfmp = fmp -> makeChild ( "Spectrum" );
- spectrum_ -> fillElement(childfmp);
- delete childfmp;
-
- childfmp = fmp -> makeChild ( "Opacity" );
- opacity_ -> fillElement(childfmp);
- delete childfmp;
-
- fmp -> setParameter ("DeltaMaxOverRadius", dltmor_);
- fmp -> setParameter ("DeltaMaxOverDistance", dltmod_);
-
- Astrobj::Generic::fillElement(fmp);
-}
-
-void Gyoto::Astrobj::UniformSphere::setParameters(FactoryMessenger* fmp){
- opticallyThin(0);
- if (!fmp) return;
-
- string name="", content="", unit="";
- FactoryMessenger * child = NULL;
-
-# if GYOTO_DEBUG_ENABLED
- GYOTO_DEBUG << "metric()" << endl;
-# endif
- metric(fmp->metric());
-
- while (fmp->getNextParameter(&name, &content, &unit)) {
- if (name=="Spectrum") {
- content = fmp -> getAttribute("kind");
- child = fmp -> getChild();
-# if GYOTO_DEBUG_ENABLED
- GYOTO_DEBUG << "spectrum()" << endl;
-# endif
- spectrum((*Spectrum::getSubcontractor(content))(child));
- delete child;
- }
- else if (name=="Opacity") {
- content = fmp -> getAttribute("kind");
- child = fmp -> getChild();
-# if GYOTO_DEBUG_ENABLED
- GYOTO_DEBUG << "opacity()" << endl;
-# endif
- opacity((*Spectrum::getSubcontractor(content))(child));
- opticallyThin(1);
- delete child;
- } else {
-# if GYOTO_DEBUG_ENABLED
- GYOTO_DEBUG << "setParameter("<<name<<", "<<content<<")\n";
-# endif
- setParameter(name, content, unit);
- }
- }
-
-}
+double UniformSphere::alpha() const { return alpha_; }
+void UniformSphere::alpha(double a) { alpha_ = a; }
-#endif
+bool UniformSphere::isotropic() const { return isotropic_; }
+void UniformSphere::isotropic(bool a) { isotropic_ = a; }
diff --git a/lib/Value.C b/lib/Value.C
index a34d88d..0143ae7 100644
--- a/lib/Value.C
+++ b/lib/Value.C
@@ -1,5 +1,6 @@
#include "GyotoValue.h"
#include "GyotoMetric.h"
+#include "GyotoSpectrum.h"
#include <iostream>
using namespace Gyoto ;
using namespace std ;
@@ -25,10 +26,15 @@ Value::Value(std::vector<double> val) : VDouble(val) {}
Value::operator std::vector<double>() const {return VDouble;}
Value::Value(Gyoto::SmartPointer<Gyoto::Metric::Generic> p)
- : Metric(p) {cerr << "In Value constructor: Metric==" << Metric() << endl;}
+ : Metric(p) {}
Value::operator Gyoto::SmartPointer<Gyoto::Metric::Generic>()
{ return Metric; }
+Value::Value(Gyoto::SmartPointer<Gyoto::Spectrum::Generic> p)
+ : Spectrum(p) {}
+Value::operator Gyoto::SmartPointer<Gyoto::Spectrum::Generic>()
+{ return Spectrum; }
+
Value& Value::operator=(Value const &right) {
# define ___local_case(member) member = right.member
___local_case(Double);
@@ -37,6 +43,7 @@ Value& Value::operator=(Value const &right) {
___local_case(String);
___local_case(VDouble);
___local_case(Metric);
+ ___local_case(Spectrum);
return *this;
# undef ___local_case
}
diff --git a/yorick/gyoto_utils.C b/yorick/gyoto_utils.C
index b039f03..8ee10ef 100644
--- a/yorick/gyoto_utils.C
+++ b/yorick/gyoto_utils.C
@@ -385,6 +385,9 @@ void ypush_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
case Gyoto::Property::metric_t:
*ypush_Metric() = val.Metric;
break;
+ case Gyoto::Property::spectrum_t:
+ *ypush_Spectrum() = val.Spectrum;
+ break;
default:
y_error("Property type unimplemented in ypush_property()");
}
@@ -420,6 +423,9 @@ void yget_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
case Gyoto::Property::metric_t:
val = *yget_Metric(iarg);
break;
+ case Gyoto::Property::spectrum_t:
+ val = *yget_Spectrum(iarg);
+ break;
default:
y_error("Property type unimplemented in yget_property()");
}
--
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