From 67b0c2ad3290be8d03c08ff0f4e17c39abfbb139 Mon Sep 17 00:00:00 2001 From: bangerth Date: Fri, 15 Mar 2013 18:31:03 +0000 Subject: [PATCH] Allow default construction of FEValuesExtractor objects, but make sure they are then invalid when used. git-svn-id: https://svn.dealii.org/trunk@28915 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 12 ++- .../include/deal.II/fe/fe_values_extractors.h | 59 ++++++++++++- tests/deal.II/fe_values_view_invalid_01.cc | 86 +++++++++++++++++++ .../fe_values_view_invalid_01/cmp/generic | 4 + tests/deal.II/fe_values_view_invalid_02.cc | 86 +++++++++++++++++++ .../fe_values_view_invalid_02/cmp/generic | 4 + tests/deal.II/fe_values_view_invalid_03.cc | 86 +++++++++++++++++++ .../fe_values_view_invalid_03/cmp/generic | 4 + 8 files changed, 339 insertions(+), 2 deletions(-) create mode 100644 tests/deal.II/fe_values_view_invalid_01.cc create mode 100644 tests/deal.II/fe_values_view_invalid_01/cmp/generic create mode 100644 tests/deal.II/fe_values_view_invalid_02.cc create mode 100644 tests/deal.II/fe_values_view_invalid_02/cmp/generic create mode 100644 tests/deal.II/fe_values_view_invalid_03.cc create mode 100644 tests/deal.II/fe_values_view_invalid_03/cmp/generic diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 8de8ff65af..275a9b8629 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -67,7 +67,17 @@ inconvenience this causes.
    -
  1. Fixed: FETools::interpolation_difference with PETSc. +
  2. Changed: FEValuesExtractors::Scalar, FEValuesExtractors::Vector and +FEValuesExtractors::SymmetricTensor could not be default constructed, and +consequently one could not easily put them into arrays (where they would +be default constructed when changing the size, and later assigned useful +values). These classes can now be default constructed to invalid +values, but can of course not be used in any useful way. +
    +(Wolfgang Bangerth, 2013/03/15) + +
  3. Fixed: FETools::interpolation_difference did not work with PETSc. +This is now fixed.
    (Timo Heister, 2013/03/01) diff --git a/deal.II/include/deal.II/fe/fe_values_extractors.h b/deal.II/include/deal.II/fe/fe_values_extractors.h index c942224f51..5d85836b08 100644 --- a/deal.II/include/deal.II/fe/fe_values_extractors.h +++ b/deal.II/include/deal.II/fe/fe_values_extractors.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------- // $Id$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -57,6 +57,17 @@ namespace FEValuesExtractors */ unsigned int component; + /** + * Default constructor. Initialize the + * object with an invalid component. This leads to + * an object that can not be used, but it allows + * objects of this kind to be put into arrays that + * require a default constructor upon resizing the + * array, and then later assigning a suitable + * object to each element of the array. + */ + Scalar (); + /** * Constructor. Take the selected * vector component as argument. @@ -115,6 +126,17 @@ namespace FEValuesExtractors */ unsigned int first_vector_component; + /** + * Default constructor. Initialize the + * object with an invalid component. This leads to + * an object that can not be used, but it allows + * objects of this kind to be put into arrays that + * require a default constructor upon resizing the + * array, and then later assigning a suitable + * object to each element of the array. + */ + Vector (); + /** * Constructor. Take the first * component of the selected vector @@ -159,6 +181,17 @@ namespace FEValuesExtractors */ unsigned int first_tensor_component; + /** + * Default constructor. Initialize the + * object with an invalid component. This leads to + * an object that can not be used, but it allows + * objects of this kind to be put into arrays that + * require a default constructor upon resizing the + * array, and then later assigning a suitable + * object to each element of the array. + */ + SymmetricTensor (); + /** * Constructor. Take the first * component of the selected tensor @@ -174,6 +207,14 @@ namespace FEValuesExtractors namespace FEValuesExtractors { + inline + Scalar::Scalar () + : + component (numbers::invalid_unsigned_int) + {} + + + inline Scalar::Scalar (const unsigned int component) : @@ -182,12 +223,28 @@ namespace FEValuesExtractors + inline + Vector::Vector () + : + first_vector_component (numbers::invalid_unsigned_int) + {} + + inline Vector::Vector (const unsigned int first_vector_component) : first_vector_component (first_vector_component) {} + + template + inline + SymmetricTensor::SymmetricTensor () + : + first_tensor_component(numbers::invalid_unsigned_int) + {} + + template inline SymmetricTensor::SymmetricTensor (const unsigned int first_tensor_component) diff --git a/tests/deal.II/fe_values_view_invalid_01.cc b/tests/deal.II/fe_values_view_invalid_01.cc new file mode 100644 index 0000000000..1312249c9b --- /dev/null +++ b/tests/deal.II/fe_values_view_invalid_01.cc @@ -0,0 +1,86 @@ +//---------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2007, 2008, 2013 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------------------------------------------------- + + +// make sure FEValuesExtractors::Scalar can be default-constructed but that it +// produces an invalid, unusable object + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +#include + + + +template +void test (const Triangulation& tr, + const FiniteElement& fe) +{ + DoFHandler dof(tr); + dof.distribute_dofs(fe); + + const QGauss quadrature(2); + FEValues fe_values (fe, quadrature, + update_values); + fe_values.reinit (dof.begin_active()); + + FEValuesExtractors::Scalar extr; // invalid object + try + { + fe_values[extr]; // invalid access + } + catch (const std::exception &exc) + { + goto ok; + } + + Assert (false, ExcMessage ("No exception!?")); + + ok: + ; +} + + + +template +void test() +{ + Triangulation tr; + GridGenerator::hyper_cube(tr); + + FESystem fe (FE_Q(1), 1); + test(tr, fe); +} + + +int main() +{ + std::ofstream logfile ("fe_values_view_invalid_01/output"); + deallog << std::setprecision (2); + + deallog.attach(logfile); + deallog.depth_console (0); + deallog.threshold_double(1.e-7); + + deal_II_exceptions::disable_abort_on_exception(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/deal.II/fe_values_view_invalid_01/cmp/generic b/tests/deal.II/fe_values_view_invalid_01/cmp/generic new file mode 100644 index 0000000000..3c4aa75009 --- /dev/null +++ b/tests/deal.II/fe_values_view_invalid_01/cmp/generic @@ -0,0 +1,4 @@ + +DEAL::ExcIndexRange (scalar.component, 0, fe_values_views_cache.scalars.size()) +DEAL::ExcIndexRange (scalar.component, 0, fe_values_views_cache.scalars.size()) +DEAL::ExcIndexRange (scalar.component, 0, fe_values_views_cache.scalars.size()) diff --git a/tests/deal.II/fe_values_view_invalid_02.cc b/tests/deal.II/fe_values_view_invalid_02.cc new file mode 100644 index 0000000000..f5b8e980d9 --- /dev/null +++ b/tests/deal.II/fe_values_view_invalid_02.cc @@ -0,0 +1,86 @@ +//---------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2007, 2008, 2013 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------------------------------------------------- + + +// make sure FEValuesExtractors::Vector can be default-constructed but that it +// produces an invalid, unusable object + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +#include + + + +template +void test (const Triangulation& tr, + const FiniteElement& fe) +{ + DoFHandler dof(tr); + dof.distribute_dofs(fe); + + const QGauss quadrature(2); + FEValues fe_values (fe, quadrature, + update_values); + fe_values.reinit (dof.begin_active()); + + FEValuesExtractors::Vector extr; // invalid object + try + { + fe_values[extr]; // invalid access + } + catch (const std::exception &exc) + { + goto ok; + } + + Assert (false, ExcMessage ("No exception!?")); + + ok: + ; +} + + + +template +void test() +{ + Triangulation tr; + GridGenerator::hyper_cube(tr); + + FESystem fe (FE_Q(1), dim); + test(tr, fe); +} + + +int main() +{ + std::ofstream logfile ("fe_values_view_invalid_02/output"); + deallog << std::setprecision (2); + + deallog.attach(logfile); + deallog.depth_console (0); + deallog.threshold_double(1.e-7); + + deal_II_exceptions::disable_abort_on_exception(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/deal.II/fe_values_view_invalid_02/cmp/generic b/tests/deal.II/fe_values_view_invalid_02/cmp/generic new file mode 100644 index 0000000000..24f691b8e0 --- /dev/null +++ b/tests/deal.II/fe_values_view_invalid_02/cmp/generic @@ -0,0 +1,4 @@ + +DEAL::ExcIndexRange (vector.first_vector_component, 0, fe_values_views_cache.vectors.size()) +DEAL::ExcIndexRange (vector.first_vector_component, 0, fe_values_views_cache.vectors.size()) +DEAL::ExcIndexRange (vector.first_vector_component, 0, fe_values_views_cache.vectors.size()) diff --git a/tests/deal.II/fe_values_view_invalid_03.cc b/tests/deal.II/fe_values_view_invalid_03.cc new file mode 100644 index 0000000000..15057948aa --- /dev/null +++ b/tests/deal.II/fe_values_view_invalid_03.cc @@ -0,0 +1,86 @@ +//---------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2007, 2008, 2013 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------------------------------------------------- + + +// make sure FEValuesExtractors::SymmetricTensor can be default-constructed +// but that it produces an invalid, unusable object + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +#include + + + +template +void test (const Triangulation& tr, + const FiniteElement& fe) +{ + DoFHandler dof(tr); + dof.distribute_dofs(fe); + + const QGauss quadrature(2); + FEValues fe_values (fe, quadrature, + update_values); + fe_values.reinit (dof.begin_active()); + + FEValuesExtractors::SymmetricTensor<2> extr; // invalid object + try + { + fe_values[extr]; // invalid access + } + catch (const std::exception &exc) + { + goto ok; + } + + Assert (false, ExcMessage ("No exception!?")); + + ok: + ; +} + + + +template +void test() +{ + Triangulation tr; + GridGenerator::hyper_cube(tr); + + FESystem fe (FE_Q(1), dim*(dim+1)/2); + test(tr, fe); +} + + +int main() +{ + std::ofstream logfile ("fe_values_view_invalid_03/output"); + deallog << std::setprecision (2); + + deallog.attach(logfile); + deallog.depth_console (0); + deallog.threshold_double(1.e-7); + + deal_II_exceptions::disable_abort_on_exception(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/deal.II/fe_values_view_invalid_03/cmp/generic b/tests/deal.II/fe_values_view_invalid_03/cmp/generic new file mode 100644 index 0000000000..7eb3843a0a --- /dev/null +++ b/tests/deal.II/fe_values_view_invalid_03/cmp/generic @@ -0,0 +1,4 @@ + +DEAL::ExcIndexRange (tensor.first_tensor_component, 0, fe_values_views_cache.symmetric_second_order_tensors.size()) +DEAL::ExcIndexRange (tensor.first_tensor_component, 0, fe_values_views_cache.symmetric_second_order_tensors.size()) +DEAL::ExcIndexRange (tensor.first_tensor_component, 0, fe_values_views_cache.symmetric_second_order_tensors.size()) -- 2.39.5