libMesh
type_n_tensor.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
27 // C++ includes
28 #include <cstdlib> // *must* precede <cmath> for proper std:abs() on PGI, Sun Studio CC
29 #include <cmath>
30 #include <vector>
31 
32 namespace libMesh
33 {
34 
46 template <unsigned int N, typename T>
47 class TypeNTensor
48 {
49 public:
50  TypeNTensor () : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
51 
52  TypeNTensor (const T &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
53 
54  TypeNTensor (const TypeVector<T> &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
55 
56  TypeNTensor (const TypeTensor<T> &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
57 
58  operator TypeVector<T> () const { libmesh_not_implemented(); return 0; }
59  operator VectorValue<T> () const { libmesh_not_implemented(); return 0; }
60 
61  operator TypeTensor<T> () const { libmesh_not_implemented(); return 0; }
62  operator TensorValue<T> () const { libmesh_not_implemented(); return 0; }
63 
68 
72  const TypeNTensor<N-1,T> slice (const unsigned int /*i*/) const
73  { return TypeNTensor<N-1,T>(); }
74 
78  TypeNTensor<N-1,T> slice (const unsigned int /*i*/)
79  { return TypeNTensor<N-1,T>(); }
80 
84  template<typename T2>
88 
92  template<typename T2>
94  { return *this; }
95 
99  template<typename T2>
103 
107  template<typename T2>
109  { return *this; }
110 
115  { return *this; }
116 
120  template <typename Scalar>
121  typename boostcopy::enable_if_c<
124  operator * (const Scalar) const
126 
130  template <typename Scalar>
131  const TypeNTensor<N,T> & operator *= (const Scalar) { return *this; }
132 
136  template <typename Scalar>
137  typename boostcopy::enable_if_c<
138  ScalarTraits<Scalar>::value,
140  operator / (const Scalar) const { return *this; }
141 
145  const TypeNTensor<N,T> & operator /= (const T) { return *this; }
146 
151  template <typename T2>
153  contract (const TypeNTensor<N,T2> &) const { return 0; }
154 
161 #ifdef LIBMESH_ENABLE_DEPRECATED
162  Real size_sq() const { libmesh_deprecated(); return 0.;}
163 #endif
164 
169  Real norm_sq() const { return 0.;}
170 
174  bool operator == (const TypeNTensor<N,T> & /*rhs*/) const
175  { return true; }
176 
182  bool operator < (const TypeNTensor<N,T> & /*rhs*/) const
183  { return false; }
184 
188  bool operator > (const TypeNTensor<N,T> & /*rhs*/) const
189  { return false; }
190 
195  void print(std::ostream & /*os = libMesh::out*/) const {}
196 
203  friend std::ostream & operator << (std::ostream & os,
204  const TypeNTensor<N,T> & t)
205  {
206  t.print(os);
207  return os;
208  }
209 
213  template<typename T2>
214  void add_scaled (const TypeNTensor<N, T2> &, const T &);
215 
219  std::vector<T> _coords;
220 
221 private:
222  static constexpr int int_pow(int b, int e)
223  {
224  return (e == 0) ? 1 : b * int_pow(b, e - 1);
225  }
226 };
227 
228 
229 template<unsigned int N, typename T>
230 template<typename T2>
231 inline
232 void TypeNTensor<N, T>::add_scaled (const TypeNTensor<N, T2> & p, const T & factor)
233 {
234  unsigned int size = int_pow(LIBMESH_DIM, N);
235  for (unsigned int i = 0; i < size ; i++)
236  _coords[i] += factor*p._coords[i];
237 }
238 
239 } // namespace libMesh
240 
241 
242 #endif // LIBMESH_TYPE_N_TENSOR_H
TypeNTensor(const T &)
Definition: type_n_tensor.h:52
static constexpr int int_pow(int b, int e)
void add_scaled(const TypeNTensor< N, T2 > &, const T &)
Add a scaled type N tensor to this type N tensor without creating a temporary.
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
Real size_sq() const
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.
Definition: type_n_tensor.h:93
CompareTypes< T, T2 >::supertype contract(const TypeNTensor< N, T2 > &) const
Multiply 2 tensors together, i.e.
const TypeNTensor< N, T > & operator-=(const TypeNTensor< N, T2 > &)
Subtract from this tensor.
This class defines a tensor in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:32
bool operator==(const TypeNTensor< N, T > &) 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.
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.
TypeNTensor(const TypeTensor< T > &)
Definition: type_n_tensor.h:56
TypeNTensor< N, T > operator-() const
Real norm_sq() const
const TypeNTensor< N, T > & operator/=(const T)
Divide every entry of this tensor by a number.
This class defines a vector in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:30
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.
bool operator>(const TypeNTensor< N, T > &) const
void print(std::ostream &) const
Do a formatted print of this tensor to a stream which defaults to libMesh::out.
This class will eventually define a rank-N tensor in LIBMESH_DIM dimensional space of type T...
Definition: tensor_tools.h:34
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
~TypeNTensor()
Destructor.
Definition: type_n_tensor.h:67
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:78
TypeNTensor(const TypeVector< T > &)
Definition: type_n_tensor.h:54
TypeNTensor< N, typename CompareTypes< T, T2 >::supertype > operator+(const TypeNTensor< N, T2 > &) const
Add two tensors.
Definition: type_n_tensor.h:86
const TypeNTensor< N-1, T > slice(const unsigned int) const
Definition: type_n_tensor.h:72
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.