*/
typedef Tensor<rank_-1,dim,Number> value_type;
+ /**
+ * Declare a type that has holds
+ * real-valued numbers with the same
+ * precision as the template argument to
+ * this class. For std::complex<number>,
+ * this corresponds to type number, and
+ * it is equal to Number for all other
+ * cases. See also the respective field
+ * in Vector<Number>.
+ *
+ * This typedef is used to
+ * represent the return type of
+ * norms.
+ */
+ typedef typename numbers::NumberTraits<Number>::real_type real_type;
+
/**
* Declare an array type which
* can be used to initialize an
* i.e. the square root of the sum of
* squares of all entries.
*/
- Number norm () const;
+ real_type norm () const;
/**
* Return the square of the
* may also be useful in other
* contexts.
*/
- Number norm_square () const;
+ real_type norm_square () const;
/**
* Fill a vector with all tensor elements.
* usual in C++, the rightmost
* index of the tensor marches fastest.
*/
- void unroll (Vector<Number> & result) const;
+ template <typename Number2>
+ void unroll (Vector<Number2> & result) const;
/**
/**
* Help function for unroll.
*/
- void unroll_recursion(Vector<Number> &result,
- unsigned int &start_index) const;
+ template <typename Number2>
+ void unroll_recursion(Vector<Number2> &result,
+ unsigned int &start_index) const;
// make the following class a
// friend to this class. in principle,
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number>::Tensor (const array_type &initializer)
}
+
template <int rank_, int dim, typename Number>
inline
typename Tensor<rank_,dim,Number>::value_type&
}
+
template <int rank_, int dim, typename Number>
inline
const typename Tensor<rank_,dim,Number>::value_type&
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number> &
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number> &
Tensor<rank_,dim,Number>::operator = (const Number d)
{
- Assert (d==0, ExcMessage ("Only assignment with zero is allowed"));
+ Assert (d==Number(0), ExcMessage ("Only assignment with zero is allowed"));
for (unsigned int i=0; i<dim; ++i)
subtensor[i] = 0;
}
+
template <int rank_, int dim, typename Number>
inline
bool
}
+
template <int rank_, int dim, typename Number>
inline
bool
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number> &
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number> &
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number> &
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number> &
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number>
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number>
}
+
template <int rank_, int dim, typename Number>
inline
Tensor<rank_,dim,Number>
}
+
template <int rank_, int dim, typename Number>
inline
-Number Tensor<rank_,dim,Number>::norm () const
+typename Tensor<rank_,dim,Number>::real_type
+Tensor<rank_,dim,Number>::norm () const
{
return std::sqrt (norm_square());
}
+
template <int rank_, int dim, typename Number>
inline
-Number Tensor<rank_,dim,Number>::norm_square () const
+typename Tensor<rank_,dim,Number>::real_type
+Tensor<rank_,dim,Number>::norm_square () const
{
- Number s = 0;
+ real_type s = 0;
for (unsigned int i=0; i<dim; ++i)
s += subtensor[i].norm_square();
}
+
+template <int rank_, int dim, typename Number>
+template <typename Number2>
+inline
+void
+Tensor<rank_, dim, Number>::unroll (Vector<Number2> &result) const
+{
+ AssertDimension (result.size(),std::pow(static_cast<double>(dim),rank_));
+ unsigned index = 0;
+ unroll_recursion (result, index);
+}
+
+
+
+template <int rank_, int dim, typename Number>
+template <typename Number2>
+inline
+void
+Tensor<rank_, dim, Number>::unroll_recursion (Vector<Number2> &result,
+ unsigned int &index) const
+{
+ for (unsigned i=0; i<dim; ++i)
+ {
+ operator[](i).unroll_recursion(result, index);
+ }
+}
+
+
+
template <int rank_, int dim, typename Number>
inline
void Tensor<rank_,dim,Number>::clear ()
}
+
template <int rank_, int dim, typename Number>
inline
std::size_t
}
+
template <int rank_, int dim, typename Number>
template <class Archive>
inline
typedef Number value_type;
+ /**
+ * Declare a type that has holds
+ * real-valued numbers with the same
+ * precision as the template argument to
+ * this class. For std::complex<number>,
+ * this corresponds to type number, and
+ * it is equal to Number for all other
+ * cases. See also the respective field
+ * in Vector<Number>.
+ *
+ * This typedef is used to
+ * represent the return type of
+ * norms.
+ */
+ typedef typename numbers::NumberTraits<Number>::real_type real_type;
+
/**
* Constructor. Set to zero.
*/
* <tt>l<sub>2</sub></tt> norm of
* the vector.
*/
- Number norm () const;
+ real_type norm () const;
/**
* Return the square of the
* may also be useful in other
* contexts.
*/
- Number norm_square () const;
+ real_type norm_square () const;
/**
* Reset all values to zero.
typedef Number value_type;
+ /**
+ * Declare a type that has holds
+ * real-valued numbers with the same
+ * precision as the template argument to
+ * this class. For std::complex<number>,
+ * this corresponds to type number, and
+ * it is equal to Number for all other
+ * cases. See also the respective field
+ * in Vector<Number>.
+ *
+ * This typedef is used to
+ * represent the return type of
+ * norms.
+ */
+ typedef typename numbers::NumberTraits<Number>::real_type real_type;
+
/**
* Declare an array type which can
* be used to initialize statically
* <tt>l<sub>2</sub></tt> norm of
* the vector.
*/
- Number norm () const;
+ real_type norm () const;
/**
* Return the square of the
* may also be useful in other
* contexts.
*/
- Number norm_square () const;
+ real_type norm_square () const;
/**
* Reset all values to zero.
* usual in C++, the rightmost
* index marches fastest.
*/
- void unroll (Vector<Number> &result) const;
+ template <typename Number2>
+ void unroll (Vector<Number2> &result) const;
/**
* Determine an estimate for
* case, even if it should be
* public for your compiler.
*/
- void unroll_recursion (Vector<Number> &result,
- unsigned int &start_index) const;
+ template <typename Number2>
+ void unroll_recursion (Vector<Number2> &result,
+ unsigned int &start_index) const;
private:
/**
template <int dim, typename Number>
inline
-Number Tensor<0,dim,Number>::norm () const
+typename Tensor<0,dim,Number>::real_type
+Tensor<0,dim,Number>::norm () const
{
- return std::abs (value);
+ return numbers::NumberTraits<Number>::abs (value);
}
template <int dim, typename Number>
inline
-Number Tensor<0,dim,Number>::norm_square () const
+typename Tensor<0,dim,Number>::real_type
+Tensor<0,dim,Number>::norm_square () const
{
- return value*value;
+ return numbers::NumberTraits<Number>::abs_square (value);
}
value = 0;
}
+
+
template <int dim, typename Number>
template <class Archive>
inline
template <int dim, typename Number>
inline
-Number Tensor<1,dim,Number>::norm () const
+typename Tensor<1,dim,Number>::real_type
+Tensor<1,dim,Number>::norm () const
{
return std::sqrt (norm_square());
}
template <int dim, typename Number>
inline
-Number Tensor<1,dim,Number>::norm_square () const
+typename Tensor<1,dim,Number>::real_type
+Tensor<1,dim,Number>::norm_square () const
{
- Number s = 0;
+ real_type s = 0;
for (unsigned int i=0; i<dim; ++i)
- s += values[i] * values[i];
+ s += numbers::NumberTraits<Number>::abs_square(values[i]);
return s;
}
+template <int dim, typename Number>
+template <typename Number2>
+inline
+void
+Tensor<1,dim,Number>::unroll (Vector<Number2> &result) const
+{
+ Assert (result.size()==dim,
+ ExcDimensionMismatch(dim, result.size()));
+
+ unsigned index = 0;
+ unroll_recursion (result,index);
+}
+
+
+
+template<int dim, typename Number>
+template <typename Number2>
+inline
+void
+Tensor<1,dim,Number>::unroll_recursion (Vector<Number2> &result,
+ unsigned int &index) const
+{
+ for (unsigned i=0; i<dim; ++i)
+ result(index++) = operator[](i);
+}
+
+
+
template <int dim, typename Number>
inline
void Tensor<1,dim,Number>::clear ()
+++ /dev/null
-//---------------------------------------------------------------------------
-// $Id$
-// Version: $Name$
-//
-// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006 by the deal.II authors
-//
-// This file is subject to QPL and may not be distributed
-// without copyright and license information. Please refer
-// to the file deal.II/doc/license.html for the text and
-// further information on this license.
-//
-//---------------------------------------------------------------------------
-
-
-#include <base/tensor.h>
-#include <cmath>
-#include <lac/vector.h>
-
-DEAL_II_NAMESPACE_OPEN
-
-
-// storage for static variables
-template <int dim, typename Number>
-const unsigned int Tensor<1,dim,Number>::dimension;
-
-template <int rank, int dim, typename Number>
-const unsigned int Tensor<rank,dim,Number>::dimension;
-
-
-template <int dim, typename Number>
-void
-Tensor<1,dim,Number>::unroll (Vector<Number> &result) const
-{
- Assert (result.size()==dim,
- ExcDimensionMismatch(dim, result.size()));
-
- unsigned index = 0;
- unroll_recursion (result,index);
-}
-
-
-
-template <int rank_, int dim, typename Number>
-void
-Tensor<rank_, dim, Number>::unroll (Vector<Number> &result) const
-{
- Assert(result.size()==std::pow(static_cast<Number>(dim),rank_),
- ExcDimensionMismatch(static_cast<unsigned int>(std::pow(static_cast<Number>(dim),rank_)),
- result.size()));
-
- unsigned index = 0;
- unroll_recursion (result, index);
-}
-
-
-
-template <int rank_, int dim, typename Number>
-void
-Tensor<rank_, dim, Number>::unroll_recursion (Vector<Number> &result,
- unsigned int &index) const
-{
- for (unsigned i=0; i<dim; ++i)
- {
- operator[](i).unroll_recursion(result, index);
- }
-}
-
-
-
-template<int dim, typename Number>
-void
-Tensor<1,dim,Number>::unroll_recursion (Vector<Number> &result,
- unsigned int &index) const
-{
- for (unsigned i=0; i<dim; ++i)
- result(index++) = operator[](i);
-}
-
-
-template class Tensor<1, 1, double>;
-template class Tensor<1, 2, double>;
-template class Tensor<1, 3, double>;
-template class Tensor<2, 1, double>;
-template class Tensor<2, 2, double>;
-template class Tensor<2, 3, double>;
-template class Tensor<3, 1, double>;
-template class Tensor<3, 2, double>;
-template class Tensor<3, 3, double>;
-template class Tensor<4, 1, double>;
-template class Tensor<4, 2, double>;
-template class Tensor<4, 3, double>;
-
-DEAL_II_NAMESPACE_CLOSE