]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Fix an obscure corner case where add_data_vector could not detect itself whether...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 30 Mar 2001 11:06:57 +0000 (11:06 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 30 Mar 2001 11:06:57 +0000 (11:06 +0000)
git-svn-id: https://svn.dealii.org/trunk@4352 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/numerics/data_out.h
deal.II/deal.II/source/numerics/data_out.cc
deal.II/doc/news/2001/c-3-1.html

index e6dadb5fdc2e451153e4b709ce4244ff332dd685..d28a42eb12c988f9b0c116b1747139a11da28d71 100644 (file)
 #define __deal2__data_out_h
 
 
-//TODO:[?] DataOut determines whether something is a DoF or cell vector by the size of the vector.
-//    This will fail if someone is using DG0 elements,
-//    since there the number of elements of both types of vectors is the
-//    same, but the ordering will usually differ. Errors cannot be plotted
-//    anyway, since they are float vectors.
-
-
 
 #include <base/smartpointer.h>
 #include <base/multithread_info.h>
@@ -159,6 +152,29 @@ template <int dof_handler_dim, int patch_dim, int patch_space_dim=patch_dim>
 class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
 {
   public:
+                                    /**
+                                     * Type describing what the
+                                     * vector given to
+                                     * @ref{add_data_vector} is: a
+                                     * vector that has one entry per
+                                     * degree of freedom in a
+                                     * @ref{DoFHandler} object (such
+                                     * as solution vectors), or one
+                                     * entry per cell in the
+                                     * triangulation underlying the
+                                     * @ref{DoFHandler} object (such
+                                     * as error per cell data). The
+                                     * value @p{type_automatic} tells
+                                     * @ref{add_data_vector} to find
+                                     * out itself (see the
+                                     * documentation of
+                                     * @p{add_data_vector} for the
+                                     * method used).
+                                     */
+    enum DataVectorType {
+         type_dof_data, type_cell_data, type_automatic
+    };
+    
                                     /**
                                      * Constructor
                                      */
@@ -202,7 +218,31 @@ class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
                                      * the number of active cells on
                                      * the present grid, in which
                                      * case it is assumed to be a
-                                     * cell data vector.
+                                     * cell data vector. As the
+                                     * number of degrees of freedom
+                                     * and of cells is usually not
+                                     * equal, the function can
+                                     * determine itself which type of
+                                     * vector it is given; however,
+                                     * there is one corner case,
+                                     * namely if you compute with
+                                     * piecewise constant elements
+                                     * and have one scalar quantity,
+                                     * then there are as many cells
+                                     * as there are degrees of
+                                     * freedom, but they may be
+                                     * ordered differently. In that
+                                     * case, you can change the last
+                                     * argument of the function from
+                                     * its default value
+                                     * @p{type_automatic} to either
+                                     * @p{type_dof_data} or @p{type_cell_data},
+                                     * depending on what the vector
+                                     * represents. Apart from this
+                                     * corner case, you can leave the
+                                     * argument at its default value
+                                     * and let the function determine
+                                     * the type of the vector itself.
                                      *
                                      * If it is a vector holding DoF
                                      * data, the names given shall be
@@ -227,7 +267,8 @@ class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
                                      * are valid and which are not.
                                      */
     void add_data_vector (const Vector<double>           &data,
-                         const std::vector<std::string> &names);
+                         const std::vector<std::string> &names,
+                         const DataVectorType            type = type_automatic);
 
                                     /**
                                      * This function is an
@@ -254,7 +295,8 @@ class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
                                      * each component to @p{name}
                                      */
     void add_data_vector (const Vector<double> &data,
-                         const std::string    &name);
+                         const std::string    &name,
+                         const DataVectorType  type = type_automatic);
 
                                     /**
                                      * Release the pointers to the
@@ -385,12 +427,6 @@ class DataOut_DoFData : public DataOutInterface<patch_dim,patch_space_dim>
                                          * data vector.
                                          */
        std::vector<std::string> names;
-       
-                                        /**
-                                         * Physical unit name of this
-                                         * component.
-                                         */
-       std::string   units;
     };
 
                                     /**
index 66ddf28414f9f73a989c4109bfeec26cf457f37a..76b0acfcf4c27ad134c943bfa285113e8050426c 100644 (file)
@@ -57,8 +57,7 @@ DataOut_DoFData<dof_handler_dim,patch_dim,patch_space_dim>::
 DataEntry::memory_consumption () const
 {
   return (sizeof (data) +
-         MemoryConsumption::memory_consumption (names) +
-         MemoryConsumption::memory_consumption (units));
+         MemoryConsumption::memory_consumption (names));
 };
 
 
@@ -100,8 +99,10 @@ attach_dof_handler (const DoFHandler<dof_handler_dim> &d)
 
 template <int dof_handler_dim, int patch_dim, int patch_space_dim>
 void
-DataOut_DoFData<dof_handler_dim,patch_dim,patch_space_dim>::add_data_vector (const Vector<double> &vec,
-                                                            const std::vector<std::string> &names)
+DataOut_DoFData<dof_handler_dim,patch_dim,patch_space_dim>::
+add_data_vector (const Vector<double>           &vec,
+                const std::vector<std::string> &names,
+                const DataVectorType            type)
 {
   Assert (dofs != 0, ExcNoDoFHandlerSelected ());
 
@@ -109,16 +110,46 @@ DataOut_DoFData<dof_handler_dim,patch_dim,patch_space_dim>::add_data_vector (con
                                   // vectors
   Assert ((vec.size() == dofs->get_tria().n_active_cells()) ||
          (vec.size() == dofs->n_dofs()),
-         ExcInvalidVectorSize(vec.size(), dofs->get_tria().n_active_cells(), dofs->n_dofs()));
+         ExcInvalidVectorSize(vec.size(), dofs->get_tria().n_active_cells(),
+                              dofs->n_dofs()));
   
                                   // either cell data and one name,
                                   // or dof data and n_components names
-  if (vec.size() == dofs->get_tria().n_active_cells())
-    Assert (names.size() == 1,
-           ExcInvalidNumberOfNames (names.size(), 1));
-  if (vec.size() == dofs->n_dofs())
-    Assert (names.size() == dofs->get_fe().n_components(),
-           ExcInvalidNumberOfNames (names.size(), dofs->get_fe().n_components()));
+  DataVectorType actual_type = type;
+  if (type == type_automatic)
+    {
+      if (vec.size() == dofs->get_tria().n_active_cells())
+       actual_type = type_cell_data;
+      else
+       actual_type = type_dof_data;
+    };
+  
+  switch (actual_type)
+    {
+      case type_cell_data:
+           Assert (vec.size() == dofs->get_tria().n_active_cells(),
+                   ExcInvalidVectorSize (vec.size(),
+                                         dofs->n_dofs(),
+                                         dofs->get_tria().n_active_cells()));
+           Assert (names.size() == 1,
+                   ExcInvalidNumberOfNames (names.size(), 1));
+           break;
+      
+      case type_dof_data:
+           Assert (vec.size() == dofs->n_dofs(),
+                   ExcInvalidVectorSize (vec.size(),
+                                         dofs->n_dofs(),
+                                         dofs->get_tria().n_active_cells()));
+           Assert (names.size() == dofs->get_fe().n_components(),
+                   ExcInvalidNumberOfNames (names.size(), dofs->get_fe().n_components()));
+           break;
+
+      case type_automatic:
+                                            // this case should have
+                                            // been handled above...
+           Assert (false, ExcInternalError());
+    };
+  
   for (unsigned int i=0; i<names.size(); ++i)
     Assert (names[i].find_first_not_of("abcdefghijklmnopqrstuvwxyz"
                                       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -126,23 +157,19 @@ DataOut_DoFData<dof_handler_dim,patch_dim,patch_space_dim>::add_data_vector (con
            ExcInvalidCharacter (names[i]));
   
   DataEntry new_entry (&vec, names);
-  if (vec.size() == dofs->n_dofs())
+  if (actual_type == type_dof_data)
     dof_data.push_back (new_entry);
   else
-    if (vec.size() == dofs->get_tria().n_active_cells())
-      cell_data.push_back (new_entry);
-    else
-      Assert (false,
-             ExcInvalidVectorSize (vec.size(),
-                                   dofs->n_dofs(),
-                                   dofs->get_tria().n_active_cells()));
+    cell_data.push_back (new_entry);
 };
 
 
 template <int dof_handler_dim, int patch_dim, int patch_space_dim>
 void
-DataOut_DoFData<dof_handler_dim,patch_dim,patch_space_dim>::add_data_vector (const Vector<double> &vec,
-                                                            const std::string         &name)
+DataOut_DoFData<dof_handler_dim,patch_dim,patch_space_dim>::
+add_data_vector (const Vector<double> &vec,
+                const std::string    &name,
+                const DataVectorType  type)
 {
   unsigned int n_components = dofs->get_fe().n_components ();
 
@@ -168,7 +195,7 @@ DataOut_DoFData<dof_handler_dim,patch_dim,patch_space_dim>::add_data_vector (con
        };
     };
   
-  add_data_vector (vec, names);
+  add_data_vector (vec, names, type);
 }
 
 
index 917b44fa2648c04af9776125f06380fbc5ba78d8..516d99eea2215b0c1070342a51d014c5cfeb3109 100644 (file)
@@ -315,6 +315,19 @@ documentation, etc</a>.
 <h3>deal.II</h3>
 
 <ol>
+  <li> <p>
+       New/fixed: In some obscure corner cases, the detection logic in <code
+       class="member">DataOut_DoFData::add_data_vector</code> would
+       not have been able to detect whether something is a DoF data
+       vector or a vector of cell data, and in some equally rare cases
+       this would also have made a difference. This is now fixed by
+       adding another argument to the function telling it either to
+       automatically detect the vector type (default) or to assume
+       that it has a certain type (for these corner cases).
+       <br>
+       (WB 2001/03/30)
+       </p>
+
   <li> <p>
        Removed: the <code class="class">ProblemBase</code> class,
        which has been deprecated since before the release of 

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.