Reference documentation for deal.II version GIT relicensing-216-gcda843ca70 2024-03-28 12:20:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
mapping_q_eulerian.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2008 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
17
20
21#include <deal.II/fe/fe.h>
22#include <deal.II/fe/fe_tools.h>
24
26
34#include <deal.II/lac/vector.h>
35
36#include <memory>
37
39
40
41
42// .... MAPPING Q EULERIAN CONSTRUCTOR
43
44
45template <int dim, typename VectorType, int spacedim>
47 const unsigned int degree,
48 const DoFHandler<dim, spacedim> &euler_dof_handler,
49 const VectorType &euler_vector,
50 const unsigned int level)
51 : MappingQ<dim, spacedim>(degree)
52 , euler_vector(&euler_vector)
53 , euler_dof_handler(&euler_dof_handler)
54 , level(level)
55 , support_quadrature(degree)
56 , fe_values(euler_dof_handler.get_fe(),
57 support_quadrature,
59{}
60
61
62
63template <int dim, typename VectorType, int spacedim>
64std::unique_ptr<Mapping<dim, spacedim>>
66{
67 return std::make_unique<MappingQEulerian<dim, VectorType, spacedim>>(
68 this->get_degree(), *euler_dof_handler, *euler_vector, this->level);
69}
70
71
72
73// .... SUPPORT QUADRATURE CONSTRUCTOR
74
75template <int dim, typename VectorType, int spacedim>
77 SupportQuadrature(const unsigned int map_degree)
78 : Quadrature<dim>(Utilities::fixed_power<dim>(map_degree + 1))
79{
80 // first we determine the support points on the unit cell in lexicographic
81 // order, which are (in accordance with MappingQ) the support points of
82 // QGaussLobatto.
83 const QGaussLobatto<dim> q_iterated(map_degree + 1);
84 const unsigned int n_q_points = q_iterated.size();
85
86 // we then need to define a renumbering vector that allows us to go from a
87 // lexicographic numbering scheme to a hierarchic one.
88 const std::vector<unsigned int> renumber =
89 FETools::lexicographic_to_hierarchic_numbering<dim>(map_degree);
90
91 // finally we assign the quadrature points in the required order.
92 for (unsigned int q = 0; q < n_q_points; ++q)
93 this->quadrature_points[renumber[q]] = q_iterated.point(q);
94}
95
96
97
98// .... COMPUTE MAPPING SUPPORT POINTS
99
100template <int dim, typename VectorType, int spacedim>
101boost::container::small_vector<Point<spacedim>,
104 const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
105{
106 // get the vertices as the first 2^dim mapping support points
107 const std::vector<Point<spacedim>> a = compute_mapping_support_points(cell);
108
109 boost::container::small_vector<Point<spacedim>,
111 vertex_locations(a.begin(),
113
114 return vertex_locations;
115}
116
117
118
119template <int dim, typename VectorType, int spacedim>
120std::vector<Point<spacedim>>
122 const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
123{
124 const bool mg_vector = level != numbers::invalid_unsigned_int;
125
126 const types::global_dof_index n_dofs =
127 mg_vector ? euler_dof_handler->n_dofs(level) : euler_dof_handler->n_dofs();
128 const types::global_dof_index vector_size = euler_vector->size();
129
130 (void)n_dofs;
131 (void)vector_size;
132
133 AssertDimension(vector_size, n_dofs);
134
135 // we then transform our tria iterator into a dof iterator so we can access
136 // data not associated with triangulations
137 typename DoFHandler<dim, spacedim>::cell_iterator dof_cell(*cell,
139
140 Assert(mg_vector || dof_cell->is_active() == true, ExcInactiveCell());
141
142 // our quadrature rule is chosen so that each quadrature point corresponds
143 // to a support point in the undeformed configuration. We can then query
144 // the given displacement field at these points to determine the shift
145 // vector that maps the support points to the deformed configuration.
146
147 // We assume that the given field contains dim displacement components, but
148 // that there may be other solution components as well (e.g. pressures).
149 // this class therefore assumes that the first dim components represent the
150 // actual shift vector we need, and simply ignores any components after
151 // that. This implies that the user should order components appropriately,
152 // or create a separate dof handler for the displacements.
153 const unsigned int n_support_pts = support_quadrature.size();
154 const unsigned int n_components = euler_dof_handler->get_fe(0).n_components();
155
156 Assert(n_components >= spacedim,
157 ExcDimensionMismatch(n_components, spacedim));
158
159 std::vector<Vector<typename VectorType::value_type>> shift_vector(
160 n_support_pts, Vector<typename VectorType::value_type>(n_components));
161
162 std::vector<types::global_dof_index> dof_indices(
163 euler_dof_handler->get_fe(0).n_dofs_per_cell());
164 // fill shift vector for each support point using an fe_values object. make
165 // sure that the fe_values variable isn't used simultaneously from different
166 // threads
167 std::lock_guard<std::mutex> lock(fe_values_mutex);
168 fe_values.reinit(dof_cell);
169 if (mg_vector)
170 {
171 dof_cell->get_mg_dof_indices(dof_indices);
172 fe_values.get_function_values(*euler_vector, dof_indices, shift_vector);
173 }
174 else
175 fe_values.get_function_values(*euler_vector, shift_vector);
176
177 // and finally compute the positions of the support points in the deformed
178 // configuration.
179 std::vector<Point<spacedim>> a(n_support_pts);
180 for (unsigned int q = 0; q < n_support_pts; ++q)
181 {
182 a[q] = fe_values.quadrature_point(q);
183 for (unsigned int d = 0; d < spacedim; ++d)
184 a[q][d] += shift_vector[q][d];
185 }
186
187 return a;
188}
189
190
191
192template <int dim, typename VectorType, int spacedim>
197 const Quadrature<dim> &quadrature,
198 const typename Mapping<dim, spacedim>::InternalDataBase &internal_data,
200 &output_data) const
201{
202 // call the function of the base class, but ignoring
203 // any potentially detected cell similarity between
204 // the current and the previous cell
207 quadrature,
208 internal_data,
209 output_data);
210 // also return the updated flag since any detected
211 // similarity wasn't based on the mapped field, but
212 // the original vertices which are meaningless
214}
215
216
217// explicit instantiations
218#include "mapping_q_eulerian.inst"
219
220
SupportQuadrature(const unsigned int map_degree)
FEValues< dim, spacedim > fe_values
SmartPointer< const DoFHandler< dim, spacedim >, MappingQEulerian< dim, VectorType, spacedim > > euler_dof_handler
virtual std::vector< Point< spacedim > > compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const override
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::unique_ptr< Mapping< dim, spacedim > > clone() const override
virtual boost::container::small_vector< Point< spacedim >, GeometryInfo< dim >::vertices_per_cell > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const override
MappingQEulerian(const unsigned int degree, const DoFHandler< dim, spacedim > &euler_dof_handler, const VectorType &euler_vector, const unsigned int level=numbers::invalid_unsigned_int)
SmartPointer< const VectorType, MappingQEulerian< dim, VectorType, spacedim > > euler_vector
Threads::Mutex fe_values_mutex
const SupportQuadrature support_quadrature
const unsigned int level
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
Definition mapping_q.cc:785
std::vector< Point< dim > > quadrature_points
Definition quadrature.h:338
const Point< dim > & point(const unsigned int i) const
unsigned int size() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
unsigned int level
Definition grid_out.cc:4616
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInactiveCell()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
typename ActiveSelector::cell_iterator cell_iterator
@ update_values
Shape function values.
@ update_quadrature_points
Transformed quadrature points.
static const unsigned int invalid_unsigned_int
Definition types.h:220