KADATH
ope_id.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 "ope_eq.hpp"
21 #include "tensor.hpp"
22 #include "system_of_eqs.hpp"
23 #include "name_tools.hpp"
24 namespace Kadath {
25 // For tensors
26 Ope_id::Ope_id(const System_of_eqs* zesys, const Term_eq* tt, int val, char* name, Array<int>* ttype) :
27  Ope_eq(zesys, tt->get_dom(), 0), target(tt),
28  valence (val), name_ind(name), type_ind(ttype) {
29  need_sum = false ;
30  for (int i=0 ; i<valence ; i++)
31  for (int j=i+1 ; j<valence ; j++)
32  if (name_ind[i]==name_ind[j])
33  need_sum = true ;
34 }
35 
36 // For scalars and double
37 Ope_id::Ope_id(const System_of_eqs* zesys, const Term_eq* tt) :
38  Ope_eq(zesys, tt->get_dom(), 0), target(tt),
39  valence (0), name_ind(0x0), type_ind(0x0), need_sum(false) {
40 }
41 
43  if (name_ind!=0x0)
44  delete [] name_ind ;
45  if (type_ind!=0x0)
46  delete type_ind ;
47 }
48 
50 
51  Term_eq auxi (*target) ;
52  // First put the names (not for doubles or scalars...)
53  if (name_ind !=0x0) {
54  for (int i=0 ; i<valence ; i++)
55  auxi.val_t->set_name_ind(i, name_ind[i]) ;
56  auxi.val_t->name_affected = true ;
57  if (auxi.der_t!=0x0) {
58  for (int i=0 ; i<valence ; i++)
59  auxi.der_t->set_name_ind(i, name_ind[i]) ;
60  auxi.der_t->name_affected = true ;
61  }
62  }
63 
64  // Manip of the indices if needed :
65  for (int i=0 ; i<valence ; i++)
66  if (auxi.val_t->get_index_type(i) != (*type_ind)(i)) {
67  // Manipulation using the metric :
68  syst->get_met()->manipulate_ind (auxi, i) ;
69  }
70 
71  if (!need_sum)
72  return auxi ;
73  else {
74  // Doit encore sommer sur certains indices :
75  if (auxi.der_t==0x0)
76  return Term_eq (dom, auxi.val_t->do_summation_one_dom(dom)) ;
77  else
79  }
80 }
81 }
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
Abstract class that describes the various operators that can appear in the equations.
Definition: ope_eq.hpp:32
const System_of_eqs * syst
The associated System_of_eqs.
Definition: ope_eq.hpp:35
int dom
Index of the Domain where the operator is defined.
Definition: ope_eq.hpp:36
int valence
Valence of the result.
Definition: ope_eq.hpp:76
Term_eq action() const override
Computes the action of the current Ope_eq using its various parts.
Definition: ope_id.cpp:49
Ope_id(const System_of_eqs *syst, const Term_eq *so, int valence, char *names, Array< int > *ttype)
Constructor.
Definition: ope_id.cpp:26
const Term_eq * target
The input&#160;Term_eq.
Definition: ope_eq.hpp:75
char * name_ind
The names of the various indices (if a Tensor of valence >0)
Definition: ope_eq.hpp:77
Array< int > * type_ind
The type of the indices.
Definition: ope_eq.hpp:78
bool need_sum
True if an inner contraction is needed to compute the result.
Definition: ope_eq.hpp:79
~Ope_id() override
Destructor.
Definition: ope_id.cpp:42
Class used to describe and solve a system of equations.
const Metric * get_met() const
Returns a pointer on the Metric.
bool name_affected
Indicator that states if the indices have been given names.
Definition: tensor.hpp:172
void set_name_ind(int dd, char name)
Sets the name of one index ; the names must have been affected first.
int get_index_type(int i) const
Gives the type (covariant or contravariant) of a given index.
Definition: tensor.hpp:526
Tensor do_summation_one_dom(int dd) const
Does the inner contraction of the Tensor in a given domain.
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