]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Extend ComponentSelect so that it can handle multiple nonzero components
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 12 Feb 2006 23:37:49 +0000 (23:37 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 12 Feb 2006 23:37:49 +0000 (23:37 +0000)
git-svn-id: https://svn.dealii.org/trunk@12339 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/function.h
deal.II/base/source/function.cc
deal.II/doc/news/changes.html

index 64de7c90f1ab7abb2286724cc62b28fc06fc972f..9dead166ac10e11d9c966e7add6ac885c367c13f 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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
@@ -580,25 +580,29 @@ class ConstantFunction : public ZeroFunction<dim>
 
 
 /**
- * This is a constant vector-valued function, that is different from
- * zero only in one component.
- *
- * It is especially useful as a weight function for
- * <tt>VectorTools::integrate_difference</tt>, where it allows to integrate
- * only one component.
+ * This is a constant vector-valued function, in which one or more
+ * components of the vector have a constant value and all other
+ * components are zero.  It is especially useful as a weight function
+ * for <tt>VectorTools::integrate_difference</tt>, where it allows to
+ * integrate only one or a few vector components, rather than the
+ * entire vector-valued solution. See the @ref step_20 "step-20"
+ * tutorial program for a detailed explanation.
  *
  * @ingroup functions
- * @author Guido Kanschat, 2000
+ * @author Guido Kanschat, 2000, Wolfgang Bangerth 2006
  */
 template <int dim>
 class ComponentSelectFunction : public ConstantFunction<dim>
 {
   public:
                                     /**
-                                     * Constructor. Arguments denote
-                                     * the component selected, the
-                                     * value for that component and
-                                     * the total number of components.
+                                     * Constructor if only a single
+                                     * component shall be
+                                     * non-zero. Arguments denote the
+                                     * component selected, the value
+                                     * for that component and the
+                                     * total number of vector
+                                     * components.
                                      */
     ComponentSelectFunction (const unsigned int selected,
                             const double       value,
@@ -613,6 +617,23 @@ class ComponentSelectFunction : public ConstantFunction<dim>
                                      */
     ComponentSelectFunction (const unsigned int selected,
                             const unsigned int n_components);
+
+                                     /**
+                                     * Constructor if multiple
+                                     * components shall have
+                                     * non-zero, unit values
+                                     * (i.e. this should be a mask
+                                     * for multiple components). The
+                                     * first argument denotes a
+                                     * half-open interval of
+                                     * components (for example
+                                     * std::pair(0,dim) for the first
+                                     * dim components), and the
+                                     * second argument is the total
+                                     * number of vector components.
+                                     */
+    ComponentSelectFunction (const std::pair<unsigned int, unsigned int> &selected,
+                            const unsigned int n_components);    
     
                                     /**
                                      * Return the value of the function
@@ -654,9 +675,11 @@ class ComponentSelectFunction : public ConstantFunction<dim>
 
   protected:
                                     /**
-                                     * Index of the selected component.
+                                     * Half-open interval of the
+                                     * indices of selected
+                                     * components.
                                      */
-    const unsigned int selected;
+    const std::pair<unsigned int,unsigned int> selected_components;
 };
 
 
index 86ebdb96d725203278c86b61f13475b93332fa38..ae2a58fbf3103b92485eb998d7980f2ac8991ce9 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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
@@ -410,7 +410,7 @@ ComponentSelectFunction (const unsigned int selected,
                          const unsigned int n_components)
                :
                ConstantFunction<dim> (value, n_components),
-                selected(selected)
+                selected_components(std::make_pair(selected,selected+1))
 {}
 
 
@@ -421,11 +421,29 @@ ComponentSelectFunction (const unsigned int selected,
                          const unsigned int n_components)
                :
                ConstantFunction<dim> (1., n_components),
-                selected(selected)
+                selected_components(std::make_pair(selected,selected+1))
 {}
 
 
 
+template <int dim>
+ComponentSelectFunction<dim>::
+ComponentSelectFunction (const std::pair<unsigned int,unsigned int> &selected,
+                         const unsigned int n_components)
+               :
+               ConstantFunction<dim> (1., n_components),
+                selected_components(selected)
+{
+  Assert (selected_components.first < selected_components.second,
+          ExcMessage ("The upper bound of the interval must be larger than "
+                      "the lower bound"));
+  Assert (selected_components.second <= n_components,
+          ExcMessage ("The upper bound of the interval must be less than "
+                      "or equal to the total number of vector components"));
+}
+
+
+
 template <int dim>
 void ComponentSelectFunction<dim>::vector_value (const Point<dim> &,
                                                 Vector<double>   &return_value) const
@@ -433,8 +451,10 @@ void ComponentSelectFunction<dim>::vector_value (const Point<dim> &,
   Assert (return_value.size() == this->n_components,
          ExcDimensionMismatch (return_value.size(), this->n_components));
 
-  std::fill (return_value.begin(), return_value.end(), 0.);
-  return_value(selected) = this->function_value;
+  return_value = 0;
+  std::fill (return_value.begin()+selected_components.first,
+             return_value.begin()+selected_components.second,
+             this->function_value);
 }
 
 
@@ -447,12 +467,8 @@ void ComponentSelectFunction<dim>::vector_value_list (const std::vector<Point<di
          ExcDimensionMismatch(values.size(), points.size()));
 
   for (unsigned int i=0; i<points.size(); ++i)
-    {
-      Assert (values[i].size() == this->n_components,
-             ExcDimensionMismatch(values[i].size(), this->n_components));
-      std::fill (values[i].begin(), values[i].end(), 0.);
-      values[i](selected) = this->function_value;
-    }
+    ComponentSelectFunction<dim>::vector_value (points[i],
+                                                values[i]);
 }
 
 
index 5af80a1e35e68bcdfb474b618ad7b09a9d8523f0..3d3895cceeee1066ebb42fe5b4d6bc5a93e85507 100644 (file)
@@ -238,19 +238,25 @@ inconvenience this causes.
 <h3>base</h3>
 
 <ol>
+  <li> <p>Improved: The <code class="class">ComponentSelect</code> class can
+       now also handle the case that one wants to select multiple vector
+       components at once, not only a single one.
+       <br>
+       (WB 2006/02/12)
+       </p>
 
-  <li> <p>Improved: a new function <code class="class">TableBase</code>::<code
-  class="member">fill</code>, filling the whole table with the same element has
-  been introduced.
-  <br>
-  (GK 2006/01/18)
-  </p>
+  <li> <p>Improved: A new function <code class="class">TableBase</code>::<code
+       class="member">fill</code>, filling the whole table with the same
+       element has been introduced.
+       <br>
+       (GK 2006/01/18)
+       </p>
 
   <li> <p>Improved: <code class="class">DataOutBase</code> now writes binary
-  files for OpenDX.
-  <br>
-  (GK 2006/01/18)
-  </p>
+       files for OpenDX.
+       <br>
+       (GK 2006/01/18)
+       </p>
 
   <li> <p>
        New: There are now functions

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.