From ae6b9c5f89d0204b8af97f4ee93710a6eb254b8e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 25 Jul 2005 20:39:15 +0000 Subject: [PATCH] new tests. git-svn-id: https://svn.dealii.org/trunk@11199 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/bits/Makefile | 3 +- tests/bits/christian_1.cc | 192 ++++++++++++++++++++++++++++++++++++++ tests/bits/christian_2.cc | 54 +++++++++++ 3 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 tests/bits/christian_1.cc create mode 100644 tests/bits/christian_2.cc diff --git a/tests/bits/Makefile b/tests/bits/Makefile index a258b02eca..86cbc8c7f4 100644 --- a/tests/bits/Makefile +++ b/tests/bits/Makefile @@ -68,7 +68,8 @@ tests_x = geometry_info_* \ fe_q_3d* \ rt_* \ nedelec_* \ - get_fe_from_name + get_fe_from_name \ + christian_* # tests for the hp branch: # fe_collection_* diff --git a/tests/bits/christian_1.cc b/tests/bits/christian_1.cc new file mode 100644 index 0000000000..2b46ced9e2 --- /dev/null +++ b/tests/bits/christian_1.cc @@ -0,0 +1,192 @@ +//---------------------------- christian_1.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005 by the deal.II authors and Christian Kamm +// +// 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. +// +//---------------------------- christian_1.cc --------------------------- + +// check intergrid transfer + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace DoFToolsEx +{ + /// transfers solution between differently refined grids + template + void transfer(const DoFHandler& source_dof, const InVector& source_vector, const DoFHandler& target_dof, OutVector& target_vector); +} + +/** + * Detailed desc. + * Does it make sense to have InVector and OutVector templates? Shouldn't just one Vector be enough? + * + * @param + * + */ +template +void +DoFToolsEx::transfer(const DoFHandler& source_dof, const InVector& source_vector, const DoFHandler& target_dof, OutVector& target_vector) +{ + // any sanity tests? Trias derived from same coarse grid? + + // build mappings between the cells + InterGridMap source2target, target2source; + source2target.make_mapping(source_dof, target_dof); + target2source.make_mapping(target_dof, source_dof); + + // setup temporary vector + InVector local_dofs(source_dof.get_fe().dofs_per_cell); + + // iterate over all active source cells + typedef typename DoFHandler::active_cell_iterator cell_iterator; + cell_iterator cell = source_dof.begin_active(), endc = source_dof.end(); + for(; cell != endc; ++cell) + { + if(cell->level() == source2target[cell]->level()) + { + // cell has not been coarsend, but possibly been refined + cell->get_dof_values(source_vector, local_dofs); + source2target[cell]->set_dof_values_by_interpolation(local_dofs, target_vector); + } + else + { + // the source cell has been coarsened + Assert(cell->level() > source2target[cell]->level(), ExcInternalError()); + target2source[ source2target[cell] ]->get_interpolated_dof_values(source_vector, local_dofs); + source2target[cell]->set_dof_values(local_dofs, target_vector); + } + } + + // handle hanging node constraints inside or outside of this function? +} + + +class TestFunction : public Function<2> +{ + public: + TestFunction() : Function<2>() {}; + virtual double value(const Point<2> &p, + const unsigned int) const + { return std::sin(3.14159*p(0))*std::sin(3.14159*p(1)); }; +}; + +int main() +{ + std::ofstream logfile("christian_1.output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + + // build test-case trias + Triangulation<2> tria; + Triangulation<2> refined_tria; + Triangulation<2> coarse_tria; + Triangulation<2> both_tria; + + // make grids + GridGenerator::hyper_cube(tria, 0, 1); + tria.refine_global(2); + GridGenerator::hyper_cube(refined_tria, 0, 1); + refined_tria.refine_global(3); + GridGenerator::hyper_cube(coarse_tria, 0, 1); + coarse_tria.refine_global(1); + GridGenerator::hyper_cube(both_tria, 0, 1); + both_tria.refine_global(2); + Triangulation<2>::active_cell_iterator it = both_tria.begin_active(); + it->set_refine_flag(); + (++it)->set_refine_flag(); + for(int i = 1; i < 8; ++i, ++it); + it->set_coarsen_flag(); + (++it)->set_coarsen_flag(); + (++it)->set_coarsen_flag(); + (++it)->set_coarsen_flag(); + both_tria.execute_coarsening_and_refinement(); + + // finite element + FE_Q<2> fe(1); + + // dof handlers + DoFHandler<2> dof(tria), refined_dof(refined_tria), coarse_dof(coarse_tria), both_dof(both_tria); + dof.distribute_dofs(fe); + refined_dof.distribute_dofs(fe); + coarse_dof.distribute_dofs(fe); + both_dof.distribute_dofs(fe); + + // interpolate test function onto tria + Vector sol(dof.n_dofs()); + TestFunction test_function; + VectorTools::interpolate(dof, test_function, sol); + + // setup solution vectors + Vector refined_sol(refined_dof.n_dofs()), coarse_sol(coarse_dof.n_dofs()), both_sol(both_dof.n_dofs()); + + // transfer solutions + DoFToolsEx::transfer(dof, sol, refined_dof, refined_sol); + DoFToolsEx::transfer(dof, sol, coarse_dof, coarse_sol); + DoFToolsEx::transfer(dof, sol, both_dof, both_sol); + + // handle hanging nodes + ConstraintMatrix both_constraints; + DoFTools::make_hanging_node_constraints(both_dof, both_constraints); + both_constraints.close(); + both_constraints.distribute(both_sol); + + // reference output using DataOut to create seperate files + DataOut<2> data_out; + data_out.attach_dof_handler(dof); + data_out.add_data_vector(sol, "base"); + data_out.build_patches(); + data_out.write_gnuplot(logfile); + + data_out.clear(); + data_out.attach_dof_handler(refined_dof); + data_out.add_data_vector(refined_sol, "refined"); + data_out.build_patches(); + data_out.write_gnuplot(logfile); + + data_out.clear(); + data_out.attach_dof_handler(coarse_dof); + data_out.add_data_vector(coarse_sol, "coarse"); + data_out.build_patches(); + data_out.write_gnuplot(logfile); + + data_out.clear(); + data_out.attach_dof_handler(both_dof); + data_out.add_data_vector(both_sol, "both"); + data_out.build_patches(); + data_out.write_gnuplot(logfile); + + // test output using DataOutStack + DataOutStack<2> data_out_stack; + data_out_stack.declare_data_vector("dof", DataOutStack<2>::dof_vector); + data_out_stack.new_parameter_value(0.,0.); + data_out_stack.attach_dof_handler(dof); + data_out_stack.add_data_vector(sol, "dof"); + data_out_stack.build_patches(); + data_out_stack.finish_parameter_value(); + data_out_stack.write_gnuplot(logfile); +} diff --git a/tests/bits/christian_2.cc b/tests/bits/christian_2.cc new file mode 100644 index 0000000000..7b0c292deb --- /dev/null +++ b/tests/bits/christian_2.cc @@ -0,0 +1,54 @@ +//---------------------------- christian_2.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005 by the deal.II authors and Christian Kamm +// +// 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. +// +//---------------------------- christian_2.cc --------------------------- + +// check one aspect of DataOutStack in 2+1d + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + + +int main() +{ + std::ofstream logfile("christian_2.output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + Triangulation<2> tria; + GridGenerator::hyper_cube(tria, 0, 1); + FE_Q<2> fe(1); + + DoFHandler<2> dof(tria); + dof.distribute_dofs(fe); + + Vector sol(dof.n_dofs()); + for (unsigned int i=0; i data_out_stack; + data_out_stack.declare_data_vector("dof", DataOutStack<2>::dof_vector); + data_out_stack.new_parameter_value(2.5,1.); + data_out_stack.attach_dof_handler(dof); + data_out_stack.add_data_vector(sol, "dof"); + data_out_stack.build_patches(); + data_out_stack.finish_parameter_value(); + + data_out_stack.write_gnuplot(logfile); +} -- 2.39.5