KADATH
base_tensor.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 #ifndef __BASE_TENSOR_HPP_
21 #define __BASE_TENSOR_HPP_
22 
23 
24 
25 // Headers C
26 #include "headcpp.hpp"
27 #include "space.hpp"
28 
29 // Types of basis :
30 #define CARTESIAN_BASIS 0
31 #define SPHERICAL_BASIS 1
32 #define MTZ_BASIS 2
33 
34 namespace Kadath {
35 
36  //-----------------------------------//
37  // class Base_tensor //
38  //-----------------------------------//
39 
49 class Base_tensor : public Memory_mapped {
50 
51  // Data :
52  // -----
53 protected:
54  const Space& space ;
56 
57 
58  // Constructors - Destructor
59  // -------------------------
60 
61 public:
66  explicit Base_tensor(const Space& sp) : space{sp}, basis{sp.get_nbr_domains()} {basis = -1 ;};
72  Base_tensor (const Space& sp, int bb) : space{sp}, basis{sp.get_nbr_domains()} {basis = bb ;}
74  Base_tensor(const Base_tensor& so) : space{so.space}, basis{so.basis} {}
80  Base_tensor (const Space& sp, FILE* fd) : space{sp}, basis{fd} {}
81 
82 #ifdef TENSOR_MOVE_SEMANTIC
83  Base_tensor(Base_tensor && so) : space{so.space}, basis{std::move(so.basis)} {}
84  Base_tensor & operator=(Base_tensor && so) {assert(&space == &so.space); basis = std::move(so.basis); return *this;}
85 #endif
86  virtual ~Base_tensor() = default;
87 
88 public:
89 
91  int& set_basis(int nd) {return basis.set(nd) ;}
93  int get_basis (int nd) const {return basis(nd) ;}
95  void operator= (const Base_tensor&) ;
97  void swap(Base_tensor & so) {assert(&space == &so.space); basis.swap(so.basis);}
98 
102  const Space& get_space () const {return space;} ;
103 
104  void save (FILE*fd) const {basis.save(fd) ;}
105 
106  // Outputs
107  // -------
108  friend ostream& operator<<(ostream& , const Base_tensor& ) ;
109  friend bool operator== (const Base_tensor&, const Base_tensor&) ;
110  friend bool operator!= (const Base_tensor&, const Base_tensor&) ;
111 };
112 
113 inline void Base_tensor::operator= (const Base_tensor& so) {
114  assert (&space==&so.get_space()) ;
115  for (int i=0 ; i<basis.get_size(0) ; i++)
116  basis.set(i) = so.basis(i) ;
117 }
118 
119 
120 inline bool operator!= (const Base_tensor& b1, const Base_tensor& b2) {
121  return !(b1 == b2);
122 }
123 
124 }
125 #endif
void swap(Array< T > &so)
Swaps contents between the two arrays (beware when using it with arrays of allocated pointers).
Definition: array.hpp:152
reference set(const Index &pos)
Read/write of an element.
Definition: array.hpp:186
int get_size(int i) const
Returns the size of a given dimension.
Definition: array.hpp:331
void save(FILE *fd, Array_ordering order=last_index) const
Save in a file.
Definition: array.hpp:502
Describes the tensorial basis used by the various tensors.
Definition: base_tensor.hpp:49
Base_tensor(const Space &sp, FILE *fd)
Constructor from a file.
Definition: base_tensor.hpp:80
Base_tensor(const Base_tensor &so)
Copy constructor.
Definition: base_tensor.hpp:74
friend bool operator!=(const Base_tensor &, const Base_tensor &)
Tests the difference of two basis.
Base_tensor(const Space &sp, int bb)
Constructor where the basis is the same everywhere.
Definition: base_tensor.hpp:72
int get_basis(int nd) const
Read only the basis in a given domain.
Definition: base_tensor.hpp:93
const Space & get_space() const
void save(FILE *fd) const
Saving function.
Array< int > basis
The basis in each Domain.
Definition: base_tensor.hpp:55
void swap(Base_tensor &so)
Sylvain's stuff.
Definition: base_tensor.hpp:97
Base_tensor(const Space &sp)
Constructor, does not affect anything.
Definition: base_tensor.hpp:66
void operator=(const Base_tensor &)
Affectation operator.
friend bool operator==(const Base_tensor &, const Base_tensor &)
Tests equality of two basis.
Definition: base_tensor.cpp:51
int & set_basis(int nd)
Read/write the basis in a given domain.
Definition: base_tensor.hpp:91
const Space & space
The associated Space.
Definition: base_tensor.hpp:54
friend ostream & operator<<(ostream &, const Base_tensor &)
Display.
Definition: base_tensor.cpp:26
virtual ~Base_tensor()=default
Destructor.
The Space class is an ensemble of domains describing the whole space of the computation.
Definition: space.hpp:1362