]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Disallow assignment of DoF accessors.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 13 Nov 2010 00:51:14 +0000 (00:51 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 13 Nov 2010 00:51:14 +0000 (00:51 +0000)
git-svn-id: https://svn.dealii.org/trunk@22712 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/dofs/dof_accessor.h
deal.II/include/deal.II/dofs/dof_accessor.templates.h
tests/deal.II/dof_accessor_01.cc [new file with mode: 0644]
tests/deal.II/dof_accessor_01/cmp/generic [new file with mode: 0644]

index a6ec3164fef8d5dd289f30861197677634c4382a..371e5af56d981a17444ac7b787aa7467d1fee529 100644 (file)
@@ -347,6 +347,16 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
 <h3>deal.II</h3>
 
 <ol>
+  <li><p>Fixed: For DoF iterators, it was previously possible to write
+  code like <code>*it1 = *it2</code>, presumably with the intent to
+  copy the entire cell pointed to on the right hand side onto the cell
+  pointed to at the left. However, this is not what happens since
+  iterators are not pointers but only point to accessor classes. The
+  assignment operator has therefore been removed.
+  <br>
+  (WB, 2010/11/12)
+  </p></li>
+
   <li><p>New: There is now a class TriaAccessor<0,1,spacedim> that allows
   to write things like
   @code
index ba7b68c90cff92cec257a6977955f082d7d3ffa5..4827e71b32f76c3b9251cd774f7fe53060ea3ffa 100644 (file)
@@ -270,12 +270,6 @@ class DoFAccessor : public internal::DoFAccessor::Inheritance<structdim, DH::dim
     const DH &
     get_dof_handler () const;
 
-                                    /**
-                                     * Copy operator.
-                                     */
-    DoFAccessor<structdim,DH> &
-    operator = (const DoFAccessor<structdim,DH> &da);
-
                                     /**
                                      * Implement the copy operator needed
                                      * for the iterator classes.
@@ -726,6 +720,27 @@ class DoFAccessor : public internal::DoFAccessor::Inheritance<structdim, DH::dim
     template <typename> friend class TriaRawIterator;
 
 
+  private:
+                                    /**
+                                     *  Copy operator. This is normally used
+                                     *  in a context like <tt>iterator a,b;
+                                     *  *a=*b;</tt>. Presumably, the intent
+                                     *  here is to copy the object pointed to
+                                     *  by @p b to the object pointed to by
+                                     *  @p a. However, the result of
+                                     *  dereferencing an iterator is not an
+                                     *  object but an accessor; consequently,
+                                     *  this operation is not useful for
+                                     *  iterators on triangulations. We
+                                     *  declare this function here private,
+                                     *  thus it may not be used from outside.
+                                     *  Furthermore it is not implemented and
+                                     *  will give a linker error if used
+                                     *  anyway.
+                                     */
+    DoFAccessor<structdim,DH> &
+    operator = (const DoFAccessor<structdim,DH> &da);
+
                                     /**
                                      * Make the DoFHandler class a friend so
                                      * that it can call the set_xxx()
index 7c0b4244b411fd45b12226377a631f2074c520e5..ec9e7a713c1315089af981496328b3813d4a9424 100644 (file)
@@ -97,18 +97,6 @@ DoFAccessor<structdim,DH>::get_dof_handler () const
 }
 
 
-//TODO: This seems to set only the DH, not the other data.
-
-template <int structdim, class DH>
-inline
-DoFAccessor<structdim,DH> &
-DoFAccessor<structdim,DH>::operator = (const DoFAccessor<structdim,DH> &da)
-{
-  this->set_dof_handler (da.dof_handler);
-  return *this;
-}
-
-
 
 template <int structdim, class DH>
 inline
diff --git a/tests/deal.II/dof_accessor_01.cc b/tests/deal.II/dof_accessor_01.cc
new file mode 100644 (file)
index 0000000..5b38de4
--- /dev/null
@@ -0,0 +1,73 @@
+//----------------------------  dof_accessor_01.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2010 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.
+//
+//----------------------------  dof_accessor_01.cc  ---------------------------
+
+// verify that iterators can be copied. when you just copy the
+// iterator itself, everything is alright: the copy operator of the
+// iterator calls Accessor::copy_from.
+//
+// the test was originally written because at that time it was
+// possible to do something like *it1 = *it2 for DoF iterators --
+// likely not what the author intended since it does not copy the
+// cell2 into the cell1, only the accessor. furthermore, the operator=
+// was wrongly implemented, so it was removed in the process
+
+
+#include "../tests.h"
+#include <grid/tria.h>
+#include <grid/tria_iterator.h>
+#include <grid/tria_accessor.h>
+#include <grid/grid_generator.h>
+
+#include <fe/fe_system.h>
+#include <fe/fe_q.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_accessor.h>
+
+#include <fstream>
+
+
+template <int dim>
+void test ()
+{
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube (tria);
+  tria.refine_global (2);
+
+  FE_Q<dim> fe(1);
+  DoFHandler<dim> dof_handler (tria);
+  dof_handler.distribute_dofs (fe);
+
+  typename DoFHandler<dim>::active_cell_iterator
+    cell = dof_handler.begin_active();
+  ++cell;
+
+  typename DoFHandler<dim>::face_iterator
+    face = dof_handler.begin_active()->face(0);
+  face = cell->face(0);
+  deallog << cell->face(0) << ' ' << face << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("dof_accessor_01/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  test<1> ();
+  test<2> ();
+  test<3> ();
+
+  return 0;
+}
diff --git a/tests/deal.II/dof_accessor_01/cmp/generic b/tests/deal.II/dof_accessor_01/cmp/generic
new file mode 100644 (file)
index 0000000..0c55aa3
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::-1 -1
+DEAL::40 40
+DEAL::281 281

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.