KADATH
vector.hpp
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  /*
21  * Definition of class Vector
22  *
23  */
24 
25 #ifndef __VECTOR_HPP_
26 #define __VECTOR_HPP_
27 
28 #include "tensor.hpp"
29 
30 namespace Kadath {
31 
32  //-------------------------//
33  // class Vector //
34  //-------------------------//
35 
36 
41  class Vector : public Tensor {
42  public:
43 
49  Vector(const Space& sp, int tipe, const Base_tensor& ba) : Tensor{sp, 1, tipe, ba} {}
50 
51  Vector(const Vector& a) : Tensor{a} {}
52  Vector (const Space& sp, FILE*ff) : Tensor{sp, ff} {assert (valence==1) ;}
53 
57  Vector(const Tensor& a) : Tensor{a} {assert(valence == 1) ;}
58 
59  // Mutators / assignment
60  // ---------------------
61  public:
62 
63  Vector & operator=(const Vector&) ;
64  Vector & operator=(const Tensor&) override;
65  Vector & operator=(double) override;
66  void annule_hard() override;
67 
68 #ifdef TENSOR_MOVE_SEMANTIC
69  Vector(Vector && so) : Tensor{std::move(so)} {}
70  Vector & operator=(Vector && so) {this->Tensor::operator=(std::move(so)); return *this;}
71 #endif //#ifdef TENSOR_MOVE_SEMANTIC
72 
73  // Accessors
74  // ---------
75  public:
76  using Tensor::set;
77  Scalar& set(int ) ;
78  const Scalar& operator()(int ) const;
79  const Scalar& at(int) const;
80 
81 
82  virtual int position(const Array<int>& idx) const {
83  assert (idx.get_ndim() == 1) ;
84  assert (idx.get_size(0) == 1) ;
85  assert ((idx(0) >= 1) && (idx(0) <= espace.get_ndim())) ;
86 
87  return (idx(0) - 1) ;
88  }
89 
90  virtual int position(const Index& idx) const {
91  assert ((idx(0)>=0) && (idx(0)<ndim)) ;
92  return (idx(0)) ;
93  }
94 
98  int get_index_type() const {return type_indice(0) ;};
99 
100  virtual Array<int> indices(int place) const {
101  assert((place>=0) && (place<espace.get_ndim())) ;
102 
103  Array<int> res(1) ;
104  res = place + 1;
105  return res ;
106  }
107  };
108 }
109 #endif
int get_ndim() const
Returns the number of dimensions.
Definition: array.hpp:323
int get_size(int i) const
Returns the size of a given dimension.
Definition: array.hpp:331
Describes the tensorial basis used by the various tensors.
Definition: base_tensor.hpp:49
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
The Space class is an ensemble of domains describing the whole space of the computation.
Definition: space.hpp:1362
int get_ndim() const
Returns the number of dimensions.
Definition: space.hpp:1373
Tensor handling.
Definition: tensor.hpp:149
int ndim
The dimension/.
Definition: tensor.hpp:156
const Scalar & operator()() const
Read only for a Scalar.
virtual Tensor & operator=(const Tensor &)
Assignment to a Tensor.
Definition: tensor_math.cpp:27
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...)
Definition: tensor.hpp:157
Array< int > type_indice
1D array of integers of size valence containing the type of each index: COV for a covariant one and C...
Definition: tensor.hpp:170
Scalar & set()
Read/write for a Scalar.
Definition: tensor.hpp:364
const Space & espace
The Space.
Definition: tensor.hpp:154
A class derived from Tensor to deal specificaly with objects of valence 1 (and so also 1-forms).
Definition: vector.hpp:41
int get_index_type() const
Returns the type of the objects (CON or COV)
Definition: vector.hpp:98
const Scalar & at(int) const
Readonly access to a component.
Vector(const Space &sp, FILE *ff)
Constructor from file.
Definition: vector.hpp:52
Vector & operator=(const Vector &)
Assignment to another Vector.
Definition: vector.cpp:25
Vector(const Vector &a)
Copy constructor.
Definition: vector.hpp:51
virtual Array< int > indices(int place) const
Gives the values of the indices corresponding to a location in the array used for storage of the comp...
Definition: vector.hpp:100
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
Definition: tensor_impl.hpp:91
void annule_hard() override
Sets the Tensor to zero (hard version ; no logical state used).
virtual int position(const Index &idx) const
Gives the location of a given component in the array used for storage (Index version).
Definition: vector.hpp:90
Vector(const Tensor &a)
Constructor from a Tensor .
Definition: vector.hpp:57
Vector(const Space &sp, int tipe, const Base_tensor &ba)
Standard constructor.
Definition: vector.hpp:49
virtual int position(const Array< int > &idx) const
Gives the location of a given component in the array used for storage (Array version).
Definition: vector.hpp:82