Reference documentation for deal.II version 9.0.0
mapping_q1_eulerian.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/base/std_cxx14/memory.h>
17 
18 #include <deal.II/fe/mapping_q1_eulerian.h>
19 #include <deal.II/lac/vector.h>
20 #include <deal.II/lac/block_vector.h>
21 #include <deal.II/lac/la_vector.h>
22 #include <deal.II/lac/la_parallel_vector.h>
23 #include <deal.II/lac/la_parallel_block_vector.h>
24 #include <deal.II/lac/petsc_parallel_vector.h>
25 #include <deal.II/lac/petsc_parallel_block_vector.h>
26 #include <deal.II/lac/trilinos_vector.h>
27 #include <deal.II/lac/trilinos_parallel_block_vector.h>
28 #include <deal.II/lac/trilinos_parallel_block_vector.h>
29 #include <deal.II/grid/tria_iterator.h>
30 #include <deal.II/dofs/dof_handler.h>
31 #include <deal.II/dofs/dof_accessor.h>
32 #include <deal.II/fe/fe.h>
33 
34 
35 #include <array>
36 
37 DEAL_II_NAMESPACE_OPEN
38 
39 
40 template <int dim, class VectorType, int spacedim>
42 MappingQ1Eulerian (const DoFHandler<dim,spacedim> &shiftmap_dof_handler,
43  const VectorType &euler_transform_vectors)
44  :
45  MappingQGeneric<dim,spacedim>(1),
46  euler_transform_vectors(&euler_transform_vectors),
47  shiftmap_dof_handler(&shiftmap_dof_handler)
48 {}
49 
50 
51 
52 template <int dim, class VectorType, int spacedim>
53 std::array<Point<spacedim>, GeometryInfo<dim>::vertices_per_cell>
56 (const typename Triangulation<dim,spacedim>::cell_iterator &cell) const
57 {
58  std::array<Point<spacedim>, GeometryInfo<dim>::vertices_per_cell> vertices;
59  // The assertions can not be in the constructor, since this would
60  // require to call dof_handler.distribute_dofs(fe) *before* the mapping
61  // object is constructed, which is not necessarily what we want.
62 
63  //TODO: Only one of these two assertions should be relevant
64  AssertDimension (spacedim, shiftmap_dof_handler->get_fe().n_dofs_per_vertex());
65  AssertDimension (shiftmap_dof_handler->get_fe(0).n_components(), spacedim);
66 
67  AssertDimension (shiftmap_dof_handler->n_dofs(), euler_transform_vectors->size());
68 
69  // cast the Triangulation<dim>::cell_iterator into a
70  // DoFHandler<dim>::cell_iterator which is necessary for access to
71  // DoFCellAccessor::get_dof_values()
72  typename DoFHandler<dim,spacedim>::cell_iterator dof_cell (*cell, shiftmap_dof_handler);
73 
74  // We require the cell to be active since we can only then get nodal
75  // values for the shifts
76  Assert (dof_cell->active() == true, ExcInactiveCell());
77 
78  // now get the values of the shift vectors at the vertices
79  Vector<double> mapping_values (shiftmap_dof_handler->get_fe().dofs_per_cell);
80  dof_cell->get_dof_values (*euler_transform_vectors, mapping_values);
81 
82  for (unsigned int i=0; i<GeometryInfo<dim>::vertices_per_cell; ++i)
83  {
84  Point<spacedim> shift_vector;
85 
86  // pick out the value of the shift vector at the present
87  // vertex. since vertex dofs are always numbered first, we can
88  // access them easily
89  for (unsigned int j=0; j<spacedim; ++j)
90  shift_vector[j] = mapping_values(i*spacedim+j);
91 
92  // compute new support point by old (reference) value and added
93  // shift
94  vertices[i] = cell->vertex(i) + shift_vector;
95  }
96  return vertices;
97 }
98 
99 
100 
101 template <int dim, class VectorType, int spacedim>
102 std::vector<Point<spacedim> >
105 {
106  const std::array<Point<spacedim>, GeometryInfo<dim>::vertices_per_cell>
107  vertices = this->get_vertices(cell);
108 
109  std::vector<Point<spacedim> > a(GeometryInfo<dim>::vertices_per_cell);
110  for (unsigned int i=0; i<GeometryInfo<dim>::vertices_per_cell; ++i)
111  a[i] = vertices[i];
112 
113  return a;
114 }
115 
116 
117 
118 
119 
120 template <int dim, class VectorType, int spacedim>
121 std::unique_ptr<Mapping<dim,spacedim> >
123 {
124  return std_cxx14::make_unique<MappingQ1Eulerian<dim,VectorType,spacedim>>(*this);
125 }
126 
127 
128 
129 template <int dim, class VectorType, int spacedim>
134  const Quadrature<dim> &quadrature,
135  const typename Mapping<dim,spacedim>::InternalDataBase &internal_data,
137 {
138  // call the function of the base class, but ignoring
139  // any potentially detected cell similarity between
140  // the current and the previous cell
143  quadrature,
144  internal_data,
145  output_data);
146  // also return the updated flag since any detected
147  // similarity wasn't based on the mapped field, but
148  // the original vertices which are meaningless
150 }
151 
152 
153 
154 // explicit instantiations
155 #include "mapping_q1_eulerian.inst"
156 
157 
158 DEAL_II_NAMESPACE_CLOSE
MappingQ1Eulerian(const DoFHandler< dim, spacedim > &euler_dof_handler, const VectorType &euler_vector)
virtual CellSimilarity::Similarity fill_fe_values(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const CellSimilarity::Similarity cell_similarity, const Quadrature< dim > &quadrature, const typename Mapping< dim, spacedim >::InternalDataBase &internal_data, internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &output_data) const override
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1248
virtual CellSimilarity::Similarity fill_fe_values(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const CellSimilarity::Similarity cell_similarity, const Quadrature< dim > &quadrature, const typename Mapping< dim, spacedim >::InternalDataBase &internal_data, ::internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &output_data) const override
virtual std::vector< Point< spacedim > > compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const override
ActiveSelector::cell_iterator cell_iterator
Definition: dof_handler.h:257
#define Assert(cond, exc)
Definition: exceptions.h:1142
virtual std::unique_ptr< Mapping< dim, spacedim > > clone() const override
virtual std::array< Point< spacedim >, GeometryInfo< dim >::vertices_per_cell > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const override