type_n_tensor.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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  operator TypeVector<T> () const { libmesh_not_implemented(); return 0; }
65  operator VectorValue<T> () const { libmesh_not_implemented(); return 0; }
66 
67  operator TypeTensor<T> () const { libmesh_not_implemented(); return 0; }
68  operator TensorValue<T> () const { libmesh_not_implemented(); return 0; }
69 
74 
78  const TypeNTensor<N-1,T> slice (const unsigned int /*i*/) const
79  { return TypeNTensor<N-1,T>(); }
80 
84  TypeNTensor<N-1,T> slice (const unsigned int /*i*/)
85  { return TypeNTensor<N-1,T>(); }
86 
90  template<typename T2>
94 
98  template<typename T2>
100  { return *this; }
101 
105  template<typename T2>
109 
113  template<typename T2>
115  { return *this; }
116 
121  { return *this; }
122 
126  template <typename Scalar>
127  typename boostcopy::enable_if_c<
130  operator * (const Scalar) const
132 
136  template <typename Scalar>
137  const TypeNTensor<N,T> & operator *= (const Scalar) { return *this; }
138 
142  template <typename Scalar>
143  typename boostcopy::enable_if_c<
146  operator / (const Scalar) const { return *this; }
147 
151  const TypeNTensor<N,T> & operator /= (const T) { return *this; }
152 
162  template <typename T2>
164  contract (const TypeNTensor<N,T2> &) const { return 0; }
165 
172 #ifdef LIBMESH_ENABLE_DEPRECATED
173  Real size_sq() const { libmesh_deprecated(); return 0.;}
174 #endif
175 
180  Real norm_sq() const { return 0.;}
181 
185  bool operator == (const TypeNTensor<N,T> & /*rhs*/) const
186  { return true; }
187 
193  bool operator < (const TypeNTensor<N,T> & /*rhs*/) const
194  { return false; }
195 
199  bool operator > (const TypeNTensor<N,T> & /*rhs*/) const
200  { return false; }
201 
206  void print(std::ostream & /*os = libMesh::out*/) const {}
207 
214  friend std::ostream & operator << (std::ostream & os,
215  const TypeNTensor<N,T> & t)
216  {
217  t.print(os);
218  return os;
219  }
220 
224  template<typename T2>
225  void add_scaled (const TypeNTensor<N, T2> &, const T &);
226 
230  std::vector<T> _coords;
231 
232 private:
233  static constexpr int int_pow(int b, int e)
234  {
235  return (e == 0) ? 1 : b * int_pow(b, e - 1);
236  }
237 };
238 
239 
240 template<unsigned int N, typename T>
241 template<typename T2>
242 inline
243 void TypeNTensor<N, T>::add_scaled (const TypeNTensor<N, T2> & p, const T & factor)
244 {
245  unsigned int size = int_pow(LIBMESH_DIM, N);
246  for (unsigned int i = 0; i < size ; i++)
247  _coords[i] += factor*p._coords[i];
248 }
249 
250 template <unsigned int N, typename T, typename Scalar>
251 typename boostcopy::enable_if_c<
254 operator * (const Scalar &, const TypeNTensor<N, T> &)
255 {
256  libmesh_not_implemented();
258 }
259 
260 template <unsigned int N, typename T, typename Scalar>
261 typename boostcopy::enable_if_c<
263  TypeNTensor<N,typename CompareTypes<Scalar, T>::supertype>>::type
264 operator / (const Scalar &, const TypeNTensor<N, T> &)
265 {
266  libmesh_not_implemented();
268 }
269 
270 
271 } // namespace libMesh
272 
273 
274 #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 > &)
Real size_sq() const
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< T, Scalar >::supertype > >::type operator/(const Scalar) const
void print(std::ostream &) const
TypeNTensor< N, T > operator-() const
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< T, Scalar >::supertype > >::type operator*(const Scalar) const
void add_scaled(const TypeNTensor< N, T2 > &, const T &)
const TypeNTensor< N, T > & operator+=(const TypeNTensor< N, T2 > &)
Definition: type_n_tensor.h:99
const TypeNTensor< N, T > & operator-=(const TypeNTensor< N, T2 > &)
const TypeNTensor< N-1, T > slice(const unsigned int) const
Definition: type_n_tensor.h:78
TypeNTensor(const TypeTensor< T > &)
Definition: type_n_tensor.h:62
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)
bool operator==(const TypeNTensor< N, T > &) const
tuple_of< N, unsigned int > index_type
Definition: type_n_tensor.h:54
const TypeNTensor< N, T > & operator*=(const Scalar)
std::vector< T > _coords
Real norm_sq() const
typename tuple_n< I, T >::template type<> tuple_of
Definition: tuple_of.h:21
TypeNTensor< N, typename CompareTypes< T, T2 >::supertype > operator+(const TypeNTensor< N, T2 > &) const
Definition: type_n_tensor.h:92
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
friend std::ostream & operator<<(std::ostream &os, const TypeNTensor< N, T > &t)
TypeNTensor< N-1, T > slice(const unsigned int)
Definition: type_n_tensor.h:84
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:58
CompareTypes< T, T2 >::supertype contract(const TypeNTensor< N, T2 > &) const