From 02098efac96e492c71f0007a8f00fc4f3a50cf88 Mon Sep 17 00:00:00 2001 From: Tobias Leicht Date: Tue, 18 Mar 2008 10:34:21 +0000 Subject: [PATCH] Add a test for SolutionTransfer. git-svn-id: https://svn.dealii.org/trunk@15902 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/bits/Makefile | 3 +- tests/bits/solution_transfer.cc | 189 ++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 tests/bits/solution_transfer.cc diff --git a/tests/bits/Makefile b/tests/bits/Makefile index 7aa33fc36b..bd588a4c38 100644 --- a/tests/bits/Makefile +++ b/tests/bits/Makefile @@ -95,7 +95,8 @@ tests_x = grid_generator_?? \ face_orientation_* \ max_n_cells_* \ joa_* \ - neighboring_cells_at_two_faces + neighboring_cells_at_two_faces \ + solution_transfer # tests for the hp branch: # fe_collection_* diff --git a/tests/bits/solution_transfer.cc b/tests/bits/solution_transfer.cc new file mode 100644 index 0000000000..0cbdf0933c --- /dev/null +++ b/tests/bits/solution_transfer.cc @@ -0,0 +1,189 @@ +//---------------------------- solution_transfer.cc --------------------------- +// fe_data_test.cc,v 1.14 2003/11/28 11:52:35 guido Exp +// Version: +// +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007 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. +// +//---------------------------- solution_transfer.cc --------------------------- + + +#include "../tests.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +template +class MyFunction : public Function +{ + public: + MyFunction () : Function() {}; + + virtual double value (const Point &p, + const unsigned int) const + { double f=sin(p[0]*4); + if (dim>1) + f*=cos(p[1]*4); + if (dim>2) + f*=exp(p[2]*4); + return f; + }; +}; + + +template +void transfer(std::ostream &out) +{ + MyFunction function; + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(5-dim); + FE_Q fe_q(1); + FE_DGQ fe_dgq(1); + DoFHandler q_dof_handler(tria); + DoFHandler dgq_dof_handler(tria); + Vector q_solution; + Vector dgq_solution; + MappingQ1 mapping; + DataOut q_data_out, dgq_data_out; + ConstraintMatrix cm; + cm.close(); + + q_dof_handler.distribute_dofs (fe_q); + q_solution.reinit(q_dof_handler.n_dofs()); + + dgq_dof_handler.distribute_dofs (fe_dgq); + dgq_solution.reinit(dgq_dof_handler.n_dofs()); + + VectorTools::interpolate (mapping, q_dof_handler, function, q_solution); + VectorTools::project (mapping, dgq_dof_handler, cm, + QGauss(3), function, dgq_solution); + + q_data_out.attach_dof_handler (q_dof_handler); + q_data_out.add_data_vector (q_solution, "solution"); + q_data_out.build_patches (); + deallog << "Initial solution, FE_Q" << std::endl << std::endl; + q_data_out.write_gnuplot (out); + + dgq_data_out.attach_dof_handler (dgq_dof_handler); + dgq_data_out.add_data_vector (dgq_solution, "solution"); + dgq_data_out.build_patches (); + deallog << "Initial solution, FE_DGQ" << std::endl << std::endl; + dgq_data_out.write_gnuplot (out); + + SolutionTransfer q_soltrans(q_dof_handler); + SolutionTransfer dgq_soltrans(dgq_dof_handler); + + // test a): pure refinement + typename Triangulation::active_cell_iterator cell=tria.begin_active(), + endc=tria.end(); + ++cell; + ++cell; + for (; cell!=endc; ++cell) + cell->set_refine_flag(); + + tria.prepare_coarsening_and_refinement(); + q_soltrans.prepare_for_pure_refinement(); + dgq_soltrans.prepare_for_pure_refinement(); + tria.execute_coarsening_and_refinement(); + q_dof_handler.distribute_dofs (fe_q); + dgq_dof_handler.distribute_dofs (fe_dgq); + + q_soltrans.refine_interpolate(q_solution); + dgq_soltrans.refine_interpolate(dgq_solution); + + q_data_out.clear_data_vectors(); + q_data_out.add_data_vector (q_solution, "solution"); + q_data_out.build_patches (); + deallog << "Interpolated/tranferred solution after pure refinement, FE_Q" + << std::endl << std::endl; + q_data_out.write_gnuplot (out); + + dgq_data_out.clear_data_vectors(); + dgq_data_out.add_data_vector (dgq_solution, "solution"); + dgq_data_out.build_patches (); + deallog << "Interpolated/tranferred solution after pure refinement, FE_DGQ" + << std::endl << std::endl; + dgq_data_out.write_gnuplot (out); + + // test b): with coarsening + q_soltrans.clear(); + dgq_soltrans.clear(); + + cell=tria.begin_active(tria.n_levels()-1); + endc=tria.end(tria.n_levels()-1); + cell->set_refine_flag(); + ++cell; + for (; cell!=endc; ++cell) + cell->set_coarsen_flag(); + Vector q_old_solution=q_solution, + dgq_old_solution=dgq_solution; + tria.prepare_coarsening_and_refinement(); + q_soltrans.prepare_for_coarsening_and_refinement(q_old_solution); + dgq_soltrans.prepare_for_coarsening_and_refinement(dgq_old_solution); + tria.execute_coarsening_and_refinement(); + q_dof_handler.distribute_dofs (fe_q); + dgq_dof_handler.distribute_dofs (fe_dgq); + q_solution.reinit(q_dof_handler.n_dofs()); + dgq_solution.reinit(dgq_dof_handler.n_dofs()); + q_soltrans.interpolate(q_old_solution, q_solution); + dgq_soltrans.interpolate(dgq_old_solution, dgq_solution); + + q_data_out.clear_data_vectors(); + q_data_out.add_data_vector (q_solution, "solution"); + q_data_out.build_patches (); + deallog << "Interpolated/tranferred solution after coarsening and refinement, FE_Q" + << std::endl << std::endl; + q_data_out.write_gnuplot (out); + + dgq_data_out.clear_data_vectors(); + dgq_data_out.add_data_vector (dgq_solution, "solution"); + dgq_data_out.build_patches (); + deallog << "Interpolated/tranferred solution after coarsening and refinement, FE_DGQ" + << std::endl << std::endl; + dgq_data_out.write_gnuplot (out); +} + + +int main() +{ + std::ofstream logfile("solution_transfer/output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + deallog << " 1D solution transfer" << std::endl; + transfer<1>(logfile); + + deallog << " 2D solution transfer" << std::endl; + transfer<2>(logfile); + + deallog << " 3D solution transfer" << std::endl; + transfer<3>(logfile); +} + + + -- 2.39.5