version GIT relicensing-7278-g091132d5eb 2026-12-02 03:10: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
39
40
41
42template <int dim, typename VectorType, int spacedim>
44 const unsigned int degree,
45 const DoFHandler<dim, spacedim> &euler_dof_handler,
46 const VectorType &euler_vector,
47 const unsigned int level)
48 : MappingQEulerian(degree,
49 euler_dof_handler,
50 euler_vector,
52 level)
53{}
54
55
56
57template <int dim, typename VectorType, int spacedim>
59 const unsigned int degree,
60 const DoFHandler<dim, spacedim> &euler_dof_handler,
61 const VectorType &euler_vector,
62 const ComponentMask &component_mask,
63 const unsigned int level)
64 : MappingQ<dim, spacedim>(degree)
65 , euler_vector(&euler_vector)
66 , euler_dof_handler(&euler_dof_handler)
67 , component_mask([&]() {
68 AssertThrow(euler_dof_handler.get_fe_collection().size() != 0,
69 ExcMessage("The DoFHandler must have a finite element assigned "
70 "before constructing the mapping."));
71 const unsigned int n_components = euler_dof_handler.get_fe().n_components();
72 AssertThrow(n_components >= spacedim,
73 ExcDimensionMismatch(n_components, spacedim));
74 ComponentMask selected_components = component_mask;
75 if (selected_components.represents_the_all_selected_mask())
76 {
77 selected_components = ComponentMask(n_components, false);
78 for (unsigned int d = 0; d < spacedim; ++d)
79 selected_components.set(d, true);
80 }
81 AssertThrow(selected_components.size() == n_components,
82 ExcDimensionMismatch(selected_components.size(), n_components));
83 AssertThrow(selected_components.n_selected_components() == spacedim,
84 ExcMessage("Select exactly spacedim displacement components."));
85 return selected_components;
86 }())
87 , level(level)
88 , support_quadrature(degree)
89 , mapping_q(degree)
90 , fe_values(mapping_q,
91 euler_dof_handler.get_fe(),
92 support_quadrature,
94{}
95
96
97
98template <int dim, typename VectorType, int spacedim>
99std::unique_ptr<Mapping<dim, spacedim>>
101{
102 return std::make_unique<MappingQEulerian<dim, VectorType, spacedim>>(
103 this->get_degree(),
104 *euler_dof_handler,
105 *euler_vector,
106 component_mask,
107 this->level);
108}
109
110
111
112template <int dim, typename VectorType, int spacedim>
114 SupportQuadrature(const unsigned int map_degree)
115 : Quadrature<dim>(Utilities::fixed_power<dim>(map_degree + 1))
116{
117 // first we determine the support points on the unit cell in lexicographic
118 // order, which are (in accordance with MappingQ) the support points of
119 // QGaussLobatto.
120 const QGaussLobatto<dim> q_iterated(map_degree + 1);
121 const unsigned int n_q_points = q_iterated.size();
122
123 // we then need to define a renumbering vector that allows us to go from a
124 // lexicographic numbering scheme to a hierarchic one.
125 const std::vector<unsigned int> renumber =
126 FETools::lexicographic_to_hierarchic_numbering<dim>(map_degree);
127
128 // finally we assign the quadrature points in the required order.
129 for (unsigned int q = 0; q < n_q_points; ++q)
130 this->quadrature_points[renumber[q]] = q_iterated.point(q);
131}
132
133
134
135template <int dim, typename VectorType, int spacedim>
136boost::container::small_vector<Point<spacedim>,
137#ifndef _MSC_VER
138 ReferenceCells::max_n_vertices<dim>()
139#else
141#endif
142 >
144 const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
145{
146 boost::container::small_vector<Point<spacedim>, 200> points;
147 compute_mapping_support_points(cell, points);
148
149 boost::container::small_vector<Point<spacedim>,
150#ifndef _MSC_VER
151 ReferenceCells::max_n_vertices<dim>()
152#else
154#endif
155 >
156 vertex_locations(points.begin(), points.begin() + cell->n_vertices());
157
158 return vertex_locations;
159}
160
161
162
163template <int dim, typename VectorType, int spacedim>
164void
167 boost::container::small_vector<Point<spacedim>, 200> &points) const
168{
169 const bool mg_vector = level != numbers::invalid_unsigned_int;
170
171 const types::global_dof_index n_dofs =
172 mg_vector ? euler_dof_handler->n_dofs(level) : euler_dof_handler->n_dofs();
173 const types::global_dof_index vector_size = euler_vector->size();
174 AssertDimension(vector_size, n_dofs);
175
176 // we then transform our tria iterator into a dof iterator so we can access
177 // data not associated with triangulations
178 typename DoFHandler<dim, spacedim>::cell_iterator dof_cell(*cell,
180
181 Assert(mg_vector || dof_cell->is_active() == true, ExcInactiveCell());
182
183 // our quadrature rule is chosen so that each quadrature point corresponds
184 // to a support point in the undeformed configuration. We can then query
185 // the given displacement field at these points to determine the shift
186 // vector that maps the support points to the deformed configuration.
187
188 const unsigned int n_support_pts = support_quadrature.size();
189 const unsigned int n_components = euler_dof_handler->get_fe(0).n_components();
190
191 std::vector<Vector<typename VectorType::value_type>> shift_vector(
192 n_support_pts, Vector<typename VectorType::value_type>(n_components));
193
194 std::vector<types::global_dof_index> dof_indices(
195 euler_dof_handler->get_fe(0).n_dofs_per_cell());
196 // fill shift vector for each support point using an fe_values object. make
197 // sure that the fe_values variable isn't used simultaneously from different
198 // threads
199 std::scoped_lock lock(fe_values_mutex);
200 fe_values.reinit(dof_cell);
201 if (mg_vector)
202 {
203 dof_cell->get_mg_dof_indices(dof_indices);
204 fe_values.get_function_values(*euler_vector, dof_indices, shift_vector);
205 }
206 else
207 fe_values.get_function_values(*euler_vector, shift_vector);
208
209 // and finally compute the positions of the support points in the deformed
210 // configuration.
211 points.resize(n_support_pts);
212 for (unsigned int q = 0; q < n_support_pts; ++q)
213 {
214 points[q] = fe_values.quadrature_point(q);
215 unsigned int d = 0;
216 for (unsigned int c = 0; c < n_components; ++c)
217 if (component_mask[c])
218 points[q][d++] += shift_vector[q][c];
219 }
220}
221
222
223
224template <int dim, typename VectorType, int spacedim>
229 const Quadrature<dim> &quadrature,
230 const typename Mapping<dim, spacedim>::InternalDataBase &internal_data,
232 &output_data) const
233{
234 // call the function of the base class, but ignoring
235 // any potentially detected cell similarity between
236 // the current and the previous cell
239 quadrature,
240 internal_data,
241 output_data);
242 // also return the updated flag since any detected
243 // similarity wasn't based on the mapped field, but
244 // the original vertices which are meaningless
246}
247
248
249// explicit instantiations
250#include "fe/mapping_q_eulerian.inst"
251
252
void set(const unsigned int index, const bool value)
bool represents_the_all_selected_mask() const
unsigned int size() const
unsigned int n_selected_components(const unsigned int overall_number_of_components=numbers::invalid_unsigned_int) const
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
const ComponentMask component_mask
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)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
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