]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Change second argument of the SolutionTransfer class to be a Vector type, not just...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 27 Aug 2008 18:09:59 +0000 (18:09 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 27 Aug 2008 18:09:59 +0000 (18:09 +0000)
git-svn-id: https://svn.dealii.org/trunk@16675 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/numerics/solution_transfer.h
deal.II/deal.II/source/numerics/solution_transfer.cc
deal.II/doc/news/changes.h
deal.II/examples/step-15/step-15.cc
deal.II/examples/step-28/step-28.cc
deal.II/examples/step-33/step-33.cc

index 1495bc5f3fb6bb1d8767f6a9afdd5e02d971c5f3..6a79ade8da66d6401a5707ab0ef167330806611d 100644 (file)
@@ -60,13 +60,7 @@ DEAL_II_NAMESPACE_OPEN
  * dof_handler->distribute_dofs (fe);
  * @endverbatim
  *
- * Then there are three different possibilities of how to proceed. Either
- * @verbatim
- *                                     // resize and interpolate a solution
- *                                     // vector `in-place'
- * soltrans.refine_interpolate(solution);
- * @endverbatim
- * or, when the old solution vector is still needed,
+ * Then to proceed do
  * @verbatim
  *                                     // take a copy of the solution vector
  * Vector<double> solution_old(solution);
@@ -89,6 +83,8 @@ DEAL_II_NAMESPACE_OPEN
  * vector<Vector<double> > solutions(n_vectors, Vector<double> (n));
  * soltrans.refine_interpolate(solutions_old, solutions);
  * @endverbatim
+ * This is used in several of the tutorial programs, for example
+ * @ref step_31 "step-31".
  *
  * <li> If the grid will be refined AND coarsened
  * then use @p SolutionTransfer as follows
@@ -151,7 +147,7 @@ DEAL_II_NAMESPACE_OPEN
  * interpolated and set into the vector @p out that is at the end the
  * discrete function @p in interpolated on the refined mesh.
  *
- * The <tt>refine_interpolate(in,out)</tt> function can be called multiply for
+ * The <tt>refine_interpolate(in,out)</tt> function can be called multiple times for
  * arbitrary many discrete functions (solution vectors) on the original grid. 
  *
  * <li> Solution transfer while coarsening and refinement. After 
@@ -202,7 +198,7 @@ DEAL_II_NAMESPACE_OPEN
  * @ingroup numerics
  * @author Ralf Hartmann, 1999
  */
-template<int dim, typename number, class DH=DoFHandler<dim> >
+template<int dim, typename VectorType=Vector<double>, class DH=DoFHandler<dim> >
 class SolutionTransfer
 {
   public:
@@ -246,14 +242,14 @@ class SolutionTransfer
                                      * onto the new (refined and/or
                                      * coarsenend) grid.
                                      */
-    void prepare_for_coarsening_and_refinement (const std::vector<Vector<number> > &all_in);
+    void prepare_for_coarsening_and_refinement (const std::vector<VectorType> &all_in);
     
                                     /**
                                      * Same as previous function
                                      * but for only one discrete function
                                      * to be interpolated.
                                      */
-    void prepare_for_coarsening_and_refinement (const Vector<number> &in);
+    void prepare_for_coarsening_and_refinement (const VectorType &in);
                      
                                     /**
                                      * This function
@@ -273,17 +269,8 @@ class SolutionTransfer
                                      * allowed. e.g. for interpolating several
                                      * functions.
                                      */
-    void refine_interpolate (const Vector<number> &in,
-                            Vector<number> &out) const;
-    
-                                    /**
-                                     * Same as <tt>interpolate(in,out)</tt>
-                                     * but it interpolates
-                                     * just 'in-place'. Therefore @p vec will be
-                                     * reinitialized to the new needed vector
-                                     * dimension.
-                                     */
-    void refine_interpolate (Vector<number> &vec) const;
+    void refine_interpolate (const VectorType &in,
+                            VectorType &out) const;
       
                                     /**
                                      * This function
@@ -319,8 +306,8 @@ class SolutionTransfer
                                      * (@p n_dofs_refined). Otherwise
                                      * an assertion will be thrown.
                                      */
-    void interpolate (const std::vector<Vector<number> >&all_in,
-                     std::vector<Vector<number> >      &all_out) const;
+    void interpolate (const std::vector<VectorType>&all_in,
+                     std::vector<VectorType>      &all_out) const;
       
                                     /**
                                      * Same as the previous function.
@@ -335,8 +322,8 @@ class SolutionTransfer
                                      * in one step by using
                                      * <tt>interpolate (all_in, all_out)</tt>
                                      */
-    void interpolate (const Vector<number> &in,
-                     Vector<number>       &out) const;
+    void interpolate (const VectorType &in,
+                     VectorType       &out) const;
 
                                     /**
                                      * Determine an estimate for the
@@ -456,7 +443,7 @@ class SolutionTransfer
        unsigned int memory_consumption () const;
        
        std::vector<unsigned int>    *indices_ptr;
-       std::vector<Vector<number> > *dof_values_ptr;
+       std::vector<Vector<typename VectorType::value_type> > *dof_values_ptr;
     };
 
                                     /**
@@ -477,7 +464,7 @@ class SolutionTransfer
                                      * of all cells that'll be coarsened
                                      * will be stored in this vector.
                                      */
-    std::vector<std::vector<Vector<number> > > dof_values_on_cell;
+    std::vector<std::vector<Vector<typename VectorType::value_type> > > dof_values_on_cell;
 };
 
 
index 8b71edda6e57c1985e64a002b5cffb2986261892..35660fb7e9b542a6840d35dedd7f00f050563539 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
+//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
 #include <grid/tria_iterator.h>
 #include <fe/fe.h>
 #include <lac/vector.h>
+#include <lac/petsc_vector.h>
+#include <lac/trilinos_vector.h>
+#include <lac/block_vector.h>
+#include <lac/petsc_block_vector.h>
+#include <lac/trilinos_block_vector.h>
 #include <numerics/solution_transfer.h>
 
 DEAL_II_NAMESPACE_OPEN
 
 
 
-template<int dim, typename number, class DH>
-SolutionTransfer<dim, number, DH>::SolutionTransfer(const DH &dof):
+template<int dim, typename VectorType, class DH>
+SolutionTransfer<dim, VectorType, DH>::SolutionTransfer(const DH &dof):
                dof_handler(&dof),
                n_dofs_old(0),
                prepared_for(none)
 {}
 
 
-template<int dim, typename number, class DH>
-SolutionTransfer<dim, number, DH>::~SolutionTransfer()
+template<int dim, typename VectorType, class DH>
+SolutionTransfer<dim, VectorType, DH>::~SolutionTransfer()
 {
   clear ();
 }
 
 
-template<int dim, typename number, class DH>
-SolutionTransfer<dim, number, DH>::Pointerstruct::Pointerstruct():
+template<int dim, typename VectorType, class DH>
+SolutionTransfer<dim, VectorType, DH>::Pointerstruct::Pointerstruct():
                indices_ptr(0),
                dof_values_ptr(0)
 {}
 
 
 
-template<int dim, typename number, class DH>
-void SolutionTransfer<dim, number, DH>::clear ()
+template<int dim, typename VectorType, class DH>
+void SolutionTransfer<dim, VectorType, DH>::clear ()
 {
   indices_on_cell.clear();
   dof_values_on_cell.clear();
@@ -60,8 +65,8 @@ void SolutionTransfer<dim, number, DH>::clear ()
 }
 
 
-template<int dim, typename number, class DH>
-void SolutionTransfer<dim, number, DH>::prepare_for_pure_refinement()
+template<int dim, typename VectorType, class DH>
+void SolutionTransfer<dim, VectorType, DH>::prepare_for_pure_refinement()
 { 
   Assert(prepared_for!=pure_refinement, ExcAlreadyPrepForRef());
   Assert(prepared_for!=coarsening_and_refinement, 
@@ -95,10 +100,10 @@ void SolutionTransfer<dim, number, DH>::prepare_for_pure_refinement()
 }
 
 
-template<int dim, typename number, class DH>  
+template<int dim, typename VectorType, class DH>  
 void
-SolutionTransfer<dim, number, DH>::refine_interpolate(const Vector<number> &in,
-                                                 Vector<number>       &out) const
+SolutionTransfer<dim, VectorType, DH>::refine_interpolate(const VectorType &in,
+                                                 VectorType       &out) const
 {
   Assert(prepared_for==pure_refinement, ExcNotPrepared());
   Assert(in.size()==n_dofs_old, ExcWrongVectorSize(in.size(),n_dofs_old));
@@ -108,7 +113,7 @@ SolutionTransfer<dim, number, DH>::refine_interpolate(const Vector<number> &in,
          ExcMessage ("Vectors cannot be used as input and output"
                      " at the same time!"));
 
-  Vector<number> local_values(0);
+  Vector<typename VectorType::value_type> local_values(0);
 
   typename DH::cell_iterator cell = dof_handler->begin(),
                             endc = dof_handler->end();
@@ -149,22 +154,10 @@ SolutionTransfer<dim, number, DH>::refine_interpolate(const Vector<number> &in,
 }
 
 
-template<int dim, typename number, class DH>  
-void SolutionTransfer<dim, number, DH>::refine_interpolate (Vector<number> &vec) const
-{
-  Assert(vec.size()==n_dofs_old, ExcWrongVectorSize(vec.size(),n_dofs_old));
-
-  Vector<number> vec_old(vec);
-  vec.reinit(dof_handler->n_dofs());
-  
-  refine_interpolate(vec_old, vec);
-}
-
-
-template<int dim, typename number, class DH>
+template<int dim, typename VectorType, class DH>
 void
-SolutionTransfer<dim, number, DH>::
-prepare_for_coarsening_and_refinement(const std::vector<Vector<number> > &all_in)
+SolutionTransfer<dim, VectorType, DH>::
+prepare_for_coarsening_and_refinement(const std::vector<VectorType> &all_in)
 {
   Assert(prepared_for!=pure_refinement, ExcAlreadyPrepForRef());
   Assert(!prepared_for!=coarsening_and_refinement, 
@@ -219,9 +212,9 @@ prepare_for_coarsening_and_refinement(const std::vector<Vector<number> > &all_in
     (n_cells_to_stay_or_refine)
     .swap(indices_on_cell);
   
-  std::vector<std::vector<Vector<number> > >
+  std::vector<std::vector<Vector<typename VectorType::value_type> > >
     (n_coarsen_fathers,
-     std::vector<Vector<number> > (in_size))
+     std::vector<Vector<typename VectorType::value_type> > (in_size))
     .swap(dof_values_on_cell);
   
                                   // we need counters for
@@ -246,14 +239,16 @@ prepare_for_coarsening_and_refinement(const std::vector<Vector<number> > &all_in
       else if (cell->has_children() && cell->child(0)->coarsen_flag_set())
        {
                                           // note that if one child has the
-                                          // coaresen flag, then all should
+                                          // coarsen flag, then all should
                                           // have if Tria::prepare_* has
                                           // worked correctly
          for (unsigned int i=1; i<cell->n_children(); ++i)
            Assert(cell->child(i)->coarsen_flag_set(),
                   ExcTriaPrepCoarseningNotCalledBefore());
          const unsigned int dofs_per_cell=cell->get_fe().dofs_per_cell;
-         std::vector<Vector<number> >(in_size, Vector<number>(dofs_per_cell))
+
+         std::vector<Vector<typename VectorType::value_type> >(in_size,
+                                                               Vector<typename VectorType::value_type>(dofs_per_cell))
            .swap(dof_values_on_cell[n_cf]);
       
          for (unsigned int j=0; j<in_size; ++j)
@@ -274,19 +269,19 @@ prepare_for_coarsening_and_refinement(const std::vector<Vector<number> > &all_in
 }
 
 
-template<int dim, typename number, class DH>
+template<int dim, typename VectorType, class DH>
 void
-SolutionTransfer<dim, number, DH>::prepare_for_coarsening_and_refinement(const Vector<number> &in)
+SolutionTransfer<dim, VectorType, DH>::prepare_for_coarsening_and_refinement(const VectorType &in)
 {
-  std::vector<Vector<number> > all_in=std::vector<Vector<number> >(1, in);
+  std::vector<VectorType> all_in=std::vector<VectorType>(1, in);
   prepare_for_coarsening_and_refinement(all_in);
 }
 
 
-template<int dim, typename number, class DH>
-void SolutionTransfer<dim, number, DH>::
-interpolate (const std::vector<Vector<number> > &all_in,
-            std::vector<Vector<number> >       &all_out) const
+template<int dim, typename VectorType, class DH>
+void SolutionTransfer<dim, VectorType, DH>::
+interpolate (const std::vector<VectorType> &all_in,
+            std::vector<VectorType>       &all_out) const
 {
   Assert(prepared_for==coarsening_and_refinement, ExcNotPrepared());
   const unsigned int size=all_in.size();
@@ -303,7 +298,7 @@ interpolate (const std::vector<Vector<number> > &all_in,
              ExcMessage ("Vectors cannot be used as input and output"
                          " at the same time!"));
 
-  Vector<number> local_values;
+  Vector<typename VectorType::value_type> local_values;
   std::vector<unsigned int> dofs;
 
   typename std::map<std::pair<unsigned int, unsigned int>, Pointerstruct>::const_iterator
@@ -321,7 +316,7 @@ interpolate (const std::vector<Vector<number> > &all_in,
          const std::vector<unsigned int> * const indexptr
            =pointerstruct->second.indices_ptr;
 
-         const std::vector<Vector<number> > * const valuesptr
+         const std::vector<Vector<typename VectorType::value_type> > * const valuesptr
            =pointerstruct->second.dof_values_ptr;
 
          const unsigned int dofs_per_cell=cell->get_fe().dofs_per_cell;
@@ -399,18 +394,18 @@ interpolate (const std::vector<Vector<number> > &all_in,
 
 
 
-template<int dim, typename number, class DH>
-void SolutionTransfer<dim, number, DH>::interpolate(const Vector<number> &in,
-                                               Vector<number>       &out) const
+template<int dim, typename VectorType, class DH>
+void SolutionTransfer<dim, VectorType, DH>::interpolate(const VectorType &in,
+                                               VectorType       &out) const
 {
   Assert (in.size()==n_dofs_old,
          ExcWrongVectorSize(in.size(), n_dofs_old));
   Assert (out.size()==dof_handler->n_dofs(),
          ExcWrongVectorSize(out.size(), dof_handler->n_dofs()));
 
-  std::vector<Vector<number> > all_in(1);
+  std::vector<VectorType> all_in(1);
   all_in[0] = in;
-  std::vector<Vector<number> > all_out(1);
+  std::vector<VectorType> all_out(1);
   all_out[0] = out;
   interpolate(all_in,
              all_out);
@@ -419,9 +414,9 @@ void SolutionTransfer<dim, number, DH>::interpolate(const Vector<number> &in,
 
 
 
-template<int dim, typename number, class DH>
+template<int dim, typename VectorType, class DH>
 unsigned int
-SolutionTransfer<dim, number, DH>::memory_consumption () const
+SolutionTransfer<dim, VectorType, DH>::memory_consumption () const
 {
                                   // at the moment we do not include the memory
                                   // consumption of the cell_map as we have no
@@ -436,19 +431,41 @@ SolutionTransfer<dim, number, DH>::memory_consumption () const
 
 
 
-template<int dim, typename number, class DH>
+template<int dim, typename VectorType, class DH>
 unsigned int
-SolutionTransfer<dim, number, DH>::Pointerstruct::memory_consumption () const
+SolutionTransfer<dim, VectorType, DH>::Pointerstruct::memory_consumption () const
 {
   return sizeof(*this);
 }
 
 
 
-template class SolutionTransfer<deal_II_dimension, float, DoFHandler<deal_II_dimension> >;
-template class SolutionTransfer<deal_II_dimension, double, DoFHandler<deal_II_dimension> >;
-template class SolutionTransfer<deal_II_dimension, float, hp::DoFHandler<deal_II_dimension> >;
-template class SolutionTransfer<deal_II_dimension, double, hp::DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, Vector<float>, DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, Vector<double>, DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, Vector<float>, hp::DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, Vector<double>, hp::DoFHandler<deal_II_dimension> >;
+
+template class SolutionTransfer<deal_II_dimension, BlockVector<float>, DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, BlockVector<double>, DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, BlockVector<float>, hp::DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, BlockVector<double>, hp::DoFHandler<deal_II_dimension> >;
+
+
+#ifdef DEAL_II_USE_PETSC
+template class SolutionTransfer<deal_II_dimension, PETScWrappers::Vector, DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, PETScWrappers::Vector, hp::DoFHandler<deal_II_dimension> >;
+
+template class SolutionTransfer<deal_II_dimension, PETScWrappers::BlockVector, DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, PETScWrappers::BlockVector, hp::DoFHandler<deal_II_dimension> >;
+#endif
+
+#ifdef DEAL_II_USE_TRILINOS
+template class SolutionTransfer<deal_II_dimension, TrilinosWrappers::Vector, DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, TrilinosWrappers::Vector, hp::DoFHandler<deal_II_dimension> >;
+
+template class SolutionTransfer<deal_II_dimension, TrilinosWrappers::BlockVector, DoFHandler<deal_II_dimension> >;
+template class SolutionTransfer<deal_II_dimension, TrilinosWrappers::BlockVector, hp::DoFHandler<deal_II_dimension> >;
+#endif
 
 /*----------------------------   solution_transfer.cc     ----------------------*/
 
index ee5bee6ff8e8efbf08ec38fd489574c9012eec06..ab6d9e7acb21b1e2d90a1f2f5522c4f58b8c33fc 100644 (file)
@@ -30,6 +30,22 @@ inconvenience this causes.
 </p>
 
 <ol>
+  <li>
+  <p> 
+  Changed: The SolutionTransfer class used to take a type as second
+  template argument that denoted the scalar upon which Vector objects
+  were built, in order to allow interpolating Vector@<float@> objects,
+  for example. This argument has now been changed to a vector type,
+  and been given a default of Vector@<double@>; however, one can
+  now also pass in BlockVector objects, or objects of type
+  PETScWrappers::Vector, etc. On the downside, the old
+  SolutionTransfer::refine_interpolate function with only a single
+  argument has been deleted since there is no reliable way to resize
+  a vector unless it is a plain Vector@<double@>.
+  <br>
+  (WB 2008/08/28)
+  </p>
+
   <li>
   <p> 
   Changed: The FiniteElement::get_prolongation_matrix and
@@ -43,7 +59,7 @@ inconvenience this causes.
   <br>
   (Tobias Leicht 2008/07/08 as of branch_anisotropic at 2006/07/04)
   </p>
-
+  
   <li>
   <p>
   Changed: <code>GeometryInfo::children_per_cell</code> has been
index 501d7973ea0ba80691d4401dd5030b8e1cb6b6c6..bfd33111b19e97a92ccc071664165c24943a5c06 100644 (file)
@@ -1171,7 +1171,7 @@ void MinimizationProblem<1>::refine_grid ()
                                    // a <code>SolutionTransfer</code> object with the
                                    // present <code>DoFHandler</code> and attach the
                                    // solution vector to it:
-  SolutionTransfer<dim,double> solution_transfer(dof_handler);
+  SolutionTransfer<dim> solution_transfer(dof_handler);
   solution_transfer.prepare_for_coarsening_and_refinement (present_solution);
 
                                    // Then we do the actual refinement, and
index c635cc6320567f2f3cb6cf2d5de8e9c39b0032eb..8fd821af2bf9f4281c0013ee88f6630057ed3b8e 100644 (file)
@@ -1468,7 +1468,7 @@ void EnergyGroup<dim>::refine_grid (const Vector<float> &error_indicators,
     else if (error_indicators(cell_index) < coarsen_threshold)
       cell->set_coarsen_flag ();
       
-  SolutionTransfer<dim, double> soltrans(dof_handler);
+  SolutionTransfer<dim> soltrans(dof_handler);
 
   triangulation.prepare_coarsening_and_refinement();
   soltrans.prepare_for_coarsening_and_refinement(solution);
index a2672f04a73b11bdd78cc855ac1acdc1fd7abecf..d3ba19b962bc28b06acfe9f97dc4f09bff65a148 100644 (file)
@@ -2879,16 +2879,19 @@ ConservationLaw<dim>::refine_grid (const Vector<double> &refinement_indicators)
          cell->set_coarsen_flag();
     }
 
-                                  // Then we need to transfer the various
-                                  // solution vectors from the old to the new
-                                  // grid and carries while we do the
-                                  // refinement. The SolutionTransfer class
-                                  // is our friend here; it has a fairly
-                                  // extensive documentation, including
-                                  // examples, so we won't comment much on
-                                  // the following code. The last three lines
-                                  // simply re-set the sizes of some other
-                                  // vectors to the now correct size:
+                                  // Then we need to transfer the
+                                  // various solution vectors from
+                                  // the old to the new grid while we
+                                  // do the refinement. The
+                                  // SolutionTransfer class is our
+                                  // friend here; it has a fairly
+                                  // extensive documentation,
+                                  // including examples, so we won't
+                                  // comment much on the following
+                                  // code. The last three lines
+                                  // simply re-set the sizes of some
+                                  // other vectors to the now correct
+                                  // size:
   std::vector<Vector<double> > transfer_in;
   std::vector<Vector<double> > transfer_out;
 
@@ -2897,7 +2900,7 @@ ConservationLaw<dim>::refine_grid (const Vector<double> &refinement_indicators)
 
   triangulation.prepare_coarsening_and_refinement();
 
-  SolutionTransfer<dim, double> soltrans(dof_handler);
+  SolutionTransfer<dim> soltrans(dof_handler);
   soltrans.prepare_for_coarsening_and_refinement(transfer_in);
 
   triangulation.execute_coarsening_and_refinement ();

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.