[Debian-astro-commits] [gyoto] 109/221: Convert most of NumericalMetricLorene to the 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 3ab767866961fcbd5f54f304bfa057da4f26422e
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Wed Nov 26 14:58:49 2014 +0100

    Convert most of NumericalMetricLorene to the Object/Property paradigm.
---
 include/GyotoNumericalMetricLorene.h |  18 ++++-
 lib/NumericalMetricLorene.C          | 133 ++++++++++++++++++-----------------
 2 files changed, 86 insertions(+), 65 deletions(-)

diff --git a/include/GyotoNumericalMetricLorene.h b/include/GyotoNumericalMetricLorene.h
index 47fdf6e..8580c52 100644
--- a/include/GyotoNumericalMetricLorene.h
+++ b/include/GyotoNumericalMetricLorene.h
@@ -52,7 +52,7 @@ class Gyoto::Metric::NumericalMetricLorene
 
  private:
   char* filename_; ///< Lorene .d data file(s) path
-  char* mapkind_; ///< Kind of Lorene mapping Map_af or Map_et
+  bool mapet_; ///< Kind of Lorene mapping: 'false' for Map_af, 'true' for Map_et
   int has_surface_; ///< 1 if the metric source has a surface
   int specify_marginalorbits_; ///< 1 if marginal orbits are specified in file
   double horizon_; ///< Value of horizon (or any innermost limit)
@@ -77,6 +77,7 @@ class Gyoto::Metric::NumericalMetricLorene
   void free(); ///< deallocate memory
 
  public:
+  GYOTO_PROPERTY;
   NumericalMetricLorene(); ///< Constructor
   NumericalMetricLorene(const NumericalMetricLorene&); ///< Copy constructor
   virtual NumericalMetricLorene* clone() const ;
@@ -86,6 +87,20 @@ class Gyoto::Metric::NumericalMetricLorene
    * Access functions to get or set private attributes
    */
   virtual void setMetricSource();
+
+  void        directory(std::string const &dir) ;
+  std::string directory() const ;
+  double initialTime() const ;
+  void   initialTime(double t0);
+  double horizon() const ;
+  void   horizon(double t0);
+  bool hasSurface() const;
+  void hasSurface(bool s);
+  bool specifyMarginalOrbits() const;
+  void specifyMarginalOrbits(bool s);
+  bool mapEt() const;
+  void mapEt(bool s);
+
   char const * getFileName() const;
   Lorene::Vector** getShift_tab() const;
   Lorene::Scalar** getLapse_tab() const;
@@ -178,7 +193,6 @@ class Gyoto::Metric::NumericalMetricLorene
   virtual int setParameter(std::string, std::string, std::string);
 #ifdef GYOTO_USE_XERCES
   virtual void fillElement(FactoryMessenger *fmp); /// < called from Factory
-  virtual void setParameters(FactoryMessenger *fmp);
 #endif
 
 };
diff --git a/lib/NumericalMetricLorene.C b/lib/NumericalMetricLorene.C
index 20718e2..8558256 100644
--- a/lib/NumericalMetricLorene.C
+++ b/lib/NumericalMetricLorene.C
@@ -28,10 +28,27 @@ using namespace Lorene;
 using namespace Gyoto;
 using namespace Gyoto::Metric;
 
+// Keep File first here, so it is processed last in fillElement() 
+GYOTO_PROPERTY_FILENAME(NumericalMetricLorene,
+			File, directory, Generic::properties);
+GYOTO_PROPERTY_DOUBLE(NumericalMetricLorene,
+		      Time, initialTime, &File);
+GYOTO_PROPERTY_DOUBLE(NumericalMetricLorene,
+		      Horizon, horizon, &Time);
+GYOTO_PROPERTY_BOOL(NumericalMetricLorene,
+		    HasSurface, HasNoSurface, hasSurface, &Horizon);
+GYOTO_PROPERTY_BOOL(NumericalMetricLorene,
+		    SpecifyMarginalOrbits, DontSpecifyMarginalOrbits,
+		    specifyMarginalOrbits, &HasSurface);
+GYOTO_PROPERTY_BOOL(NumericalMetricLorene,
+		    MapEt, MapAf,
+		    mapEt, &SpecifyMarginalOrbits);
+GYOTO_PROPERTY_FINALIZE(NumericalMetricLorene, MapEt);
+
 NumericalMetricLorene::NumericalMetricLorene() :
   WIP("Metric::NumericalMetricLorene"),
   Generic(GYOTO_COORDKIND_SPHERICAL, "NumericalMetricLorene"),
-  mapkind_(NULL),
+  mapet_(true),
   initial_time_(0.),
   has_surface_(0),
   specify_marginalorbits_(0),
@@ -58,7 +75,7 @@ NumericalMetricLorene::NumericalMetricLorene() :
 
 NumericalMetricLorene::NumericalMetricLorene(const NumericalMetricLorene&o) :
   Generic(GYOTO_COORDKIND_SPHERICAL,"NumericalMetricLorene"),
-  mapkind_(NULL),
+  mapet_(o.mapet_),
   initial_time_(o.initial_time_),
   has_surface_(o.has_surface_),
   specify_marginalorbits_(o.specify_marginalorbits_),
@@ -81,7 +98,7 @@ NumericalMetricLorene::NumericalMetricLorene(const NumericalMetricLorene&o) :
   rmb_(o.rmb_)
 {
   GYOTO_DEBUG << endl;
-  NumericalMetricLorene::setMetricSource();
+  if (o.filename_) directory(o.filename_);
 }
 
 NumericalMetricLorene* NumericalMetricLorene::clone() const{
@@ -185,15 +202,12 @@ void NumericalMetricLorene::setMetricSource() {
     Mg3d* grid = new Mg3d(resu) ;
     Map* map;
     /* Use Map_af for collapse + Kerr + BS, Map_et for star imaging */
-    if (mapkind_=="MapEt"){
+    if (mapet_) { // Map_et case
       //Map_et* map = new Map_et(*grid, resu) ;
       map = new Map_et(*grid, resu) ;
-    }else if (mapkind_=="MapAf"){
+    } else {      // Map_af case
       //      Map_af* map = new Map_af(*grid, resu) ;
       map = new Map_af(*grid, resu) ;
-    }else{
-      cout << "MapKind= " << mapkind_ << endl;
-      throwError("In NumericalMetricLorene: bad mapping kind.");
     }
     Scalar* lapse = new Scalar(*map, *grid, resu) ;
     (*lapse).std_spectral_base() ;
@@ -1586,43 +1600,58 @@ void NumericalMetricLorene::setParticleProperties(Worldline * line,
   line -> setCst(cst,3);
 }
 
+void NumericalMetricLorene::directory(std::string const &dir) {
+  char const * const cdir=dir.c_str();
+  filename_ = new char[strlen(cdir)+1];
+  strcpy(filename_, cdir);
+  setMetricSource();
+}
+
+std::string NumericalMetricLorene::directory() const {
+  return filename_?string(filename_):string("");
+}
+
+bool NumericalMetricLorene::hasSurface() const {return  has_surface_;}
+void NumericalMetricLorene::hasSurface(bool s) {
+  has_surface_ = s;
+  if (filename_!=NULL){
+    throwError("In NumericalMetricLorene::setParameter "
+	       "please provide Surface information before File in XML");
+  }
+}
+
+bool NumericalMetricLorene::specifyMarginalOrbits() const {
+  return specify_marginalorbits_;
+}
+void NumericalMetricLorene::specifyMarginalOrbits(bool s) {
+  specify_marginalorbits_=s;
+  if (filename_!=NULL){
+    throwError("In NumericalMetricLorene::setParameter "
+	       "please provide Marginal orbits information "
+	       "before File in XML");
+  }
+}
+
+bool NumericalMetricLorene::mapEt() const {return  mapet_;}
+void NumericalMetricLorene::mapEt(bool s) {
+  mapet_ = s;
+  if (filename_!=NULL){
+    throwError("In NumericalMetricLorene::setParameter "
+	       "please provide MapET/MapAF information before File in XML");
+  }
+}
+
+double NumericalMetricLorene::initialTime() const {return initial_time_;}
+void NumericalMetricLorene::initialTime(double t0) {initial_time_=t0;}
+
+double NumericalMetricLorene::horizon() const {return horizon_;}
+void NumericalMetricLorene::horizon(double r0) {horizon_=r0;}
+
 int  NumericalMetricLorene::setParameter(string name,
 					  string content,
 					  string unit) {
   GYOTO_DEBUG << endl;
-  if (name=="File") {
-    if (mapkind_!="MapEt" && mapkind_!="MapAf"){
-      throwError("In NumericalMetricLorene::setParameter "
-		 "please provide Map kind before File in XML");
-    }
-    filename_ = new char[strlen(content.c_str())+1];
-    strcpy(filename_,content.c_str());
-    setMetricSource();
-  }
-  else if (name=="MapEt") {
-    mapkind_="MapEt";
-  }
-  else if (name=="MapAf") {
-    mapkind_="MapAf";
-  }
-  else if (name=="Time") initial_time_=atof(content.c_str());
-  else if (name=="HasSurface") {
-    if (filename_!=NULL){
-      throwError("In NumericalMetricLorene::setParameter "
-		 "please provide Surface information before File in XML");
-    }
-    has_surface_=1;
-  }
-  else if (name=="SpecifyMarginalOrbits") {
-    if (filename_!=NULL){
-      throwError("In NumericalMetricLorene::setParameter "
-		 "please provide Marginel orbits information "
-		 "before File in XML");
-    }
-    specify_marginalorbits_=1;
-  }
-  else if (name=="Horizon") horizon_=atof(content.c_str());
-  else if (name=="RefineIntegStep"){
+  if (name=="RefineIntegStep"){
     refine_=1;
     double parms[2];
     if (FactoryMessenger::parseArray(content, parms, 2) != 2)
@@ -1637,15 +1666,6 @@ int  NumericalMetricLorene::setParameter(string name,
 #ifdef GYOTO_USE_XERCES
 void NumericalMetricLorene::fillElement(Gyoto::FactoryMessenger *fmp) {
   GYOTO_DEBUG << endl;
-  fmp -> setParameter("File", filename_);
-  if      (!strcmp(mapkind_, "MapEt")) fmp->setParameter("MapEt");
-  else if (!strcmp(mapkind_, "MapAf")) fmp->setParameter("MapAf");
-  fmp -> setParameter("Time", initial_time_);
-  if (has_surface_)
-    fmp -> setParameter("HasSurface");
-  if (specify_marginalorbits_)
-    fmp -> setParameter("SpecifyMarginalOrbits");
-  fmp -> setParameter("Horizon", horizon_);
   if (refine_) {
     double parms[2] = {r_refine_, h0_refine_};
     fmp -> setParameter("RefineIntegStep", parms, 2);
@@ -1653,17 +1673,4 @@ void NumericalMetricLorene::fillElement(Gyoto::FactoryMessenger *fmp) {
   Generic::fillElement(fmp);
 }
 
-void NumericalMetricLorene::setParameters(FactoryMessenger* fmp) {
-  GYOTO_DEBUG << endl;
-  string name="", content="", unit="";
-  if (fmp) {
-    while (fmp->getNextParameter(&name, &content, &unit)) {
-      if (name == "File") content = fmp -> fullPath( content );
-      GYOTO_DEBUG << "Setting \"" << name << "\" to \"" << content
-		  << "\" (in unit \"" << unit << "\")\n";
-      setParameter(name, content, unit);
-    }
-  }
-}
-
 #endif

-- 
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