Reference documentation for deal.II version 8.5.1
mapping_q_eulerian.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2016 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/utilities.h>
17 #include <deal.II/base/quadrature_lib.h>
18 #include <deal.II/lac/vector.h>
19 #include <deal.II/lac/block_vector.h>
20 #include <deal.II/lac/la_vector.h>
21 #include <deal.II/lac/parallel_vector.h>
22 #include <deal.II/lac/parallel_block_vector.h>
23 #include <deal.II/lac/petsc_vector.h>
24 #include <deal.II/lac/petsc_block_vector.h>
25 #include <deal.II/lac/trilinos_vector.h>
26 #include <deal.II/lac/trilinos_block_vector.h>
27 #include <deal.II/lac/trilinos_parallel_block_vector.h>
28 #include <deal.II/grid/tria_iterator.h>
29 #include <deal.II/dofs/dof_handler.h>
30 #include <deal.II/dofs/dof_accessor.h>
31 #include <deal.II/fe/fe.h>
32 #include <deal.II/fe/fe_tools.h>
33 #include <deal.II/fe/mapping_q_eulerian.h>
34 #include <deal.II/fe/mapping_q1_eulerian.h>
35 
36 DEAL_II_NAMESPACE_OPEN
37 
38 
39 
40 // .... MAPPING Q EULERIAN CONSTRUCTOR
41 
42 template <int dim, class VectorType, int spacedim>
44 MappingQEulerianGeneric (const unsigned int degree,
45  const MappingQEulerian<dim, VectorType, spacedim> &mapping_q_eulerian)
46  :
47  MappingQGeneric<dim,spacedim>(degree),
48  mapping_q_eulerian (mapping_q_eulerian),
49  support_quadrature(degree),
50  fe_values(mapping_q_eulerian.euler_dof_handler->get_fe(),
51  support_quadrature,
53 {}
54 
55 template <int dim, class VectorType, int spacedim>
57 MappingQEulerian (const unsigned int degree,
58  const VectorType &euler_vector,
60  :
61  MappingQ<dim,spacedim>(degree, true),
64 {
65  // reset the q1 mapping we use for interior cells (and previously
66  // set by the MappingQ constructor) to a MappingQ1Eulerian with the
67  // current vector
70 
71  // also reset the qp mapping pointer with our own class
72  this->qp_mapping.reset (new MappingQEulerianGeneric(degree,*this));
73 }
74 
75 
76 
77 template <int dim, class VectorType, int spacedim>
79 MappingQEulerian (const unsigned int degree,
80  const DoFHandler<dim,spacedim> &euler_dof_handler,
81  const VectorType &euler_vector)
82  :
83  MappingQ<dim,spacedim>(degree, true),
84  euler_vector(&euler_vector),
85  euler_dof_handler(&euler_dof_handler)
86 {
87  // reset the q1 mapping we use for interior cells (and previously
88  // set by the MappingQ constructor) to a MappingQ1Eulerian with the
89  // current vector
92 
93  // also reset the qp mapping pointer with our own class
94  this->qp_mapping.reset (new MappingQEulerianGeneric(degree,*this));
95 }
96 
97 
98 
99 template <int dim, class VectorType, int spacedim>
102 {
103  return new MappingQEulerian<dim,VectorType,spacedim>(this->get_degree(),
104  *euler_vector,
105  *euler_dof_handler);
106 }
107 
108 
109 
110 // .... SUPPORT QUADRATURE CONSTRUCTOR
111 
112 template <int dim, class VectorType, int spacedim>
115 SupportQuadrature (const unsigned int map_degree)
116  :
117  Quadrature<dim>(Utilities::fixed_power<dim>(map_degree+1))
118 {
119  // first we determine the support points on the unit cell in lexicographic
120  // order, which are (in accordance with MappingQ) the support points of
121  // QGaussLobatto.
122  const QGaussLobatto<dim> q_iterated(map_degree+1);
123  const unsigned int n_q_points = q_iterated.size();
124 
125  // we then need to define a renumbering vector that allows us to go from a
126  // lexicographic numbering scheme to a hierarchic one. this fragment is
127  // taking almost verbatim from the MappingQ class.
128  std::vector<unsigned int> renumber(n_q_points);
129  std::vector<unsigned int> dpo(dim+1, 1U);
130  for (unsigned int i=1; i<dpo.size(); ++i)
131  dpo[i]=dpo[i-1]*(map_degree-1);
132 
134  renumber);
135 
136  // finally we assign the quadrature points in the required order.
137  for (unsigned int q=0; q<n_q_points; ++q)
138  this->quadrature_points[renumber[q]] = q_iterated.point(q);
139 }
140 
141 
142 
143 // .... COMPUTE MAPPING SUPPORT POINTS
144 
145 template <int dim, class VectorType, int spacedim>
146 std_cxx11::array<Point<spacedim>, GeometryInfo<dim>::vertices_per_cell>
149 (const typename Triangulation<dim,spacedim>::cell_iterator &cell) const
150 {
151  // get the vertices as the first 2^dim mapping support points
152  const std::vector<Point<spacedim> > a
153  = dynamic_cast<const MappingQEulerianGeneric &>(*this->qp_mapping).compute_mapping_support_points(cell);
154 
155  std_cxx11::array<Point<spacedim>, GeometryInfo<dim>::vertices_per_cell> vertex_locations;
156  std::copy (a.begin(),
158  vertex_locations.begin());
159 
160  return vertex_locations;
161 }
162 
163 
164 
165 template <int dim, class VectorType, int spacedim>
166 std_cxx11::array<Point<spacedim>, GeometryInfo<dim>::vertices_per_cell>
169 (const typename Triangulation<dim,spacedim>::cell_iterator &cell) const
170 {
171  return mapping_q_eulerian.get_vertices (cell);
172 }
173 
174 
175 
176 
177 template <int dim, class VectorType, int spacedim>
178 std::vector<Point<spacedim> >
181 {
182  // first, basic assertion with respect to vector size,
183 
184  const types::global_dof_index n_dofs = mapping_q_eulerian.euler_dof_handler->n_dofs();
185  const types::global_dof_index vector_size = mapping_q_eulerian.euler_vector->size();
186  (void)n_dofs;
187  (void)vector_size;
188 
189  AssertDimension(vector_size,n_dofs);
190 
191  // we then transform our tria iterator into a dof iterator so we can access
192  // data not associated with triangulations
193  typename DoFHandler<dim,spacedim>::cell_iterator dof_cell(*cell,
194  mapping_q_eulerian.euler_dof_handler);
195 
196  Assert (dof_cell->active() == true, ExcInactiveCell());
197 
198  // our quadrature rule is chosen so that each quadrature point corresponds
199  // to a support point in the undeformed configuration. we can then query
200  // the given displacement field at these points to determine the shift
201  // vector that maps the support points to the deformed configuration.
202 
203  // we assume that the given field contains dim displacement components, but
204  // that there may be other solution components as well (e.g. pressures).
205  // this class therefore assumes that the first dim components represent the
206  // actual shift vector we need, and simply ignores any components after
207  // that. this implies that the user should order components appropriately,
208  // or create a separate dof handler for the displacements.
209 
210  const unsigned int n_support_pts = support_quadrature.size();
211  const unsigned int n_components = mapping_q_eulerian.euler_dof_handler->get_fe().n_components();
212 
213  Assert (n_components >= spacedim, ExcDimensionMismatch(n_components, spacedim) );
214 
215  std::vector<Vector<typename VectorType::value_type> >
216  shift_vector(n_support_pts,
218 
219  // fill shift vector for each support point using an fe_values object. make
220  // sure that the fe_values variable isn't used simultaneously from different
221  // threads
223  fe_values.reinit(dof_cell);
224  fe_values.get_function_values(*mapping_q_eulerian.euler_vector, shift_vector);
225 
226  // and finally compute the positions of the support points in the deformed
227  // configuration.
228  std::vector<Point<spacedim> > a(n_support_pts);
229  for (unsigned int q=0; q<n_support_pts; ++q)
230  {
231  a[q] = fe_values.quadrature_point(q);
232  for (unsigned int d=0; d<spacedim; ++d)
233  a[q](d) += shift_vector[q](d);
234  }
235 
236  return a;
237 }
238 
239 
240 
241 template<int dim, class VectorType, int spacedim>
246  const Quadrature<dim> &quadrature,
247  const typename Mapping<dim,spacedim>::InternalDataBase &internal_data,
249 {
250  // call the function of the base class, but ignoring
251  // any potentially detected cell similarity between
252  // the current and the previous cell
255  quadrature,
256  internal_data,
257  output_data);
258  // also return the updated flag since any detected
259  // similarity wasn't based on the mapped field, but
260  // the original vertices which are meaningless
262 }
263 
264 
265 
266 // explicit instantiations
267 #include "mapping_q_eulerian.inst"
268 
269 
270 DEAL_II_NAMESPACE_CLOSE
Shape function values.
std_cxx11::shared_ptr< const MappingQGeneric< dim, spacedim > > q1_mapping
Definition: mapping_q.h:355
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1146
static ::ExceptionBase & ExcInactiveCell()
const Point< dim > & point(const unsigned int i) const
Transformed quadrature points.
virtual std::vector< Point< spacedim > > compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
ActiveSelector::cell_iterator cell_iterator
Definition: dof_handler.h:256
MappingQEulerianGeneric(const unsigned int degree, const MappingQEulerian< dim, VectorType, spacedim > &mapping_q_eulerian)
unsigned int global_dof_index
Definition: types.h:88
virtual std_cxx11::array< Point< spacedim >, GeometryInfo< dim >::vertices_per_cell > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
#define Assert(cond, exc)
Definition: exceptions.h:313
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
virtual std_cxx11::array< Point< spacedim >, GeometryInfo< dim >::vertices_per_cell > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
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::FEValues::MappingRelatedData< dim, spacedim > &output_data) const
Abstract base class for mapping classes.
Definition: dof_tools.h:46
SmartPointer< const VectorType, MappingQEulerian< dim, VectorType, spacedim > > euler_vector
MappingQEulerian(const unsigned int degree, const DoFHandler< dim, spacedim > &euler_dof_handler, const VectorType &euler_vector)
std::vector< Point< dim > > quadrature_points
Definition: quadrature.h:228
unsigned int size() const
void lexicographic_to_hierarchic_numbering(const FiniteElementData< dim > &fe_data, std::vector< unsigned int > &l2h)
Definition: fe_tools.cc:3120
Definition: mpi.h:48
SmartPointer< const DoFHandler< dim, spacedim >, MappingQEulerian< dim, VectorType, spacedim > > euler_dof_handler
virtual Mapping< dim, spacedim > * clone() const
std_cxx11::shared_ptr< const MappingQGeneric< dim, spacedim > > qp_mapping
Definition: mapping_q.h:371
const MappingQEulerian< dim, VectorType, spacedim > & mapping_q_eulerian