From: David Wells Date: Sat, 14 May 2016 19:34:06 +0000 (-0400) Subject: Add tests for twisted grid generator input. X-Git-Tag: v8.5.0-rc1~1033^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1db2c1313d41dbd6109a71528a82504117f4d48d;p=dealii.git Add tests for twisted grid generator input. These tests verify that the right exceptions are raised when input data would result in cells with negative measure. --- diff --git a/tests/grid/twisted_parallelepiped_01.cc b/tests/grid/twisted_parallelepiped_01.cc new file mode 100644 index 0000000000..a6ca2280f4 --- /dev/null +++ b/tests/grid/twisted_parallelepiped_01.cc @@ -0,0 +1,87 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * Verify that the correct exception (ExcInvalidInputOrientation) is thrown + * when this function is called for invalid input. + */ + +template +void check_parallelepiped (std::ofstream &logfile) +{ + // Data structure defining dim coordinates that make up a + // parallelepiped. + std_cxx11::array, dim> edges; + + switch (dim) + { + case 1: + edges[0][0] = -0.5; + break; + + case 2: + edges[0][1] = 0.5; + edges[1][0] = 0.5; + break; + + case 3: + edges[0][0] = 1.0; + edges[1][1] = 1.0; + edges[2][2] = -1.0; + break; + + default: + Assert (false, ExcInternalError ()); + } + + Point origin; + + Triangulation triangulation; + std::vector subdivisions; + + try + { + GridGenerator::subdivided_parallelepiped(triangulation, origin, edges, + subdivisions, false); + } + catch (ExceptionBase &exc) + { + logfile << exc.get_exc_name() << std::endl; + } +} + +int main () +{ + deal_II_exceptions::disable_abort_on_exception(); + std::ofstream logfile ("output"); + + check_parallelepiped<1>(logfile); + check_parallelepiped<2>(logfile); + check_parallelepiped<3>(logfile); + logfile << "OK" << std::endl; +} diff --git a/tests/grid/twisted_parallelepiped_01.debug.output b/tests/grid/twisted_parallelepiped_01.debug.output new file mode 100644 index 0000000000..3a8ca65a9d --- /dev/null +++ b/tests/grid/twisted_parallelepiped_01.debug.output @@ -0,0 +1,4 @@ +ExcInvalidInputOrientation ("The triangulation you are trying to create will consist of cells" " with negative measures. This is usually the result of input data" " that does not define a right-handed coordinate system. The usual" " fix for this is to ensure that in 1D the given point is to the" " right of the origin (or the given edge tensor is positive), in 2D" " that the two edges (and their cross product) obey the right-hand" " rule (which may usually be done by switching the order of the" " points or edge tensors), or in 3D that the edges form a" " right-handed coordinate system (which may also be accomplished by" " switching the order of the first two points or edge tensors).") +ExcInvalidInputOrientation ("The triangulation you are trying to create will consist of cells" " with negative measures. This is usually the result of input data" " that does not define a right-handed coordinate system. The usual" " fix for this is to ensure that in 1D the given point is to the" " right of the origin (or the given edge tensor is positive), in 2D" " that the two edges (and their cross product) obey the right-hand" " rule (which may usually be done by switching the order of the" " points or edge tensors), or in 3D that the edges form a" " right-handed coordinate system (which may also be accomplished by" " switching the order of the first two points or edge tensors).") +ExcInvalidInputOrientation ("The triangulation you are trying to create will consist of cells" " with negative measures. This is usually the result of input data" " that does not define a right-handed coordinate system. The usual" " fix for this is to ensure that in 1D the given point is to the" " right of the origin (or the given edge tensor is positive), in 2D" " that the two edges (and their cross product) obey the right-hand" " rule (which may usually be done by switching the order of the" " points or edge tensors), or in 3D that the edges form a" " right-handed coordinate system (which may also be accomplished by" " switching the order of the first two points or edge tensors).") +OK diff --git a/tests/grid/twisted_parallelepiped_02.cc b/tests/grid/twisted_parallelepiped_02.cc new file mode 100644 index 0000000000..c8a37f09c0 --- /dev/null +++ b/tests/grid/twisted_parallelepiped_02.cc @@ -0,0 +1,87 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * Verify that the correct exception (ExcGridHasInvalidCell) is thrown when + * this function is called for invalid input. + */ + +template +void check_parallelepiped (std::ofstream &logfile) +{ + // Data structure defining dim coordinates that make up a + // parallelepiped. + std_cxx11::array, dim> edges; + + switch (dim) + { + case 1: + edges[0][0] = -0.5; + break; + + case 2: + edges[0][1] = 0.5; + edges[1][0] = 0.5; + break; + + case 3: + edges[0][0] = 1.0; + edges[1][1] = 1.0; + edges[2][2] = -1.0; + break; + + default: + Assert (false, ExcInternalError ()); + } + + Point origin; + + Triangulation triangulation; + std::vector subdivisions; + + try + { + GridGenerator::subdivided_parallelepiped(triangulation, origin, edges, + subdivisions, false); + } + catch (ExceptionBase &exc) + { + logfile << exc.get_exc_name() << std::endl; + } +} + +int main () +{ + deal_II_exceptions::disable_abort_on_exception(); + std::ofstream logfile ("output"); + + check_parallelepiped<1>(logfile); + check_parallelepiped<2>(logfile); + check_parallelepiped<3>(logfile); + logfile << "OK" << std::endl; +} diff --git a/tests/grid/twisted_parallelepiped_02.release.output b/tests/grid/twisted_parallelepiped_02.release.output new file mode 100644 index 0000000000..b4453d8f8f --- /dev/null +++ b/tests/grid/twisted_parallelepiped_02.release.output @@ -0,0 +1,4 @@ +ExcGridHasInvalidCell(cell_no) +ExcGridHasInvalidCell(cell_no) +ExcGridHasInvalidCell(cell_no) +OK