From ab0a76edd169a93948e56379632d78b4a203d082 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Mon, 29 Aug 2016 15:28:02 -0400 Subject: [PATCH] assert unique names in DataOut --- include/deal.II/base/data_out_base.h | 9 ++++++ source/base/data_out_base.cc | 46 ++++++++++++++++++++++++++++ source/numerics/data_out.cc | 2 ++ source/numerics/data_out_faces.cc | 2 ++ source/numerics/data_out_rotation.cc | 2 ++ source/numerics/data_out_stack.cc | 2 ++ 6 files changed, 63 insertions(+) diff --git a/include/deal.II/base/data_out_base.h b/include/deal.II/base/data_out_base.h index 78eb6e6619..5fecae47c3 100644 --- a/include/deal.II/base/data_out_base.h +++ b/include/deal.II/base/data_out_base.h @@ -2473,6 +2473,15 @@ protected: std::vector > get_vector_data_ranges () const; + /** + * Validate that the names of the datasets returned by get_dataset_names() and + * get_vector_data_ranges() are valid. This currently consists of checking + * that names are not used more than once. If an invalid state is encountered, + * an Assert() will be triggered in debug mode. + */ + void validate_dataset_names () const; + + /** * The default number of subdivisions for patches. This is filled by * parse_parameters() and should be obeyed by build_patches() in derived diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 43d0829517..031e4075ac 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -7247,6 +7247,52 @@ DataOutInterface::get_vector_data_ranges () const } +template +void +DataOutInterface:: +validate_dataset_names () const +{ +#ifdef DEBUG + { + // Check that names for datasets are only used once. This is somewhat + // complicated, because vector ranges might have a name or not. + std::set all_names; + + const std::vector > + ranges = this->get_vector_data_ranges(); + const std::vector data_names = this->get_dataset_names(); + const unsigned int n_data_sets = data_names.size(); + std::vector data_set_written (n_data_sets, false); + + for (unsigned int n_th_vector=0; n_th_vector(ranges[n_th_vector]); + if (name != "") + { + Assert(all_names.find(name) == all_names.end(), + ExcMessage("Error: names of fields in DataOut need to be unique, " + "but '" + name + "' is used more than once.")); + all_names.insert(name); + for (unsigned int i=std_cxx11::get<0>(ranges[n_th_vector]); + i<=std_cxx11::get<1>(ranges[n_th_vector]); + ++i) + data_set_written[i] = true; + } + } + + for (unsigned int data_set=0; data_set::build_patches Assert (n_subdivisions >= 1, Exceptions::DataOut::ExcInvalidNumberOfSubdivisions(n_subdivisions)); + this->validate_dataset_names(); + // First count the cells we want to create patches of. Also fill the object // that maps the cell indices to the patch numbers, as this will be needed // for generation of neighborship information. diff --git a/source/numerics/data_out_faces.cc b/source/numerics/data_out_faces.cc index ca4562f486..15284f736a 100644 --- a/source/numerics/data_out_faces.cc +++ b/source/numerics/data_out_faces.cc @@ -294,6 +294,8 @@ void DataOutFaces::build_patches (const Mapping & Assert (this->triangulation != 0, Exceptions::DataOut::ExcNoTriangulationSelected()); + this->validate_dataset_names(); + unsigned int n_datasets = this->cell_data.size(); for (unsigned int i=0; idof_data.size(); ++i) n_datasets += this->dof_data[i]->n_output_variables; diff --git a/source/numerics/data_out_rotation.cc b/source/numerics/data_out_rotation.cc index 9b29b06807..653b6d2766 100644 --- a/source/numerics/data_out_rotation.cc +++ b/source/numerics/data_out_rotation.cc @@ -414,6 +414,8 @@ void DataOutRotation::build_patches (const unsigned int n_pa Assert (n_subdivisions >= 1, Exceptions::DataOut::ExcInvalidNumberOfSubdivisions(n_subdivisions)); + this->validate_dataset_names(); + unsigned int n_datasets=this->cell_data.size(); for (unsigned int i=0; idof_data.size(); ++i) n_datasets+= this->dof_data[i]->n_output_variables; diff --git a/source/numerics/data_out_stack.cc b/source/numerics/data_out_stack.cc index 638c71cb28..229fd16fe6 100644 --- a/source/numerics/data_out_stack.cc +++ b/source/numerics/data_out_stack.cc @@ -246,6 +246,8 @@ void DataOutStack::build_patches (const unsigned in Assert (dof_handler != 0, Exceptions::DataOut::ExcNoDoFHandlerSelected()); + this->validate_dataset_names(); + const unsigned int n_components = dof_handler->get_fe().n_components(); const unsigned int n_datasets = dof_data.size() * n_components + cell_data.size(); -- 2.39.5