From cc73e5a26a4a04823b235f3380f2361da1f2bcf4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 3 Apr 2020 22:01:07 -0600 Subject: [PATCH] Add a test for complex-valued tensors. --- tests/data_out/data_out_complex_05_tensor.cc | 122 ++++++++++++++++++ .../data_out_complex_05_tensor.output | 81 ++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 tests/data_out/data_out_complex_05_tensor.cc create mode 100644 tests/data_out/data_out_complex_05_tensor.output diff --git a/tests/data_out/data_out_complex_05_tensor.cc b/tests/data_out/data_out_complex_05_tensor.cc new file mode 100644 index 0000000000..6172961f36 --- /dev/null +++ b/tests/data_out/data_out_complex_05_tensor.cc @@ -0,0 +1,122 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Like the _05 test, just for tensor-valued quantities. + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include "../tests.h" + + + +template +void +check() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, 0., 1.); + + // Create a vector-valued finite element + FESystem fe(FE_Q(1), dim * dim); + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe); + + // Pick a special solution function: constant in space, but one + // where the individual tensor components have the form c-c*i + // (counting components from 1, for uniqueness of components). This + // allows us to check that the ordering of components in the output + // file is correct. + // + // For example, in 2d, the ordering of output components should then + // be + // [1 2 3 4] [-1 -2 -3 -4] + // where [...] indicates which components jointly form a tensor. + Vector> v(dof_handler.n_dofs()); + for (unsigned int i = 0; i < v.size(); ++i) + v(i) = std::complex(1, -1) * double(i % fe.n_components() + 1); + + DataOut data_out; + data_out.attach_dof_handler(dof_handler); + data_out.add_data_vector( + v, + std::vector(dim * dim, "tensor_field"), + DataOut::type_dof_data, + std::vector( + dim * dim, DataComponentInterpretation::component_is_part_of_tensor)); + data_out.build_patches(); + + data_out.write_gnuplot(deallog.get_file_stream()); +} + + + +int +main() +{ + initlog(); + + try + { + check<1>(); + check<2>(); + check<3>(); + } + catch (std::exception &exc) + { + deallog << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + } + catch (...) + { + deallog << std::endl + << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + } +} diff --git a/tests/data_out/data_out_complex_05_tensor.output b/tests/data_out/data_out_complex_05_tensor.output new file mode 100644 index 0000000000..a596dcc819 --- /dev/null +++ b/tests/data_out/data_out_complex_05_tensor.output @@ -0,0 +1,81 @@ + +# This file was generated by the deal.II library. + + +# +# For a description of the GNUPLOT format see the GNUPLOT manual. +# +# +0.00000 1.00000 -1.00000 +1.00000 1.00000 -1.00000 + + +# This file was generated by the deal.II library. + + +# +# For a description of the GNUPLOT format see the GNUPLOT manual. +# +# +0.00000 0.00000 1.00000 2.00000 3.00000 4.00000 -1.00000 -2.00000 -3.00000 -4.00000 +1.00000 0.00000 1.00000 2.00000 3.00000 4.00000 -1.00000 -2.00000 -3.00000 -4.00000 + +0.00000 1.00000 1.00000 2.00000 3.00000 4.00000 -1.00000 -2.00000 -3.00000 -4.00000 +1.00000 1.00000 1.00000 2.00000 3.00000 4.00000 -1.00000 -2.00000 -3.00000 -4.00000 + + +# This file was generated by the deal.II library. + + +# +# For a description of the GNUPLOT format see the GNUPLOT manual. +# +# +0.00000 0.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +1.00000 0.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +0.00000 0.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +0.00000 1.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +0.00000 0.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +0.00000 0.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +1.00000 0.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +1.00000 1.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +1.00000 0.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +1.00000 0.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +0.00000 1.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +1.00000 1.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +0.00000 1.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +0.00000 1.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +1.00000 1.00000 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +1.00000 1.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +0.00000 0.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +1.00000 0.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +0.00000 0.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +0.00000 1.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +1.00000 0.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +1.00000 1.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + +0.00000 1.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 +1.00000 1.00000 1.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 -1.00000 -2.00000 -3.00000 -4.00000 -5.00000 -6.00000 -7.00000 -8.00000 -9.00000 + + -- 2.39.5