From dca8eba171d40dfe74bcd2c5e3781432aef8ca13 Mon Sep 17 00:00:00 2001 From: guido Date: Wed, 10 Mar 1999 14:18:33 +0000 Subject: [PATCH] Extractor in VectorFunction: made but not tested git-svn-id: https://svn.dealii.org/trunk@986 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/function_time.h | 2 +- deal.II/base/include/base/job_identifier.h | 2 + deal.II/base/include/base/logstream.h | 42 ++++++---- deal.II/base/include/base/parameter_handler.h | 12 ++- deal.II/base/include/base/smartpointer.h | 2 +- deal.II/base/include/base/tensor.h | 6 +- deal.II/base/include/base/tensor_base.h | 4 +- deal.II/base/include/base/tensor_function.h | 76 +++++++++++++++++-- deal.II/base/include/base/tensorindex.h | 6 +- deal.II/base/source/log.cc | 14 ++-- deal.II/base/source/tensor_function.cc | 74 ++++++++++++++---- 11 files changed, 187 insertions(+), 53 deletions(-) diff --git a/deal.II/base/include/base/function_time.h b/deal.II/base/include/base/function_time.h index 21cb151f14..a3c1d46abe 100644 --- a/deal.II/base/include/base/function_time.h +++ b/deal.II/base/include/base/function_time.h @@ -88,7 +88,7 @@ class FunctionTime { double time; }; - +/*------------------------------ Inline functions ------------------------------*/ inline double FunctionTime::get_time () const diff --git a/deal.II/base/include/base/job_identifier.h b/deal.II/base/include/base/job_identifier.h index 4bd3e282de..3659615975 100644 --- a/deal.II/base/include/base/job_identifier.h +++ b/deal.II/base/include/base/job_identifier.h @@ -24,6 +24,8 @@ private: string id; }; +/*------------------------------ Inline functions ------------------------------*/ + extern JobIdentifier dealjobid; #endif diff --git a/deal.II/base/include/base/logstream.h b/deal.II/base/include/base/logstream.h index 9a70de5bf2..28a6478077 100644 --- a/deal.II/base/include/base/logstream.h +++ b/deal.II/base/include/base/logstream.h @@ -67,7 +67,8 @@ class LogStream ostream *file; bool was_endl; - unsigned int std_depth, file_depth; + unsigned int std_depth; + unsigned int file_depth; public: /** @@ -101,16 +102,7 @@ class LogStream * colon and there is a double * colon after the last prefix. */ - void push (const string& text) { - // strange enough: if make this - // function non-inline with - // gcc2.8, we get very strange - // compiler errors... - string pre=prefixes.top(); - pre += text; - pre += string(":"); - prefixes.push(pre); - } + void push (const string& text); /** * Remove the last prefix. @@ -164,7 +156,7 @@ class LogStream * tells the #LogStream# that the end of * the line is reached. */ - LogStream & operator << (void (*f)(LogStream &)); + LogStream & operator << (void (f)(LogStream &)); /** * Declare this function as a friend. @@ -178,10 +170,7 @@ class LogStream * Remove this function at the first * possible time. */ - ostream & get_std_stream () { - return *std; - }; - + ostream & get_std_stream (); }; @@ -190,6 +179,27 @@ class LogStream /* ----------------------------- Inline functions and templates ---------------- */ +inline +void +LogStream::push (const string& text) +{ + // strange enough: if make this + // function non-inline with + // gcc2.8, we get very strange + // compiler errors... + string pre=prefixes.top(); + pre += text; + pre += string(":"); + prefixes.push(pre); +} + +inline +ostream & +LogStream::get_std_stream () +{ + return *std; +} + template inline void writestuff(LogStream& s, const T& t) diff --git a/deal.II/base/include/base/parameter_handler.h b/deal.II/base/include/base/parameter_handler.h index f94dcd541c..6664741021 100644 --- a/deal.II/base/include/base/parameter_handler.h +++ b/deal.II/base/include/base/parameter_handler.h @@ -572,7 +572,8 @@ struct Patterns { * @author Wolfgang Bangerth, October 1997, revised February 1998 * @see MultipleParameterLoop */ -class ParameterHandler { +class ParameterHandler +{ public: /** * Constructor. @@ -616,7 +617,7 @@ class ParameterHandler { * Return status of this object: * #true#=clean or #false#=error occured. */ - bool ok() const { return status; }; + bool ok() const; /** * clear status bit and contents. @@ -1212,7 +1213,14 @@ class MultipleParameterLoop : public ParameterHandler { }; +/*------------------------------ Inline functions ------------------------------*/ +inline +bool +ParameterHandler::ok() const +{ + return status; +} /********************** parameter-handler.h ****************************/ /* end of #ifndef __parameter_handler_H */ diff --git a/deal.II/base/include/base/smartpointer.h b/deal.II/base/include/base/smartpointer.h index 57bfd85444..62cb6171f6 100644 --- a/deal.II/base/include/base/smartpointer.h +++ b/deal.II/base/include/base/smartpointer.h @@ -105,7 +105,7 @@ class SmartPointer -/* --------------------------- Template functions ------------------------------*/ +/* --------------------------- inline Template functions ------------------------------*/ template diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index 93ae01a757..ba62696522 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -7,6 +7,7 @@ #include +template class Tensor; /** * Provide a general tensor class with an arbitrary rank, i.e. with @@ -22,7 +23,8 @@ * runtime-dependent dimension. */ template -class Tensor { +class Tensor // +{ public: /** * Provide a way to get the @@ -168,7 +170,7 @@ class Tensor { /** * Help function for unroll. */ - void unroll_recursion(Vector & result, unsigned& start_index) const; + void unroll_recursion(Vector & result, unsigned int& start_index) const; template<> friend void Tensor::unroll_recursion(Vector &, unsigned&) const; diff --git a/deal.II/base/include/base/tensor_base.h b/deal.II/base/include/base/tensor_base.h index 2c20f2e45d..53724c43c4 100644 --- a/deal.II/base/include/base/tensor_base.h +++ b/deal.II/base/include/base/tensor_base.h @@ -184,7 +184,7 @@ class Tensor<1,dim> { * Help function for unroll. */ void unroll_recursion (Vector & result, - unsigned& start_index) const; + unsigned int& start_index) const; template<> friend void Tensor<2,dim>::unroll_recursion(Vector &, @@ -194,7 +194,7 @@ class Tensor<1,dim> { /** * Exception */ -DeclException2(ExcWrongVectorSize, unsigned, int, << "Tensor has " << arg1 +DeclException2(ExcWrongVectorSize, int, int, << "Tensor has " << arg1 << " entries, but vector has size " << arg2); DeclException1 (ExcDimTooSmall, int, diff --git a/deal.II/base/include/base/tensor_function.h b/deal.II/base/include/base/tensor_function.h index 2acdd8122f..36ef35f69d 100644 --- a/deal.II/base/include/base/tensor_function.h +++ b/deal.II/base/include/base/tensor_function.h @@ -8,21 +8,31 @@ #include #include +#include +#include +#include #include #include #include #include template class Vector; +template class VectorFunction; +template class TensorFunction; /** * Base class for multi-valued functions. - * - * + * While #TensorFunction# provides a highly structured class for multi-valued + * functions, #VectorFunction# is on a lower level. The results are #Vectors# of + * values without further structure. The dimension of the result is determined at + * execution time. + * @author Guido Kanschat, 1999 */ template -class VectorFunction : - public FunctionTime +class VectorFunction // + : + public FunctionTime, + public Subscriptor { public: /** @@ -78,8 +88,61 @@ class VectorFunction : /** * Number of vector components. */ - const unsigned n_components; + const unsigned int n_components; + + /** + * Access #VectorFunction# as a #Function#. + * This class allows to store a reference to a + * #VectorFunction# and an #index#. Later on, it + * can be used as a normal single valued #Function#. + */ + class Extractor + : public Function + { + public: + /** + * Constructor. + * The arguments are the #VectorFunction# to be + * accessed and the component index. + */ + Extractor(const VectorFunction& f, unsigned int index); + /** + * Compute function value. + */ + virtual double operator() (const Point& p) const; + + /** + * Compute several values. + */ + virtual void value_list (const vector > &points, + vector &values) const; + + + /** + * Compute derivative. + */ + virtual Tensor<1,dim> gradient (const Point& p) const; + + /** + * Compute several derivatives. + */ + virtual void gradient_list (const vector > &points, + vector > &gradients) const; + + private: + /** + * Pointer to the #VectorFunction#. + */ + const SmartPointer > vectorfunction; + + /** + * Index in #VectorFunction#. + */ + const unsigned int index; + }; + + /** * Exception */ @@ -115,7 +178,8 @@ class VectorFunction : * @author Guido Kanschat, 1999 */ template -class TensorFunction : +class TensorFunction // + : public VectorFunction { public: diff --git a/deal.II/base/include/base/tensorindex.h b/deal.II/base/include/base/tensorindex.h index b45d895765..51ff5adff9 100644 --- a/deal.II/base/include/base/tensorindex.h +++ b/deal.II/base/include/base/tensorindex.h @@ -25,7 +25,7 @@ private: /** * Field of indices. */ - unsigned index[rank]; + unsigned int index[rank]; public: /** * Constructor taking #rank# indices. @@ -38,8 +38,8 @@ public: * in #n#th component * */ - unsigned operator () (unsigned n) const; - DeclException1(ExcRank, unsigned, + unsigned int operator () (unsigned int n) const; + DeclException1(ExcRank, int, << "Index " << arg1 << " higher than maximum " << rank-1); }; diff --git a/deal.II/base/source/log.cc b/deal.II/base/source/log.cc index 520acdd938..fc7ad7b23e 100644 --- a/deal.II/base/source/log.cc +++ b/deal.II/base/source/log.cc @@ -28,25 +28,29 @@ LogStream::attach(ostream& o) -void LogStream::detach () { +void LogStream::detach () +{ file = 0; }; -void LogStream::pop () { +void LogStream::pop () +{ prefixes.pop(); }; -void LogStream::depth_console(unsigned n) { +void LogStream::depth_console(unsigned n) +{ std_depth = n; }; -void LogStream::depth_file(unsigned n) { +void LogStream::depth_file(unsigned n) +{ file_depth = n; }; @@ -67,7 +71,7 @@ LogStream& LogStream::operator << (const char* c) LogStream& -LogStream::operator << (void (*f)(LogStream &)) +LogStream::operator << (void (f)(LogStream &)) { f(*this); return *this; diff --git a/deal.II/base/source/tensor_function.cc b/deal.II/base/source/tensor_function.cc index f886a6694c..c51dcd5439 100644 --- a/deal.II/base/source/tensor_function.cc +++ b/deal.II/base/source/tensor_function.cc @@ -29,14 +29,16 @@ VectorFunction::operator () (const Point &, unsigned) const } */ -template void +template +void VectorFunction::value (const Point &, Vector &) const { Assert (false, ExcPureFunctionCalled()); } -template void +template +void VectorFunction::value_list (const vector > &, vector > &) const { @@ -44,13 +46,64 @@ VectorFunction::value_list (const vector > &, } -template void +template +void VectorFunction::gradient_list (const vector > &, vector > > &) const { Assert (false, ExcPureFunctionCalled()); } +template +VectorFunction::Extractor::Extractor(const VectorFunction& f, + unsigned int index) + : + vectorfunction(f), + index(index) +{} + +template +double +VectorFunction::Extractor::operator() (const Point& p) const +{ + Vector v(vectorfunction->n_components); + vectorfunction->value(p,v); + return v(index); +} + + +template +Tensor<1,dim> +VectorFunction::Extractor::gradient (const Point&) const +{ + Assert(false, ExcNotImplemented()); + return Tensor<1,dim>(); +} + +template +void +VectorFunction::Extractor::value_list (const vector > &points, + vector &values) const +{ + vector > v(values.size(), + Vector(vectorfunction->n_components)); + vectorfunction->value_list(p,v); + for (unsigned int i=0 ; i +void +VectorFunction::Extractor::gradient_list (const vector > &points, + vector > &gradients) const +{ + vector > > v(values.size(), + vector >(vectorfunction->n_components)); + vectorfunction->value_list(p,v); + for (unsigned int i=0 ; i::value_list (const vector > &points, }; - - template Tensor TensorFunction::gradient (const Point &) const @@ -129,21 +180,14 @@ TensorFunction::gradient_list (const vector > &points, gradients[i] = gradient(points[i]); }; -/* + template void -TensorFunction::value (const Point &p, vector &erg) const +TensorFunction::value (const Point &p, + Vector &erg) const { Tensor h = operator()(p); h.unroll(erg); } -*/ - - -template void -TensorFunction::value (const Point &, Vector &) const -{ - Assert(false, ExcNotImplemented()); -} template void -- 2.39.5