From: bangerth Date: Sat, 13 Oct 2007 02:16:26 +0000 (+0000) Subject: Fix a bug where we didn't properly read to the end of the line when we should have... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c34301dfb948b3fe8b414aa99442c144a008dd53;p=dealii-svn.git Fix a bug where we didn't properly read to the end of the line when we should have. Add testsuite files. git-svn-id: https://svn.dealii.org/trunk@15309 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/source/data_out_base.cc b/deal.II/base/source/data_out_base.cc index 8503ea35de..bfc90d4fb5 100644 --- a/deal.II/base/source/data_out_base.cc +++ b/deal.II/base/source/data_out_base.cc @@ -28,7 +28,6 @@ // array of nodes. ////////////////////////////////////////////////////////////////////// - #include #include #include @@ -4565,8 +4564,18 @@ DataOutReader::read (std::istream &in) { in >> vector_data_ranges[i].template get<0>() >> vector_data_ranges[i].template get<1>(); + + // read in the name of that vector + // range. because it is on a separate + // line, we first need to read to the + // end of the previous line (nothing + // should be there any more after we've + // read the previous two integers) and + // then read the entire next line for + // the name std::string name; getline(in, name); + getline(in, name); vector_data_ranges[i].template get<2>() = name; } diff --git a/tests/bits/data_out_04.cc b/tests/bits/data_out_04.cc new file mode 100644 index 0000000000..7dedf67803 --- /dev/null +++ b/tests/bits/data_out_04.cc @@ -0,0 +1,153 @@ +//---------------------------- data_out_04.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004, 2004, 2007 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- data_out_04.cc --------------------------- + + +// write the data in deal.II intermediate form, read it back in, and +// make sure that the result is the same + +// this is as the _03 test except that it tests our ability to read and write +// files with vector components in them + +#include "../tests.h" +#include "data_out_common.cc" +#include +#include + + +std::string output_file_name = "data_out_04/output"; + + +// have a class that makes sure we can get at the patches and data set +// names that the base class generates +template +class XDataOut : public DataOut +{ + public: + const std::vector > & + get_patches() const + { return DataOut::get_patches(); } + + std::vector + get_dataset_names () const + { return DataOut::get_dataset_names(); } + + std::vector > + get_vector_data_ranges () const + { + // if we have enough components for a + // vector solution, make the last dim + // components a vector + std::vector > + retval; + if (get_dataset_names().size() >= dim) + retval.push_back (boost::tuple + + (get_dataset_names().size()-dim, + get_dataset_names().size()-1, + "vector_data")); + return retval; + } +}; + +// have a class that makes sure we can get at the patches and data set +// names that the base class generates +template +class XDataOutReader : public DataOutReader +{ + public: + const std::vector > & + get_patches() const + { return DataOutReader::get_patches(); } + + std::vector + get_dataset_names () const + { return DataOutReader::get_dataset_names(); } + + std::vector > + get_vector_data_ranges () const + { + return DataOutReader::get_vector_data_ranges (); + } +}; + + +template +void +check_this (const DoFHandler &dof_handler, + const Vector &v_node, + const Vector &v_cell) +{ + XDataOut data_out; + data_out.attach_dof_handler (dof_handler); + data_out.add_data_vector (v_node, "node_data"); + data_out.add_data_vector (v_cell, "cell_data"); + data_out.build_patches (); + + { + std::ofstream tmp ("data_out_04.tmp"); + data_out.write_deal_II_intermediate (tmp); + } + + XDataOutReader reader; + { + std::ifstream tmp ("data_out_04.tmp"); + reader.read (tmp); + } + + // finally make sure that we have + // read everything back in + // correctly + Assert (data_out.get_dataset_names() == reader.get_dataset_names(), + ExcInternalError()); + + Assert (data_out.get_patches().size() == reader.get_patches().size(), + ExcInternalError()); + + for (unsigned int i=0; i() + << ' ' + << data_out.get_vector_data_ranges()[i].template get<1>() + << ' ' + << data_out.get_vector_data_ranges()[i].template get<2>() + << std::endl; + Assert (data_out.get_vector_data_ranges()[i].template get<0>() + == + reader.get_vector_data_ranges()[i].template get<0>(), + ExcInternalError()); + Assert (data_out.get_vector_data_ranges()[i].template get<1>() + == + reader.get_vector_data_ranges()[i].template get<1>(), + ExcInternalError()); + Assert (data_out.get_vector_data_ranges()[i].template get<2>() + == + reader.get_vector_data_ranges()[i].template get<2>(), + ExcInternalError()); + } + + // for good measure, delete tmp file + remove ("data_out_04.tmp"); + + deallog << "OK" << std::endl; +} + + diff --git a/tests/bits/data_out_04/cmp/generic b/tests/bits/data_out_04/cmp/generic new file mode 100644 index 0000000000..1fd133e8d0 --- /dev/null +++ b/tests/bits/data_out_04/cmp/generic @@ -0,0 +1,75 @@ + +DEAL::Checking Q1 in 1d: +DEAL::1 +DEAL::1 1 vector_data +DEAL::OK +DEAL::Checking Q1 in 2d: +DEAL::1 +DEAL::0 1 vector_data +DEAL::OK +DEAL::Checking Q1 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking Q2 in 1d: +DEAL::1 +DEAL::1 1 vector_data +DEAL::OK +DEAL::Checking Q2 in 2d: +DEAL::1 +DEAL::0 1 vector_data +DEAL::OK +DEAL::Checking Q2 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking Q3 in 1d: +DEAL::1 +DEAL::1 1 vector_data +DEAL::OK +DEAL::Checking Q3 in 2d: +DEAL::1 +DEAL::0 1 vector_data +DEAL::OK +DEAL::Checking Q3 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ0 in 1d: +DEAL::1 +DEAL::1 1 vector_data +DEAL::OK +DEAL::Checking DGQ0 in 2d: +DEAL::1 +DEAL::0 1 vector_data +DEAL::OK +DEAL::Checking DGQ0 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ1 in 1d: +DEAL::1 +DEAL::1 1 vector_data +DEAL::OK +DEAL::Checking DGQ1 in 2d: +DEAL::1 +DEAL::0 1 vector_data +DEAL::OK +DEAL::Checking DGQ1 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ2 in 1d: +DEAL::1 +DEAL::1 1 vector_data +DEAL::OK +DEAL::Checking DGQ2 in 2d: +DEAL::1 +DEAL::0 1 vector_data +DEAL::OK +DEAL::Checking DGQ2 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking Nedelec1 in 2d: +DEAL::1 +DEAL::1 2 vector_data +DEAL::OK +DEAL::Checking Nedelec1 in 3d: +DEAL::1 +DEAL::1 3 vector_data +DEAL::OK diff --git a/tests/bits/data_out_faces_04.cc b/tests/bits/data_out_faces_04.cc new file mode 100644 index 0000000000..1c319bebed --- /dev/null +++ b/tests/bits/data_out_faces_04.cc @@ -0,0 +1,172 @@ +//---------------------------- data_out_faces_04.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004, 2004, 2006, 2007 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- data_out_faces_04.cc --------------------------- + + +// write the data in deal.II intermediate form, read it back in, and +// make sure that the result is the same + +// this is as the _03 test except that it tests our ability to read and write +// files with vector components in them + +#include "../tests.h" +#include "data_out_common.cc" +#include +#include + + +std::string output_file_name = "data_out_faces_04/output"; + + +// have a class that makes sure we can get at the patches and data set +// names that the base class generates +template +class XDataOut : public DataOutFaces +{ + public: + const std::vector > & + get_patches() const + { return DataOutFaces::get_patches(); } + + std::vector + get_dataset_names () const + { return DataOutFaces::get_dataset_names(); } + + std::vector > + get_vector_data_ranges () const + { + return DataOutFaces::get_vector_data_ranges (); + } +}; + +// have a class that makes sure we can get at the patches and data set +// names that the base class generates +template +class XDataOutReader : public DataOutReader +{ + public: + const std::vector > & + get_patches() const + { return DataOutReader::get_patches(); } + + std::vector + get_dataset_names () const + { return DataOutReader::get_dataset_names(); } + + std::vector > + get_vector_data_ranges () const + { + return DataOutReader::get_vector_data_ranges (); + } +}; + + + +void +my_check_this (const DoFHandler<1> &, + const Vector &, + const Vector &) +{ + // don't check in 1d +} + + + + +template +void +my_check_this (const DoFHandler &dof_handler, + const Vector &v_node, + const Vector &v_cell) +{ + XDataOut data_out; + data_out.attach_dof_handler (dof_handler); + data_out.add_data_vector (v_node, "node_data"); + data_out.add_data_vector (v_cell, "cell_data"); + data_out.build_patches (); + + { + std::ofstream tmp ("data_out_faces_04.tmp"); + data_out.write_deal_II_intermediate (tmp); + } + + XDataOutReader reader; + { + std::ifstream tmp ("data_out_faces_04.tmp"); + reader.read (tmp); + } + + // finally make sure that we have + // read everything back in + // correctly + Assert (data_out.get_dataset_names() == reader.get_dataset_names(), + ExcInternalError()); + + Assert (data_out.get_patches().size() == reader.get_patches().size(), + ExcInternalError()); + + for (unsigned int i=0; i() + << ' ' + << data_out.get_vector_data_ranges()[i].template get<1>() + << ' ' + << data_out.get_vector_data_ranges()[i].template get<2>() + << std::endl; + Assert (data_out.get_vector_data_ranges()[i].template get<0>() + == + reader.get_vector_data_ranges()[i].template get<0>(), + ExcInternalError()); + Assert (data_out.get_vector_data_ranges()[i].template get<1>() + == + reader.get_vector_data_ranges()[i].template get<1>(), + ExcInternalError()); + Assert (data_out.get_vector_data_ranges()[i].template get<2>() + == + reader.get_vector_data_ranges()[i].template get<2>(), + ExcInternalError()); + } + + // for good measure, delete tmp file + remove ("data_out_faces_04.tmp"); + + deallog << "OK" << std::endl; +} + + + + +template +void +check_this (const DoFHandler &dof_handler, + const Vector &v_node, + const Vector &v_cell) +{ + // since we can't forward declare + // check_this in this file (it is forward + // declared in data_out_common.cc), we + // also can't make the driver file aware of + // the overload for 1d. to avoid linker + // errors, we can consequently not overload + // check_this, and need this forwarder + // function + my_check_this (dof_handler, v_node, v_cell); +} diff --git a/tests/bits/data_out_faces_04/cmp/generic b/tests/bits/data_out_faces_04/cmp/generic new file mode 100644 index 0000000000..c46f50e999 --- /dev/null +++ b/tests/bits/data_out_faces_04/cmp/generic @@ -0,0 +1,49 @@ + +DEAL::Checking Q1 in 1d: +DEAL::Checking Q1 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking Q1 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking Q2 in 1d: +DEAL::Checking Q2 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking Q2 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking Q3 in 1d: +DEAL::Checking Q3 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking Q3 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ0 in 1d: +DEAL::Checking DGQ0 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ0 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ1 in 1d: +DEAL::Checking DGQ1 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ1 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ2 in 1d: +DEAL::Checking DGQ2 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ2 in 3d: +DEAL::0 +DEAL::OK +DEAL::Checking Nedelec1 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking Nedelec1 in 3d: +DEAL::0 +DEAL::OK diff --git a/tests/bits/data_out_rotation_04.cc b/tests/bits/data_out_rotation_04.cc new file mode 100644 index 0000000000..a5f9c28e71 --- /dev/null +++ b/tests/bits/data_out_rotation_04.cc @@ -0,0 +1,171 @@ +//---------------------------- data_out_rotation_04.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004, 2004, 2006, 2007 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- data_out_rotation_04.cc --------------------------- + + +// write the data in deal.II intermediate form, read it back in, and +// make sure that the result is the same + +// this is as the _03 test except that it tests our ability to read and write +// files with vector components in them + +#include "../tests.h" +#include "data_out_common.cc" +#include +#include + + +std::string output_file_name = "data_out_rotation_04/output"; + + +// have a class that makes sure we can get at the patches and data set +// names that the base class generates +template +class XDataOut : public DataOutRotation +{ + public: + const std::vector > & + get_patches() const + { return DataOutRotation::get_patches(); } + + std::vector + get_dataset_names () const + { return DataOutRotation::get_dataset_names(); } + + std::vector > + get_vector_data_ranges () const + { + return DataOutRotation::get_vector_data_ranges (); + } +}; + +// have a class that makes sure we can get at the patches and data set +// names that the base class generates +template +class XDataOutReader : public DataOutReader +{ + public: + const std::vector > & + get_patches() const + { return DataOutReader::get_patches(); } + + std::vector + get_dataset_names () const + { return DataOutReader::get_dataset_names(); } + + std::vector > + get_vector_data_ranges () const + { + return DataOutReader::get_vector_data_ranges (); + } +}; + + +void +my_check_this (const DoFHandler<3> &, + const Vector &, + const Vector &) +{ + // no checks in 3d +} + + + +template +void +my_check_this (const DoFHandler &dof_handler, + const Vector &v_node, + const Vector &v_cell) +{ + XDataOut data_out; + data_out.attach_dof_handler (dof_handler); + data_out.add_data_vector (v_node, "node_data"); + data_out.add_data_vector (v_cell, "cell_data"); + data_out.build_patches (4); + + { + std::ofstream tmp ("data_out_rotation_04.tmp"); + // use full precision to avoid + // errors + tmp.precision (20); + data_out.write_deal_II_intermediate (tmp); + } + + XDataOutReader reader; + { + std::ifstream tmp ("data_out_rotation_04.tmp"); + reader.read (tmp); + } + + // finally make sure that we have + // read everything back in + // correctly + Assert (data_out.get_dataset_names() == reader.get_dataset_names(), + ExcInternalError()); + + Assert (data_out.get_patches().size() == reader.get_patches().size(), + ExcInternalError()); + + for (unsigned int i=0; i() + << ' ' + << data_out.get_vector_data_ranges()[i].template get<1>() + << ' ' + << data_out.get_vector_data_ranges()[i].template get<2>() + << std::endl; + Assert (data_out.get_vector_data_ranges()[i].template get<0>() + == + reader.get_vector_data_ranges()[i].template get<0>(), + ExcInternalError()); + Assert (data_out.get_vector_data_ranges()[i].template get<1>() + == + reader.get_vector_data_ranges()[i].template get<1>(), + ExcInternalError()); + Assert (data_out.get_vector_data_ranges()[i].template get<2>() + == + reader.get_vector_data_ranges()[i].template get<2>(), + ExcInternalError()); + } + + // for good measure, delete tmp file + remove ("data_out_rotation_04.tmp"); + + deallog << "OK" << std::endl; +} + + +template +void +check_this (const DoFHandler &dof_handler, + const Vector &v_node, + const Vector &v_cell) +{ + // since we can't forward declare + // check_this in this file (it is forward + // declared in data_out_common.cc), we + // also can't make the driver file aware of + // the overload for 1d. to avoid linker + // errors, we can consequently not overload + // check_this, and need this forwarder + // function + my_check_this (dof_handler, v_node, v_cell); +} diff --git a/tests/bits/data_out_rotation_04/cmp/generic b/tests/bits/data_out_rotation_04/cmp/generic new file mode 100644 index 0000000000..c2f2c15a00 --- /dev/null +++ b/tests/bits/data_out_rotation_04/cmp/generic @@ -0,0 +1,47 @@ + +DEAL::Checking Q1 in 1d: +DEAL::0 +DEAL::OK +DEAL::Checking Q1 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking Q1 in 3d: +DEAL::Checking Q2 in 1d: +DEAL::0 +DEAL::OK +DEAL::Checking Q2 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking Q2 in 3d: +DEAL::Checking Q3 in 1d: +DEAL::0 +DEAL::OK +DEAL::Checking Q3 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking Q3 in 3d: +DEAL::Checking DGQ0 in 1d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ0 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ0 in 3d: +DEAL::Checking DGQ1 in 1d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ1 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ1 in 3d: +DEAL::Checking DGQ2 in 1d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ2 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking DGQ2 in 3d: +DEAL::Checking Nedelec1 in 2d: +DEAL::0 +DEAL::OK +DEAL::Checking Nedelec1 in 3d: