From 4e6bdcee04f155a45db74e0aa6e9c45677892181 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 9 Jul 2021 13:25:16 -0600 Subject: [PATCH] Add tests. --- tests/data_out/pvtu_physical_units_01.cc | 81 ++++++++ ...tu_physical_units_01.with_zlib=true.output | 111 ++++++++++ tests/data_out/pvtu_physical_units_02.cc | 87 ++++++++ ...tu_physical_units_02.with_zlib=true.output | 106 ++++++++++ tests/data_out/vtu_physical_units_01.cc | 86 ++++++++ ...tu_physical_units_01.with_zlib=true.output | 195 ++++++++++++++++++ tests/data_out/vtu_physical_units_02.cc | 92 +++++++++ ...tu_physical_units_02.with_zlib=true.output | 187 +++++++++++++++++ 8 files changed, 945 insertions(+) create mode 100644 tests/data_out/pvtu_physical_units_01.cc create mode 100644 tests/data_out/pvtu_physical_units_01.with_zlib=true.output create mode 100644 tests/data_out/pvtu_physical_units_02.cc create mode 100644 tests/data_out/pvtu_physical_units_02.with_zlib=true.output create mode 100644 tests/data_out/vtu_physical_units_01.cc create mode 100644 tests/data_out/vtu_physical_units_01.with_zlib=true.output create mode 100644 tests/data_out/vtu_physical_units_02.cc create mode 100644 tests/data_out/vtu_physical_units_02.with_zlib=true.output diff --git a/tests/data_out/pvtu_physical_units_01.cc b/tests/data_out/pvtu_physical_units_01.cc new file mode 100644 index 0000000000..411124282c --- /dev/null +++ b/tests/data_out/pvtu_physical_units_01.cc @@ -0,0 +1,81 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2006 - 2020 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. +// +// --------------------------------------------------------------------- + + +// Check that one can output physical units along with output +// fields. This test is for scalar quantities and checks the +// pvtu writer. + + +#include + +#include +#include + +#include "../tests.h" + +#include "patches.h" + +// Output data on repetitions of the unit hypercube + +template +void +check(DataOutBase::VtkFlags flags, std::ostream &out) +{ + std::vector names(5); + names[0] = "x1"; + names[1] = "x2"; + names[2] = "x3"; + names[3] = "x4"; + names[4] = "i"; + + std::vector< + std::tuple> + vectors; + DataOutBase::write_pvtu_record(out, {"abc.vtu"}, names, vectors, flags); +} + + +template +void +check_all(std::ostream &log) +{ + DataOutBase::VtkFlags flags; + + // Set the units of some but not all output quantities + flags.physical_units["x1"] = "kg/s"; + flags.physical_units["x3"] = "N/m"; + flags.physical_units["i"] = "J/K"; + + log << "==============================" << std::endl + << dim << spacedim << ".vtu" << std::endl + << "==============================" << std::endl; + check(flags, log); +} + +int +main() +{ + initlog(); + + check_all<1, 1>(deallog.get_file_stream()); + check_all<1, 2>(deallog.get_file_stream()); + check_all<2, 2>(deallog.get_file_stream()); + check_all<2, 3>(deallog.get_file_stream()); + check_all<3, 3>(deallog.get_file_stream()); +} diff --git a/tests/data_out/pvtu_physical_units_01.with_zlib=true.output b/tests/data_out/pvtu_physical_units_01.with_zlib=true.output new file mode 100644 index 0000000000..a1e340316f --- /dev/null +++ b/tests/data_out/pvtu_physical_units_01.with_zlib=true.output @@ -0,0 +1,111 @@ + +============================== +11.vtu +============================== + + + + + + + + + + + + + + + + + +============================== +12.vtu +============================== + + + + + + + + + + + + + + + + + +============================== +22.vtu +============================== + + + + + + + + + + + + + + + + + +============================== +23.vtu +============================== + + + + + + + + + + + + + + + + + +============================== +33.vtu +============================== + + + + + + + + + + + + + + + + + diff --git a/tests/data_out/pvtu_physical_units_02.cc b/tests/data_out/pvtu_physical_units_02.cc new file mode 100644 index 0000000000..f2cf11bc84 --- /dev/null +++ b/tests/data_out/pvtu_physical_units_02.cc @@ -0,0 +1,87 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2006 - 2020 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. +// +// --------------------------------------------------------------------- + + +// Check that one can output physical units along with output +// fields. This test is for vector-valued quantities and checks the +// pvtu writer. + + +#include + +#include +#include + +#include "../tests.h" + +#include "patches.h" + +// Output data on repetitions of the unit hypercube + +template +void +check(DataOutBase::VtkFlags flags, std::ostream &out) +{ + std::vector names(5); + names[0] = "x1"; + names[1] = "x2"; + names[2] = "x3"; + names[3] = "x4"; + names[4] = "i"; + for (unsigned int i = 1; i < 1 + dim; ++i) + names[i] = "v"; + + std::vector< + std::tuple> + vectors{{1, + 1 + dim - 1, + "v", + DataComponentInterpretation::component_is_part_of_vector}}; + DataOutBase::write_pvtu_record(out, {"abc.vtu"}, names, vectors, flags); +} + + +template +void +check_all(std::ostream &log) +{ + DataOutBase::VtkFlags flags; + + // Set the units of some but not all output quantities + flags.physical_units["x1"] = "kg/s"; + flags.physical_units["v"] = "m/s"; + + log << "==============================" << std::endl + << dim << spacedim << ".vtu" << std::endl + << "==============================" << std::endl; + check(flags, log); +} + +int +main() +{ + std::stringstream ss; + check_all<1, 1>(ss); + check_all<1, 2>(ss); + check_all<2, 2>(ss); + check_all<2, 3>(ss); + check_all<3, 3>(ss); + + std::ofstream logfile("output"); + filter_out_xml_key(ss, "DataArray", logfile); +} diff --git a/tests/data_out/pvtu_physical_units_02.with_zlib=true.output b/tests/data_out/pvtu_physical_units_02.with_zlib=true.output new file mode 100644 index 0000000000..d72b903b61 --- /dev/null +++ b/tests/data_out/pvtu_physical_units_02.with_zlib=true.output @@ -0,0 +1,106 @@ +============================== +11.vtu +============================== + + + + + + + + + + + + + + + + + +============================== +12.vtu +============================== + + + + + + + + + + + + + + + + + +============================== +22.vtu +============================== + + + + + + + + + + + + + + + + +============================== +23.vtu +============================== + + + + + + + + + + + + + + + + +============================== +33.vtu +============================== + + + + + + + + + + + + + + + diff --git a/tests/data_out/vtu_physical_units_01.cc b/tests/data_out/vtu_physical_units_01.cc new file mode 100644 index 0000000000..6196ff1d1a --- /dev/null +++ b/tests/data_out/vtu_physical_units_01.cc @@ -0,0 +1,86 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2006 - 2020 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. +// +// --------------------------------------------------------------------- + + +// Check that one can output physical units along with output fields + + +#include + +#include +#include + +#include "../tests.h" + +#include "patches.h" + +// Output data on repetitions of the unit hypercube + +template +void +check(DataOutBase::VtkFlags flags, std::ostream &out) +{ + const unsigned int np = 4; + + std::vector> patches(np); + + create_patches(patches); + + std::vector names(5); + names[0] = "x1"; + names[1] = "x2"; + names[2] = "x3"; + names[3] = "x4"; + names[4] = "i"; + std::vector< + std::tuple> + vectors; + DataOutBase::write_vtu(patches, names, vectors, flags, out); +} + + +template +void +check_all(std::ostream &log) +{ + DataOutBase::VtkFlags flags; + + // Set the units of some but not all output quantities + flags.physical_units["x1"] = "kg/s"; + flags.physical_units["x3"] = "N/m"; + flags.physical_units["i"] = "J/K"; + + log << "==============================" << std::endl + << dim << spacedim << ".vtu" << std::endl + << "==============================" << std::endl; + check(flags, log); +} + +int +main() +{ + std::stringstream ss; + check_all<1, 1>(ss); + check_all<1, 2>(ss); + check_all<2, 2>(ss); + check_all<2, 3>(ss); + check_all<3, 3>(ss); + + std::ofstream logfile("output"); + filter_out_xml_key(ss, "DataArray", logfile); +} diff --git a/tests/data_out/vtu_physical_units_01.with_zlib=true.output b/tests/data_out/vtu_physical_units_01.with_zlib=true.output new file mode 100644 index 0000000000..af283a06f3 --- /dev/null +++ b/tests/data_out/vtu_physical_units_01.with_zlib=true.output @@ -0,0 +1,195 @@ +============================== +11.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +============================== +12.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +============================== +22.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +============================== +23.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +============================== +33.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data_out/vtu_physical_units_02.cc b/tests/data_out/vtu_physical_units_02.cc new file mode 100644 index 0000000000..93a3676eb9 --- /dev/null +++ b/tests/data_out/vtu_physical_units_02.cc @@ -0,0 +1,92 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2006 - 2020 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. +// +// --------------------------------------------------------------------- + + +// Check that one can output physical units along with output +// fields. This test is for vector-valued quantities + + +#include + +#include +#include + +#include "../tests.h" + +#include "patches.h" + +// Output data on repetitions of the unit hypercube + +template +void +check(DataOutBase::VtkFlags flags, std::ostream &out) +{ + const unsigned int np = 4; + + std::vector> patches(np); + + create_patches(patches); + + std::vector names(5); + names[0] = "x1"; + names[1] = "x2"; + names[2] = "x3"; + names[3] = "x4"; + names[4] = "i"; + for (unsigned int i = 1; i < 1 + dim; ++i) + names[i] = "v"; + + std::vector< + std::tuple> + vectors{{1, + 1 + dim - 1, + "v", + DataComponentInterpretation::component_is_part_of_vector}}; + DataOutBase::write_vtu(patches, names, vectors, flags, out); +} + + +template +void +check_all(std::ostream &log) +{ + DataOutBase::VtkFlags flags; + + // Set the units of some but not all output quantities + flags.physical_units["x1"] = "kg/s"; + flags.physical_units["v"] = "m/s"; + + log << "==============================" << std::endl + << dim << spacedim << ".vtu" << std::endl + << "==============================" << std::endl; + check(flags, log); +} + +int +main() +{ + std::stringstream ss; + check_all<1, 1>(ss); + check_all<1, 2>(ss); + check_all<2, 2>(ss); + check_all<2, 3>(ss); + check_all<3, 3>(ss); + + std::ofstream logfile("output"); + filter_out_xml_key(ss, "DataArray", logfile); +} diff --git a/tests/data_out/vtu_physical_units_02.with_zlib=true.output b/tests/data_out/vtu_physical_units_02.with_zlib=true.output new file mode 100644 index 0000000000..0281f1523e --- /dev/null +++ b/tests/data_out/vtu_physical_units_02.with_zlib=true.output @@ -0,0 +1,187 @@ +============================== +11.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +============================== +12.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +============================== +22.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +============================== +23.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +============================== +33.vtu +============================== + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5