This fixes a testcase reported by Claire Br. on the mailing list.
<ol>
+ <li> Fixed: hp::SolutionTransfer could get confused when dealing with
+ FE_Nothing elements. This is now fixed.
+ <br>
+ (Claire Br, Wolfgang Bangerth, 2015/09/23)
+ </li>
+
<li> Improved: The construction of the non-local graph for quick data
exchange of TrilinosWrappers::SparseMatrix became very slow for a few
thousand processors. This has been fixed.
typename BaseClass::ExcVectorDoesNotMatch());
- Vector<number> tmp1(dofs_per_cell);
- Vector<number> tmp2(dofs_per_cell);
-
- interpolated_values = 0;
-
- // later on we will have to push the values interpolated from the child
- // to the mother cell into the output vector. unfortunately, there are
- // two types of elements: ones where you add up the contributions from
- // the different child cells, and ones where you overwrite.
- //
- // an example for the first is piecewise constant (and discontinuous)
- // elements, where we build the value on the coarse cell by averaging
- // the values from the cell (i.e. by adding up a fraction of the values
- // of their values)
- //
- // an example for the latter are the usual continuous elements. the
- // value on a vertex of a coarse cell must there be the same,
- // irrespective of the adjacent cell we are presently on. so we always
- // overwrite. in fact, we must, since we cannot know in advance how many
- // neighbors there will be, so there is no way to compute the average
- // with fixed factors
- //
- // so we have to find out to which type this element belongs. the
- // difficulty is: the finite element may be a composed one, so we can
- // only hope to do this for each shape function individually. in fact,
- // there are even weird finite elements (for example the Raviart-Thomas
- // element) which have shape functions that are additive (interior ones)
- // and others that are overwriting (face degrees of freedom that need to
- // be continuous across the face).
- for (unsigned int child=0; child<this->n_children(); ++child)
+ // see if the finite element we have on the current cell has any
+ // degrees of freedom to begin with; if not (e.g., when
+ // interpolating FE_Nothing), then simply skip all of the
+ // following since the output vector would be of size zero
+ // anyway (and in fact is of size zero, see the assertion above)
+ if (fe.dofs_per_cell > 0)
{
- // get the values from the present child, if necessary by
- // interpolation itself either from its own children or
- // by interpolating from the finite element on an active
- // child to the finite element space requested here
- this->child(child)->get_interpolated_dof_values (values,
- tmp1,
- fe_index);
- // interpolate these to the mother cell
- fe.get_restriction_matrix(child, this->refinement_case()).vmult (tmp2, tmp1);
-
- // and add up or set them in the output vector
- for (unsigned int i=0; i<dofs_per_cell; ++i)
- if (fe.restriction_is_additive(i))
- interpolated_values(i) += tmp2(i);
- else if (tmp2(i) != number())
- interpolated_values(i) = tmp2(i);
+ Vector<number> tmp1(dofs_per_cell);
+ Vector<number> tmp2(dofs_per_cell);
+
+ interpolated_values = 0;
+
+ // later on we will have to push the values interpolated from the child
+ // to the mother cell into the output vector. unfortunately, there are
+ // two types of elements: ones where you add up the contributions from
+ // the different child cells, and ones where you overwrite.
+ //
+ // an example for the first is piecewise constant (and discontinuous)
+ // elements, where we build the value on the coarse cell by averaging
+ // the values from the cell (i.e. by adding up a fraction of the values
+ // of their values)
+ //
+ // an example for the latter are the usual continuous elements. the
+ // value on a vertex of a coarse cell must there be the same,
+ // irrespective of the adjacent cell we are presently on. so we always
+ // overwrite. in fact, we must, since we cannot know in advance how many
+ // neighbors there will be, so there is no way to compute the average
+ // with fixed factors
+ //
+ // so we have to find out to which type this element belongs. the
+ // difficulty is: the finite element may be a composed one, so we can
+ // only hope to do this for each shape function individually. in fact,
+ // there are even weird finite elements (for example the Raviart-Thomas
+ // element) which have shape functions that are additive (interior ones)
+ // and others that are overwriting (face degrees of freedom that need to
+ // be continuous across the face).
+ for (unsigned int child=0; child<this->n_children(); ++child)
+ {
+ // get the values from the present child, if necessary by
+ // interpolation itself either from its own children or
+ // by interpolating from the finite element on an active
+ // child to the finite element space requested here
+ this->child(child)->get_interpolated_dof_values (values,
+ tmp1,
+ fe_index);
+ // interpolate these to the mother cell
+ fe.get_restriction_matrix(child, this->refinement_case()).vmult (tmp2, tmp1);
+
+ // and add up or set them in the output vector
+ for (unsigned int i=0; i<dofs_per_cell; ++i)
+ if (fe.restriction_is_additive(i))
+ interpolated_values(i) += tmp2(i);
+ else if (tmp2(i) != number())
+ interpolated_values(i) = tmp2(i);
+ }
}
}
}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// Test case by Claire Br. based on an earlier one written by K. Bzowski
+
+
+#include "../tests.h"
+
+#include <deal.II/base/logstream.h>
+
+#include <deal.II/grid/tria.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/hp/dof_handler.h>
+#include <deal.II/grid/tria_iterator.h>
+
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/fe/fe_nothing.h>
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/hp/fe_collection.h>
+
+#include <deal.II/numerics/solution_transfer.h>
+
+#include <deal.II/numerics/data_out.h>
+#include <iostream>
+#include <fstream>
+
+using namespace dealii;
+
+int main()
+{
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ Triangulation<2> triangulation(Triangulation<2>::none);
+ GridGenerator::hyper_cube (triangulation);
+ triangulation.refine_global(1);
+
+ hp::FECollection<2> fe_collection;
+ fe_collection.push_back(FE_Q<2>(1));
+ //fe_collection.push_back(FE_Q<2>(2));
+ fe_collection.push_back(FE_Nothing<2>());
+
+ hp::DoFHandler<2> dof_handler(triangulation);
+
+ // Assign FE
+ hp::DoFHandler<2>::active_cell_iterator cell = dof_handler.begin_active();
+ hp::DoFHandler<2>::active_cell_iterator endc = dof_handler.end();
+
+ /*
+ * -----------
+ * | 0 | 0 |
+ * -----------
+ * | 1 | 1 | 0 - FEQ, 1 - FE_Nothing
+ * -----------
+ */
+
+ cell->set_active_fe_index(1);
+ cell++;
+ cell->set_active_fe_index(1);
+ cell++;
+ cell->set_active_fe_index(0);
+ cell++;
+ cell->set_active_fe_index(0);
+
+ dof_handler.distribute_dofs (fe_collection);
+
+ // Init solution
+ Vector<double> solution(dof_handler.n_dofs());
+ solution = 1.0;
+
+
+ // Vector to visualize the FE of each cell
+ Vector<double> FE_Type (triangulation.n_active_cells());
+ unsigned int cnt_cells (0);
+ cell = dof_handler.begin_active(),
+ endc = dof_handler.end();
+ for (; cell!=endc; ++cell)
+ {
+ unsigned int fe_index = cell->active_fe_index();
+ FE_Type[cnt_cells] = fe_index;
+ ++ cnt_cells;
+ }
+
+ // Save output
+ DataOut<2, hp::DoFHandler<2> > data_out;
+ data_out.attach_dof_handler (dof_handler);
+ data_out.add_data_vector (solution, "Solution");
+ data_out.add_data_vector (FE_Type, "FE_Type");
+ data_out.build_patches();
+ data_out.write_gnuplot (deallog.get_file_stream());
+
+
+ /* Set refine flags:
+ * -----------
+ * | | R |
+ * -----------
+ * | R | |
+ * -----------
+ */
+
+
+ cell = dof_handler.begin_active();
+ cell->set_refine_flag();
+ cell++;
+ cell++;
+ cell++;
+ cell->set_refine_flag();
+
+ triangulation.prepare_coarsening_and_refinement();
+
+ // Interpolate solution
+ SolutionTransfer<2, Vector<double>, hp::DoFHandler<2> > solution_trans(dof_handler);
+ solution_trans.prepare_for_coarsening_and_refinement(solution);
+
+ triangulation.execute_coarsening_and_refinement ();
+
+ dof_handler.distribute_dofs(fe_collection);
+
+ Vector<double> new_solution(dof_handler.n_dofs());
+ solution_trans.interpolate(solution, new_solution);
+
+ FE_Type.reinit(triangulation.n_active_cells());
+ cnt_cells=0;
+ cell = dof_handler.begin_active(),
+ endc = dof_handler.end();
+ for (; cell!=endc; ++cell)
+ {
+ unsigned int fe_index = cell->active_fe_index();
+ FE_Type[cnt_cells] = fe_index;
+ ++ cnt_cells;
+ }
+
+ // Save new solution
+ DataOut<2, hp::DoFHandler<2> > data_out2;
+ data_out2.attach_dof_handler (dof_handler);
+ data_out2.add_data_vector (new_solution, "Solution");
+ data_out2.add_data_vector(FE_Type, "FE_type" );
+ data_out2.build_patches();
+ data_out2.write_gnuplot(deallog.get_file_stream());
+
+ // Solution reinitialization
+
+ dof_handler.distribute_dofs (fe_collection);
+ solution.reinit(dof_handler.n_dofs());
+ solution = 1.0;
+
+ /* Set coarsen flags:
+ * -----------
+ * | | C |
+ * -----------
+ * | C | |
+ * -----------
+ */
+
+ endc = dof_handler.end();
+ for (cell=dof_handler.begin_active(); cell!=endc; cell++)
+ if (cell->level() > 1)
+ cell->set_coarsen_flag();
+
+ triangulation.prepare_coarsening_and_refinement();
+
+ // Interpolate solution
+ SolutionTransfer<2, Vector<double>, hp::DoFHandler<2> > solution_trans2(dof_handler);
+ solution_trans2.prepare_for_coarsening_and_refinement(solution);
+
+ triangulation.execute_coarsening_and_refinement ();
+
+ dof_handler.distribute_dofs (fe_collection);
+
+ Vector<double> new_solution2(dof_handler.n_dofs());
+ solution_trans2.interpolate(solution, new_solution2);
+
+ FE_Type.reinit(triangulation.n_active_cells());
+ cnt_cells=0;
+ cell = dof_handler.begin_active(),
+ endc = dof_handler.end();
+ for (; cell!=endc; ++cell)
+ {
+ unsigned int fe_index = cell->active_fe_index();
+ FE_Type[cnt_cells] = fe_index;
+ ++ cnt_cells;
+ }
+
+ // Save new solution
+ DataOut<2, hp::DoFHandler<2> > data_out3;
+ data_out3.attach_dof_handler (dof_handler);
+ data_out3.add_data_vector (new_solution2, "Solution");
+ data_out3.add_data_vector(FE_Type, "FE_type" );
+ data_out3.build_patches();
+ data_out3.write_gnuplot(deallog.get_file_stream());
+}
+
--- /dev/null
+
+# This file was generated by the deal.II library.
+
+
+#
+# For a description of the GNUPLOT format see the GNUPLOT manual.
+#
+# <x> <y> <Solution> <FE_Type>
+0.00000 0.00000 0.00000 1.00000
+0.500000 0.00000 0.00000 1.00000
+
+0.00000 0.500000 0.00000 1.00000
+0.500000 0.500000 0.00000 1.00000
+
+
+0.500000 0.00000 0.00000 1.00000
+1.00000 0.00000 0.00000 1.00000
+
+0.500000 0.500000 0.00000 1.00000
+1.00000 0.500000 0.00000 1.00000
+
+
+0.00000 0.500000 1.00000 0.00000
+0.500000 0.500000 1.00000 0.00000
+
+0.00000 1.00000 1.00000 0.00000
+0.500000 1.00000 1.00000 0.00000
+
+
+0.500000 0.500000 1.00000 0.00000
+1.00000 0.500000 1.00000 0.00000
+
+0.500000 1.00000 1.00000 0.00000
+1.00000 1.00000 1.00000 0.00000
+
+
+# This file was generated by the deal.II library.
+
+
+#
+# For a description of the GNUPLOT format see the GNUPLOT manual.
+#
+# <x> <y> <Solution> <FE_type>
+0.500000 0.00000 0.00000 1.00000
+1.00000 0.00000 0.00000 1.00000
+
+0.500000 0.500000 0.00000 1.00000
+1.00000 0.500000 0.00000 1.00000
+
+
+0.00000 0.500000 1.00000 0.00000
+0.500000 0.500000 1.00000 0.00000
+
+0.00000 1.00000 1.00000 0.00000
+0.500000 1.00000 1.00000 0.00000
+
+
+0.00000 0.00000 0.00000 1.00000
+0.250000 0.00000 0.00000 1.00000
+
+0.00000 0.250000 0.00000 1.00000
+0.250000 0.250000 0.00000 1.00000
+
+
+0.250000 0.00000 0.00000 1.00000
+0.500000 0.00000 0.00000 1.00000
+
+0.250000 0.250000 0.00000 1.00000
+0.500000 0.250000 0.00000 1.00000
+
+
+0.00000 0.250000 0.00000 1.00000
+0.250000 0.250000 0.00000 1.00000
+
+0.00000 0.500000 0.00000 1.00000
+0.250000 0.500000 0.00000 1.00000
+
+
+0.250000 0.250000 0.00000 1.00000
+0.500000 0.250000 0.00000 1.00000
+
+0.250000 0.500000 0.00000 1.00000
+0.500000 0.500000 0.00000 1.00000
+
+
+0.500000 0.500000 1.00000 0.00000
+0.750000 0.500000 1.00000 0.00000
+
+0.500000 0.750000 1.00000 0.00000
+0.750000 0.750000 1.00000 0.00000
+
+
+0.750000 0.500000 1.00000 0.00000
+1.00000 0.500000 1.00000 0.00000
+
+0.750000 0.750000 1.00000 0.00000
+1.00000 0.750000 1.00000 0.00000
+
+
+0.500000 0.750000 1.00000 0.00000
+0.750000 0.750000 1.00000 0.00000
+
+0.500000 1.00000 1.00000 0.00000
+0.750000 1.00000 1.00000 0.00000
+
+
+0.750000 0.750000 1.00000 0.00000
+1.00000 0.750000 1.00000 0.00000
+
+0.750000 1.00000 1.00000 0.00000
+1.00000 1.00000 1.00000 0.00000
+
+
+# This file was generated by the deal.II library.
+
+
+#
+# For a description of the GNUPLOT format see the GNUPLOT manual.
+#
+# <x> <y> <Solution> <FE_type>
+0.00000 0.00000 0.00000 1.00000
+0.500000 0.00000 0.00000 1.00000
+
+0.00000 0.500000 0.00000 1.00000
+0.500000 0.500000 0.00000 1.00000
+
+
+0.500000 0.00000 0.00000 1.00000
+1.00000 0.00000 0.00000 1.00000
+
+0.500000 0.500000 0.00000 1.00000
+1.00000 0.500000 0.00000 1.00000
+
+
+0.00000 0.500000 1.00000 0.00000
+0.500000 0.500000 1.00000 0.00000
+
+0.00000 1.00000 1.00000 0.00000
+0.500000 1.00000 1.00000 0.00000
+
+
+0.500000 0.500000 1.00000 0.00000
+1.00000 0.500000 1.00000 0.00000
+
+0.500000 1.00000 1.00000 0.00000
+1.00000 1.00000 1.00000 0.00000
+
+