ESTER
Evolution STEllaire en Rotation
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
symbolic.h
Go to the documentation of this file.
1 #ifndef _SYMBOLIC_H
2 #define _SYMBOLIC_H
3 
4 #include "ester-config.h"
5 #include <vector>
6 #include <map>
7 #include <string>
8 #include <iostream>
9 #include <cmath>
10 #include "matrix.h"
11 #include "mapping.h"
12 #include "solver.h"
13 
14 class rational {
15  int n,d;
16  rational &reduce();
17  static int gcd(int a,int b);
18 public:
19  rational(int num=1,int den=1);
20  int num() const;
21  int den() const;
22  double eval() const;
23  rational operator+(const rational &q) const;
24  inline rational operator+() const {return *this;};
25  rational operator-() const;
26  inline rational operator-(const rational &q) const {return *this+(-q);};
27  rational operator*(const rational &q) const;
28  rational inv() const;
29  inline rational operator/(const rational &q) const {return *this*q.inv();};
30  inline rational &operator+=(const rational &q) {return *this=*this+q;};
31  inline rational &operator-=(const rational &q) {return *this=*this-q;};
32  inline rational &operator*=(const rational &q) {return *this=*this*q;};
33  inline rational &operator/=(const rational &q) {return *this=*this/q;};
34  rational pow(int) const;
35  bool operator==(const rational &q) const;
36  inline bool operator!=(const rational &q) const {return !(*this==q);};
37  bool operator>(const rational &q) const;
38  bool operator<(const rational &q) const;
39  inline bool operator>=(const rational &q) const {return !(*this<q);};;
40  inline bool operator<=(const rational &q) const {return !(*this>q);};;
41  friend std::ostream& operator<<(std::ostream& os, const rational&);
42 };
43 
44 inline rational operator+(const int &n,const rational &q) {return q+rational(n);}
45 inline rational operator-(const int &n,const rational &q) {return -q+rational(n);}
46 inline rational operator*(const int &n,const rational &q) {return q*rational(n);}
47 inline rational operator/(const int &n,const rational &q) {return q.inv()*rational(n);}
48 
49 inline rational operator+(const rational &q,const int &n) {return q+rational(n);}
50 inline rational operator-(const rational &q,const int &n) {return q-rational(n);}
51 inline rational operator*(const rational &q,const int &n) {return q*rational(n);}
52 inline rational operator/(const rational &q,const int &n) {return q*rational(1,n);}
53 
54 inline double operator+(const double &n,const rational &q) {return n+q.eval();}
55 inline double operator-(const double &n,const rational &q) {return n-q.eval();}
56 inline double operator*(const double &n,const rational &q) {return n*q.eval();}
57 inline double operator/(const double &n,const rational &q) {return n/q.eval();}
58 
59 inline double operator+(const rational &q,const double &n) {return q.eval()+n;}
60 inline double operator-(const rational &q,const double &n) {return q.eval()-n;}
61 inline double operator*(const rational &q,const double &n) {return q.eval()*n;}
62 inline double operator/(const rational &q,const double &n) {return q.eval()/n;}
63 
64 rational abs(const rational &q);
65 
66 std::ostream& operator<<(std::ostream& os, const rational&);
67 
68 
69 class symbolic;
70 class sym_vec;
71 class sym_tens;
72 
73 class sym {
74  class sym_expr;
75  class symbol;
76  class sym_deriv;
77  class sym_num;
78  class sym_add;
79  class sym_prod;
80  class sym_sin;
81  class sym_cos;
82  class sym_exp;
83  class sym_log;
84 
87 
88 public:
89  sym();
90  sym(const sym &);
91  explicit sym(const double &);
92  explicit sym(const int &);
93  sym(const rational &q);
94  ~sym();
95 
96  symbolic *check_context() const;
97  symbolic *check_context(const sym &s) const;
98  symbolic *check_context(const sym_vec &s) const;
99  symbolic *check_context(const sym_tens &s) const;
100 
101  sym &operator=(const sym &);
102  sym &operator=(double n) {return *this=sym(n);};
103  friend sym operator+(const sym &,const sym &);
104  friend sym operator*(const sym &,const sym &);
105  sym &operator+=(const sym &s) {return *this=*this+s;};
106  sym &operator-=(const sym &s) {return *this=*this+sym(-1)*s;};
107  sym &operator*=(const sym &s) {return *this=*this*s;};
108  sym &operator/=(const sym &s) {return *this=*this*pow(s,-1);};
109  sym &operator+=(double n) {return *this+=sym(n);};
110  sym &operator-=(double n) {return *this-=sym(n);};
111  sym &operator*=(double n) {return *this*=sym(n);};
112  sym &operator/=(double n) {return *this/=sym(n);};
113  friend sym pow(const sym &,const rational &);
114  friend sym sin(const sym &);
115  friend sym cos(const sym &);
116  friend sym exp(const sym &);
117  friend sym log(const sym &);
118  friend sym diff(const sym &,const sym &);
119  friend sym jacobian(const sym &,const sym &);
120  bool operator==(const sym &s) const;
121  inline bool operator!=(const sym &s) const {return !(*this==s);};
122  inline bool operator==(double n) const {return *this==sym(n);};
123  inline bool operator!=(double n) const {return !(*this==sym(n));};
124 
125  matrix eval() const;
126 
127  friend bool sort_pair_d(const std::pair<sym_expr *,double> &,const std::pair<sym_expr *,double> &);
128  friend bool sort_pair_r(const std::pair<sym_expr *,rational> &,const std::pair<sym_expr *,rational> &);
129  friend std::ostream& operator<<(std::ostream& os, const sym::sym_expr&);
130  friend std::ostream& operator<<(std::ostream& os, const sym&);
131 
132  friend sym trig_simplify(const sym &);
133 
134  void add(solver *op,std::string eq_name,std::string var_name) const;
135  void add(solver *op,std::string eq_name,std::string var_name,const matrix &d) const;
136  void add_ex(solver *op,int n,std::string eq_name,std::string var_name) const;
137  void add_ex(solver *op,int n,std::string eq_name,std::string var_name,const matrix &d) const;
138 
139  void bc_top1_add(solver *op,int n,std::string eq_name,std::string var_name) const;
140  void bc_top2_add(solver *op,int n,std::string eq_name,std::string var_name) const;
141  void bc_bot1_add(solver *op,int n,std::string eq_name,std::string var_name) const;
142  void bc_bot2_add(solver *op,int n,std::string eq_name,std::string var_name) const;
143  void bc_top1_add(solver *op,int n,std::string eq_name,std::string var_name,const matrix &d) const;
144  void bc_top2_add(solver *op,int n,std::string eq_name,std::string var_name,const matrix &d) const;
145  void bc_bot1_add(solver *op,int n,std::string eq_name,std::string var_name,const matrix &d) const;
146  void bc_bot2_add(solver *op,int n,std::string eq_name,std::string var_name,const matrix &d) const;
147 
148  friend class symbolic;
149  friend class sym_vec;
150  friend class sym_tens;
151 };
152 
153 sym operator+(const sym &,const sym &);
154 inline sym operator+(double n,const sym &s) {return s+sym(n);};
155 inline sym operator+(const sym &s,double n) {return s+sym(n);};
156 inline sym operator+(const sym &s) {return s;};
157 sym operator*(const sym &,const sym &);
158 inline sym operator*(double n,const sym &s) {return s*sym(n);};
159 inline sym operator*(const sym &s,double n) {return s*sym(n);};
160 inline sym operator-(const sym &s) {return (-1)*s;};
161 template <class T>
162  sym operator-(const sym &s1,const T &s2) {return s1+(-s2);};
163 inline sym operator-(double n,const sym &s2) {return n+(-s2);};
164 sym pow(const sym &,const rational &);
165 inline sym pow(const sym &s,const int &n) {return pow(s,rational(n));}
166 template <class T>
167  sym operator/(const sym &s1,const T &s2) {return s1*pow(s2,-1);};
168 inline sym operator/(double n,const sym &s2) {return n*pow(s2,-1);};
169 inline sym sqrt(const sym &s) {return pow(s,rational(1,2));};
170 sym sin(const sym &);
171 sym cos(const sym &);
172 sym tan(const sym &);
173 sym exp(const sym &);
174 sym log(const sym &);
175 sym pow(const sym &,const sym &);
176 inline sym pow(const sym &s,const double &n) {return pow(s,sym(n));}
177 sym pow(const double &n,const sym &s);
178 sym diff(const sym &,const sym &);
179 sym jacobian(const sym &,const sym &);
180 
181 std::ostream& operator<<(std::ostream& os, const sym&);
182 
183 sym trig_simplify(const sym &);
184 sym_vec trig_simplify(const sym_vec &);
186 
188 
189 class sym_vec {
190  sym s[3];
192 
193  void set_context(symbolic *context);
194 public:
196 
197  symbolic *check_context() const;
198  symbolic *check_context(const sym &s) const;
199  symbolic *check_context(const sym_vec &s) const;
200  symbolic *check_context(const sym_tens &s) const;
201 
202  bool is_covariant();
203  bool is_contravariant();
204  void set_type(sym_vec_type);
205  sym_vec set_variance(const sym_vec &) const;
207  sym &operator()(int);
208  sym operator()(int) const;
209  sym operator,(const sym_vec &) const;
210  sym_vec operator,(const sym_tens &) const;
211  sym_vec operator+(const sym_vec &) const;
212  friend sym_vec operator-(const sym_vec &v);
213  sym_vec operator*(const sym &) const;
214  sym_vec operator*(double n) const {return (*this)*sym(n);};
215  sym_vec operator/(const sym &) const;
216  sym_vec operator/(double n) const {return (*this)/sym(n);};
217  friend sym_vec cross(const sym_vec &,const sym_vec &);
218  friend sym_tens tensor(const sym_vec &,const sym_vec &);
219  sym D(const sym &) const;
220  sym_vec D(const sym_vec &) const;
221 
222  friend class symbolic;
223  friend class sym;
224  friend class sym_tens;
225 };
226 inline sym_vec operator+(const sym_vec &v) {return v;};
227 sym_vec operator-(const sym_vec &v);
228 inline sym_vec operator-(const sym_vec &v,const sym_vec &w) {return v+(-w);};
229 inline sym_vec operator*(const sym &s,const sym_vec &v) {return v*s;};
230 inline sym_vec operator*(double n,const sym_vec &v) {return v*n;};
231 sym_vec cross(const sym_vec &,const sym_vec &);
232 sym_tens tensor(const sym_vec &,const sym_vec &);
233 
234 std::ostream& operator<<(std::ostream& os, const sym_vec&);
235 
236 class sym_tens {
237  sym s[3][3];
239 
240  void set_context(symbolic *context);
241 public:
243 
244  symbolic *check_context() const;
245  symbolic *check_context(const sym &s) const;
246  symbolic *check_context(const sym_vec &s) const;
247  symbolic *check_context(const sym_tens &s) const;
248 
249  bool is_covariant(int);
250  bool is_contravariant(int);
252  sym_tens set_variance(const sym_tens &) const;
254  sym &operator()(int,int);
255  sym operator()(int,int) const;
256  sym_vec operator,(const sym_vec &) const;
257  sym_tens operator,(const sym_tens &) const;
258  sym_tens operator+(const sym_tens &) const;
259  friend sym_tens operator-(const sym_tens &v);
260  sym_tens operator*(const sym &) const;
261  sym_tens operator*(double n) const {return (*this)*sym(n);};
262  sym_tens operator/(const sym &) const;
263  sym_tens operator/(double n) const {return (*this)/sym(n);};
264  friend sym_tens tensor(const sym_vec &,const sym_vec &);
265  sym operator%(const sym_tens &) const;
266  sym_tens T() const;
267 
268  friend class symbolic;
269  friend class sym;
270  friend class sym_vec;
271 };
272 
273 inline sym_tens operator+(const sym_tens &v) {return v;};
274 sym_tens operator-(const sym_tens &v);
275 inline sym_tens operator-(const sym_tens &v,const sym_tens &w) {return v+(-w);};
276 inline sym_tens operator*(const sym &s,const sym_tens &v) {return v*s;};
277 inline sym_tens operator*(double n,const sym_tens &v) {return v*n;};
278 
279 std::ostream& operator<<(std::ostream& os, const sym_tens&);
280 
281 class symbolic {
282  std::map<std::string,sym::symbol> vars;
283  std::map<std::string,matrix> val;
284  std::map<std::string,int> par;
287  int maxder;
288  inline sym d(const sym &s,int k) {return diff(s,x[k]);};
289  inline sym G(int i,int j,int k) {return christoffel(i,j,k);};
290 
291  void add(const sym &s,solver *op,int n,std::string type,
292  std::string eq_name,std::string var_name,const matrix &d);
293  void add_bc(const sym &s,solver *op,int n,std::string type,
294  std::string eq_name,std::string var_name,const matrix &d);
295 
296 public:
300  sym x[3];
301  static double tol;
302  static bool expand_products;
303  static bool trig_simplify;
304  static bool axisymmetric;
305  static bool spherical;
306  static double round_to_tol(double);
307  const sym &one;
308  symbolic();
309  ~symbolic() {};
310  void init();
311  sym regvar(const std::string &name);
312  sym regconst(const std::string &name);
313  sym regvar_indep(const std::string &name);
314  sym var(const std::string &name);
315 
316  void set_value(const char *name,const matrix &value,int parity=0);
317  void set_map(const mapping &map);
318 
319  sym::sym_expr *derive(const sym::sym_expr &,const sym::symbol &);
320  matrix get_value(const sym::sym_expr &);
321 
322  sym Dz(const sym &);
323  sym Dt(const sym &);
324  sym Dphi(const sym &);
325  sym det(const sym_tens &);
326  sym_tens inv(const sym_tens &);
327 
328  sym_vec contravariant(const sym_vec &);
329  sym_vec covariant(const sym_vec &);
334 
335  double perm(int i,int j,int k);
336 
337  sym_vec gradient(const sym &);
338  sym christoffel(int,int,int);
339  sym covderiv(const sym_vec &,int,int);
340  sym_tens gradient(const sym_vec &);
341  sym divergence(const sym_vec &v);
342  sym_vec divergence(const sym_tens &t);
343  sym laplacian(const sym &s);
344  sym_vec curl(const sym_vec &v);
345  sym_vec laplacian(const sym_vec &v);
346  sym_tens stress(const sym_vec &v);
347 
348  friend class sym;
349 };
350 
351 inline sym_vec contravariant(const sym_vec &s) {return s.check_context()->contravariant(s);};
352 inline sym_vec covariant(const sym_vec &s) {return s.check_context()->covariant(s);};
357 
358 inline sym_vec grad(const sym &s) {return s.check_context()->gradient(s);};
359 inline sym_tens grad(const sym_vec &v) {return v.check_context()->gradient(v);};
360 inline sym div(const sym_vec &v) {return v.check_context()->divergence(v);};
361 inline sym_vec div(const sym_tens &t) {return t.check_context()->divergence(t);};
363 inline sym lap(const sym &s) {return s.check_context()->laplacian(s);};
364 inline sym_vec curl(const sym_vec &v) {return v.check_context()->curl(v);};
365 inline sym_vec lap(const sym_vec &v) {return v.check_context()->laplacian(v);};
366 inline sym_tens stress(const sym_vec &v) {return v.check_context()->stress(v);};
367 
368 inline sym Dz(const sym &s) {return s.check_context()->Dz(s);};
369 inline sym Dt(const sym &s) {return s.check_context()->Dt(s);};
370 inline sym Dphi(const sym &s) {return s.check_context()->Dphi(s);};
371 
372 
373 // Abstract node type
375 public:
376  virtual ~sym_expr() {};
377  virtual int order() const=0;
378  virtual sym_expr *clone() const=0;
379  virtual sym_expr *reduce() {return this;};
380  virtual sym_expr *derive(const sym_expr &)=0;
381  virtual int comp(const sym_expr &s) const=0; // 1 if this>s, 0 if this==s, -1 if this<s
382  virtual matrix eval() const=0;
383  virtual std::ostream &print(std::ostream&) const=0;
384  bool operator>(const sym_expr &s) const {return this->comp(s)==1;};
385  bool operator<(const sym_expr &s) const {return this->comp(s)==-1;};
386  bool operator==(const sym_expr &s) const {return this->comp(s)==0;};
387  bool operator>=(const sym_expr &s) const {return this->comp(s)!=-1;};
388  bool operator<=(const sym_expr &s) const {return this->comp(s)!=1;};
389  bool operator!=(const sym_expr &s) const {return this->comp(s)!=0;};
390  sym_expr *add(const sym_expr &);
391  sym_expr *mult(const sym_expr &);
392  sym_expr *pow(const rational &);
393  sym_expr *sin();
394  sym_expr *cos();
395  sym_expr *exp();
396  sym_expr *log();
397 };
398 
399 std::ostream& operator<<(std::ostream& os, const sym::sym_expr&);
400 
401 // Node types
402 
403 class sym::sym_num: public sym_expr {
404 public:
405  int order() const {return 0;};
406  double value;
407  sym_num() {};
408  sym_num(const double &);
409  sym_num *clone() const;
410  int comp(const sym_expr &) const;
411  sym_expr *reduce();
412  sym_expr *derive(const sym_expr &);
413  matrix eval() const;
414  std::ostream &print(std::ostream&) const;
415 };
416 
417 class sym::symbol: public sym_expr {
418 public:
419  int order() const {return 1;};
420  std::string name;
423  symbol *clone() const;
424  int comp(const sym_expr &) const;
425  sym_expr *derive(const sym_expr &);
426  matrix eval() const;
427  std::ostream &print(std::ostream&) const;
428 };
429 
430 class sym::sym_deriv: public sym_expr {
431 public:
432  sym_deriv() {};
433  ~sym_deriv();
434  sym_deriv(const sym_deriv &);
435  int order() const {return 2;};
436  symbolic *context;
439  sym_deriv *clone() const;
440  int comp(const sym_expr &) const;
441  sym_expr *reduce();
442  sym_expr *derive(const sym_expr &);
443  static sym_deriv *create(sym_expr *,const symbol &);
444  matrix eval() const;
445  std::ostream &print(std::ostream&) const;
446 };
447 
448 class sym::sym_add: public sym_expr {
449 public:
450  int order() const {return 3;};
451  std::vector<std::pair<sym_expr *,double> > oper;
452  sym_add() {};
453  sym_add(const sym_add &);
454  ~sym_add();
455  sym_add *clone() const;
456  int comp(const sym_expr &) const;
457  sym_expr *reduce();
458  sym_expr *derive(const sym_expr &);
459  matrix eval() const;
460  std::ostream &print(std::ostream&) const;
461  static sym_add *create(sym_expr *,sym_expr *);
462  sym_expr *multiply(const sym_add &);
463  sym_expr *power(int n);
464 };
465 
466 class sym::sym_prod: public sym_expr {
467 public:
468  int order() const {return 4;};
469  std::vector<std::pair<sym_expr *,rational> > oper;
470  sym_prod() {};
471  sym_prod(const sym_prod &);
472  ~sym_prod();
473  sym_prod *clone() const;
474  int comp(const sym_expr &) const;
475  sym_expr *reduce();
476  sym_expr *derive(const sym_expr &);
477  matrix eval() const;
478  std::ostream &print(std::ostream&) const;
479  static sym_prod *create(sym_expr *,sym_expr *);
480  static sym_prod *create_pow(sym_expr *,const rational &);
481 };
482 
483 bool sort_pair_d(const std::pair<sym::sym_expr *,double> &,const std::pair<sym::sym_expr *,double> &);
484 bool sort_pair_r(const std::pair<sym::sym_expr *,rational> &,const std::pair<sym::sym_expr *,rational> &);
485 
486 class sym::sym_sin: public sym_expr {
487 public:
488  int order() const {return 5;};
489  sym_expr *oper;
490  sym_sin() {};
491  ~sym_sin();
492  sym_sin(const sym_sin &);
493  sym_sin *clone() const;
494  int comp(const sym_expr &) const;
495  sym_expr *reduce();
496  sym_expr *derive(const sym_expr &);
497  matrix eval() const;
498  std::ostream &print(std::ostream&) const;
499  static sym_sin *create(sym_expr *);
500 };
501 
502 class sym::sym_cos: public sym_expr {
503 public:
504  int order() const {return 6;};
505  sym_expr *oper;
506  sym_cos() {};
507  ~sym_cos();
508  sym_cos(const sym_cos &);
509  sym_cos *clone() const;
510  int comp(const sym_expr &) const;
511  sym_expr *reduce();
512  sym_expr *derive(const sym_expr &);
513  matrix eval() const;
514  std::ostream &print(std::ostream&) const;
515  static sym_cos *create(sym_expr *);
516 };
517 
518 class sym::sym_exp: public sym_expr {
519 public:
520  int order() const {return 7;};
521  sym_expr *oper;
522  sym_exp() {};
523  ~sym_exp();
524  sym_exp(const sym_exp &);
525  sym_exp *clone() const;
526  int comp(const sym_expr &) const;
527  sym_expr *reduce();
528  sym_expr *derive(const sym_expr &);
529  matrix eval() const;
530  std::ostream &print(std::ostream&) const;
531  static sym_exp *create(sym_expr *);
532 };
533 
534 class sym::sym_log: public sym_expr {
535 public:
536  int order() const {return 8;};
537  sym_expr *oper;
538  sym_log() {};
539  ~sym_log();
540  sym_log(const sym_log &);
541  sym_log *clone() const;
542  int comp(const sym_expr &) const;
543  sym_expr *reduce();
544  sym_expr *derive(const sym_expr &);
545  matrix eval() const;
546  std::ostream &print(std::ostream&) const;
547  static sym_log *create(sym_expr *);
548 };
549 
550 #endif
symbolic * check_context() const
Definition: sym_tens.cpp:25
static sym_prod * create(sym_expr *, sym_expr *)
Definition: sym_expr.cpp:846
friend sym diff(const sym &, const sym &)
Definition: sym.cpp:245
void bc_top2_add(solver *op, int n, std::string eq_name, std::string var_name) const
Definition: sym.cpp:293
sym trig_simplify(const sym &)
Definition: sym.cpp:50
sym_expr * reduce()
Definition: sym_expr.cpp:893
sym jacobian(const sym &, const sym &)
Definition: sym.cpp:258
bool operator>=(const sym_expr &s) const
Definition: symbolic.h:387
bool sort_pair_r(const std::pair< sym::sym_expr *, rational > &, const std::pair< sym::sym_expr *, rational > &)
sym & operator/=(const sym &s)
Definition: symbolic.h:108
sym_tens set_variance(const sym_tens &) const
Definition: sym_tens.cpp:89
sym::sym_expr * derive(const sym::sym_expr &, const sym::symbol &)
Definition: symbolic.cpp:167
friend sym_tens tensor(const sym_vec &, const sym_vec &)
Definition: sym_vec.cpp:234
~sym_add()
Definition: sym_expr.cpp:263
sym div(const sym_vec &v)
Definition: symbolic.h:360
sym()
Definition: sym.cpp:8
virtual std::ostream & print(std::ostream &) const =0
bool operator>=(const rational &q) const
Definition: symbolic.h:39
sym_expr * reduce()
Definition: sym_expr.cpp:962
sym Dphi(const sym &)
Definition: symbolic.cpp:273
rational operator/(const rational &q) const
Definition: symbolic.h:29
bool is_indep
Definition: symbolic.h:421
sym_log()
Definition: symbolic.h:538
rational operator*(const int &n, const rational &q)
Definition: symbolic.h:46
static double tol
Definition: symbolic.h:301
sym_expr * sin()
Definition: sym_expr.cpp:49
sym G(int i, int j, int k)
Definition: symbolic.h:289
friend sym operator+(const sym &, const sym &)
Definition: sym.cpp:143
friend std::ostream & operator<<(std::ostream &os, const rational &)
Definition: rational.cpp:129
int order() const
Definition: symbolic.h:405
static bool axisymmetric
Definition: symbolic.h:304
sym_vec operator+(const sym_vec &) const
Definition: sym_vec.cpp:157
sym var(const std::string &name)
Definition: symbolic.cpp:118
sym laplacian(const sym &s)
Returns the symbolic expression of the laplacian of s.
Definition: symbolic.cpp:504
Definition: symbolic.h:518
Definition: symbolic.h:403
sym & operator-=(const sym &s)
Definition: symbolic.h:106
static bool trig_simplify
Definition: symbolic.h:303
A solver object stores a system of equation to solve.
Definition: solver.h:73
void add_ex(solver *op, int n, std::string eq_name, std::string var_name) const
Definition: sym.cpp:286
sym cos(const sym &)
Definition: sym.cpp:194
bool operator<(const rational &q) const
Definition: rational.cpp:121
sym_tens stress(const sym_vec &v)
Definition: symbolic.cpp:534
sym diff(const sym &, const sym &)
Definition: sym.cpp:245
sym_tens g
Definition: symbolic.h:299
sym_tens(sym_vec_type type_set0=CONTRAVARIANT, sym_vec_type type_set1=CONTRAVARIANT)
Definition: sym_tens.cpp:10
static sym_cos * create(sym_expr *)
Definition: sym_expr.cpp:995
sym_tens stress(const sym_vec &v)
Definition: symbolic.h:366
sym_num()
Definition: symbolic.h:407
rational operator-(const int &n, const rational &q)
Definition: symbolic.h:45
void set_context(symbolic *context)
Definition: sym_vec.cpp:16
sym one_
Definition: symbolic.h:286
void set_type(sym_vec_type)
Definition: sym_vec.cpp:84
sym_expr * reduce()
Definition: sym_expr.cpp:197
Definition: symbolic.h:486
Definition: symbolic.h:466
sym r
Definition: symbolic.h:297
int comp(const sym_expr &) const
Definition: sym_expr.cpp:882
matrix eval() const
Definition: sym_expr.cpp:1080
The matrix class is used to facilitate the work with regular dense matrices.
Definition: matrix.h:9
int order() const
Definition: symbolic.h:419
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:1180
sym_vec operator/(const sym &) const
Definition: sym_vec.cpp:197
sym Dphi(const sym &s)
Definition: symbolic.h:370
virtual matrix eval() const =0
sym_expr * reduce()
Definition: sym_expr.cpp:1124
sym_tens contravariant_covariant(const sym_tens &)
Definition: symbolic.cpp:348
sym_tens contravariant_covariant(const sym_tens &s)
Definition: symbolic.h:354
sym_prod * clone() const
Definition: sym_expr.cpp:604
sym_vec operator*(const sym &) const
Definition: sym_vec.cpp:184
void set_type(sym_vec_type, sym_vec_type)
Definition: sym_tens.cpp:87
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:922
Definition: symbolic.h:281
sym & operator*=(const sym &s)
Definition: symbolic.h:107
friend sym sin(const sym &)
Definition: sym.cpp:182
sym D(const sym &) const
Definition: sym_vec.cpp:248
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:1071
friend sym_vec operator-(const sym_vec &v)
Definition: sym_vec.cpp:172
int order() const
Definition: symbolic.h:435
rational & operator-=(const rational &q)
Definition: symbolic.h:31
sym_expr * exp()
Definition: sym_expr.cpp:57
const sym & one
Definition: symbolic.h:307
friend sym log(const sym &)
Definition: sym.cpp:223
sym & operator=(double n)
Definition: symbolic.h:102
sym_expr * cos()
Definition: sym_expr.cpp:53
sym_cos * clone() const
Definition: sym_expr.cpp:947
sym_tens operator*(const sym &) const
Definition: sym_tens.cpp:193
int n
Definition: symbolic.h:15
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:226
static bool spherical
Definition: symbolic.h:305
void add_bc(const sym &s, solver *op, int n, std::string type, std::string eq_name, std::string var_name, const matrix &d)
Definition: symbolic.cpp:592
~sym_prod()
Definition: sym_expr.cpp:588
sym_prod()
Definition: symbolic.h:470
friend class sym
Definition: symbolic.h:223
matrix eval() const
Definition: sym.cpp:276
friend bool sort_pair_r(const std::pair< sym_expr *, rational > &, const std::pair< sym_expr *, rational > &)
sym rzz
Definition: symbolic.h:298
Definition: symbolic.h:374
sym_exp()
Definition: symbolic.h:522
sym theta
Definition: symbolic.h:297
bool is_const
Definition: symbolic.h:421
matrix eval() const
Definition: sym_expr.cpp:918
Definition: symbolic.h:187
int order() const
Definition: symbolic.h:450
std::ostream & operator<<(std::ostream &os, const rational &)
Definition: rational.cpp:129
sym & operator/=(double n)
Definition: symbolic.h:112
Definition: symbolic.h:73
sym_add()
Definition: symbolic.h:452
sym_expr * oper
Definition: symbolic.h:437
static double round_to_tol(double)
Definition: symbolic.cpp:66
int den() const
Definition: rational.cpp:12
matrix eval() const
Definition: sym_expr.cpp:816
sym_expr * pow(const rational &)
Definition: sym_expr.cpp:45
static sym_add * create(sym_expr *, sym_expr *)
Definition: sym_expr.cpp:532
int num() const
Definition: rational.cpp:8
double value
Definition: symbolic.h:405
~sym_cos()
Definition: sym_expr.cpp:938
sym s[3][3]
Definition: symbolic.h:237
std::string name
Definition: symbolic.h:419
sym_expr * oper
Definition: symbolic.h:520
sym_expr * oper
Definition: symbolic.h:504
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:515
sym_vec contravariant(const sym_vec &)
Definition: symbolic.cpp:301
rational & operator+=(const rational &q)
Definition: symbolic.h:30
symbolic * context
Definition: symbolic.h:83
int comp(const sym_expr &) const
Definition: sym_expr.cpp:608
friend bool sort_pair_d(const std::pair< sym_expr *, double > &, const std::pair< sym_expr *, double > &)
virtual sym_expr * clone() const =0
sym regvar_indep(const std::string &name)
Definition: symbolic.cpp:109
sym & operator()(int)
Definition: sym_vec.cpp:102
matrix eval() const
Definition: sym_expr.cpp:249
static bool expand_products
Definition: symbolic.h:302
sym det(const sym_tens &)
Definition: symbolic.cpp:277
bool sort_pair_d(const std::pair< sym::sym_expr *, double > &, const std::pair< sym::sym_expr *, double > &)
sym regconst(const std::string &name)
Definition: symbolic.cpp:101
int comp(const sym_expr &) const
Definition: sym_expr.cpp:118
sym_tens T() const
Definition: sym_tens.cpp:240
sym rtt
Definition: symbolic.h:298
sym rt
Definition: symbolic.h:298
sym_exp * clone() const
Definition: sym_expr.cpp:1016
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:974
void init()
Definition: symbolic.cpp:59
sym log(const sym &)
Definition: sym.cpp:223
Definition: symbolic.h:236
~sym_deriv()
Definition: sym_expr.cpp:169
sym sqrt_g
Definition: symbolic.h:297
void set_map(const mapping &map)
Definition: symbolic.cpp:145
sym_vec operator,(const sym_vec &) const
Definition: sym_tens.cpp:146
sym Dz(const sym &s)
Definition: symbolic.h:368
int d
Definition: symbolic.h:15
int comp(const sym_expr &) const
Definition: sym_expr.cpp:1020
sym sin(const sym &)
Definition: sym.cpp:182
Definition: symbolic.h:417
rational(int num=1, int den=1)
Definition: rational.cpp:16
sym divergence(const sym_vec &v)
Definition: symbolic.cpp:468
bool operator!=(const rational &q) const
Definition: symbolic.h:36
int order() const
Definition: symbolic.h:488
~sym_sin()
Definition: sym_expr.cpp:869
static sym_prod * create_pow(sym_expr *, const rational &)
Definition: sym_expr.cpp:857
symbolic * check_context() const
Definition: sym_vec.cpp:23
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:497
sym_vec_type
Definition: symbolic.h:187
sym phi
Definition: symbolic.h:297
friend sym jacobian(const sym &, const sym &)
Definition: sym.cpp:258
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:798
rational operator+() const
Definition: symbolic.h:24
bool is_covariant()
Definition: sym_vec.cpp:82
sym zeta
Definition: symbolic.h:297
sym_tens contravariant_contravariant(const sym_tens &s)
Definition: symbolic.h:353
rational operator+(const int &n, const rational &q)
Definition: symbolic.h:44
sym_tens operator*(double n) const
Definition: symbolic.h:261
sym operator,(const sym_vec &) const
Definition: sym_vec.cpp:123
int comp(const sym_expr &) const
Definition: sym_expr.cpp:283
sym operator%(const sym_tens &) const
Definition: sym_tens.cpp:223
bool operator<=(const rational &q) const
Definition: symbolic.h:40
sym_add * clone() const
Definition: sym_expr.cpp:279
int maxder
Definition: symbolic.h:287
int comp(const sym_expr &) const
Definition: sym_expr.cpp:183
Definition: symbolic.h:14
virtual int order() const =0
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:253
~sym_log()
Definition: sym_expr.cpp:1100
friend sym pow(const sym &, const rational &)
Definition: sym.cpp:167
void bc_bot2_add(solver *op, int n, std::string eq_name, std::string var_name) const
Definition: sym.cpp:297
symbolic * check_context() const
Definition: sym.cpp:70
rational inv() const
Definition: rational.cpp:89
sym_num * clone() const
Definition: sym_expr.cpp:71
double perm(int i, int j, int k)
Definition: symbolic.cpp:411
bool operator!=(const sym &s) const
Definition: symbolic.h:121
sym_expr * reduce()
Definition: sym_expr.cpp:303
sym sqrt(const sym &s)
Definition: symbolic.h:169
double eval() const
Definition: rational.cpp:53
static sym_sin * create(sym_expr *)
Definition: sym_expr.cpp:926
sym tan(const sym &)
Definition: sym.cpp:206
sym Dt(const sym &)
Definition: symbolic.cpp:270
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:129
rational operator-(const rational &q) const
Definition: symbolic.h:26
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:103
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:1165
rational operator*(const rational &q) const
Definition: rational.cpp:57
sym_vec curl(const sym_vec &v)
Definition: symbolic.h:364
Definition: mapping.h:13
rational & reduce()
Definition: rational.cpp:37
~symbolic()
Definition: symbolic.h:309
sym & operator*=(double n)
Definition: symbolic.h:111
bool operator<(const sym_expr &s) const
Definition: symbolic.h:385
sym_vec(sym_vec_type type_set=CONTRAVARIANT)
Definition: sym_vec.cpp:10
sym_tens covariant_covariant(const sym_tens &s)
Definition: symbolic.h:356
sym_expr * reduce()
Definition: sym_expr.cpp:86
sym_expr * reduce()
Definition: sym_expr.cpp:628
Definition: symbolic.h:430
rational & operator*=(const rational &q)
Definition: symbolic.h:32
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:905
friend sym_tens operator-(const sym_tens &v)
Definition: sym_tens.cpp:180
Definition: symbolic.h:502
sym_expr * multiply(const sym_add &)
Definition: sym_expr.cpp:543
Definition: symbolic.h:448
friend class sym
Definition: symbolic.h:269
virtual int comp(const sym_expr &s) const =0
bool operator==(const sym_expr &s) const
Definition: symbolic.h:386
void bc_bot1_add(solver *op, int n, std::string eq_name, std::string var_name) const
Definition: sym.cpp:295
bool operator>(const rational &q) const
Definition: rational.cpp:117
symbolic * context
Definition: symbolic.h:435
std::vector< std::pair< sym_expr *, rational > > oper
Definition: symbolic.h:468
int comp(const sym_expr &) const
Definition: sym_expr.cpp:1113
symbolic * context
Definition: symbolic.h:422
rational & operator/=(const rational &q)
Definition: symbolic.h:33
int comp(const sym_expr &) const
Definition: sym_expr.cpp:951
friend sym operator*(const sym &, const sym &)
Definition: sym.cpp:155
int comp(const sym_expr &) const
Definition: sym_expr.cpp:75
virtual sym_expr * derive(const sym_expr &)=0
bool operator!=(const sym_expr &s) const
Definition: symbolic.h:389
void add(solver *op, std::string eq_name, std::string var_name) const
Definition: sym.cpp:282
sym_sin * clone() const
Definition: sym_expr.cpp:878
sym rzt
Definition: symbolic.h:298
bool operator>(const sym_expr &s) const
Definition: symbolic.h:384
bool is_contravariant()
Definition: sym_vec.cpp:83
int order() const
Definition: symbolic.h:468
friend sym cos(const sym &)
Definition: sym.cpp:194
sym_log * clone() const
Definition: sym_expr.cpp:1109
sym_vec contravariant(const sym_vec &s)
Definition: symbolic.h:351
sym_sin()
Definition: symbolic.h:490
sym_vec curl(const sym_vec &v)
Definition: symbolic.cpp:510
sym & operator=(const sym &)
Definition: sym.cpp:37
sym_tens contravariant_contravariant(const sym_tens &)
Definition: symbolic.cpp:327
bool operator==(double n) const
Definition: symbolic.h:122
sym exp(const sym &)
Definition: sym.cpp:211
bool is_covariant(int)
Definition: sym_tens.cpp:85
sym_expr * derive(const sym_expr &)
Definition: sym_expr.cpp:94
sym_expr * add(const sym_expr &)
Definition: sym_expr.cpp:37
sym pow(const sym &, const rational &)
Definition: sym.cpp:167
int order() const
Definition: symbolic.h:536
~sym_exp()
Definition: sym_expr.cpp:1007
symbolic()
Definition: symbolic.cpp:13
virtual ~sym_expr()
Definition: symbolic.h:376
sym_expr * log()
Definition: sym_expr.cpp:61
sym_tens covariant_contravariant(const sym_tens &)
Definition: symbolic.cpp:369
symbol * clone() const
Definition: sym_expr.cpp:114
virtual sym_expr * reduce()
Definition: symbolic.h:379
static sym_log * create(sym_expr *)
Definition: sym_expr.cpp:1184
sym_tens inv(const sym_tens &)
Definition: symbolic.cpp:286
sym covderiv(const sym_vec &, int, int)
Definition: symbolic.cpp:442
sym_tens covariant_contravariant(const sym_tens &s)
Definition: symbolic.h:355
sym_deriv()
Definition: symbolic.h:432
sym & operator()(int, int)
Definition: sym_tens.cpp:103
std::map< std::string, int > par
Definition: symbolic.h:284
matrix get_value(const sym::sym_expr &)
Definition: symbolic.cpp:232
sym_expr * power(int n)
Definition: sym_expr.cpp:558
void set_value(const char *name, const matrix &value, int parity=0)
Definition: symbolic.cpp:133
sym_vec operator*(double n) const
Definition: symbolic.h:214
matrix eval() const
Definition: sym_expr.cpp:505
std::map< std::string, sym::symbol > vars
Definition: symbolic.h:282
friend std::ostream & operator<<(std::ostream &os, const sym::sym_expr &)
Definition: sym_expr.cpp:32
sym x[3]
Definition: symbolic.h:300
sym_vec operator/(double n) const
Definition: symbolic.h:216
sym_deriv * clone() const
Definition: sym_expr.cpp:179
std::vector< std::pair< sym_expr *, double > > oper
Definition: symbolic.h:450
matrix eval() const
Definition: sym_expr.cpp:159
rational operator/(const int &n, const rational &q)
Definition: symbolic.h:47
sym Dt(const sym &s)
Definition: symbolic.h:369
Definition: symbolic.h:189
sym & operator+=(const sym &s)
Definition: symbolic.h:105
void add(const sym &s, solver *op, int n, std::string type, std::string eq_name, std::string var_name, const matrix &d)
Definition: symbolic.cpp:546
sym s[3]
Definition: symbolic.h:190
sym_vec gradient(const sym &)
Definition: symbolic.cpp:419
static int gcd(int a, int b)
Definition: rational.cpp:22
sym_tens g_
Definition: symbolic.h:299
sym rz
Definition: symbolic.h:298
sym Dz(const sym &)
Definition: symbolic.cpp:267
friend sym trig_simplify(const sym &)
Definition: sym.cpp:50
sym_vec grad(const sym &s)
Definition: symbolic.h:358
Definition: symbolic.h:534
mapping map
Definition: symbolic.h:285
rational operator-() const
Definition: rational.cpp:81
friend sym_vec cross(const sym_vec &, const sym_vec &)
Definition: sym_vec.cpp:210
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:163
sym_expr * oper
Definition: symbolic.h:488
bool operator==(const rational &q) const
Definition: rational.cpp:113
static sym_exp * create(sym_expr *)
Definition: sym_expr.cpp:1088
sym & operator+=(double n)
Definition: symbolic.h:109
sym_tens operator+(const sym_tens &) const
Definition: sym_tens.cpp:164
bool operator!=(double n) const
Definition: symbolic.h:123
rational pow(int) const
Definition: rational.cpp:95
sym_vec cross(const sym_vec &, const sym_vec &)
Definition: sym_vec.cpp:210
sym_expr * expr
Definition: symbolic.h:86
friend sym exp(const sym &)
Definition: sym.cpp:211
void bc_top1_add(solver *op, int n, std::string eq_name, std::string var_name) const
Definition: sym.cpp:291
sym_tens operator/(double n) const
Definition: symbolic.h:263
sym & operator-=(double n)
Definition: symbolic.h:110
sym christoffel(int, int, int)
Definition: symbolic.cpp:431
bool operator==(const sym &s) const
Definition: sym.cpp:274
sym_tens covariant_covariant(const sym_tens &)
Definition: symbolic.cpp:390
sym_tens operator/(const sym &) const
Definition: sym_tens.cpp:208
sym_expr * mult(const sym_expr &)
Definition: sym_expr.cpp:41
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:1084
void set_context(symbolic *context)
Definition: sym_tens.cpp:17
bool is_contravariant(int)
Definition: sym_tens.cpp:86
sym d(const sym &s, int k)
Definition: symbolic.h:288
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:991
matrix eval() const
Definition: sym_expr.cpp:1176
sym_tens tensor(const sym_vec &, const sym_vec &)
Definition: sym_vec.cpp:234
sym_vec covariant(const sym_vec &)
Definition: symbolic.cpp:314
std::map< std::string, matrix > val
Definition: symbolic.h:283
static sym_deriv * create(sym_expr *, const symbol &)
Definition: sym_expr.cpp:215
int order() const
Definition: symbolic.h:504
symbol var
Definition: symbolic.h:438
matrix eval() const
Definition: sym_expr.cpp:987
~sym()
Definition: sym.cpp:12
rational abs(const rational &q)
Definition: rational.cpp:125
friend sym_tens tensor(const sym_vec &, const sym_vec &)
Definition: sym_vec.cpp:234
sym regvar(const std::string &name)
Definition: symbolic.cpp:79
sym_vec set_variance(const sym_vec &) const
Definition: sym_vec.cpp:86
sym_vec covariant(const sym_vec &s)
Definition: symbolic.h:352
sym_expr * oper
Definition: symbolic.h:536
bool operator<=(const sym_expr &s) const
Definition: symbolic.h:388
Definition: symbolic.h:187
sym_expr * reduce()
Definition: sym_expr.cpp:1031
std::ostream & print(std::ostream &) const
Definition: sym_expr.cpp:826
sym lap(const sym &s)
Returns the laplacian of the expression s.
Definition: symbolic.h:363
sym_vec_type type
Definition: symbolic.h:191
sym_vec_type type[2]
Definition: symbolic.h:238
int order() const
Definition: symbolic.h:520
matrix eval() const
Definition: sym_expr.cpp:99
sym_cos()
Definition: symbolic.h:506