]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add assertion 3055/head
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 2 Sep 2016 16:09:44 +0000 (18:09 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 2 Sep 2016 16:20:42 +0000 (18:20 +0200)
source/numerics/data_out_dof_data.cc
tests/numerics/data_out_11.cc [new file with mode: 0644]
tests/numerics/data_out_11.debug.output [new file with mode: 0644]

index 7253049b44f6e984a419a3c759d7fc4f5980efdd..6f424b6ec21f60b43aea6ffe1a90f8eabd52119d 100644 (file)
@@ -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<DataComponentInterpretation::DataComponentInterpretation> &
   data_component_interpretation
diff --git a/tests/numerics/data_out_11.cc b/tests/numerics/data_out_11.cc
new file mode 100644 (file)
index 0000000..fae2a58
--- /dev/null
@@ -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 <deal.II/numerics/data_out.h>
+
+#include <deal.II/lac/vector.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/fe/fe_system.h>
+#include <deal.II/fe/mapping_q_generic.h>
+
+
+
+void test()
+{
+  const int dim = 2;
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria, -1, 1);
+  FESystem<dim> fe(FE_Q<dim>(1), dim+1);
+  DoFHandler<dim> dof_handler(tria);
+  dof_handler.distribute_dofs(fe);
+  Vector<double> vec(dof_handler.n_dofs());
+  vec = 1.;
+
+  // "forget" to put a name on the last component -> should trigger assertion
+  std::vector<std::string> names (dim, "u");
+
+  std::vector<DataComponentInterpretation::DataComponentInterpretation>
+  component_interpretation
+  (dim, DataComponentInterpretation::component_is_part_of_vector);
+
+  MappingQGeneric<dim> mapping(2);
+
+  // variant 1
+  {
+    DataOut<dim> 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<dim> data_out;
+    data_out.attach_dof_handler(dof_handler);
+    try
+      {
+        data_out.add_data_vector (vec, names, DataOut<dim>::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 (file)
index 0000000..471bff5
--- /dev/null
@@ -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

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.