From: guido Date: Fri, 5 Feb 1999 19:54:26 +0000 (+0000) Subject: the way to TensorFunction X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d4f4f5fd6a776f8f5b28412c56fd4fcb4a9eff8;p=dealii-svn.git the way to TensorFunction git-svn-id: https://svn.dealii.org/trunk@765 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index 3806731eb5..d9a394bce6 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -1,5 +1,5 @@ /*---------------------------- tensor.h ---------------------------*/ -/* $Id$ */ +/* $Id$ */ #ifndef __tensor_H #define __tensor_H /*---------------------------- tensor.h ---------------------------*/ diff --git a/deal.II/base/include/base/tensor_function.h b/deal.II/base/include/base/tensor_function.h new file mode 100644 index 0000000000..b69eb82e1e --- /dev/null +++ b/deal.II/base/include/base/tensor_function.h @@ -0,0 +1,118 @@ +/*---------------------------- tensorfunction.h ---------------------------*/ +/* $Id$ */ +/* Copyright G. Kanschat, University of Heidelberg, 1999 */ +#ifndef __tensorfunction_H +#define __tensorfunction_H +/*---------------------------- tensorfunction.h ---------------------------*/ + + +#include +#include +#include +#include +#include + + +template +class Tensor; + +/** + * This class is a model for a tensor valued function. + * It returns the value + * at a given point through the #operator ()# member functions, + * which are virtual. It also has a function to return a whole list of + * values at different points to reduce the overhead of the virtual function + * calls; this function is preset to successively call the function returning + * one value at a time. + * + * There are other functions return the gradient of the function at one or + * several points. You only have to overload those functions you need; the + * functions returning several values at a time will call those returning + * only one value, while those ones will throw an exception when called but + * not overloaded. + * + * Usually, efficiency of your program increases if you overload the + * complex virtual functions, too. + * + * @author Guido Kanschat, 1999 + */ +template +class TensorFunction : + public FunctionTime +{ + public: + /** + * Constructor. May take an initial vakue + * for the time variable, which defaults + * to zero. + */ + TensorFunction (const double initial_time = 0.0); + + /** + * Virtual destructor; absolutely + * necessary in this case. + */ + virtual ~TensorFunction (); + + /** + * Return the value of the function + * at the given point. + */ + virtual Tensor operator () (const Point &p) const; + + /** + * Set #values# to the point values + * of the function at the #points#. + * It is assumed that #values# + * already has the right size, i.e. + * the same size as the #points# + * array. + */ + virtual void value_list (const vector > &points, + vector > &values) const; + + /** + * Return one component of the value. + */ + virtual double operator() (TensorIndex i, const Point& p) const; + + + /** + * Return the gradient of the function + * at the given point. + */ + virtual Tensor gradient (const Point &p) const; + + /** + * Set #gradients# to the gradients of + * the function at the #points#. + * It is assumed that #values# + * already has the right size, i.e. + * the same size as the #points# array. + */ + virtual void gradient_list (const vector > &points, + vector > &gradients) const; + + /** + * Exception + */ + DeclException0 (ExcPureFunctionCalled); + /** + * Exception + */ + DeclException2 (ExcVectorHasWrongSize, + int, int, + << "The vector has size " << arg1 << " but should have " + << arg2 << " elements."); + +}; + + + + + + +/*---------------------------- tensorfunction.h ---------------------------*/ +/* end of #ifndef __tensorfunction_H */ +#endif +/*---------------------------- tensorfunction.h ---------------------------*/ diff --git a/deal.II/base/include/base/tensorindex.h b/deal.II/base/include/base/tensorindex.h new file mode 100644 index 0000000000..b45d895765 --- /dev/null +++ b/deal.II/base/include/base/tensorindex.h @@ -0,0 +1,203 @@ +/*---------------------------- tensorindex.h ---------------------------*/ +/* $Id$ */ +#ifndef __tensorindex_H +#define __tensorindex_H +/*---------------------------- tensorindex.h ---------------------------*/ + +#include + +/** + * + * Rank-independent access to elements of #Tensor#. A little class + * template remembering #rank# integers. + * + * This template is implemented only for ranks between 1 and 4. If you + * really need higher ranks, please modify the source code accordingly + * or contact the developer. + * + * @author Guido Kanschat, 1999 + * + */ +template +class TensorIndex +{ +private: + /** + * Field of indices. + */ + unsigned index[rank]; +public: + /** + * Constructor taking #rank# indices. + */ + TensorIndex(...); + + /** + * + * Access operator returning index + * in #n#th component + * + */ + unsigned operator () (unsigned n) const; + DeclException1(ExcRank, unsigned, + << "Index " << arg1 << " higher than maximum " << rank-1); +}; + + +template<> +class TensorIndex<4> +{ +private: + /** + * Field of indices. + */ + unsigned index[4]; +public: + /** + * Constructor taking #rank# indices. + */ + TensorIndex(unsigned i0, unsigned i1, unsigned i2, unsigned i3) + { + index[0] = i0; + index[1] = i1; + index[2] = i2; + index[3] = i3; + } + + + /** + * + * Access operator returning index + * in #n#th component + * + */ + unsigned int operator () (unsigned int n) const + { + Assert(n<4, ExcRank(n)); + return index[n]; + + } + DeclException1(ExcRank, unsigned, + << "Index " << arg1 << " higher than maximum 3"); +}; + +template<> +class TensorIndex<3> +{ +private: + /** + * Field of indices. + */ + unsigned index[3]; +public: + /** + * Constructor taking #rank# indices. + */ + TensorIndex(unsigned i0, unsigned i1, unsigned i2) + { + index[0] = i0; + index[1] = i1; + index[2] = i2; + } + + + /** + * + * Access operator returning index + * in #n#th component + * + */ + unsigned operator () (unsigned n) const + { + Assert(n<3, ExcRank(n)); + return index[n]; + + } + + DeclException1(ExcRank, unsigned, + << "Index " << arg1 << " higher than maximum 2"); +}; + +template<> +class TensorIndex<2> +{ +private: + /** + * Field of indices. + */ + unsigned index[4]; +public: + /** + * Constructor taking #rank# indices. + */ + TensorIndex(unsigned i0, unsigned i1) + { + index[0] = i0; + index[1] = i1; + } + + + /** + * + * Access operator returning index + * in #n#th component + * + */ + unsigned operator () (unsigned n) const + { + Assert(n<2, ExcRank(n)); + return index[n]; + + } + DeclException1(ExcRank, unsigned, + << "Index " << arg1 << " higher than maximum 1"); +}; + +template<> +class TensorIndex<1> +{ +private: + /** + * Field of indices. + */ + unsigned index[1]; +public: + /** + * Constructor taking #rank# indices. + */ + TensorIndex(unsigned i0) + { + index[0] = i0; + } + + + /** + * + * Access operator returning index + * in #n#th component + * + */ + unsigned operator () (unsigned n) const + { + Assert(n<1, ExcRank(n)); + return index[n]; + + } + DeclException1(ExcRank, unsigned, + << "Index " << arg1 << " higher than maximum 0"); +}; + +template +inline unsigned +TensorIndex::operator() (unsigned n) const +{ + Assert(n +#include +#include + + +template +TensorFunction::TensorFunction (const double initial_time) : + FunctionTime(initial_time) +{}; + + + +template +TensorFunction::~TensorFunction () +{}; + + + +template +double +TensorFunction::operator () (TensorIndex i, + const Point &) const +{ + int k=i(0); + k++; + + Assert (false, ExcPureFunctionCalled()); + return 0; +}; + + + +template +void +TensorFunction::value_list (const vector > &points, + vector > &values) const +{ + Assert (values.size() == points.size(), + ExcVectorHasWrongSize(values.size(), points.size())); + + for (unsigned int i=0; ioperator() (points[i]); +}; + + + + +template +Tensor +TensorFunction::gradient (const Point &) const +{ + Assert (false, ExcPureFunctionCalled()); + return Tensor(); +}; + + + +template +void +TensorFunction::gradient_list (const vector > &points, + vector > &gradients) const +{ + Assert (gradients.size() == points.size(), + ExcVectorHasWrongSize(gradients.size(), points.size())); + + for (unsigned int i=0; i; +template class TensorFunction<2,1>; +template class TensorFunction<3,1>; +template class TensorFunction<4,1>; +template class TensorFunction<1,2>; +template class TensorFunction<2,2>; +template class TensorFunction<3,2>; +template class TensorFunction<4,2>; +template class TensorFunction<1,3>; +template class TensorFunction<2,3>; +template class TensorFunction<3,3>; +template class TensorFunction<4,3>;