From c7054e7544119ce45cf939614fb579325e3e19cf Mon Sep 17 00:00:00 2001 From: hartmann Date: Fri, 24 Oct 2003 09:18:33 +0000 Subject: [PATCH] Check for right sizes of in and output vectors. git-svn-id: https://svn.dealii.org/trunk@8153 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/numerics/solution_transfer.h | 85 +++++++++++++++---- .../source/numerics/solution_transfer.cc | 33 ++++--- 2 files changed, 82 insertions(+), 36 deletions(-) diff --git a/deal.II/deal.II/include/numerics/solution_transfer.h b/deal.II/deal.II/include/numerics/solution_transfer.h index 2d43a7c169..a6510d86f8 100644 --- a/deal.II/deal.II/include/numerics/solution_transfer.h +++ b/deal.II/deal.II/include/numerics/solution_transfer.h @@ -43,28 +43,71 @@ * (i.e. not locally coarsened) then use @p{SolutionTransfer} as follows * @begin{verbatim} * SolutionTransfer soltrans(*dof_handler); + * // flag some cells for refinement, e.g. + * GridRefinement::refine_and_coarsen_fixed_fraction( + * *tria, error_indicators, 0.3, 0); + * // prepare the triangulation + * // for refinement, + * tria->prepare_coarsening_and_refinement(); + * // tell the SolutionTransfer object + * // that we intent to do pure refinement, * soltrans.prepare_for_pure_refinement(); - * // some refinement e.g. - * tria->refine_and_coarsen_fixed_fraction(error_indicator, 0.3, 0); + * // actually execute the refinement, * tria->execute_coarsening_and_refinement(); + * // and redistribute dofs. * dof_handler->distribute_dofs (fe); - * soltrans.refine_interpolate(solution, interpolated_solution); - * // if necessary interpolate some - * // more functions - * soltrans.refine_interpolate(sol2, interpolated_sol2); + * @end{verbatim} + * + * Then there are three different possibilities of how to proceed. Either + * @begin{verbatim} + * // resize and interpolate a solution + * // vector `in-place' + * soltrans.refine_interpolate(solution); + * @end{verbatim} + * or, when the old solution vector is still needed, + * @begin{verbatim} + * // take a copy of the solution vector + * Vector solution_old(solution); + * // resize solution vector to the correct + * // size, as the @p{refine_interpolate} + * // function requires the vectors to be + * // of right sizes + * solution.reinit(dof_handler->n_dofs()); + * // and finally interpolate + * soltrans.refine_interpolate(solution_old, solution); + * @end{verbatim} + * + * Although the @p{refine_interpolate} functions are allowed to be + * called multiple times, e.g. for interpolating several solution + * vectors, there is following possibility of interpolating several + * functions simultaneously. + * @begin{verbatim} + * vector > solutions_old(n_vectors, Vector (n)); * ... + * vector > solutions(n_vectors, Vector (n)); + * soltrans.refine_interpolate(solutions_old, solutions); * @end{verbatim} - * @item If the grid will be coarsenend and refined + * @item If the grid will be refined AND coarsened * then use @p{SolutionTransfer} as follows * @begin{verbatim} * SolutionTransfer soltrans(*dof_handler); - * // some refinement e.g. - * tria->refine_and_coarsen_fixed_fraction(error_indicator, 0.3, 0.05); - * // very important: + * // flag some cells for refinement + * // and coarsening, e.g. + * GridRefinement::refine_and_coarsen_fixed_fraction( + * *tria, error_indicators, 0.3, 0.05); + * // prepare the triangulation, * tria->prepare_coarsening_and_refinement(); + * // prepare the SolutionTransfer object + * // for coarsening and refinement and give + * // the solution vector that we intent to + * // interpolate later, * soltrans.prepare_for_coarsening_and_refinement(solution); + * // actually execute the refinement, * tria->execute_coarsening_and_refinement (); + * // redistribute dofs, * dof_handler->distribute_dofs (fe); + * // and interpolate the solution + * Vector interpolate_solution(dof_handler->n_dofs()); * soltrans.interpolate(solution, interpolated_solution); * @end{verbatim} * @@ -109,7 +152,7 @@ * interpolated and set into the vector @p{out} that is at the end the * discrete function @p{in} interpolated on the refined mesh. * - * The @p{refine_interpolate(in,out)} function can be called multiplely for + * The @p{refine_interpolate(in,out)} function can be called multiply for * arbitrary many discrete functions (solution vectors) on the original grid. * * @item Solution transfer while coarsening and refinement. After @@ -267,11 +310,14 @@ class SolutionTransfer * several functions can be * performed in one step. * - * If the number of output - * vectors is different from the - * number of input vectors, or if - * their sizes are not correct, - * then this is corrected. + * The number of output vectors + * is assumed to be the same as + * the number of input + * vectors. Also, the sizes of + * the output vectors are assumed + * to be of the right size + * (@p{n_dofs_refined}). Otherwise + * an assertion will be thrown. */ void interpolate (const std::vector >&all_in, std::vector > &all_out) const; @@ -279,12 +325,15 @@ class SolutionTransfer /** * Same as the previous function. * It interpolates only one function. + * It assumes the vectors having the + * right sizes (i.e. @p{in.size()==n_dofs_old}, + * @p{out.size()==n_dofs_refined}) * * Multiple calling of this function is * NOT allowed. Interpolating * several functions can be performed * in one step by using - * @p{interpolate (all_out)} + * @p{interpolate (all_in, all_out)} */ void interpolate (const Vector &in, Vector &out) const; @@ -332,7 +381,7 @@ class SolutionTransfer DeclException2(ExcWrongVectorSize, int, int, << "The size of the vector is " << arg1 - << "although it should be " << arg2 << "."); + << " although it should be " << arg2 << "."); private: diff --git a/deal.II/deal.II/source/numerics/solution_transfer.cc b/deal.II/deal.II/source/numerics/solution_transfer.cc index 99b15d2f9a..e5bb7b4714 100644 --- a/deal.II/deal.II/source/numerics/solution_transfer.cc +++ b/deal.II/deal.II/source/numerics/solution_transfer.cc @@ -282,24 +282,16 @@ interpolate (const std::vector > &all_in, std::vector > &all_out) const { Assert(prepared_for==coarsening_and_refinement, ExcNotPrepared()); - for (unsigned int i=0; i(dof_handler->n_dofs())); - else - for (unsigned int i=0; in_dofs()) - all_out[i].reinit (dof_handler->n_dofs()); - - for (unsigned int i=0; in_dofs(), + ExcWrongVectorSize(all_out[i].size(), dof_handler->n_dofs())); + for (unsigned int i=0; i > &all_in, // data vectors on this // cell and prolong it // to its children - for (unsigned int j=0; joperator[](i)); @@ -358,7 +350,7 @@ interpolate (const std::vector > &all_in, // distribute the // stored data to the // new vectors - for (unsigned int j=0; joperator[](j)(i); } @@ -375,6 +367,11 @@ template void SolutionTransfer::interpolate(const Vector &in, Vector &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); all_in[0] = in; std::vector > all_out(1); -- 2.39.5