libMesh
type_n_tensor.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_TYPE_N_TENSOR_H
21 #define LIBMESH_TYPE_N_TENSOR_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/type_vector.h"
26 #include "libmesh/tuple_of.h"
27 
28 // C++ includes
29 #include <cstdlib> // *must* precede <cmath> for proper std:abs() on PGI, Sun Studio CC
30 #include <cmath>
31 #include <vector>
32 
33 namespace libMesh
34 {
35 
47 template <unsigned int N, typename T>
48 class TypeNTensor
49 {
50 public:
55 
56  TypeNTensor () : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
57 
58  TypeNTensor (const T &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
59 
60  TypeNTensor (const TypeVector<T> &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
61 
62  TypeNTensor (const TypeTensor<T> &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
63 
64  TypeNTensor (const TypeNTensor<N,T> &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
65 
66  TypeNTensor & operator = (const TypeNTensor<N,T> &) { libmesh_not_implemented(); return *this; }
67 
68  operator TypeVector<T> () const { libmesh_not_implemented(); return 0; }
69  operator VectorValue<T> () const { libmesh_not_implemented(); return 0; }
70 
71  operator TypeTensor<T> () const { libmesh_not_implemented(); return 0; }
72  operator TensorValue<T> () const { libmesh_not_implemented(); return 0; }
73 
77  ~TypeNTensor() = default;
78 
82  const TypeNTensor<N-1,T> slice (const unsigned int /*i*/) const
83  {
84  libmesh_not_implemented();
85  return TypeNTensor<N-1,T>();
86  }
87 
91  TypeNTensor<N-1,T> slice (const unsigned int /*i*/)
92  {
93  libmesh_not_implemented();
94  return TypeNTensor<N-1,T>();
95  }
96 
97  template <typename Scalar>
98  typename boostcopy::enable_if_c<
100  TypeNTensor &>::type
101  operator = (const Scalar & libmesh_dbg_var(p))
102  { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
103 
107  template<typename T2>
110  {
111  libmesh_not_implemented();
113  }
114 
118  template<typename T2>
120  {
121  libmesh_not_implemented();
122  return *this;
123  }
124 
128  template<typename T2>
131  {
132  libmesh_not_implemented();
134  }
135 
139  template<typename T2>
141  {
142  libmesh_not_implemented();
143  return *this;
144  }
145 
150  {
151  libmesh_not_implemented();
152  return *this;
153  }
154 
158  template <typename Scalar>
159  typename boostcopy::enable_if_c<
162  operator * (const Scalar) const
163  {
164  libmesh_not_implemented();
166  }
167 
171  template <typename Scalar>
172  const TypeNTensor<N,T> & operator *= (const Scalar)
173  {
174  libmesh_not_implemented();
175  return *this;
176  }
177 
181  template <typename Scalar>
182  typename boostcopy::enable_if_c<
185  operator / (const Scalar) const
186  {
187  libmesh_not_implemented();
188  return *this;
189  }
190 
195  {
196  libmesh_not_implemented();
197  return *this;
198  }
199 
209  template <typename T2>
211  contract (const TypeNTensor<N,T2> &) const
212  {
213  libmesh_not_implemented();
214  return 0;
215  }
216 
221  auto norm() const -> decltype(std::norm(T()))
222  {
223  libmesh_not_implemented();
224  return 0.;
225  }
226 
231  auto norm_sq() const -> decltype(std::norm(T()))
232  {
233  libmesh_not_implemented();
234  return 0.;
235  }
236 
240  void zero() { libmesh_not_implemented(); }
241 
245  bool operator == (const TypeNTensor<N,T> & /*rhs*/) const
246  {
247  libmesh_not_implemented();
248  return true;
249  }
250 
256  bool operator < (const TypeNTensor<N,T> & /*rhs*/) const
257  {
258  libmesh_not_implemented();
259  return false;
260  }
261 
265  bool operator > (const TypeNTensor<N,T> & /*rhs*/) const
266  {
267  libmesh_not_implemented();
268  return false;
269  }
270 
275  void print(std::ostream & /*os = libMesh::out*/) const {}
276 
283  friend std::ostream & operator << (std::ostream & os,
284  const TypeNTensor<N,T> & t)
285  {
286  t.print(os);
287  return os;
288  }
289 
293  template<typename T2>
294  void add_scaled (const TypeNTensor<N, T2> &, const T &);
295 
299  std::vector<T> _coords;
300 
301 private:
302  static constexpr int int_pow(int b, int e)
303  {
304  return (e == 0) ? 1 : b * int_pow(b, e - 1);
305  }
306 };
307 
308 
309 template<unsigned int N, typename T>
310 template<typename T2>
311 inline
312 void TypeNTensor<N, T>::add_scaled (const TypeNTensor<N, T2> & p, const T & factor)
313 {
314  unsigned int size = int_pow(LIBMESH_DIM, N);
315  for (unsigned int i = 0; i < size ; i++)
316  _coords[i] += factor*p._coords[i];
317 }
318 
319 template <unsigned int N, typename T, typename Scalar>
320 typename boostcopy::enable_if_c<
323 operator * (const Scalar &, const TypeNTensor<N, T> &)
324 {
325  libmesh_not_implemented();
327 }
328 
329 template <unsigned int N, typename T, typename Scalar>
330 typename boostcopy::enable_if_c<
332  TypeNTensor<N,typename CompareTypes<Scalar, T>::supertype>>::type
333 operator / (const Scalar &, const TypeNTensor<N, T> &)
334 {
335  libmesh_not_implemented();
337 }
338 
339 
340 } // namespace libMesh
341 
342 
343 #endif // LIBMESH_TYPE_N_TENSOR_H
TypeNTensor(const T &)
Definition: type_n_tensor.h:58
static constexpr int int_pow(int b, int e)
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< Scalar, T >::supertype > >::type operator/(const Scalar &, const TypeNTensor< N, T > &)
TypeNTensor & operator=(const TypeNTensor< N, T > &)
Definition: type_n_tensor.h:66
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< T, Scalar >::supertype > >::type operator/(const Scalar) const
Divide every entry of a tensor by a number.
void print(std::ostream &) const
Do a formatted print of this tensor to a stream which defaults to libMesh::out.
TypeNTensor< N, T > operator-() const
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< T, Scalar >::supertype > >::type operator*(const Scalar) const
Multiply every entry of a tensor by a number.
void add_scaled(const TypeNTensor< N, T2 > &, const T &)
Add a scaled type N tensor to this type N tensor without creating a temporary.
TypeNTensor(const TypeNTensor< N, T > &)
Definition: type_n_tensor.h:64
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
const TypeNTensor< N, T > & operator+=(const TypeNTensor< N, T2 > &)
Add to this tensor.
const TypeNTensor< N, T > & operator-=(const TypeNTensor< N, T2 > &)
Subtract from this tensor.
const TypeNTensor< N-1, T > slice(const unsigned int) const
Definition: type_n_tensor.h:82
This class defines a tensor in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:36
TypeNTensor(const TypeTensor< T > &)
Definition: type_n_tensor.h:62
auto norm_sq() const -> decltype(std::norm(T()))
typename tuple_n< Index, T >::template type<> tuple_of
Definition: tuple_of.h:22
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< Scalar, T >::supertype > >::type operator*(const Scalar &, const TypeNTensor< N, T > &)
const TypeNTensor< N, T > & operator/=(const T)
Divide every entry of this tensor by a number.
bool operator==(const TypeNTensor< N, T > &) const
auto norm() const -> decltype(std::norm(T()))
This class defines a vector in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:34
tuple_of< N, unsigned int > index_type
Helper typedef for generic index programming.
Definition: type_n_tensor.h:54
const TypeNTensor< N, T > & operator*=(const Scalar)
Multiply every entry of this tensor by a number.
std::vector< T > _coords
The coordinates of the TypeNTensor.
This class will eventually define a rank-N tensor in LIBMESH_DIM dimensional space of type T...
Definition: tensor_tools.h:38
TypeNTensor< N, typename CompareTypes< T, T2 >::supertype > operator+(const TypeNTensor< N, T2 > &) const
Add two tensors.
~TypeNTensor()=default
Destructor.
friend std::ostream & operator<<(std::ostream &os, const TypeNTensor< N, T > &t)
Does a formatted print (as above) but supports the syntax:
TypeNTensor< N-1, T > slice(const unsigned int)
Definition: type_n_tensor.h:91
void zero()
Set all entries of the tensor to 0.
bool operator>(const TypeNTensor< N, T > &) const
TypeNTensor(const TypeVector< T > &)
Definition: type_n_tensor.h:60
static const bool value
Definition: compare_types.h:64
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
CompareTypes< T, T2 >::supertype contract(const TypeNTensor< N, T2 > &) const
Multiply 2 tensors together to return a scalar, i.e.