17 #include <deal.II/base/quadrature_lib.h> 18 #include <deal.II/base/qprojector.h> 19 #include <deal.II/base/thread_management.h> 20 #include <deal.II/base/utilities.h> 21 #include <deal.II/lac/vector.h> 22 #include <deal.II/lac/block_vector.h> 23 #include <deal.II/lac/parallel_vector.h> 24 #include <deal.II/lac/parallel_block_vector.h> 25 #include <deal.II/lac/petsc_parallel_vector.h> 26 #include <deal.II/lac/petsc_block_vector.h> 27 #include <deal.II/lac/petsc_parallel_block_vector.h> 28 #include <deal.II/lac/trilinos_vector.h> 29 #include <deal.II/lac/trilinos_block_vector.h> 30 #include <deal.II/lac/constraint_matrix.h> 31 #include <deal.II/grid/tria.h> 32 #include <deal.II/grid/tria_iterator.h> 33 #include <deal.II/grid/grid_generator.h> 34 #include <deal.II/fe/fe_tools.h> 35 #include <deal.II/fe/fe.h> 36 #include <deal.II/fe/fe_values.h> 37 #include <deal.II/dofs/dof_handler.h> 38 #include <deal.II/dofs/dof_accessor.h> 39 #include <deal.II/dofs/dof_tools.h> 40 #include <deal.II/hp/dof_handler.h> 42 #include <deal.II/base/std_cxx11/shared_ptr.h> 44 #include <deal.II/base/index_set.h> 49 DEAL_II_NAMESPACE_OPEN
53 template <
int dim,
int spacedim,
54 template <
int,
int>
class DoFHandlerType1,
55 template <
int,
int>
class DoFHandlerType2,
56 class InVector,
class OutVector>
60 const DoFHandlerType2<dim, spacedim> &dof2,
70 template <
int dim,
int spacedim,
71 template <
int,
int>
class DoFHandlerType1,
72 template <
int,
int>
class DoFHandlerType2,
73 class InVector,
class OutVector>
77 const DoFHandlerType2<dim, spacedim> &dof2,
81 Assert(&dof1.get_triangulation()==&dof2.get_triangulation(), ExcTriangulationMismatch());
83 Assert(u1.size()==dof1.n_dofs(),
84 ExcDimensionMismatch(u1.size(), dof1.n_dofs()));
85 Assert(u2.size()==dof2.n_dofs(),
86 ExcDimensionMismatch(u2.size(), dof2.n_dofs()));
88 #ifdef DEAL_II_WITH_PETSC 89 if (dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1) != 0)
95 Assert(dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1)->local_size() == dof1.n_locally_owned_dofs(),
96 ExcDimensionMismatch(dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1)->local_size(), dof1.n_locally_owned_dofs()));
99 if (dynamic_cast<PETScWrappers::MPI::Vector *>(&u2) != 0)
102 Assert(dynamic_cast<PETScWrappers::MPI::Vector *>(&u2)->local_size() == dof2.n_locally_owned_dofs(),
103 ExcDimensionMismatch(dynamic_cast<PETScWrappers::MPI::Vector *>(&u2)->local_size(), dof2.n_locally_owned_dofs()));
117 std::map<const FiniteElement<dim,spacedim> *,
118 std::map<const FiniteElement<dim,spacedim> *,
119 std_cxx11::shared_ptr<FullMatrix<double> > > >
120 interpolation_matrices;
122 typename DoFHandlerType1<dim,spacedim>::active_cell_iterator cell1 = dof1.begin_active(),
124 typename DoFHandlerType2<dim,spacedim>::active_cell_iterator cell2 = dof2.begin_active(),
128 std::vector<types::global_dof_index> dofs;
129 dofs.reserve (DoFTools::max_dofs_per_cell (dof2));
132 OutVector touch_count(u2);
140 dof1.get_triangulation().locally_owned_subdomain();
142 for (; cell1!=endc1; ++cell1, ++cell2)
143 if ((cell1->subdomain_id() == subdomain_id)
147 Assert(cell1->get_fe().n_components() == cell2->get_fe().n_components(),
148 ExcDimensionMismatch (cell1->get_fe().n_components(),
149 cell2->get_fe().n_components()));
158 const bool hanging_nodes_not_allowed
159 = ((cell2->get_fe().dofs_per_vertex != 0) &&
162 if (hanging_nodes_not_allowed)
163 for (
unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
164 Assert (cell1->at_boundary(face) ||
165 cell1->neighbor(face)->level() == cell1->level(),
166 ExcHangingNodesNotAllowed(0));
169 const unsigned int dofs_per_cell1 = cell1->get_fe().dofs_per_cell;
170 const unsigned int dofs_per_cell2 = cell2->get_fe().dofs_per_cell;
171 u1_local.
reinit (dofs_per_cell1);
172 u2_local.
reinit (dofs_per_cell2);
178 if (interpolation_matrices[&cell1->get_fe()][&cell2->get_fe()].get() == 0)
180 std_cxx11::shared_ptr<FullMatrix<double> >
183 interpolation_matrices[&cell1->get_fe()][&cell2->get_fe()]
184 = interpolation_matrix;
188 *interpolation_matrix);
191 cell1->get_dof_values(u1, u1_local);
192 interpolation_matrices[&cell1->get_fe()][&cell2->get_fe()]
193 ->vmult(u2_local, u1_local);
195 dofs.resize (dofs_per_cell2);
196 cell2->get_dof_indices(dofs);
198 for (
unsigned int i=0; i<dofs_per_cell2; ++i)
200 u2(dofs[i])+=u2_local(i);
201 touch_count(dofs[i]) += 1;
206 Assert (cell2 == endc2, ExcInternalError());
208 u2.compress(VectorOperation::add);
209 touch_count.compress(VectorOperation::add);
214 IndexSet locally_owned_dofs = dof2.locally_owned_dofs();
225 Assert(touch_count(i) !=
typename OutVector::value_type(),
227 u2(i) /= touch_count(i);
231 u2.compress(VectorOperation::insert);
238 template <
int dim,
class InVector,
class OutVector,
int spacedim>
243 OutVector &u1_interpolated)
249 ExcDimensionMismatch(u1_interpolated.size(), dof1.
n_dofs()));
251 #ifdef DEAL_II_WITH_PETSC 252 if (dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1) != 0)
259 ExcDimensionMismatch(dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1)->local_size(), dof1.
n_locally_owned_dofs()));
262 if (dynamic_cast<PETScWrappers::MPI::Vector *>(&u1_interpolated) != 0)
266 ExcDimensionMismatch(dynamic_cast<PETScWrappers::MPI::Vector *>(&u1_interpolated)->local_size(), dof1.
n_locally_owned_dofs()));
277 const bool hanging_nodes_not_allowed=
280 const unsigned int dofs_per_cell1=dof1.
get_fe().dofs_per_cell;
293 interpolation_matrix);
294 for (; cell!=endc; ++cell)
295 if ((cell->subdomain_id() == subdomain_id)
299 if (hanging_nodes_not_allowed)
300 for (
unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
301 Assert (cell->at_boundary(face) ||
302 cell->neighbor(face)->level() == cell->level(),
303 ExcHangingNodesNotAllowed(0));
305 cell->get_dof_values(u1, u1_local);
306 interpolation_matrix.
vmult(u1_int_local, u1_local);
307 cell->set_dof_values(u1_int_local, u1_interpolated);
312 u1_interpolated.compress(VectorOperation::insert);
318 template <
int>
class DoFHandlerType,
319 class InVector,
class OutVector,
int spacedim>
324 OutVector &u1_interpolated)
326 Assert(u1.size() == dof1.n_dofs(),
327 ExcDimensionMismatch(u1.size(), dof1.n_dofs()));
328 Assert(u1_interpolated.size() == dof1.n_dofs(),
329 ExcDimensionMismatch(u1_interpolated.size(), dof1.n_dofs()));
331 #ifdef DEAL_II_WITH_PETSC 332 if (dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1) != 0)
338 Assert(dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1)->local_size() == dof1.n_locally_owned_dofs(),
339 ExcDimensionMismatch(dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1)->local_size(), dof1.n_locally_owned_dofs()));
342 if (dynamic_cast<PETScWrappers::MPI::Vector *>(&u1_interpolated) != 0)
345 Assert(dynamic_cast<PETScWrappers::MPI::Vector *>(&u1_interpolated)->local_size() == dof1.n_locally_owned_dofs(),
346 ExcDimensionMismatch(dynamic_cast<PETScWrappers::MPI::Vector *>(&u1_interpolated)->local_size(), dof1.n_locally_owned_dofs()));
354 dof1.get_triangulation().locally_owned_subdomain();
356 typename DoFHandlerType<dim>::active_cell_iterator cell = dof1.begin_active(),
362 std::map<const FiniteElement<dim> *,
363 std_cxx11::shared_ptr<FullMatrix<double> > > interpolation_matrices;
365 for (; cell!=endc; ++cell)
366 if ((cell->subdomain_id() == subdomain_id)
371 ExcDimensionMismatch(cell->get_fe().n_components(),
381 const bool hanging_nodes_not_allowed=
384 if (hanging_nodes_not_allowed)
385 for (
unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
386 Assert (cell->at_boundary(face) ||
387 cell->neighbor(face)->level() == cell->level(),
388 ExcHangingNodesNotAllowed(0));
390 const unsigned int dofs_per_cell1 = cell->get_fe().dofs_per_cell;
394 if (interpolation_matrices[&cell->get_fe()] != 0)
396 interpolation_matrices[&cell->get_fe()] =
397 std_cxx11::shared_ptr<FullMatrix<double> >
400 *interpolation_matrices[&cell->get_fe()]);
403 u1_local.
reinit (dofs_per_cell1);
404 u1_int_local.
reinit (dofs_per_cell1);
406 cell->get_dof_values(u1, u1_local);
407 interpolation_matrices[&cell->get_fe()]->vmult(u1_int_local, u1_local);
408 cell->set_dof_values(u1_int_local, u1_interpolated);
413 u1_interpolated.compress(VectorOperation::insert);
422 template <
int dim,
int spacedim,
class InVector>
428 InVector &u1_interpolated)
432 interpolate(dof2, u2, dof1, constraints1, u1_interpolated);
436 #ifdef DEAL_II_WITH_PETSC 437 template <
int dim,
int spacedim>
449 IndexSet dof2_locally_relevant_dofs;
451 dof2_locally_relevant_dofs);
457 dof2_locally_relevant_dofs,
460 interpolate(dof2, u2, dof1, constraints1, u1_interpolated);
465 #ifdef DEAL_II_WITH_TRILINOS 466 template <
int dim,
int spacedim>
478 IndexSet dof2_locally_relevant_dofs;
480 dof2_locally_relevant_dofs);
486 dof2_locally_relevant_dofs,
489 interpolate(dof2, u2, dof1, constraints1, u1_interpolated);
494 template <
int dim,
int spacedim,
typename Number>
503 IndexSet dof2_locally_relevant_dofs;
505 dof2_locally_relevant_dofs);
508 u2 (dof2_locally_owned_dofs,
509 dof2_locally_relevant_dofs,
513 u2.update_ghost_values ();
514 interpolate(dof2, u2, dof1, constraints1, u1_interpolated);
520 template <
int dim,
class InVector,
class OutVector,
int spacedim>
526 OutVector &u1_interpolated)
530 if (dof1.
get_fe().dofs_per_vertex==0 && dof2.
get_fe().dofs_per_vertex==0
536 ExcDimensionMismatch(dof1.
get_fe().n_components(), dof2.
get_fe().n_components()));
539 ExcDimensionMismatch(u1_interpolated.size(), dof1.
n_dofs()));
544 internal::back_interpolate(dof1, constraints1, u1, dof2, constraints2,
551 template <
int dim,
class InVector,
class OutVector,
int spacedim>
555 OutVector &u1_difference)
561 ExcDimensionMismatch(u1_difference.size(), dof1.
n_dofs()));
563 #ifdef DEAL_II_WITH_PETSC 564 if (dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1) != 0)
571 ExcDimensionMismatch(dynamic_cast<const PETScWrappers::MPI::Vector *>(&u1)->local_size(), dof1.
n_locally_owned_dofs()));
574 if (dynamic_cast<PETScWrappers::MPI::Vector *>(&u1_difference) != 0)
578 ExcDimensionMismatch(dynamic_cast<PETScWrappers::MPI::Vector *>(&u1_difference)->local_size(), dof1.
n_locally_owned_dofs()));
589 const bool hanging_nodes_not_allowed=
592 const unsigned int dofs_per_cell=dof1.
get_fe().dofs_per_cell;
607 for (; cell!=endc; ++cell)
608 if ((cell->subdomain_id() == subdomain_id)
612 if (hanging_nodes_not_allowed)
613 for (
unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
614 Assert (cell->at_boundary(face) ||
615 cell->neighbor(face)->level() == cell->level(),
616 ExcHangingNodesNotAllowed(0));
618 cell->get_dof_values(u1, u1_local);
619 difference_matrix.
vmult(u1_diff_local, u1_local);
620 cell->set_dof_values(u1_diff_local, u1_difference);
626 u1_difference.compress(VectorOperation::insert);
635 template <
int dim,
class InVector,
class OutVector,
int spacedim>
641 OutVector &u1_difference)
643 back_interpolate(dof1, constraints1, u1, dof2, constraints2, u1_difference);
644 u1_difference.sadd(-1, u1);
648 #ifdef DEAL_II_WITH_TRILINOS 649 template <
int dim,
int spacedim>
657 back_interpolate(dof1, constraints1, u1, dof2, constraints2, u1_difference);
665 u1_completely_distributed = u1;
667 u1_difference.
sadd(-1, u1_completely_distributed);
675 template <
int dim,
class InVector,
class OutVector,
int spacedim>
681 OutVector &u1_difference)
687 if (dof1.
get_fe().dofs_per_vertex==0 && dof2.
get_fe().dofs_per_vertex==0
692 internal::interpolation_difference(dof1, constraints1, u1, dof2, constraints2, u1_difference);
698 template <
int dim,
class InVector,
class OutVector,
int spacedim>
706 ExcDimensionMismatch(dof1.
get_fe().n_components(), dof2.
get_fe().n_components()));
714 const unsigned int n1 = dof1.
get_fe().dofs_per_cell;
715 const unsigned int n2 = dof2.
get_fe().dofs_per_cell;
719 std::vector<types::global_dof_index> dofs(n2);
727 cell1->get_dof_values(u1, u1_local);
728 matrix.
vmult(u2_local, u1_local);
729 cell2->get_dof_indices(dofs);
730 for (
unsigned int i=0; i<n2; ++i)
732 u2(dofs[i])+=u2_local(i);
741 template <
int dim,
class InVector,
class OutVector,
int spacedim>
754 template <
int dim,
class InVector,
class OutVector,
int spacedim>
762 ExcDimensionMismatch(dof1.
get_fe().n_components(), dof2.
get_fe().n_components()));
771 const unsigned int dofs_per_cell = dof2.
get_fe().dofs_per_cell;
782 for (; cell!=endc; ++cell)
783 Assert (cell->has_children(), ExcGridNotRefinedAtLeastOnce());
790 endc=dof2.
end(level);
792 for (; cell!=endc; ++cell)
798 bool active_children=
false;
799 for (
unsigned int child_n=0; child_n<cell->n_children(); ++child_n)
800 if (cell->child(child_n)->active())
802 active_children=
true;
815 cell->get_interpolated_dof_values(u3, dof_values);
816 cell->set_dof_values_by_interpolation(dof_values, u2);
830 #include "fe_tools_interpolate.inst" 835 DEAL_II_NAMESPACE_CLOSE
const MPI_Comm & get_mpi_communicator() const
active_cell_iterator begin_active(const unsigned int level=0) const
const types::subdomain_id invalid_subdomain_id
const MPI_Comm & get_mpi_communicator() const
void sadd(const TrilinosScalar s, const VectorBase &V)
const Triangulation< dim, spacedim > & get_triangulation() const
void distribute(VectorType &vec) const
ActiveSelector::active_cell_iterator active_cell_iterator
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
ActiveSelector::cell_iterator cell_iterator
unsigned int global_dof_index
#define Assert(cond, exc)
types::global_dof_index n_dofs() const
unsigned int n_locally_owned_dofs() const
unsigned int n_components() const
const Epetra_Map & vector_partitioner() const
unsigned int subdomain_id
cell_iterator end() const
const MPI_Comm & get_mpi_communicator() const
cell_iterator begin(const unsigned int level=0) const
size_type n_constraints() const
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
bool is_element(const size_type index) const
const unsigned int dofs_per_vertex
const IndexSet & locally_owned_dofs() const
const FiniteElement< dim, spacedim > & get_fe() const