]> https://gitweb.dealii.org/ - dealii.git/commitdiff
assert unique names in DataOut
authorTimo Heister <timo.heister@gmail.com>
Mon, 29 Aug 2016 19:28:02 +0000 (15:28 -0400)
committerTimo Heister <timo.heister@gmail.com>
Tue, 6 Sep 2016 21:17:57 +0000 (17:17 -0400)
include/deal.II/base/data_out_base.h
source/base/data_out_base.cc
source/numerics/data_out.cc
source/numerics/data_out_faces.cc
source/numerics/data_out_rotation.cc
source/numerics/data_out_stack.cc

index 78eb6e661912cc9995f74252fd093cce23a3dbfc..5fecae47c3ac04e3e84610ad810624ec6dffc8ca 100644 (file)
@@ -2473,6 +2473,15 @@ protected:
   std::vector<std_cxx11::tuple<unsigned int, unsigned int, std::string> >
   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
index 43d0829517963c975443a5e9e2881469671faa3c..031e4075ac19dcd77ddfe56d4c4d6b2c402cc8fa 100644 (file)
@@ -7247,6 +7247,52 @@ DataOutInterface<dim,spacedim>::get_vector_data_ranges () const
 }
 
 
+template <int dim, int spacedim>
+void
+DataOutInterface<dim,spacedim>::
+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<std::string> all_names;
+
+    const std::vector<std_cxx11::tuple<unsigned int, unsigned int, std::string> >
+    ranges = this->get_vector_data_ranges();
+    const std::vector<std::string> data_names = this->get_dataset_names();
+    const unsigned int n_data_sets = data_names.size();
+    std::vector<bool> data_set_written (n_data_sets, false);
+
+    for (unsigned int n_th_vector=0; n_th_vector<ranges.size(); ++n_th_vector)
+      {
+        const std::string &name = std_cxx11::get<2>(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<n_data_sets; ++data_set)
+      if (data_set_written[data_set] == false)
+        {
+          const std::string &name =  data_names[data_set];
+          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);
+        }
+  }
+#endif
+}
+
 
 
 // ---------------------------------------------- DataOutReader ----------
index 5920e81d41bf35c1ab269aaa67e490f80d7a99ce..c63f0ee5f8be2261033b7964d02502215cf02055 100644 (file)
@@ -338,6 +338,8 @@ void DataOut<dim,DoFHandlerType>::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.
index ca4562f486db5776464744791b38eeab8ec90132..15284f736a7b97961e7bb8dec06f830166ec0b70 100644 (file)
@@ -294,6 +294,8 @@ void DataOutFaces<dim,DoFHandlerType>::build_patches (const Mapping<dimension> &
   Assert (this->triangulation != 0,
           Exceptions::DataOut::ExcNoTriangulationSelected());
 
+  this->validate_dataset_names();
+
   unsigned int n_datasets     = this->cell_data.size();
   for (unsigned int i=0; i<this->dof_data.size(); ++i)
     n_datasets += this->dof_data[i]->n_output_variables;
index 9b29b0680701ce46728a0128d482be01ca5db6ed..653b6d27667a1c1ab0fcebb71a1f5c2ba0237565 100644 (file)
@@ -414,6 +414,8 @@ void DataOutRotation<dim,DoFHandlerType>::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; i<this->dof_data.size(); ++i)
     n_datasets+= this->dof_data[i]->n_output_variables;
index 638c71cb28f7c7fff8f238e9b1d98ba90e57e1ff..229fd16fe658992ce60f9a7be76b9523f163a27a 100644 (file)
@@ -246,6 +246,8 @@ void DataOutStack<dim,spacedim,DoFHandlerType>::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();

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.