From da9d163d95c8e20f7719921d4c5c6ef62fe9f639 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sun, 12 Feb 2006 23:37:49 +0000 Subject: [PATCH] Extend ComponentSelect so that it can handle multiple nonzero components git-svn-id: https://svn.dealii.org/trunk@12339 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/function.h | 51 ++++++++++++++++++++-------- deal.II/base/source/function.cc | 38 +++++++++++++++------ deal.II/doc/news/changes.html | 26 ++++++++------ 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/deal.II/base/include/base/function.h b/deal.II/base/include/base/function.h index 64de7c90f1..9dead166ac 100644 --- a/deal.II/base/include/base/function.h +++ b/deal.II/base/include/base/function.h @@ -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 /** - * 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 - * VectorTools::integrate_difference, 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 VectorTools::integrate_difference, 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 class ComponentSelectFunction : public ConstantFunction { 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 */ 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 &selected, + const unsigned int n_components); /** * Return the value of the function @@ -654,9 +675,11 @@ class ComponentSelectFunction : public ConstantFunction protected: /** - * Index of the selected component. + * Half-open interval of the + * indices of selected + * components. */ - const unsigned int selected; + const std::pair selected_components; }; diff --git a/deal.II/base/source/function.cc b/deal.II/base/source/function.cc index 86ebdb96d7..ae2a58fbf3 100644 --- a/deal.II/base/source/function.cc +++ b/deal.II/base/source/function.cc @@ -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 (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 (1., n_components), - selected(selected) + selected_components(std::make_pair(selected,selected+1)) {} +template +ComponentSelectFunction:: +ComponentSelectFunction (const std::pair &selected, + const unsigned int n_components) + : + ConstantFunction (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 void ComponentSelectFunction::vector_value (const Point &, Vector &return_value) const @@ -433,8 +451,10 @@ void ComponentSelectFunction::vector_value (const Point &, 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::vector_value_list (const std::vectorn_components, - ExcDimensionMismatch(values[i].size(), this->n_components)); - std::fill (values[i].begin(), values[i].end(), 0.); - values[i](selected) = this->function_value; - } + ComponentSelectFunction::vector_value (points[i], + values[i]); } diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index 5af80a1e35..3d3895ccee 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -238,19 +238,25 @@ inconvenience this causes.

base

    +
  1. Improved: The ComponentSelect class can + now also handle the case that one wants to select multiple vector + components at once, not only a single one. +
    + (WB 2006/02/12) +

    -
  2. Improved: a new function TableBase::fill, filling the whole table with the same element has - been introduced. -
    - (GK 2006/01/18) -

    +
  3. Improved: A new function TableBase::fill, filling the whole table with the same + element has been introduced. +
    + (GK 2006/01/18) +

  4. Improved: DataOutBase now writes binary - files for OpenDX. -
    - (GK 2006/01/18) -

    + files for OpenDX. +
    + (GK 2006/01/18) +

  5. New: There are now functions -- 2.39.5