deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+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: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2008 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
15
18
19#include <deal.II/fe/fe.h>
20#include <deal.II/fe/fe_tools.h>
22
24
32#include <deal.II/lac/vector.h>
33
34#include <boost/container/small_vector.hpp>
35
36#include <memory>
37
38
40
41
42
43template <int dim, typename VectorType, int spacedim>
45 const unsigned int degree,
46 const DoFHandler<dim, spacedim> &euler_dof_handler,
47 const VectorType &euler_vector,
48 const unsigned int level)
49 : MappingQ<dim, spacedim>(degree)
50 , euler_vector(&euler_vector)
51 , euler_dof_handler(&euler_dof_handler)
52 , level(level)
53 , support_quadrature(degree)
54 , mapping_q(degree)
55 , fe_values(mapping_q,
56 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
73template <int dim, typename VectorType, int spacedim>
75 SupportQuadrature(const unsigned int map_degree)
76 : Quadrature<dim>(Utilities::fixed_power<dim>(map_degree + 1))
77{
78 // first we determine the support points on the unit cell in lexicographic
79 // order, which are (in accordance with MappingQ) the support points of
80 // QGaussLobatto.
81 const QGaussLobatto<dim> q_iterated(map_degree + 1);
82 const unsigned int n_q_points = q_iterated.size();
83
84 // we then need to define a renumbering vector that allows us to go from a
85 // lexicographic numbering scheme to a hierarchic one.
86 const std::vector<unsigned int> renumber =
87 FETools::lexicographic_to_hierarchic_numbering<dim>(map_degree);
88
89 // finally we assign the quadrature points in the required order.
90 for (unsigned int q = 0; q < n_q_points; ++q)
91 this->quadrature_points[renumber[q]] = q_iterated.point(q);
92}
93
94
95
96template <int dim, typename VectorType, int spacedim>
97boost::container::small_vector<Point<spacedim>,
98#ifndef _MSC_VER
99 ReferenceCells::max_n_vertices<dim>()
100#else
102#endif
103 >
105 const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
106{
107 boost::container::small_vector<Point<spacedim>, 200> points;
108 compute_mapping_support_points(cell, points);
109
110 boost::container::small_vector<Point<spacedim>,
111#ifndef _MSC_VER
112 ReferenceCells::max_n_vertices<dim>()
113#else
115#endif
116 >
117 vertex_locations(points.begin(), points.begin() + cell->n_vertices());
118
119 return vertex_locations;
120}
121
122
123
124template <int dim, typename VectorType, int spacedim>
125void
128 boost::container::small_vector<Point<spacedim>, 200> &points) const
129{
130 const bool mg_vector = level != numbers::invalid_unsigned_int;
131
132 const types::global_dof_index n_dofs =
133 mg_vector ? euler_dof_handler->n_dofs(level) : euler_dof_handler->n_dofs();
134 const types::global_dof_index vector_size = euler_vector->size();
135 AssertDimension(vector_size, n_dofs);
136
137 // we then transform our tria iterator into a dof iterator so we can access
138 // data not associated with triangulations
139 typename DoFHandler<dim, spacedim>::cell_iterator dof_cell(*cell,
141
142 Assert(mg_vector || dof_cell->is_active() == true, ExcInactiveCell());
143
144 // our quadrature rule is chosen so that each quadrature point corresponds
145 // to a support point in the undeformed configuration. We can then query
146 // the given displacement field at these points to determine the shift
147 // vector that maps the support points to the deformed configuration.
148
149 // We assume that the given field contains dim displacement components, but
150 // that there may be other solution components as well (e.g. pressures).
151 // this class therefore assumes that the first dim components represent the
152 // actual shift vector we need, and simply ignores any components after
153 // that. This implies that the user should order components appropriately,
154 // or create a separate dof handler for the displacements.
155 const unsigned int n_support_pts = support_quadrature.size();
156 const unsigned int n_components = euler_dof_handler->get_fe(0).n_components();
157
158 Assert(n_components >= spacedim,
159 ExcDimensionMismatch(n_components, spacedim));
160
161 std::vector<Vector<typename VectorType::value_type>> shift_vector(
162 n_support_pts, Vector<typename VectorType::value_type>(n_components));
163
164 std::vector<types::global_dof_index> dof_indices(
165 euler_dof_handler->get_fe(0).n_dofs_per_cell());
166 // fill shift vector for each support point using an fe_values object. make
167 // sure that the fe_values variable isn't used simultaneously from different
168 // threads
169 std::scoped_lock lock(fe_values_mutex);
170 fe_values.reinit(dof_cell);
171 if (mg_vector)
172 {
173 dof_cell->get_mg_dof_indices(dof_indices);
174 fe_values.get_function_values(*euler_vector, dof_indices, shift_vector);
175 }
176 else
177 fe_values.get_function_values(*euler_vector, shift_vector);
178
179 // and finally compute the positions of the support points in the deformed
180 // configuration.
181 points.resize(n_support_pts);
182 for (unsigned int q = 0; q < n_support_pts; ++q)
183 {
184 points[q] = fe_values.quadrature_point(q);
185 for (unsigned int d = 0; d < spacedim; ++d)
186 points[q][d] += shift_vector[q][d];
187 }
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 "fe/mapping_q_eulerian.inst"
219
220
SupportQuadrature(const unsigned int map_degree)
FEValues< dim, spacedim > fe_values
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
MappingQEulerian(const unsigned int degree, const DoFHandler< dim, spacedim > &euler_dof_handler, const VectorType &euler_vector, const unsigned int level=numbers::invalid_unsigned_int)
ObserverPointer< const VectorType, MappingQEulerian< dim, VectorType, spacedim > > euler_vector
ObserverPointer< const DoFHandler< dim, spacedim >, MappingQEulerian< dim, VectorType, spacedim > > euler_dof_handler
Threads::Mutex fe_values_mutex
virtual void compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell, boost::container::small_vector< Point< spacedim >, 200 > &a) const override
const SupportQuadrature support_quadrature
virtual boost::container::small_vector< Point< spacedim >, ReferenceCells::max_n_vertices< dim >() > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const override
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:856
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
unsigned int level
Definition grid_out.cc:4642
#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.
constexpr unsigned int invalid_unsigned_int
Definition types.h:228