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_q1_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) 2001 - 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
13
16
17#include <deal.II/fe/fe.h>
19
21
29#include <deal.II/lac/vector.h>
30
31#include <boost/container/small_vector.hpp>
32
33#include <array>
34#include <memory>
35
36
38
39
40template <int dim, typename VectorType, int spacedim>
42 const DoFHandler<dim, spacedim> &shiftmap_dof_handler,
43 const VectorType &euler_transform_vectors)
44 : MappingQ1Eulerian(shiftmap_dof_handler,
45 euler_transform_vectors,
47{}
48
49
50
51template <int dim, typename VectorType, int spacedim>
53 const DoFHandler<dim, spacedim> &shiftmap_dof_handler,
54 const VectorType &euler_transform_vectors,
55 const ComponentMask &component_mask)
56 : MappingQ<dim, spacedim>(1)
57 , euler_transform_vectors(&euler_transform_vectors)
58 , shiftmap_dof_handler(&shiftmap_dof_handler)
59 , component_mask([&]() {
60 AssertThrow(shiftmap_dof_handler.get_fe_collection().size() != 0,
61 ExcMessage("The DoFHandler must have a finite element assigned "
62 "before constructing the mapping."));
63 const unsigned int n_components =
64 shiftmap_dof_handler.get_fe().n_components();
65 AssertThrow(n_components >= spacedim,
66 ExcDimensionMismatch(n_components, spacedim));
67 ComponentMask selected_components = component_mask;
68 if (selected_components.represents_the_all_selected_mask())
69 {
70 selected_components = ComponentMask(n_components, false);
71 for (unsigned int d = 0; d < spacedim; ++d)
72 selected_components.set(d, true);
73 }
74 AssertThrow(selected_components.size() == n_components,
75 ExcDimensionMismatch(selected_components.size(), n_components));
76 AssertThrow(selected_components.n_selected_components() == spacedim,
77 ExcMessage("Select exactly spacedim displacement components."));
78 return selected_components;
79 }())
80{
81 get_vertex_dof_indices();
82}
83
84
85
86template <int dim, typename VectorType, int spacedim>
87std::array<unsigned int, spacedim>
89{
90 const auto &fe = shiftmap_dof_handler->get_fe();
91 const unsigned int n_vertex_dofs = fe.n_dofs_per_vertex();
92 std::array<unsigned int, spacedim> vertex_dof_indices{};
93 unsigned int d = 0;
94 for (unsigned int c = 0; c < fe.n_components(); ++c)
95 if (component_mask[c])
96 {
97 unsigned int index = numbers::invalid_unsigned_int;
98 for (unsigned int j = 0; j < n_vertex_dofs; ++j)
99 if (fe.get_nonzero_components(j)[c])
100 {
102 fe.is_primitive(j) && index == numbers::invalid_unsigned_int,
104 "Each selected component must have one primitive vertex DoF."));
105 index = j;
106 }
110 "Each selected component must have one primitive vertex DoF."));
111 // Sampling vertex coefficients is valid only if other selected
112 // shape functions do not contribute at vertices (FE_Q_DG0, for
113 // example, also has a cell-constant mode).
114 for (unsigned int j = fe.reference_cell().n_vertices() * n_vertex_dofs;
115 j < fe.n_dofs_per_cell();
116 ++j)
117 if (fe.get_nonzero_components(j)[c])
118 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
120 fe.shape_value_component(j,
122 c) == 0.,
124 "Selected nonvertex shape functions must vanish at vertices."));
125 vertex_dof_indices[d++] = index;
126 }
127
128 return vertex_dof_indices;
129}
130
131
132
133template <int dim, typename VectorType, int spacedim>
134boost::container::small_vector<Point<spacedim>,
135#ifndef _MSC_VER
136 ReferenceCells::max_n_vertices<dim>()
137#else
139#endif
140 >
142 const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
143{
144 boost::container::small_vector<Point<spacedim>,
145#ifndef _MSC_VER
146 ReferenceCells::max_n_vertices<dim>()
147#else
149#endif
150 >
151 vertices(cell->n_vertices());
152 const auto vertex_dof_indices = get_vertex_dof_indices();
153 const unsigned int n_vertex_dofs =
154 shiftmap_dof_handler->get_fe().n_dofs_per_vertex();
155
156 AssertDimension(shiftmap_dof_handler->n_dofs(),
157 euler_transform_vectors->size());
158
159 // cast the Triangulation<dim>::cell_iterator into a
160 // DoFHandler<dim>::cell_iterator which is necessary for access to
161 // DoFCellAccessor::get_dof_values()
163 *cell, shiftmap_dof_handler);
164
165 // We require the cell to be active since we can only then get nodal
166 // values for the shifts
167 Assert(dof_cell->is_active() == true, ExcInactiveCell());
168
169 // now get the values of the shift vectors at the vertices
171 shiftmap_dof_handler->get_fe().n_dofs_per_cell());
172 dof_cell->get_dof_values(*euler_transform_vectors, mapping_values);
173
174 for (const unsigned int i : GeometryInfo<dim>::vertex_indices())
175 {
176 Point<spacedim> shift_vector;
177
178 // pick out the value of the shift vector at the present
179 // vertex. since vertex dofs are always numbered first, we can
180 // access them easily
181 for (unsigned int j = 0; j < spacedim; ++j)
182 shift_vector[j] =
183 mapping_values(i * n_vertex_dofs + vertex_dof_indices[j]);
184
185 // compute new support point by old (reference) value and added
186 // shift
187 vertices[i] = cell->vertex(i) + shift_vector;
188 }
189 return vertices;
190}
191
192
193
194template <int dim, typename VectorType, int spacedim>
195void
198 boost::container::small_vector<Point<spacedim>, 200> &points) const
199{
200 const auto vertices = this->get_vertices(cell);
201 points.assign(vertices.begin(), vertices.end());
202}
203
204
205
206template <int dim, typename VectorType, int spacedim>
207std::unique_ptr<Mapping<dim, spacedim>>
209{
210 return std::make_unique<MappingQ1Eulerian<dim, VectorType, spacedim>>(
211 *shiftmap_dof_handler, *euler_transform_vectors, component_mask);
212}
213
214
215
216template <int dim, typename VectorType, int spacedim>
221 const Quadrature<dim> &quadrature,
222 const typename Mapping<dim, spacedim>::InternalDataBase &internal_data,
224 &output_data) const
225{
226 // call the function of the base class, but ignoring
227 // any potentially detected cell similarity between
228 // the current and the previous cell
231 quadrature,
232 internal_data,
233 output_data);
234 // also return the updated flag since any detected
235 // similarity wasn't based on the mapped field, but
236 // the original vertices which are meaningless
238}
239
240
241
242// explicit instantiations
243#include "fe/mapping_q1_eulerian.inst"
244
245
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
ObserverPointer< const DoFHandler< dim, spacedim >, MappingQ1Eulerian< dim, VectorType, spacedim > > shiftmap_dof_handler
std::array< unsigned int, spacedim > get_vertex_dof_indices() const
const ComponentMask component_mask
virtual std::unique_ptr< Mapping< dim, spacedim > > clone() 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
MappingQ1Eulerian(const DoFHandler< dim, spacedim > &euler_dof_handler, const VectorType &euler_vector)
virtual void compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell, boost::container::small_vector< Point< spacedim >, 200 > &points) const override
virtual boost::container::small_vector< Point< spacedim >, ReferenceCells::max_n_vertices< dim >() > get_vertices(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
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
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
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
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
static std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices()