From 320853694cc1b85143c1598c18a7d02796333206 Mon Sep 17 00:00:00 2001 From: bangerth Date: Wed, 27 Aug 2008 18:09:59 +0000 Subject: [PATCH] Change second argument of the SolutionTransfer class to be a Vector type, not just a scalar. git-svn-id: https://svn.dealii.org/trunk@16675 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/numerics/solution_transfer.h | 43 ++---- .../source/numerics/solution_transfer.cc | 129 ++++++++++-------- deal.II/doc/news/changes.h | 18 ++- deal.II/examples/step-15/step-15.cc | 2 +- deal.II/examples/step-28/step-28.cc | 2 +- deal.II/examples/step-33/step-33.cc | 25 ++-- 6 files changed, 121 insertions(+), 98 deletions(-) diff --git a/deal.II/deal.II/include/numerics/solution_transfer.h b/deal.II/deal.II/include/numerics/solution_transfer.h index 1495bc5f3f..6a79ade8da 100644 --- a/deal.II/deal.II/include/numerics/solution_transfer.h +++ b/deal.II/deal.II/include/numerics/solution_transfer.h @@ -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 solution_old(solution); @@ -89,6 +83,8 @@ DEAL_II_NAMESPACE_OPEN * vector > solutions(n_vectors, Vector (n)); * soltrans.refine_interpolate(solutions_old, solutions); * @endverbatim + * This is used in several of the tutorial programs, for example + * @ref step_31 "step-31". * *
  • 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 refine_interpolate(in,out) function can be called multiply for + * The refine_interpolate(in,out) function can be called multiple times for * arbitrary many discrete functions (solution vectors) on the original grid. * *
  • Solution transfer while coarsening and refinement. After @@ -202,7 +198,7 @@ DEAL_II_NAMESPACE_OPEN * @ingroup numerics * @author Ralf Hartmann, 1999 */ -template > +template, class DH=DoFHandler > 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 > &all_in); + void prepare_for_coarsening_and_refinement (const std::vector &all_in); /** * Same as previous function * but for only one discrete function * to be interpolated. */ - void prepare_for_coarsening_and_refinement (const Vector &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 &in, - Vector &out) const; - - /** - * Same as interpolate(in,out) - * but it interpolates - * just 'in-place'. Therefore @p vec will be - * reinitialized to the new needed vector - * dimension. - */ - void refine_interpolate (Vector &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 >&all_in, - std::vector > &all_out) const; + void interpolate (const std::vector&all_in, + std::vector &all_out) const; /** * Same as the previous function. @@ -335,8 +322,8 @@ class SolutionTransfer * in one step by using * interpolate (all_in, all_out) */ - void interpolate (const Vector &in, - Vector &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 *indices_ptr; - std::vector > *dof_values_ptr; + std::vector > *dof_values_ptr; }; /** @@ -477,7 +464,7 @@ class SolutionTransfer * of all cells that'll be coarsened * will be stored in this vector. */ - std::vector > > dof_values_on_cell; + std::vector > > dof_values_on_cell; }; diff --git a/deal.II/deal.II/source/numerics/solution_transfer.cc b/deal.II/deal.II/source/numerics/solution_transfer.cc index 8b71edda6e..35660fb7e9 100644 --- a/deal.II/deal.II/source/numerics/solution_transfer.cc +++ b/deal.II/deal.II/source/numerics/solution_transfer.cc @@ -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 @@ -20,37 +20,42 @@ #include #include #include +#include +#include +#include +#include +#include #include DEAL_II_NAMESPACE_OPEN -template -SolutionTransfer::SolutionTransfer(const DH &dof): +template +SolutionTransfer::SolutionTransfer(const DH &dof): dof_handler(&dof), n_dofs_old(0), prepared_for(none) {} -template -SolutionTransfer::~SolutionTransfer() +template +SolutionTransfer::~SolutionTransfer() { clear (); } -template -SolutionTransfer::Pointerstruct::Pointerstruct(): +template +SolutionTransfer::Pointerstruct::Pointerstruct(): indices_ptr(0), dof_values_ptr(0) {} -template -void SolutionTransfer::clear () +template +void SolutionTransfer::clear () { indices_on_cell.clear(); dof_values_on_cell.clear(); @@ -60,8 +65,8 @@ void SolutionTransfer::clear () } -template -void SolutionTransfer::prepare_for_pure_refinement() +template +void SolutionTransfer::prepare_for_pure_refinement() { Assert(prepared_for!=pure_refinement, ExcAlreadyPrepForRef()); Assert(prepared_for!=coarsening_and_refinement, @@ -95,10 +100,10 @@ void SolutionTransfer::prepare_for_pure_refinement() } -template +template void -SolutionTransfer::refine_interpolate(const Vector &in, - Vector &out) const +SolutionTransfer::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::refine_interpolate(const Vector &in, ExcMessage ("Vectors cannot be used as input and output" " at the same time!")); - Vector local_values(0); + Vector local_values(0); typename DH::cell_iterator cell = dof_handler->begin(), endc = dof_handler->end(); @@ -149,22 +154,10 @@ SolutionTransfer::refine_interpolate(const Vector &in, } -template -void SolutionTransfer::refine_interpolate (Vector &vec) const -{ - Assert(vec.size()==n_dofs_old, ExcWrongVectorSize(vec.size(),n_dofs_old)); - - Vector vec_old(vec); - vec.reinit(dof_handler->n_dofs()); - - refine_interpolate(vec_old, vec); -} - - -template +template void -SolutionTransfer:: -prepare_for_coarsening_and_refinement(const std::vector > &all_in) +SolutionTransfer:: +prepare_for_coarsening_and_refinement(const std::vector &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 > &all_in (n_cells_to_stay_or_refine) .swap(indices_on_cell); - std::vector > > + std::vector > > (n_coarsen_fathers, - std::vector > (in_size)) + std::vector > (in_size)) .swap(dof_values_on_cell); // we need counters for @@ -246,14 +239,16 @@ prepare_for_coarsening_and_refinement(const std::vector > &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; in_children(); ++i) Assert(cell->child(i)->coarsen_flag_set(), ExcTriaPrepCoarseningNotCalledBefore()); const unsigned int dofs_per_cell=cell->get_fe().dofs_per_cell; - std::vector >(in_size, Vector(dofs_per_cell)) + + std::vector >(in_size, + Vector(dofs_per_cell)) .swap(dof_values_on_cell[n_cf]); for (unsigned int j=0; j > &all_in } -template +template void -SolutionTransfer::prepare_for_coarsening_and_refinement(const Vector &in) +SolutionTransfer::prepare_for_coarsening_and_refinement(const VectorType &in) { - std::vector > all_in=std::vector >(1, in); + std::vector all_in=std::vector(1, in); prepare_for_coarsening_and_refinement(all_in); } -template -void SolutionTransfer:: -interpolate (const std::vector > &all_in, - std::vector > &all_out) const +template +void SolutionTransfer:: +interpolate (const std::vector &all_in, + std::vector &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 > &all_in, ExcMessage ("Vectors cannot be used as input and output" " at the same time!")); - Vector local_values; + Vector local_values; std::vector dofs; typename std::map, Pointerstruct>::const_iterator @@ -321,7 +316,7 @@ interpolate (const std::vector > &all_in, const std::vector * const indexptr =pointerstruct->second.indices_ptr; - const std::vector > * const valuesptr + const std::vector > * 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 > &all_in, -template -void SolutionTransfer::interpolate(const Vector &in, - Vector &out) const +template +void SolutionTransfer::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 > all_in(1); + std::vector all_in(1); all_in[0] = in; - std::vector > all_out(1); + std::vector all_out(1); all_out[0] = out; interpolate(all_in, all_out); @@ -419,9 +414,9 @@ void SolutionTransfer::interpolate(const Vector &in, -template +template unsigned int -SolutionTransfer::memory_consumption () const +SolutionTransfer::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::memory_consumption () const -template +template unsigned int -SolutionTransfer::Pointerstruct::memory_consumption () const +SolutionTransfer::Pointerstruct::memory_consumption () const { return sizeof(*this); } -template class SolutionTransfer >; -template class SolutionTransfer >; -template class SolutionTransfer >; -template class SolutionTransfer >; +template class SolutionTransfer, DoFHandler >; +template class SolutionTransfer, DoFHandler >; +template class SolutionTransfer, hp::DoFHandler >; +template class SolutionTransfer, hp::DoFHandler >; + +template class SolutionTransfer, DoFHandler >; +template class SolutionTransfer, DoFHandler >; +template class SolutionTransfer, hp::DoFHandler >; +template class SolutionTransfer, hp::DoFHandler >; + + +#ifdef DEAL_II_USE_PETSC +template class SolutionTransfer >; +template class SolutionTransfer >; + +template class SolutionTransfer >; +template class SolutionTransfer >; +#endif + +#ifdef DEAL_II_USE_TRILINOS +template class SolutionTransfer >; +template class SolutionTransfer >; + +template class SolutionTransfer >; +template class SolutionTransfer >; +#endif /*---------------------------- solution_transfer.cc ----------------------*/ diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index ee5bee6ff8..ab6d9e7acb 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -30,6 +30,22 @@ inconvenience this causes.

      +
    1. +

      + 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@ objects, + for example. This argument has now been changed to a vector type, + and been given a default of Vector@; 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@. +
      + (WB 2008/08/28) +

      +
    2. Changed: The FiniteElement::get_prolongation_matrix and @@ -43,7 +59,7 @@ inconvenience this causes.
      (Tobias Leicht 2008/07/08 as of branch_anisotropic at 2006/07/04)

      - +
    3. Changed: GeometryInfo::children_per_cell has been diff --git a/deal.II/examples/step-15/step-15.cc b/deal.II/examples/step-15/step-15.cc index 501d7973ea..bfd33111b1 100644 --- a/deal.II/examples/step-15/step-15.cc +++ b/deal.II/examples/step-15/step-15.cc @@ -1171,7 +1171,7 @@ void MinimizationProblem<1>::refine_grid () // a SolutionTransfer object with the // present DoFHandler and attach the // solution vector to it: - SolutionTransfer solution_transfer(dof_handler); + SolutionTransfer solution_transfer(dof_handler); solution_transfer.prepare_for_coarsening_and_refinement (present_solution); // Then we do the actual refinement, and diff --git a/deal.II/examples/step-28/step-28.cc b/deal.II/examples/step-28/step-28.cc index c635cc6320..8fd821af2b 100644 --- a/deal.II/examples/step-28/step-28.cc +++ b/deal.II/examples/step-28/step-28.cc @@ -1468,7 +1468,7 @@ void EnergyGroup::refine_grid (const Vector &error_indicators, else if (error_indicators(cell_index) < coarsen_threshold) cell->set_coarsen_flag (); - SolutionTransfer soltrans(dof_handler); + SolutionTransfer soltrans(dof_handler); triangulation.prepare_coarsening_and_refinement(); soltrans.prepare_for_coarsening_and_refinement(solution); diff --git a/deal.II/examples/step-33/step-33.cc b/deal.II/examples/step-33/step-33.cc index a2672f04a7..d3ba19b962 100644 --- a/deal.II/examples/step-33/step-33.cc +++ b/deal.II/examples/step-33/step-33.cc @@ -2879,16 +2879,19 @@ ConservationLaw::refine_grid (const Vector &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 > transfer_in; std::vector > transfer_out; @@ -2897,7 +2900,7 @@ ConservationLaw::refine_grid (const Vector &refinement_indicators) triangulation.prepare_coarsening_and_refinement(); - SolutionTransfer soltrans(dof_handler); + SolutionTransfer soltrans(dof_handler); soltrans.prepare_for_coarsening_and_refinement(transfer_in); triangulation.execute_coarsening_and_refinement (); -- 2.39.5