KADATH
domain_bispheric_rect_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 #include "utilities.hpp"
22 
23 #include "bispheric.hpp"
24 #include "param.hpp"
25 #include "term_eq.hpp"
26 #include "metric.hpp"
27 #include "scalar.hpp"
28 #include "tensor_impl.hpp"
29 
30 namespace Kadath {
31 Term_eq Domain_bispheric_rect::derive_flat_cart (int type_der, char ind_der, const Term_eq& so, const Metric* manipulator) const {
32 
33  bool doder = (so.der_t==0x0) ? false : true ;
34  if ((type_der==CON) && (manipulator->p_met_con[num_dom]->der_t==0x0))
35  doder = false ;
36 
37  assert ((type_der==COV) || (type_der==CON)) ;
38  int val_res = so.val_t->get_valence() + 1 ;
39 
40  bool doname = true ;
41  if (so.val_t->get_valence()>0)
42  if (!so.val_t->is_name_affected())
43  doname = false;
44 
45  Array<int> type_ind (val_res) ;
46  type_ind.set(0) = COV ;
47  for (int i=1 ; i<val_res ; i++)
48  type_ind.set(i) = so.val_t->get_index_type(i-1) ;
49 
50  // Need for summation ?
51  bool need_sum = false ;
52  if (doname)
53  for (int i=1 ; i<val_res ; i++)
54  if (ind_der== so.val_t->get_name_ind()[i-1])
55  need_sum = true ;
56 
57  // Tensor for val
58  Base_tensor basis (so.val_t->get_space(), CARTESIAN_BASIS) ;
59  Tensor auxi_val (so.val_t->get_space(), val_res, type_ind, basis) ;
60 
61 
62  // Set the names of the indices :
63  if (doname) {
64  auxi_val.set_name_affected() ;
65  auxi_val.set_name_ind(0, ind_der) ;
66  for (int i=1 ; i<val_res ; i++)
67  auxi_val.set_name_ind(i, so.val_t->get_name_ind()[i-1]) ;
68  }
69 
70  //Loop on the components :
71  Index pos_auxi(auxi_val) ;
72  Index pos_so (*so.val_t) ;
73  do {
74  for (int i=0 ; i<val_res-1 ; i++)
75  pos_so.set(i) = pos_auxi(i+1) ;
76  auxi_val.set(pos_auxi).set_domain(num_dom) = (*so.val_t)(pos_so)(num_dom).der_abs(pos_auxi(0)+1) ;
77  }
78  while (pos_auxi.inc()) ;
79 
80  if (!doder) {
81  // No need for derivative :
82  Term_eq auxi (num_dom, auxi_val) ;
83  // If derive contravariant : manipulate first indice :
84  if (type_der==CON)
85  manipulator->manipulate_ind (auxi, 0) ;
86 
87  if (!need_sum)
88  return auxi ;
89  else
91  }
92  else {
93  // Need to compute the derivative :
94  // Tensor for der
95  Tensor auxi_der (so.val_t->get_space(), val_res, type_ind, basis) ;
96  // Set the names of the indices :
97  auxi_der.set_name_affected() ;
98  auxi_der.set_name_ind(0, ind_der) ;
99  for (int i=1 ; i<val_res ; i++)
100  auxi_der.set_name_ind(i, so.der_t->get_name_ind()[i-1]) ;
101 
102  //Loop on the components :
103  Index pos_auxi_der(auxi_der) ;
104  do {
105  for (int i=0 ; i<val_res-1 ; i++)
106  pos_so.set(i) = pos_auxi_der(i+1) ;
107  auxi_der.set(pos_auxi_der).set_domain(num_dom) = (*so.der_t)(pos_so)(num_dom).der_abs(pos_auxi_der(0)+1) ;
108  }
109  while (pos_auxi_der.inc()) ;
110 
111  // Need for derivative :
112  Term_eq auxi (num_dom, auxi_val, auxi_der) ;
113 
114  // If derive contravariant : manipulate first indice :
115  if (type_der==CON)
116  manipulator->manipulate_ind (auxi, 0) ;
117 
118  if (!need_sum)
119  return auxi ;
120  else
123  }
124 
125 }
126 }
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