From: Wolfgang Bangerth Date: Thu, 27 Dec 2018 18:23:45 +0000 (-0700) Subject: Add one test. X-Git-Tag: v9.1.0-rc1~475^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=111ecfb08aec26712d4afe5c8356116b3bd86c8c;p=dealii.git Add one test. --- diff --git a/tests/vector_tools/interpolate_with_material_id_01.cc b/tests/vector_tools/interpolate_with_material_id_01.cc new file mode 100644 index 0000000000..3116bfeffc --- /dev/null +++ b/tests/vector_tools/interpolate_with_material_id_01.cc @@ -0,0 +1,175 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// Check that interpolate_based_on_material_id() really does ignore +// material_ids not included in the provided std::map + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "../tests.h" + + + +namespace PhaseField +{ + using namespace dealii; + + typedef Vector vectorType; + + + /////////////////////////////////////////////////////////////// + + template + class Solid + { + public: + Solid(); + + ~Solid(); + + void + run(); + + private: + void + make_grid(); + + Triangulation triangulation; + FE_Q fe; + DoFHandler dof_handler; + }; + + + // constructor + template + Solid::Solid() + : fe(1) + , dof_handler(triangulation) + {} + + // destructor + template + Solid::~Solid() + { + dof_handler.clear(); + } + + + /////////////////////////////////////////////////////// + template + void + Solid::make_grid() + { + std::vector repetitions(dim, 4); + if (dim == 3) + repetitions[dim - 2] = 4; + + GridGenerator::subdivided_hyper_rectangle( + triangulation, + repetitions, + Point(), + (dim == 1 ? + Point(1.0) : + (dim == 2 ? Point(1.0, 1.0) : Point(1.0, 1.0, 1.0))), + true); + + + for (typename Triangulation::active_cell_iterator cell = + triangulation.begin_active(); + cell != triangulation.end(); + ++cell) + + if (cell->center()[0] < 0.5) + cell->set_material_id(1); + else + cell->set_material_id(0); + } + + ////////////////////////////////////////////////// + template + void + Solid::run() + { + make_grid(); + dof_handler.distribute_dofs(fe); + + vectorType dst(dof_handler.n_dofs()); + + deallog << " Initial values: " << std::endl; + dst.print(deallog.get_file_stream()); + + std::map *> function_map; + + const Functions::ConstantFunction constant_function_1(1.0); + function_map[1] = &constant_function_1; + + VectorTools::interpolate_based_on_material_id(MappingQGeneric(1), + dof_handler, + function_map, + dst); + + + deallog << " Final values: " << std::endl; + dst.print(deallog.get_file_stream()); + } +} // namespace PhaseField + + +int +main() +{ + initlog(); + + deallog.push("1d"); + PhaseField::Solid<1>().run(); + deallog.pop(); + deallog.push("2d"); + PhaseField::Solid<2>().run(); + deallog.pop(); + deallog.push("3d"); + PhaseField::Solid<3>().run(); + deallog.pop(); +} diff --git a/tests/vector_tools/interpolate_with_material_id_01.output b/tests/vector_tools/interpolate_with_material_id_01.output new file mode 100644 index 0000000000..00d1985cbc --- /dev/null +++ b/tests/vector_tools/interpolate_with_material_id_01.output @@ -0,0 +1,13 @@ + +DEAL:1d:: Initial values: +0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 +DEAL:1d:: Final values: +1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 +DEAL:2d:: Initial values: +0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 +DEAL:2d:: Final values: +1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 +DEAL:3d:: Initial values: +0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 +DEAL:3d:: Final values: +1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 0.000e+00 0.000e+00