KADATH
domain_bispheric_eta_first_for_metric.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 "headcpp.hpp"
21 
22 #include "bispheric.hpp"
23 #include "term_eq.hpp"
24 #include "metric.hpp"
25 #include "scalar.hpp"
26 #include "tensor_impl.hpp"
27 
28 namespace Kadath{
29 Term_eq Domain_bispheric_eta_first::derive_flat_cart (int type_der, char ind_der, const Term_eq& so, const Metric* manipulator) const {
30 
31  bool doder = (so.der_t==0x0) ? false : true ;
32  if ((type_der==CON) && (manipulator->p_met_con[num_dom]->der_t==0x0))
33  doder = false ;
34 
35  assert ((type_der==COV) || (type_der==CON)) ;
36  int val_res = so.val_t->get_valence() + 1 ;
37 
38  bool doname = true ;
39  if (so.val_t->get_valence()>0)
40  if (!so.val_t->is_name_affected())
41  doname = false;
42 
43  Array<int> type_ind (val_res) ;
44  type_ind.set(0) = COV ;
45  for (int i=1 ; i<val_res ; i++)
46  type_ind.set(i) = so.val_t->get_index_type(i-1) ;
47 
48  // Need for summation ?
49  bool need_sum = false ;
50  if (doname)
51  for (int i=1 ; i<val_res ; i++)
52  if (ind_der== so.val_t->get_name_ind()[i-1])
53  need_sum = true ;
54 
55  // Tensor for val
56  Base_tensor basis (so.val_t->get_space(), CARTESIAN_BASIS) ;
57  Tensor auxi_val (so.val_t->get_space(), val_res, type_ind, basis) ;
58 
59 
60  // Set the names of the indices :
61  if (doname) {
62  auxi_val.set_name_affected() ;
63  auxi_val.set_name_ind(0, ind_der) ;
64  for (int i=1 ; i<val_res ; i++)
65  auxi_val.set_name_ind(i, so.val_t->get_name_ind()[i-1]) ;
66  }
67 
68  //Loop on the components :
69  Index pos_auxi(auxi_val) ;
70  Index pos_so (*so.val_t) ;
71  do {
72  for (int i=0 ; i<val_res-1 ; i++)
73  pos_so.set(i) = pos_auxi(i+1) ;
74  auxi_val.set(pos_auxi).set_domain(num_dom) = (*so.val_t)(pos_so)(num_dom).der_abs(pos_auxi(0)+1) ;
75  }
76  while (pos_auxi.inc()) ;
77 
78  if (!doder) {
79  // No need for derivative :
80  Term_eq auxi (num_dom, auxi_val) ;
81  // If derive contravariant : manipulate first indice :
82  if (type_der==CON)
83  manipulator->manipulate_ind (auxi, 0) ;
84 
85  if (!need_sum)
86  return auxi ;
87  else
89  }
90  else {
91  // Need to compute the derivative :
92  // Tensor for der
93  Tensor auxi_der (so.val_t->get_space(), val_res, type_ind, basis) ;
94  // Set the names of the indices :
95  auxi_der.set_name_affected() ;
96  auxi_der.set_name_ind(0, ind_der) ;
97  for (int i=1 ; i<val_res ; i++)
98  auxi_der.set_name_ind(i, so.der_t->get_name_ind()[i-1]) ;
99 
100  //Loop on the components :
101  Index pos_auxi_der(auxi_der) ;
102  do {
103  for (int i=0 ; i<val_res-1 ; i++)
104  pos_so.set(i) = pos_auxi_der(i+1) ;
105  auxi_der.set(pos_auxi_der).set_domain(num_dom) = (*so.der_t)(pos_so)(num_dom).der_abs(pos_auxi_der(0)+1) ;
106  }
107  while (pos_auxi_der.inc()) ;
108 
109  // Need for derivative :
110  Term_eq auxi (num_dom, auxi_val, auxi_der) ;
111 
112  // If derive contravariant : manipulate first indice :
113  if (type_der==CON)
114  manipulator->manipulate_ind (auxi, 0) ;
115 
116  if (!need_sum)
117  return auxi ;
118  else
121  }
122 
123 }
124 }
reference set(const Index &pos)
Read/write of an element.
Definition: array.hpp:186
Describes the tensorial basis used by the various tensors.
Definition: base_tensor.hpp:49
virtual Term_eq derive_flat_cart(int, char, const Term_eq &, const Metric *) const
Computes the flat derivative of a Term_eq, in Cartesian coordinates.
int num_dom
Number of the current domain (used by the Space)
Definition: space.hpp:63
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
int & set(int i)
Read/write of the position in a given dimension.
Definition: index.hpp:72
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
Purely abstract class for metric handling.
Definition: metric.hpp:39
MMPtr_array< Term_eq > p_met_con
Array of pointers on various Term_eq.
Definition: metric.hpp:55
virtual void manipulate_ind(Term_eq &so, int ind) const
Uses the Metric to manipulate one of the index of a Term_eq (i.e.
Definition: metric.cpp:645
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
Definition: scalar.hpp:555
Tensor handling.
Definition: tensor.hpp:149
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
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_index_type(int i) const
Gives the type (covariant or contravariant) of a given index.
Definition: tensor.hpp:526
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
Tensor * val_t
Pointer on the value, if the Term_eq is a Tensor.
Definition: term_eq.hpp:68