KADATH
metric_dirac_const.cpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "space.hpp"
21 #include "tensor.hpp"
22 #include "metric.hpp"
23 #include "term_eq.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "system_of_eqs.hpp"
27 #include "metric_tensor.hpp"
28 #include "name_tools.hpp"
29 namespace Kadath {
31  Metric_dirac(met) {
32 }
33 
35  Metric_dirac (*so.p_met) {
36 }
37 
38 Metric_dirac_const::~Metric_dirac_const() {
39 }
40 
41 void Metric_dirac_const::set_system (System_of_eqs& ss, const char* name_met) {
42 
43  syst = &ss ;
44 
45  if (ss.met!=0x0) {
46  cerr << "Metric already set for the system" << endl ;
47  abort() ;
48  }
49 
50  // Position in the system :
51  place_syst = ss.ndom*ss.ncst ;
52 
53  ss.add_cst (0x0, *p_met) ;
54 
55  ss.met = this ;
56  ss.name_met = new char[LMAX] ;
57  trim_spaces (ss.name_met, name_met) ;
58 }
59 
60 
61 
62 void Metric_dirac_const::compute_cov (int dd) const {
63 
64  int dim = espace.get_ndim() ;
65  if (dim!=3) {
66  cerr << "Function only implemented for dimension 3" << endl ;
67  abort() ;
68  }
69 
70  int place = place_syst + (dd-syst->dom_min) ;
71 
72  // Right storage : simple copy.
73  if (type_tensor==COV) {
74 
75  if (p_met_cov[dd]==0x0)
76  p_met_cov[dd] = new Term_eq(*syst->cst[place]) ;
77  else
78  *p_met_cov[dd] = Term_eq(*syst->cst[place]) ;
79  }
80  else {
81  Term_eq** res = new Term_eq* [p_met->get_n_comp()] ;
82 
83 
84  Scalar val (espace) ;
85  Val_domain cmpval(espace.get_domain(dd)) ;
86 
87  // Compo 1 1
88  cmpval = (*syst->cst[place]->val_t)(2,2)(dd)*(*syst->cst[place]->val_t)(3,3)(dd)
89  -(*syst->cst[place]->val_t)(2,3)(dd)*(*syst->cst[place]->val_t)(2,3)(dd) ;
90  val.set_domain(dd) = cmpval ;
91  res[0] = new Term_eq (dd, val) ;
92 
93 
94  // Compo 1 2
95  cmpval = (*syst->cst[place]->val_t)(1,3)(dd)*(*syst->cst[place]->val_t)(2,3)(dd)
96  -(*syst->cst[place]->val_t)(1,2)(dd)*(*syst->cst[place]->val_t)(3,3)(dd) ;
97  val.set_domain(dd) = cmpval ;
98  res[1] = new Term_eq (dd, val) ;
99 
100  // Compo 1 3
101  cmpval = (*syst->cst[place]->val_t)(1,2)(dd)*(*syst->cst[place]->val_t)(2,3)(dd)
102  -(*syst->cst[place]->val_t)(1,3)(dd)*(*syst->cst[place]->val_t)(2,2)(dd) ;
103  val.set_domain(dd) = cmpval ;
104  res[2] = new Term_eq (dd, val) ;
105 
106 
107  // Compo 2 2
108  cmpval = (*syst->cst[place]->val_t)(1,1)(dd)*(*syst->cst[place]->val_t)(3,3)(dd)
109  -(*syst->cst[place]->val_t)(1,3)(dd)*(*syst->cst[place]->val_t)(1,3)(dd) ;
110  val.set_domain(dd) = cmpval ;
111  res[3] = new Term_eq (dd, val) ;
112 
113  // Compo 2 3
114  cmpval = (*syst->cst[place]->val_t)(1,3)(dd)*(*syst->cst[place]->val_t)(1,2)(dd)
115  -(*syst->cst[place]->val_t)(1,1)(dd)*(*syst->cst[place]->val_t)(2,3)(dd) ;
116  val.set_domain(dd) = cmpval ;
117  res[4] = new Term_eq (dd, val) ;
118 
119 
120  // Compo 3 3
121  cmpval = (*syst->cst[place]->val_t)(1,1)(dd)*(*syst->cst[place]->val_t)(2,2)(dd)
122  -(*syst->cst[place]->val_t)(1,2)(dd)*(*syst->cst[place]->val_t)(1,2)(dd) ;
123  val.set_domain(dd) = cmpval ;
124  res[5] = new Term_eq (dd, val) ;
125 
126 
127  // Value field :
128  Metric_tensor resval (espace, COV, basis) ;
129  resval.set(1,1) = res[0]->get_val_t() ;
130  resval.set(1,2) = res[1]->get_val_t() ;
131  resval.set(1,3) = res[2]->get_val_t() ;
132  resval.set(2,2) = res[3]->get_val_t() ;
133  resval.set(2,3) = res[4]->get_val_t() ;
134  resval.set(3,3) = res[5]->get_val_t() ;
135 
136  Metric_tensor zero (espace, COV, basis) ;
137  for (int i=1 ; i<=3 ; i++)
138  for (int j=i ; j<=3 ; j++)
139  zero.set(i,j) = 0 ;
140 
141  if (p_met_cov[dd]==0x0)
142  p_met_cov[dd] = new Term_eq(dd, resval, zero) ;
143  else
144  *p_met_cov[dd] = Term_eq(dd, resval, zero) ;
145  for (int i=0 ; i<p_met->get_n_comp() ; i++)
146  delete res [i] ;
147  delete [] res ;
148  }
149 }
150 
151 
152 void Metric_dirac_const::compute_con (int dd) const {
153  int dim = espace.get_ndim() ;
154  if (dim!=3) {
155  cerr << "Function only implemented for dimension 3" << endl ;
156  abort() ;
157  }
158 
159  int place = place_syst + (dd-syst->dom_min) ;
160 
161  // Right storage : simple copy.
162  if (type_tensor==CON) {
163 
164  if (p_met_con[dd]==0x0)
165  p_met_con[dd] = new Term_eq(*syst->cst[place]) ;
166  else
167  *p_met_con[dd] = Term_eq(*syst->cst[place]) ;
168  }
169  else {
170 
171  Term_eq** res = new Term_eq* [p_met->get_n_comp()] ;
172 
173 
174  Scalar val (espace) ;
175  Val_domain cmpval(espace.get_domain(dd)) ;
176 
177  // Compo 1 1
178  cmpval = (*syst->cst[place]->val_t)(2,2)(dd)*(*syst->cst[place]->val_t)(3,3)(dd)
179  -(*syst->cst[place]->val_t)(2,3)(dd)*(*syst->cst[place]->val_t)(2,3)(dd) ;
180  val.set_domain(dd) = cmpval ;
181  res[0] = new Term_eq (dd, val) ;
182 
183  // Compo 1 2
184  cmpval = (*syst->cst[place]->val_t)(1,3)(dd)*(*syst->cst[place]->val_t)(2,3)(dd)
185  -(*syst->cst[place]->val_t)(1,2)(dd)*(*syst->cst[place]->val_t)(3,3)(dd) ;
186  val.set_domain(dd) = cmpval ;
187  res[1] = new Term_eq (dd, val) ;
188 
189  // Compo 1 3
190  cmpval = (*syst->cst[place]->val_t)(1,2)(dd)*(*syst->cst[place]->val_t)(2,3)(dd)
191  -(*syst->cst[place]->val_t)(1,3)(dd)*(*syst->cst[place]->val_t)(2,2)(dd) ;
192  val.set_domain(dd) = cmpval ;
193  res[2] = new Term_eq (dd, val) ;
194 
195  // Compo 2 2
196  cmpval = (*syst->cst[place]->val_t)(1,1)(dd)*(*syst->cst[place]->val_t)(3,3)(dd)
197  -(*syst->cst[place]->val_t)(1,3)(dd)*(*syst->cst[place]->val_t)(1,3)(dd) ;
198  val.set_domain(dd) = cmpval ;
199  res[3] = new Term_eq (dd, val) ;
200 
201  // Compo 2 3
202  cmpval = (*syst->cst[place]->val_t)(1,3)(dd)*(*syst->cst[place]->val_t)(1,2)(dd)
203  -(*syst->cst[place]->val_t)(1,1)(dd)*(*syst->cst[place]->val_t)(2,3)(dd) ;
204  val.set_domain(dd) = cmpval ;
205  res[4] = new Term_eq (dd, val) ;
206 
207  // Compo 3 3
208  cmpval = (*syst->cst[place]->val_t)(1,1)(dd)*(*syst->cst[place]->val_t)(2,2)(dd)
209  -(*syst->cst[place]->val_t)(1,2)(dd)*(*syst->cst[place]->val_t)(1,2)(dd) ;
210  val.set_domain(dd) = cmpval ;
211  res[5] = new Term_eq (dd, val) ;
212 
213  // Value field :
214  Metric_tensor resval (espace, CON, basis) ;
215  resval.set(1,1) = res[0]->get_val_t() ;
216  resval.set(1,2) = res[1]->get_val_t() ;
217  resval.set(1,3) = res[2]->get_val_t() ;
218  resval.set(2,2) = res[3]->get_val_t() ;
219  resval.set(2,3) = res[4]->get_val_t() ;
220  resval.set(3,3) = res[5]->get_val_t() ;
221 
222  Metric_tensor zero (espace, CON, basis) ;
223  for (int i=1 ; i<=3 ; i++)
224  for (int j=i ; j<=3 ; j++)
225  zero.set(i,j) = 0 ;
226 
227  if (p_met_con[dd]==0x0)
228  p_met_con[dd] = new Term_eq(dd, resval, zero) ;
229  else
230  *p_met_con[dd] = Term_eq(dd, resval, zero) ;
231  for (int i=0 ; i<p_met->get_n_comp() ; i++)
232  delete res [i] ;
233  delete [] res ;
234  }
235 }}
Metric_tensor * p_met
Pointer on the Metric_tensor describing the metric.
Definition: metric.hpp:446
const Base_tensor & basis
The tensorial basis used.
Definition: metric.hpp:447
int place_syst
Gives the location of the metric amongst the various unknowns of the associated System_of_eqs.
Definition: metric.hpp:449
Class to deal with a conformal metric in the Dirac gauge.
Definition: metric.hpp:510
virtual void set_system(System_of_eqs &syst, const char *name)
Associate the metric to a given system of equations.
virtual void compute_con(int) const
Computes the contravariant representation, in a given Domain.
virtual void compute_cov(int) const
Computes the covariant representation, in a given Domain.
Metric_dirac_const(Metric_tensor &)
Constructor from a Metric_tensor.
Class to deal with a conformal metric in the Dirac gauge.
Definition: metric.hpp:485
Particular type of Tensor, dedicated to the desription of metrics.
int type_tensor
States if one works in the CON or COV representation.
Definition: metric.hpp:86
const Space & espace
The associated Space.
Definition: metric.hpp:42
MMPtr_array< Term_eq > p_met_cov
Array of pointers on various Term_eq.
Definition: metric.hpp:50
MMPtr_array< Term_eq > p_met_con
Array of pointers on various Term_eq.
Definition: metric.hpp:55
const System_of_eqs * syst
Pointer of the system of equations where the metric is used (only one for now).
Definition: metric.hpp:44
The class Scalar does not really implements scalars in the mathematical sense but rather tensorial co...
Definition: scalar.hpp:67
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
Definition: scalar.hpp:555
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
int get_ndim() const
Returns the number of dimensions.
Definition: space.hpp:1373
Class used to describe and solve a system of equations.
virtual void add_cst(const char *name, double cst)
Addition of a constant (number case)
int ndom
Number of domains used.
MMPtr_array< Term_eq > cst
Pointers on the Term_eq coming from the constants passed by the user.
char * name_met
Name by which the metric is recognized.
int ncst
Number of constants passed by the user.
int dom_min
Smallest domain number.
Metric * met
Pointer on the associated Metric, if defined.
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
Definition: tensor_impl.hpp:91
int get_n_comp() const
Returns the number of stored components.
Definition: tensor.hpp:514
This class is intended to describe the manage objects appearing in the equations.
Definition: term_eq.hpp:62
Tensor const & get_val_t() const
Definition: term_eq.hpp:355
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69