]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Extractor in VectorFunction: made but not tested
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 10 Mar 1999 14:18:33 +0000 (14:18 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 10 Mar 1999 14:18:33 +0000 (14:18 +0000)
git-svn-id: https://svn.dealii.org/trunk@986 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/function_time.h
deal.II/base/include/base/job_identifier.h
deal.II/base/include/base/logstream.h
deal.II/base/include/base/parameter_handler.h
deal.II/base/include/base/smartpointer.h
deal.II/base/include/base/tensor.h
deal.II/base/include/base/tensor_base.h
deal.II/base/include/base/tensor_function.h
deal.II/base/include/base/tensorindex.h
deal.II/base/source/log.cc
deal.II/base/source/tensor_function.cc

index 21cb151f147dd03e669ec1e3a4817d72fb102855..a3c1d46abe7546a751ace678ba8673be4201c6af 100644 (file)
@@ -88,7 +88,7 @@ class FunctionTime {
     double time;
 };
 
-
+/*------------------------------ Inline functions ------------------------------*/
 
 inline double
 FunctionTime::get_time () const
index 4bd3e282ded820ea5f93254d941c38a42b678e7a..365961597507901cf51c7ba7bb56706df0b5b764 100644 (file)
@@ -24,6 +24,8 @@ private:
   string id;
 };
 
+/*------------------------------ Inline functions ------------------------------*/
+
 extern JobIdentifier dealjobid;
 
 #endif
index 9a70de5bf2595508287c3607d05b20b9bf0ebeec..28a64780770d87c7c3103a3a0e36fec1d9b94955 100644 (file)
@@ -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 <class T>
 inline void
 writestuff(LogStream& s, const T& t)
index f94dcd541c12a61041c120c4ef9314393bfb6fbc..6664741021103991f48bcbc65474176957aac9fd 100644 (file)
@@ -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 */
index 57bfd85444f50d407c0b0fb1aecf361913f2f6ca..62cb6171f68d4ea63c7eb5e0663e8935df8feb8a 100644 (file)
@@ -105,7 +105,7 @@ class SmartPointer
 
 
 
-/* --------------------------- Template functions ------------------------------*/
+/* --------------------------- inline Template functions ------------------------------*/
 
 
 template <typename T>
index 93ae01a7579f7c4736a15948ae504b874768067e..ba626965225d5fb528202d5dd6776b6c6ff2515e 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <base/tensor_base.h>
 
+template <int rank_, int dim> class Tensor;
 
 /**
  * Provide a general tensor class with an arbitrary rank, i.e. with
@@ -22,7 +23,8 @@
  * runtime-dependent dimension.
  */
 template <int rank_, int dim>
-class Tensor {
+class Tensor //<rank_, dim>
+{
   public:
                                     /**
                                      * Provide a way to get the
@@ -168,7 +170,7 @@ class Tensor {
                                     /**
                                      * Help function for unroll.
                                      */
-    void unroll_recursion(Vector<double> & result, unsigned& start_index) const;
+    void unroll_recursion(Vector<double> & result, unsigned int& start_index) const;
 
     template<>
     friend void Tensor<rank_+1,dim>::unroll_recursion(Vector<double> &, unsigned&) const;
index 2c20f2e45dd438a913f164dc4af5ef858b1860e0..53724c43c433b3da4c26d82022093c29d9894c65 100644 (file)
@@ -184,7 +184,7 @@ class Tensor<1,dim> {
                                      * Help function for unroll.
                                      */
     void unroll_recursion (Vector<double> & result,
-                          unsigned& start_index) const;
+                          unsigned int& start_index) const;
 
     template<>
     friend void Tensor<2,dim>::unroll_recursion(Vector<double> &,
@@ -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,
index 2acdd8122f0efe0d3ec0eb802256e1f1294371fb..36ef35f69db7e7e998f880b2540cf96e8323cc0e 100644 (file)
@@ -8,21 +8,31 @@
 
 #include <base/exceptions.h>
 #include <vector>
+#include <base/subscriptor.h>
+#include <base/smartpointer.h>
+#include <base/function.h>
 #include <base/point.h>
 #include <base/functiontime.h>
 #include <base/tensorindex.h>
 #include <base/forward-declarations.h>
 
 template <typename number> class Vector;
+template <int dim> class VectorFunction;
+template <int rank_, int dim> 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 <int dim>
-class VectorFunction :
-  public FunctionTime
+class VectorFunction //<dim>
+  :
+  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<dim>
+    {
+      public:
+                                        /**
+                                         * Constructor.
+                                         * The arguments are the #VectorFunction# to be
+                                         * accessed and the component index.
+                                         */
+       Extractor(const VectorFunction<dim>& f, unsigned int index);
 
+                                        /**
+                                         * Compute function value.
+                                         */
+       virtual double operator() (const Point<dim>& p) const;
+
+                                        /**
+                                         * Compute several values.
+                                         */
+       virtual void value_list (const vector<Point<dim> > &points,
+                                vector<double> &values) const;
+       
+
+                                        /**
+                                         * Compute derivative.
+                                         */
+       virtual Tensor<1,dim> gradient (const Point<dim>& p) const;
+
+                                        /**
+                                         * Compute several derivatives.
+                                         */
+       virtual void gradient_list (const vector<Point<dim> > &points,
+                                   vector<Tensor<1,dim> > &gradients) const;
+       
+      private:
+                                        /**
+                                         * Pointer to the #VectorFunction#.
+                                         */
+       const SmartPointer<VectorFunction<dim> > vectorfunction;
+       
+                                        /**
+                                         * Index in #VectorFunction#.
+                                         */
+       const unsigned int index;
+    };
+    
+      
                                     /**
                                      * Exception
                                      */
@@ -115,7 +178,8 @@ class VectorFunction :
  *  @author Guido Kanschat, 1999
  */
 template <int rank_, int dim>
-class TensorFunction :
+class TensorFunction //<rank_ , dim>
+  :
   public VectorFunction<dim>
 {
   public:
index b45d895765c762214be0d56e10dfd9a19df131f5..51ff5adff9d278a35a3309bb0d6e7d6f6c55b4f1 100644 (file)
@@ -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);  
 };
 
index 520acdd938ad4ce1434da79413312071afc0a427..fc7ad7b23e85574d2749cd195acda597aebd74cb 100644 (file)
@@ -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;
index f886a6694caa33e6fcaca340a93b398954f90c2f..c51dcd5439c54cea2f149fdbc754ad8b56b4f0ec 100644 (file)
@@ -29,14 +29,16 @@ VectorFunction<dim>::operator () (const Point<dim> &, unsigned) const
 }
 */
 
-template <int dim> void
+template <int dim>
+void
 VectorFunction<dim>::value (const Point<dim>  &, Vector<double> &) const
 {
   Assert (false, ExcPureFunctionCalled());
 }
 
 
-template <int dim> void
+template <int dim>
+void
 VectorFunction<dim>::value_list (const vector<Point<dim> > &,
                                 vector<Vector<double> > &) const
 {
@@ -44,13 +46,64 @@ VectorFunction<dim>::value_list (const vector<Point<dim> > &,
 }
 
 
-template <int dim> void
+template <int dim>
+void
 VectorFunction<dim>::gradient_list (const vector<Point<dim> > &,
                                    vector<vector<Tensor<1,dim> > > &) const
 {
   Assert (false, ExcPureFunctionCalled());
 }
 
+template <int dim>
+VectorFunction<dim>::Extractor::Extractor(const VectorFunction<dim>& f,
+                                         unsigned int index)
+               :
+               vectorfunction(f),
+               index(index)
+{}
+
+template <int dim>
+double
+VectorFunction<dim>::Extractor::operator() (const Point<dim>& p) const
+{
+  Vector<double> v(vectorfunction->n_components);
+  vectorfunction->value(p,v);
+  return v(index);
+}
+
+
+template <int dim>
+Tensor<1,dim>
+VectorFunction<dim>::Extractor::gradient (const Point<dim>&) const
+{
+  Assert(false, ExcNotImplemented());
+  return Tensor<1,dim>();
+}
+
+template <int dim>
+void
+VectorFunction<dim>::Extractor::value_list (const vector<Point<dim> > &points,
+                                           vector<double> &values) const
+{
+  vector<Vector<double> > v(values.size(),
+                           Vector<double>(vectorfunction->n_components));
+  vectorfunction->value_list(p,v);
+  for (unsigned int i=0 ; i<values.size() ; ++i)
+    values[i] = v[i](index);
+}
+
+
+template <int dim>
+void
+VectorFunction<dim>::Extractor::gradient_list (const vector<Point<dim> > &points,
+                                              vector<Tensor<1,dim> > &gradients) const
+{
+  vector<vector<Tensor<1,dim> > > v(values.size(),
+                           vector<Tensor<1,dim> >(vectorfunction->n_components));
+  vectorfunction->value_list(p,v);
+  for (unsigned int i=0 ; i<values.size() ; ++i)
+    values[i] = v[i][index];
+}
 
 //////////////////////////////////////////////////////////////////////
 // TensorFunction
@@ -105,8 +158,6 @@ TensorFunction<rank_, dim>::value_list (const vector<Point<dim> > &points,
 };
 
 
-
-
 template <int rank_, int dim>
 Tensor<rank_+1,dim>
 TensorFunction<rank_, dim>::gradient (const Point<dim> &) const
@@ -129,21 +180,14 @@ TensorFunction<rank_, dim>::gradient_list (const vector<Point<dim> > &points,
     gradients[i] = gradient(points[i]);
 };
 
-/*
+
 template <int rank_, int dim> void
-TensorFunction<rank_, dim>::value (const Point<dim>  &p, vector<double> &erg) const
+TensorFunction<rank_, dim>::value (const Point<dim>  &p,
+                                  Vector<double> &erg) const
 {
   Tensor<rank_,dim> h = operator()(p);
   h.unroll(erg);
 }
-*/
-
-
-template <int rank_, int dim> void
-TensorFunction<rank_, dim>::value (const Point<dim>  &, Vector<double> &) const
-{
-  Assert(false, ExcNotImplemented());
-}
 
 
 template <int rank_, int dim> void

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.