Gyoto
GyotoWorldline.h
Go to the documentation of this file.
1 
6 /*
7  Copyright 2011 Frederic Vincent, Thibaut Paumard
8 
9  This file is part of Gyoto.
10 
11  Gyoto is free software: you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  Gyoto is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef __GyotoWorldline_H_
26 #define __GyotoWorldline_H_
27 
28 #include <iostream>
29 #include <fstream>
30 #include <string>
31 #include <GyotoDefs.h>
32 
33 namespace Gyoto {
34  class Worldline;
35  class FactoryMessenger;
36 }
37 
38 #include <GyotoSmartPointer.h>
39 #include <GyotoMetric.h>
40 #include <GyotoScreen.h>
41 #include <GyotoHooks.h>
42 
61 : protected Gyoto::Hook::Listener
62 {
63 
64  // Data :
65  // -----
66  protected:
68  double* x0_;
69  double* x1_;
70  double* x2_;
71  double* x3_;
72  double* x0dot_;
73  double* x1dot_;
74  double* x2dot_;
75  double* x3dot_;
76  size_t x_size_;
77  size_t imin_;
78  size_t i0_;
79  size_t imax_;
80  bool adaptive_;
81  double delta_;
82  double tmin_;
83  double * cst_;
84  size_t cst_n_;
85  int wait_pos_;
86  double * init_vel_;
87  size_t maxiter_ ;
88 
89  // Constructors - Destructor
90  // -------------------------
91  public:
92  Worldline() ;
93  Worldline(const size_t sz) ;
94 
95  Worldline(const Worldline& ) ;
96 
98 
111  Worldline(Worldline* orig, size_t i0, int dir, double step_max) ;
112 
113  virtual ~Worldline() ;
114 
115  size_t getImin() const;
116  size_t getImax() const;
117  size_t getI0() const;
118 
119  virtual double getMass() const = 0;
122  virtual void setInitCoord(const double coord[8], int dir = 0);
123 
131  virtual void setInitCoord(double pos[4], double vel[3], int dir=1);
132 
133  virtual void setPosition(double pos[4]);
134  virtual void setVelocity(double vel[3]);
135 
136  void reset() ;
137  void reInit() ;
138 
139  virtual std::string className() const ;
140  virtual std::string className_l() const ;
141 
142  // Memory management
143  // -----------------
144  protected:
148  void xAllocate();
149 
153  void xAllocate(size_t size);
154 
166  size_t xExpand(int dir);
167 
168  // Mutators / assignment
169  // ---------------------
170  public:
172  void operator=(const Worldline&) ;
173  void setDelta(const double delta);
174  void setDelta(double, const std::string &unit);
175  double getDelta() const ;
176  double getDelta(const std::string &unit) const ;
177  double getTmin() const ;
178  void setTmin(double tlim);
179  void adaptive (bool mode) ;
180  bool adaptive () const ;
181  void maxiter (size_t miter) ;
182  size_t maxiter () const ;
183 
188  double const * getCst() const ;
189 
191 
195  void setCst(double const * cst, size_t const ncsts) ;
196 
198 
206  const double coord[8],
207  const int dir) ;
208 
209  void getInitialCoord(double dest[8]) const;
210  void getCoord(size_t index, double dest[8]) const;
211  void getCartesianPos(size_t index, double dest[4]) const;
212 
213  void xFill(double tlim) ;
214 
237  virtual int setParameter(std::string name,
238  std::string content,
239  std::string unit) ;
240 
241 #ifdef GYOTO_USE_XERCES
242 
247  virtual void setParameters(FactoryMessenger *fmp) ;
253  virtual void fillElement(FactoryMessenger *fmp) const ;
255 #endif
256 
257  // Accessors
258  // ---------
259  public:
263  size_t get_nelements() const;
264 
268  void get_t(double *dest) const;
269 
270 
272 
288  void getCartesian(double const * const dates, size_t const n_dates,
289  double * const x, double * const y,
290  double * const z, double * const xprime=NULL,
291  double * const yprime=NULL, double * const zprime=NULL) ;
292 
296  void get_xyz(double* x, double *y, double *z) const;
297 
317  void getCoord(double const * const dates, size_t const n_dates,
318  double * const x1dest,
319  double * const x2dest, double * const x3dest,
320  double * const x0dot=NULL, double * const x1dot=NULL,
321  double * const x2dot=NULL, double * const x3dot=NULL) ;
322 
329  void getCoord(double *x0, double *x1, double *x2, double *x3) const ;
330 
339  void checkPhiTheta(double coord[8]) const;
340 
344  void getSkyPos(SmartPointer<Screen> screen, double *dalpha, double *ddellta, double *dD) const;
345 
349  void get_dot(double *x0dot, double *x1dot, double *x2dot, double *x3dot) const ;
350 
354  void get_prime(double *x1prime, double *x2prime, double *x3prime) const ;
355 
356  // Outputs
357  // -------
358  public:
359  //virtual void sauve(FILE *) const ; ///< Save in a file
360  void save_txyz(char * fichierxyz) const ;
361  void save_txyz(char* const filename, double const t1, double const mass_sun,
362  double const distance_kpc, std::string const unit, SmartPointer<Screen> sc = NULL);
363 
365  friend std::ostream& operator<<(std::ostream& , const Worldline& ) ;
366 
367  protected:
368  virtual void tell(Gyoto::Hook::Teller*);
369  class IntegState;
370 };
371 
372 
379  friend class Gyoto::SmartPointer<Gyoto::Worldline::IntegState>;
380 
381  private:
383 
388 
390 
393  Gyoto::SmartPointer<Gyoto::Metric::Generic> gg_;
394 
395  double coord_[8];
396  double norm_;
397  double normref_;
398  double delta_;
399 
401 
404  bool adaptive_;
405 
406  public:
408 
414  IntegState(Worldline * line, const double *coord, const double delta);
415 
417 
420  virtual int nextStep(double *coord);
421 
422  virtual ~IntegState();
423 };
424 
425 #endif
size_t get_nelements() const
Get number of computed dates.
Worldline * line_
Worldline that we are integrating.
Definition: GyotoWorldline.h:387
double * init_vel_
Hack in setParameters()
Definition: GyotoWorldline.h:86
virtual int nextStep(double *coord)
Make one step.
size_t maxiter() const
Get maxiter_.
void getInitialCoord(double dest[8]) const
Get initial coordinate.
void reset()
Forget integration, keeping initial contition.
double coord_[8]
Previously determined coordinate.
Definition: GyotoWorldline.h:395
void get_dot(double *x0dot, double *x1dot, double *x2dot, double *x3dot) const
Get computed 4-velocities.
Timelike or null geodesics.
Definition: GyotoWorldline.h:60
SmartPointer< Gyoto::Metric::Generic > metric_
The Gyoto::Metric in this part of the universe.
Definition: GyotoWorldline.h:67
double delta_
Initial integrating step ; defaults to 0.01.
Definition: GyotoWorldline.h:81
double const * getCst() const
Returns the worldline's cst of motion (if any)
void setTmin(double tlim)
Set tmin to a given value.
size_t getImin() const
Get index of computed date furthest in the past.
Tellers tell Listeners when they mutate.
Reference-counting pointers.
void get_t(double *dest) const
Get computed dates.
virtual int setParameter(std::string name, std::string content, std::string unit)
Set parameter by name.
double delta_
Integration step (current in case of adaptive).
Definition: GyotoWorldline.h:398
void reInit()
Reset and recompute particle properties.
double tmin_
Minimum time for integration, stop integration if t<tmin ; defaults to -DBL_MAX.
Definition: GyotoWorldline.h:82
bool adaptive_
Whether Worldline::delta_ is adaptive.
Definition: GyotoWorldline.h:404
double normref_
Initial norm of the 4-velocity.
Definition: GyotoWorldline.h:397
double getDelta() const
Get delta.
Factory / SmartPointee::Subcontractor_t interface.
Definition: GyotoFactoryMessenger.h:91
void xFill(double tlim)
Fill x0, x1... by integrating the Worldline from previously set inittial condition to time tlim...
size_t xExpand(int dir)
Expand x0, x1 etc... to hold more elements.
double * cst_
Worldline's csts of motion (if any)
Definition: GyotoWorldline.h:83
friend std::ostream & operator<<(std::ostream &, const Worldline &)
Display.
void getCartesian(double const *const dates, size_t const n_dates, double *const x, double *const y, double *const z, double *const xprime=NULL, double *const yprime=NULL, double *const zprime=NULL)
Get the 6 Cartesian coordinates for specific dates.
virtual void tell(Gyoto::Hook::Teller *)
This is how a Teller tells.
void getSkyPos(SmartPointer< Screen > screen, double *dalpha, double *ddellta, double *dD) const
Get computed positions in sky coordinates.
void checkPhiTheta(double coord[8]) const
Bring θ in [0,Π] and φ in [0,2Π].
virtual std::string className() const
"Worldline"
size_t i0_
Index of initial condition in array.
Definition: GyotoWorldline.h:78
Gyoto ubiquitous macros and typedefs.
void setInitialCondition(SmartPointer< Metric::Generic > gg, const double coord[8], const int dir)
Set or re-set the initial condition prior to integration.
Base class for metric description.
void save_txyz(char *fichierxyz) const
Save in a file.
size_t x_size_
Size of x0, x1... arrays.
Definition: GyotoWorldline.h:76
double * x0_
t or T
Definition: GyotoWorldline.h:68
bool adaptive_
Whether integration should use adaptive delta.
Definition: GyotoWorldline.h:80
double * x2_
theta or y
Definition: GyotoWorldline.h:70
double * x3dot_
phidot or zdot
Definition: GyotoWorldline.h:75
void setMetric(SmartPointer< Metric::Generic >)
Set metric Smartpointer.
double * x0dot_
tdot or Tdot
Definition: GyotoWorldline.h:72
Current state of a geodesic integration.
Definition: GyotoWorldline.h:378
void setDelta(const double delta)
Set delta.
virtual double getMass() const =0
Get mass of particule.
double getTmin() const
Get tmin value.
size_t getI0() const
Get index of initial condition.
virtual void setParameters(FactoryMessenger *fmp)
Process XML entity Uses wait_pos_ and init_vel_ to make sure setVelocity() is called after setPositio...
Can be pointed to by a SmartPointer.
Definition: GyotoSmartPointer.h:79
I might listen to a Teller.
Definition: GyotoHooks.h:64
SmartPointer< Metric::Generic > getMetric() const
Get metric.
virtual ~Worldline()
Destructor.
double * x3_
phi or z
Definition: GyotoWorldline.h:71
void get_xyz(double *x, double *y, double *z) const
Get 3-position in cartesian coordinates for computed dates.
void get_prime(double *x1prime, double *x2prime, double *x3prime) const
Get computed 3-velocities.
size_t cst_n_
Number of constants of motion.
Definition: GyotoWorldline.h:84
size_t imin_
Minimum index for which x0, x1... have been computed.
Definition: GyotoWorldline.h:77
double * x1dot_
rdot or xdot
Definition: GyotoWorldline.h:73
void getCartesianPos(size_t index, double dest[4]) const
Get Cartesian expression of 4-position at index.
size_t getImax() const
Get index of computed date furthest in the future.
Description of the observer screen.
double norm_
Current norm of the 4-velocity.
Definition: GyotoWorldline.h:396
virtual void setInitCoord(const double coord[8], int dir=0)
Set Initial coordinate.
void operator=(const Worldline &)
Assignment to another Worldline.
Gyoto::SmartPointer< Gyoto::Metric::Generic > gg_
The Metric in this end of the Universe.
Definition: GyotoWorldline.h:393
virtual std::string className_l() const
"worldline"
int wait_pos_
Hack in setParameters()
Definition: GyotoWorldline.h:85
bool adaptive() const
Get adaptive_.
double * x2dot_
thetadot or ydot
Definition: GyotoWorldline.h:74
void getCoord(size_t index, double dest[8]) const
Get coordinates corresponding to index.
Listen to me and I'll warn you when I change.
Definition: GyotoHooks.h:82
virtual void fillElement(FactoryMessenger *fmp) const
XML output.
virtual void setPosition(double pos[4])
Set initial 4-position.
double * x1_
r or x
Definition: GyotoWorldline.h:69
void setCst(double const *cst, size_t const ncsts)
Set Metric-specific constants of motion.
size_t maxiter_
Maximum number of iterations when integrating.
Definition: GyotoWorldline.h:87
void xAllocate()
Allocate x0, x1 etc. with default size.
Worldline()
Default constructor.
virtual void setVelocity(double vel[3])
Set initial 3-velocity.
size_t imax_
Maximum index for which x0, x1... have been computed.
Definition: GyotoWorldline.h:79