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