From: Martin Kronbichler Date: Fri, 2 Sep 2016 16:09:44 +0000 (+0200) Subject: Add assertion X-Git-Tag: v8.5.0-rc1~711^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c85367a1decadf8d68e000f04525c7f6ac307350;p=dealii.git Add assertion --- diff --git a/source/numerics/data_out_dof_data.cc b/source/numerics/data_out_dof_data.cc index 7253049b44..6f424b6ec2 100644 --- a/source/numerics/data_out_dof_data.cc +++ b/source/numerics/data_out_dof_data.cc @@ -1108,6 +1108,9 @@ add_data_vector Assert (data.size() == dof_handler.n_dofs(), ExcDimensionMismatch (data.size(), dof_handler.n_dofs())); + Assert (names.size() == dof_handler.get_fe().n_components(), + Exceptions::DataOut::ExcInvalidNumberOfNames (names.size(), + dof_handler.get_fe().n_components())); const std::vector & data_component_interpretation diff --git a/tests/numerics/data_out_11.cc b/tests/numerics/data_out_11.cc new file mode 100644 index 0000000000..fae2a58f98 --- /dev/null +++ b/tests/numerics/data_out_11.cc @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Check that DataOut::add_data_vector checks for consistent number of +// components in the names and in the finite element + + +#include "../tests.h" +#include + +#include +#include +#include +#include +#include +#include +#include + + + +void test() +{ + const int dim = 2; + Triangulation tria; + GridGenerator::hyper_cube(tria, -1, 1); + FESystem fe(FE_Q(1), dim+1); + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe); + Vector vec(dof_handler.n_dofs()); + vec = 1.; + + // "forget" to put a name on the last component -> should trigger assertion + std::vector names (dim, "u"); + + std::vector + component_interpretation + (dim, DataComponentInterpretation::component_is_part_of_vector); + + MappingQGeneric mapping(2); + + // variant 1 + { + DataOut data_out; + try + { + data_out.add_data_vector (dof_handler, vec, + names, component_interpretation); + data_out.build_patches(mapping, 2); + } + catch (ExceptionBase &exc) + { + deallog << exc.get_exc_name() << std::endl; + } + } + + // variant 2 + { + DataOut data_out; + data_out.attach_dof_handler(dof_handler); + try + { + data_out.add_data_vector (vec, names, DataOut::type_automatic, component_interpretation); + data_out.build_patches(mapping, 2); + } + catch (ExceptionBase &exc) + { + deallog << exc.get_exc_name() << std::endl; + } + } + + deallog << "OK" << std::endl; + +} + + +int main() +{ + deal_II_exceptions::disable_abort_on_exception(); + initlog(); + MultithreadInfo::set_thread_limit(1); + test(); + +} diff --git a/tests/numerics/data_out_11.debug.output b/tests/numerics/data_out_11.debug.output new file mode 100644 index 0000000000..471bff544c --- /dev/null +++ b/tests/numerics/data_out_11.debug.output @@ -0,0 +1,4 @@ + +DEAL::Exceptions::DataOut::ExcInvalidNumberOfNames (names.size(), dof_handler.get_fe().n_components()) +DEAL::Exceptions::DataOut::ExcInvalidNumberOfNames (names.size(), dofs->get_fe().n_components()) +DEAL::OK