KADATH
metric_flat_nophi.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 "system_of_eqs.hpp"
22 #include "tensor.hpp"
23 #include "metric_nophi.hpp"
24 #include "term_eq.hpp"
25 #include "scalar.hpp"
26 #include "tensor_impl.hpp"
27 #include "name_tools.hpp"
28 #include "metric_tensor.hpp"
29 namespace Kadath {
30 Metric_flat_nophi::Metric_flat_nophi (const Space& sp, const Base_tensor& bb) : Metric(sp), basis(bb) {
31 
32  for (int d=0 ; d<sp.get_nbr_domains() ; d++)
33  if (bb.get_basis(d)!=SPHERICAL_BASIS) {
34  cerr << "Metric_flat_nophi only defined wrt spherical tensorial basis for now..." << endl ;
35  abort() ;
36  }
37 }
38 
39 Metric_flat_nophi::Metric_flat_nophi (const Metric_flat_nophi& so) : Metric (so), basis(so.basis) {
40 }
41 
42 Metric_flat_nophi::~Metric_flat_nophi() {
43 }
44 
46  // Nothing to do everything is constant
47 }
48 
50  // Nothing to do everything is constant
51 }
52 
53 void Metric_flat_nophi::compute_cov (int dd) const {
54  Metric_tensor res (espace, COV, basis) ;
55 
56  for (int i=1 ; i<=3 ; i++)
57  for (int j=i ; j<=3 ; j++)
58  res.set(i,j).set_domain(dd) = (i==j) ? 1. : 0 ;
59  res.std_base() ;
60 
61  if (p_met_cov[dd]==0x0)
62  p_met_cov[dd] = new Term_eq(dd, res) ;
63  else
64  *p_met_cov[dd] = Term_eq (dd, res) ;
65  p_met_cov[dd]->set_der_zero() ;
66 }
67 
68 
69 int Metric_flat_nophi::give_type(int dd) const {
70  return basis.get_basis(dd) ;
71 }
72 
73 void Metric_flat_nophi::compute_con (int dd) const {
74 
75  Metric_tensor res (espace, CON, basis) ;
76  for (int i=1 ; i<=3 ; i++)
77  for (int j=i ; j<=3 ; j++)
78  res.set(i,j).set_domain(dd) = (i==j) ? 1. : 0 ;
79  res.std_base() ;
80  if (p_met_con[dd]==0x0)
81  p_met_con[dd] = new Term_eq(dd, res) ;
82  else
83  *p_met_con[dd] = Term_eq(dd, res) ;
84  p_met_con[dd]->set_der_zero() ;
85 }
86 
88  cerr << "Computation of Christo not explicit for Metric_flat_nophi" << endl ;
89  abort() ;
90 }
91 
92 void Metric_flat_nophi::manipulate_ind (Term_eq& so, int ind) const {
93  // Just change the type of the indice !
94  so.set_val_t()->set_index_type (ind) *= -1 ;
95  if (so.set_der_t() !=0x0)
96  so.set_der_t()->set_index_type (ind) *= -1 ;
97 }
98 
99 Term_eq Metric_flat_nophi::derive_partial_spher (int type_der, char ind_der, const Term_eq& so) const {
100 
101  int dom = so.get_dom() ;
102  bool donames = ((so.val_t->is_name_affected()) || (so.val_t->get_valence()==0)) ? true : false ;
103 
104  // Computation of flat gradient :
105  Term_eq auxi (espace.get_domain(dom)->partial_spher (so)) ;
106 
107  int val_res = auxi.val_t->get_valence() ;
108 
109  if (donames) {
110  // Set the names of the indices :
111  auxi.val_t->set_name_affected() ;
112  auxi.val_t->set_name_ind(0, ind_der) ;
113  for (int i=1 ; i<val_res ; i++)
114  auxi.val_t->set_name_ind(i, so.val_t->get_name_ind()[i-1]) ;
115 
116  if (auxi.der_t!=0x0) {
117  auxi.der_t->set_name_affected() ;
118  auxi.der_t->set_name_ind(0, ind_der) ;
119  for (int i=1 ; i<val_res ; i++)
120  auxi.der_t->set_name_ind(i, so.val_t->get_name_ind()[i-1]) ;
121  }
122  }
123 
124  // Manipulate if Contravariant version
125  if (type_der==CON)
126  manipulate_ind (auxi, 0) ;
127 
128  bool need_sum = false ;
129  if (donames)
130  for (int i=1 ; i<val_res ; i++)
131  if (ind_der== so.val_t->get_name_ind()[i-1])
132  need_sum = true ;
133 
134  if (!need_sum)
135  return auxi ;
136  else {
137  if (auxi.der_t==0x0)
138  return Term_eq (dom, auxi.val_t->do_summation_one_dom(dom)) ;
139  else
140  return Term_eq (dom, auxi.val_t->do_summation_one_dom(dom), auxi.der_t->do_summation_one_dom(dom)) ;
141  }
142 }
143 
144 
145 Term_eq Metric_flat_nophi::derive_partial (int type_der, char ind_der, const Term_eq& so) const {
146 
147  int dom = so.get_dom() ;
148 
149  if (p_met_con[dom]==0x0)
150  compute_con(dom) ;
151  if (p_met_cov[dom]==0x0)
152  compute_cov(dom) ;
153 
154  // so must be tensor :
155  if (so.get_type_data()!=TERM_T) {
156  cerr << "Metric_flat_nophi::derive partial only defined for tensor data" << endl ;
157  abort() ;
158  }
159 
160  switch (basis.get_basis(dom)) {
161  case SPHERICAL_BASIS :
162  return derive_partial_spher (type_der, ind_der, so) ;
163  default:
164  cerr << "Unknown tensorial basis in Metric_flat_nophi::derive_partial" << endl ;
165  abort() ;
166  }
167 }
168 
169 
170 Term_eq Metric_flat_nophi::derive_spher (int type_der, char ind_der, const Term_eq& so) const {
171 
172  // Computation of flat gradient :
173  Term_eq part_der (derive_partial(type_der, ind_der, so)) ;
174 
175  int dom = so.get_dom() ;
176  bool donames = ((so.val_t->is_name_affected()) || (so.val_t->get_valence()==0)) ? true : false ;
177 
178  Term_eq auxi (espace.get_domain(dom)->connection_spher (so)) ;
179  int val_res = auxi.val_t->get_valence() ;
180 
181  if (donames) {
182  // Set the names of the indices :
183  auxi.val_t->set_name_affected() ;
184  auxi.val_t->set_name_ind(0, ind_der) ;
185  for (int i=1 ; i<val_res ; i++)
186  auxi.val_t->set_name_ind(i, so.val_t->get_name_ind()[i-1]) ;
187 
188  if (auxi.der_t!=0x0) {
189  auxi.der_t->set_name_affected() ;
190  auxi.der_t->set_name_ind(0, ind_der) ;
191  for (int i=1 ; i<val_res ; i++)
192  auxi.der_t->set_name_ind(i, so.val_t->get_name_ind()[i-1]) ;
193  }
194  }
195 
196  // Manipulate if Contravariant version
197  if (type_der==CON)
198  manipulate_ind (auxi, 0) ;
199 
200 
201  bool need_sum = false ;
202  if (donames)
203  for (int i=1 ; i<val_res ; i++)
204  if (ind_der== so.val_t->get_name_ind()[i-1])
205  need_sum = true ;
206 
207  if (!need_sum) {
208  return (part_der + auxi) ;
209  }
210  else {
211  if (auxi.der_t==0x0) {
212 
213 
214  return (part_der + Term_eq (dom, auxi.val_t->do_summation_one_dom(dom))) ;
215  }
216  else
217  return (part_der + Term_eq (dom, auxi.val_t->do_summation_one_dom(dom), auxi.der_t->do_summation_one_dom(dom))) ;
218  }
219 }
220 
221 Term_eq Metric_flat_nophi::derive (int type_der, char ind_der, const Term_eq& so) const {
222 
223  int dom = so.get_dom() ;
224 
225  if (p_met_con[dom]==0x0)
226  compute_con(dom) ;
227  if (p_met_cov[dom]==0x0)
228  compute_cov(dom) ;
229 
230  // so must be tensor :
231  if (so.get_type_data()!=TERM_T) {
232  cerr << "Metric_flat_nophi::derive only defined for tensor data" << endl ;
233  abort() ;
234  }
235 
236  switch (basis.get_basis(dom)) {
237  case SPHERICAL_BASIS :
238  return derive_spher (type_der, ind_der, so) ;
239  default:
240  cerr << "Unknown tensorial basis in Metric_flat_nophi::derive" << endl ;
241  abort() ;
242  }
243 
244 }
245 
246 
247 Term_eq Metric_flat_nophi::derive_with_other_spher (int type_der, char ind_der, const Term_eq& so, const Metric* manipulator) const {
248  int dom = so.get_dom() ;
249 
250  // Call the domain version
251  return so.val_t->get_space().get_domain(dom)->derive_flat_spher (type_der, ind_der, so, manipulator) ;
252 }
253 
254 Term_eq Metric_flat_nophi::derive_with_other (int type_der, char ind_der, const Term_eq& so, const Metric* manipulator) const {
255 
256  int dom = so.get_dom() ;
257 
258  if (p_met_con[dom]==0x0)
259  compute_con(dom) ;
260  if (p_met_cov[dom]==0x0)
261  compute_cov(dom) ;
262 
263  // so must be tensor :
264  if (so.get_type_data()!=TERM_T) {
265  cerr << "Metric_flat_nophi::derive_with_other only defined for tensor data" << endl ;
266  abort() ;
267  }
268 
269  switch (basis.get_basis(dom)) {
270  case SPHERICAL_BASIS :
271  return derive_with_other_spher (type_der, ind_der, so, manipulator) ;
272  default:
273  cerr << "Unknown tensorial basis in Metric_flat_nophi::derive_with_other" << endl ;
274  abort() ;
275  }
276 
277 }
278 
279 void Metric_flat_nophi::set_system (System_of_eqs& ss, const char* name) {
280 
281  syst = &ss ;
282  if (syst->met!=0x0) {
283  cerr << "Metric already set for the system" << endl ;
284  abort() ;
285  }
286 
287  ss.met = this ;
288  ss.name_met = new char[LMAX] ;
289  trim_spaces (ss.name_met, name) ;
290 }
291 }
Describes the tensorial basis used by the various tensors.
Definition: base_tensor.hpp:49
int get_basis(int nd) const
Read only the basis in a given domain.
Definition: base_tensor.hpp:93
virtual Term_eq derive_flat_spher(int tipe, char ind, const Term_eq &so, const Metric *manip) const
Computes the flat derivative of a Term_eq, in spherical orthonormal coordinates.
Definition: domain.cpp:1721
virtual Term_eq connection_spher(const Term_eq &so) const
Computes the part of the gradient involving the connections, in spherical orthonormal coordinates.
Definition: domain.cpp:544
virtual Term_eq partial_spher(const Term_eq &so) const
Computes the part of the gradient containing the partial derivative of the field, in spherical orthon...
Definition: domain.cpp:383
Class that deals with flat metric assuming a axisymmetric setting (nothing depends on ).
Term_eq derive_partial_spher(int tder, char indder, const Term_eq &so) const
Computes the partial derivative part of the covariant derivative, in orthonormal spherical coordinate...
const Base_tensor & basis
The tensorial basis used.
virtual void manipulate_ind(Term_eq &, int) const
Uses the Metric to manipulate one of the index of a Term_eq (i.e.
virtual Term_eq derive(int, char, const Term_eq &) const
Computes the covariant derivative of a Term_eq (assumes Cartesian basis of decomposition).
virtual void compute_con(int) const
Computes the contravariant representation, in a given Domain.
virtual void compute_christo(int) const
Computes the Christoffel symbols, in a given Domain.
Term_eq derive_spher(int tder, char indder, const Term_eq &so) const
Computes the flat covariant derivative, in orthonormal spherical coordinates.
virtual void update()
Updates the derived quantities (Christoffels etc..) This is done only for the ones that are needed,...
virtual void compute_cov(int) const
Computes the covariant representation, in a given Domain.
Term_eq derive_with_other_spher(int tder, char indder, const Term_eq &so, const Metric *othermet) const
Computes the flat covariant derivative, in orthonormal spherical coordinates.
virtual Term_eq derive_partial(int, char, const Term_eq &) const
Computes the partial derivative of a Term_eq (assumes Cartesian basis of decomposition).
virtual int give_type(int) const
Returns the type of tensorial basis of the covariant representation, in a given Domain.
virtual void set_system(System_of_eqs &syst, const char *name)
Associate the metric to a given system of equations.
Term_eq derive_with_other(int tder, char indder, const Term_eq &so, const Metric *othermet) const
Computes the flat covariant derivative.
Metric_flat_nophi(const Space &sp, const Base_tensor &bb)
Standard constructor.
Particular type of Tensor, dedicated to the desription of metrics.
Purely abstract class for metric handling.
Definition: metric.hpp:39
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
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
Definition: scalar.hpp:555
The Space class is an ensemble of domains describing the whole space of the computation.
Definition: space.hpp:1362
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
int get_nbr_domains() const
Returns the number of Domains.
Definition: space.hpp:1375
Class used to describe and solve a system of equations.
char * name_met
Name by which the metric is recognized.
Metric * met
Pointer on the associated Metric, if defined.
void set_name_ind(int dd, char name)
Sets the name of one index ; the names must have been affected first.
void set_name_affected()
Affects the name of the indices.
Definition: tensor.hpp:435
virtual void std_base()
Sets the standard spectal bases of decomposition for each component.
Definition: tensor.cpp:385
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
Definition: tensor_impl.hpp:91
char const * get_name_ind() const
Definition: tensor.hpp:424
int get_valence() const
Returns the valence.
Definition: tensor.hpp:509
bool is_name_affected() const
Check whether the names of the indices have been affected.
Definition: tensor.hpp:429
Tensor do_summation_one_dom(int dd) const
Does the inner contraction of the Tensor in a given domain.
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
This class is intended to describe the manage objects appearing in the equations.
Definition: term_eq.hpp:62
Tensor * der_t
Pointer on the variation, if the Term_eq is a Tensor.
Definition: term_eq.hpp:69
void set_der_t(Tensor)
Sets the tensorial variation (only the values in the pertinent Domain are copied).
Definition: term_eq.cpp:171
int get_dom() const
Definition: term_eq.hpp:135
int get_type_data() const
Definition: term_eq.hpp:131
void set_val_t(Tensor)
Sets the tensorial value (only the values in the pertinent Domain are copied).
Definition: term_eq.cpp:155
Tensor * val_t
Pointer on the value, if the Term_eq is a Tensor.
Definition: term_eq.hpp:68