deal.II version 9.8.0
\(\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
fe_p1nc.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) 2016 - 2026 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
14#include <deal.II/base/config.h>
15
18#include <deal.II/base/point.h>
21#include <deal.II/base/table.h>
22#include <deal.II/base/tensor.h>
23#include <deal.II/base/types.h>
24
26#include <deal.II/fe/fe.h>
27#include <deal.II/fe/fe_data.h>
28#include <deal.II/fe/fe_p1nc.h>
30
33
36
38
39#include <Kokkos_Macros.hpp>
40
41#include <array>
42#include <memory>
43#include <ostream>
44
46
47
49 : FiniteElement<2, 2>(
51 std::vector<bool>(1, false),
52 std::vector<ComponentMask>(4, ComponentMask(1, true)))
53{
54 // face support points: 2 end vertices
55 unit_face_support_points[0].resize(2);
56 unit_face_support_points[0][0][0] = 0.0;
57 unit_face_support_points[0][1][0] = 1.0;
58
59 // initialize constraints matrix
61}
62
63
64
65std::string
67{
68 return "FE_P1NC";
69}
70
71
72
74FE_P1NC::requires_update_flags(const UpdateFlags flags) const
75{
76 UpdateFlags out = update_default;
77
78 if (flags & update_values)
80 if (flags & update_gradients)
81 out |= update_gradients;
82 if (flags & update_normal_vectors)
84 if (flags & update_hessians)
85 out |= update_hessians;
86
87 return out;
88}
89
90
91
92std::unique_ptr<FiniteElement<2, 2>>
94{
95 return std::make_unique<FE_P1NC>(*this);
96}
97
98
99
100std::vector<unsigned int>
102{
103 std::vector<unsigned int> dpo(3);
104 dpo[0] = 1; // dofs per object: vertex
105 dpo[1] = 0; // line
106 dpo[2] = 0; // quad
107 return dpo;
108}
109
110
111
115{
116 // edge midpoints
117 const Point<2> mpt[4] = {(cell->vertex(0) + cell->vertex(2)) / 2,
118 (cell->vertex(1) + cell->vertex(3)) / 2,
119 (cell->vertex(0) + cell->vertex(1)) / 2,
120 (cell->vertex(2) + cell->vertex(3)) / 2};
121
122 // center point
123 const Point<2> cpt =
124 (cell->vertex(0) + cell->vertex(1) + cell->vertex(2) + cell->vertex(3)) / 4;
125
126 const double det = (mpt[0][0] - mpt[1][0]) * (mpt[2][1] - mpt[3][1]) -
127 (mpt[2][0] - mpt[3][0]) * (mpt[0][1] - mpt[1][1]);
128
130 coeffs[0][0] =
131 ((mpt[2][1] - mpt[3][1]) * (0.5) - (mpt[0][1] - mpt[1][1]) * (0.5)) / det;
132 coeffs[1][0] =
133 ((mpt[2][1] - mpt[3][1]) * (-0.5) - (mpt[0][1] - mpt[1][1]) * (0.5)) / det;
134 coeffs[2][0] =
135 ((mpt[2][1] - mpt[3][1]) * (0.5) - (mpt[0][1] - mpt[1][1]) * (-0.5)) / det;
136 coeffs[3][0] =
137 ((mpt[2][1] - mpt[3][1]) * (-0.5) - (mpt[0][1] - mpt[1][1]) * (-0.5)) / det;
138
139 coeffs[0][1] =
140 (-(mpt[2][0] - mpt[3][0]) * (0.5) + (mpt[0][0] - mpt[1][0]) * (0.5)) / det;
141 coeffs[1][1] =
142 (-(mpt[2][0] - mpt[3][0]) * (-0.5) + (mpt[0][0] - mpt[1][0]) * (0.5)) / det;
143 coeffs[2][1] =
144 (-(mpt[2][0] - mpt[3][0]) * (0.5) + (mpt[0][0] - mpt[1][0]) * (-0.5)) / det;
145 coeffs[3][1] =
146 (-(mpt[2][0] - mpt[3][0]) * (-0.5) + (mpt[0][0] - mpt[1][0]) * (-0.5)) /
147 det;
148
149 coeffs[0][2] = 0.25 - cpt[0] * coeffs[0][0] - cpt[1] * coeffs[0][1];
150 coeffs[1][2] = 0.25 - cpt[0] * coeffs[1][0] - cpt[1] * coeffs[1][1];
151 coeffs[2][2] = 0.25 - cpt[0] * coeffs[2][0] - cpt[1] * coeffs[2][1];
152 coeffs[3][2] = 0.25 - cpt[0] * coeffs[3][0] - cpt[1] * coeffs[3][1];
153
154 return coeffs;
155}
156
157
158
159std::unique_ptr<FiniteElement<2, 2>::InternalDataBase>
161 const UpdateFlags update_flags,
162 const Mapping<2, 2> &,
163 const Quadrature<2> &quadrature,
165 &output_data) const
166{
167 auto data_ptr = std::make_unique<FiniteElement<2, 2>::InternalDataBase>();
168
169 data_ptr->update_each = requires_update_flags(update_flags);
170
171 const unsigned int n_q_points = quadrature.size();
172 output_data.initialize(n_q_points, FE_P1NC(), data_ptr->update_each);
173
174 // this is a linear element, so its second derivatives are zero
175 if (data_ptr->update_each & update_hessians)
176 output_data.shape_hessians.fill(Tensor<2, 2>());
177
178 return data_ptr;
179}
180
181
182
183std::unique_ptr<FiniteElement<2, 2>::InternalDataBase>
185 const UpdateFlags update_flags,
186 const Mapping<2, 2> &,
187 const hp::QCollection<1> &quadrature,
189 &output_data) const
190{
191 AssertDimension(quadrature.size(), 1);
192
193 auto data_ptr = std::make_unique<FiniteElement<2, 2>::InternalDataBase>();
194
195 data_ptr->update_each = requires_update_flags(update_flags);
196
197 const unsigned int n_q_points = quadrature[0].size();
198 output_data.initialize(n_q_points, FE_P1NC(), data_ptr->update_each);
199
200 // this is a linear element, so its second derivatives are zero
201 if (data_ptr->update_each & update_hessians)
202 output_data.shape_hessians.fill(Tensor<2, 2>());
203
204 return data_ptr;
205}
206
207
208
209std::unique_ptr<FiniteElement<2, 2>::InternalDataBase>
211 const UpdateFlags update_flags,
212 const Mapping<2, 2> &,
213 const Quadrature<1> &quadrature,
215 &output_data) const
216{
217 auto data_ptr = std::make_unique<FiniteElement<2, 2>::InternalDataBase>();
218
219 data_ptr->update_each = requires_update_flags(update_flags);
220
221 const unsigned int n_q_points = quadrature.size();
222 output_data.initialize(n_q_points, FE_P1NC(), data_ptr->update_each);
223
224 // this is a linear element, so its second derivatives are zero
225 if (data_ptr->update_each & update_hessians)
226 output_data.shape_hessians.fill(Tensor<2, 2>());
227
228 return data_ptr;
229}
230
231
232
233void
237 const Quadrature<2> &,
238 const Mapping<2, 2> &,
241 &mapping_data,
242 const FiniteElement<2, 2>::InternalDataBase &fe_internal,
244 const
245{
246 const UpdateFlags flags(fe_internal.update_each);
247
248 const unsigned int n_q_points = mapping_data.quadrature_points.size();
249
250 // linear shape functions
252
253 // compute on the cell
254 if (flags & update_values)
255 for (unsigned int i = 0; i < n_q_points; ++i)
256 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
257 output_data.shape_values[k][i] =
258 (coeffs[k][0] * mapping_data.quadrature_points[i][0] +
259 coeffs[k][1] * mapping_data.quadrature_points[i][1] + coeffs[k][2]);
260
261 if (flags & update_gradients)
262 for (unsigned int i = 0; i < n_q_points; ++i)
263 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
264 output_data.shape_gradients[k][i] =
265 Point<2>(coeffs[k][0], coeffs[k][1]);
266}
267
268
269
270void
273 const unsigned int face_no,
274 const hp::QCollection<1> &quadrature,
275 const Mapping<2, 2> &mapping,
278 const InternalDataBase &fe_internal,
280 &output_data) const
281{
282 AssertDimension(quadrature.size(), 1);
283
284 const UpdateFlags flags(fe_internal.update_each);
285
286 // linear shape functions
288
289 // compute on the face
290 const Quadrature<2> quadrature_on_face =
292 quadrature[0],
293 face_no,
295
296 if (flags & update_values)
297 for (unsigned int i = 0; i < quadrature_on_face.size(); ++i)
298 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
299 {
300 const Point<2> quadrature_point =
301 mapping.transform_unit_to_real_cell(cell,
302 quadrature_on_face.point(i));
303
304 output_data.shape_values[k][i] =
305 (coeffs[k][0] * quadrature_point[0] +
306 coeffs[k][1] * quadrature_point[1] + coeffs[k][2]);
307 }
308
309 if (flags & update_gradients)
310 for (unsigned int i = 0; i < quadrature_on_face.size(); ++i)
311 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
312 output_data.shape_gradients[k][i] =
313 Point<2>(coeffs[k][0], coeffs[k][1]);
314}
315
316
317
318void
321 const unsigned int face_no,
322 const unsigned int sub_no,
323 const Quadrature<1> &quadrature,
324 const Mapping<2, 2> &mapping,
327 const InternalDataBase &fe_internal,
329 &output_data) const
330{
331 const UpdateFlags flags(fe_internal.update_each);
332
333 // linear shape functions
335
336 // compute on the subface
337 const Quadrature<2> quadrature_on_subface =
339 quadrature,
340 face_no,
341 sub_no,
344
345 if (flags & update_values)
346 for (unsigned int i = 0; i < quadrature_on_subface.size(); ++i)
347 {
348 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
349 {
350 const Point<2> quadrature_point =
351 mapping.transform_unit_to_real_cell(
352 cell, quadrature_on_subface.point(i));
353
354 output_data.shape_values[k][i] =
355 (coeffs[k][0] * quadrature_point[0] +
356 coeffs[k][1] * quadrature_point[1] + coeffs[k][2]);
357 }
358 }
359
360 if (flags & update_gradients)
361 for (unsigned int i = 0; i < quadrature_on_subface.size(); ++i)
362 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
363 output_data.shape_gradients[k][i] =
364 Point<2>(coeffs[k][0], coeffs[k][1]);
365}
366
367
368
369void
371{
372 // coefficient relation between children and mother
373 interface_constraints.TableBase<2, double>::reinit(
375
376 interface_constraints(0, 0) = 0.5;
377 interface_constraints(0, 1) = 0.5;
378}
379
380
FE_P1NC()
Definition fe_p1nc.cc:48
virtual std::unique_ptr< FiniteElement< 2, 2 >::InternalDataBase > get_face_data(const UpdateFlags update_flags, const Mapping< 2, 2 > &, const hp::QCollection< 1 > &quadrature, ::internal::FEValuesImplementation::FiniteElementRelatedData< 2, 2 > &output_data) const override
Definition fe_p1nc.cc:184
static ndarray< double, 4, 3 > get_linear_shape_coefficients(const Triangulation< 2, 2 >::cell_iterator &cell)
Definition fe_p1nc.cc:113
virtual void fill_fe_subface_values(const Triangulation< 2, 2 >::cell_iterator &cell, const unsigned int face_no, const unsigned int sub_no, const Quadrature< 1 > &quadrature, const Mapping< 2, 2 > &mapping, const Mapping< 2, 2 >::InternalDataBase &mapping_internal, const internal::FEValuesImplementation::MappingRelatedData< 2, 2 > &mapping_data, const InternalDataBase &fe_internal, ::internal::FEValuesImplementation::FiniteElementRelatedData< 2, 2 > &output_data) const override
Definition fe_p1nc.cc:319
virtual std::unique_ptr< FiniteElement< 2, 2 > > clone() const override
Definition fe_p1nc.cc:93
virtual void fill_fe_face_values(const Triangulation< 2, 2 >::cell_iterator &cell, const unsigned int face_no, const hp::QCollection< 1 > &quadrature, const Mapping< 2, 2 > &mapping, const Mapping< 2, 2 >::InternalDataBase &mapping_internal, const internal::FEValuesImplementation::MappingRelatedData< 2, 2 > &mapping_data, const InternalDataBase &fe_internal, ::internal::FEValuesImplementation::FiniteElementRelatedData< 2, 2 > &output_data) const override
Definition fe_p1nc.cc:271
virtual void fill_fe_values(const Triangulation< 2, 2 >::cell_iterator &cell, const CellSimilarity::Similarity cell_similarity, const Quadrature< 2 > &quadrature, const Mapping< 2, 2 > &mapping, const Mapping< 2, 2 >::InternalDataBase &mapping_internal, const internal::FEValuesImplementation::MappingRelatedData< 2, 2 > &mapping_data, const FiniteElement< 2, 2 >::InternalDataBase &fe_internal, internal::FEValuesImplementation::FiniteElementRelatedData< 2, 2 > &output_data) const override
Definition fe_p1nc.cc:234
void initialize_constraints()
Definition fe_p1nc.cc:370
virtual std::unique_ptr< FiniteElement< 2, 2 >::InternalDataBase > get_data(const UpdateFlags update_flags, const Mapping< 2, 2 > &, const Quadrature< 2 > &quadrature, ::internal::FEValuesImplementation::FiniteElementRelatedData< 2, 2 > &output_data) const override
Definition fe_p1nc.cc:160
virtual std::unique_ptr< FiniteElement< 2, 2 >::InternalDataBase > get_subface_data(const UpdateFlags update_flags, const Mapping< 2, 2 > &, const Quadrature< 1 > &quadrature, ::internal::FEValuesImplementation::FiniteElementRelatedData< 2, 2 > &output_data) const override
Definition fe_p1nc.cc:210
virtual UpdateFlags requires_update_flags(const UpdateFlags flags) const override
Definition fe_p1nc.cc:74
static std::vector< unsigned int > get_dpo_vector()
Definition fe_p1nc.cc:101
virtual std::string get_name() const override
Definition fe_p1nc.cc:66
unsigned int n_dofs_per_cell() const
FiniteElementData(const std::vector< unsigned int > &dofs_per_object, const unsigned int n_components, const unsigned int degree, const Conformity conformity=unknown, const BlockIndices &block_indices=BlockIndices())
Definition fe_data.cc:112
ReferenceCell< dim > reference_cell() const
std::vector< std::vector< Point< dim - 1 > > > unit_face_support_points
Definition fe.h:2592
FiniteElement(const FiniteElementData< dim > &fe_data, const std::vector< bool > &restriction_is_additive_flags, const std::vector< ComponentMask > &nonzero_components)
TableIndices< 2 > interface_constraints_size() const
FullMatrix< double > interface_constraints
Definition fe.h:2573
Abstract base class for mapping classes.
Definition mapping.h:318
Definition point.h:111
static void project_to_subface(const ReferenceCell< dim > &reference_cell, const SubQuadrature &quadrature, const unsigned int face_no, const unsigned int subface_no, std::vector< Point< dim > > &q_points, const RefinementCase< dim - 1 > &ref_case=RefinementCase< dim - 1 >::isotropic_refinement)
static void project_to_face(const ReferenceCell< dim > &reference_cell, const SubQuadrature &quadrature, const unsigned int face_no, std::vector< Point< dim > > &q_points)
const Point< dim > & point(const unsigned int i) const
unsigned int size() const
Point< spacedim > & vertex(const unsigned int i) const
unsigned int size() const
Definition collection.h:314
void initialize(const unsigned int n_quadrature_points, const FiniteElement< dim, spacedim > &fe, const UpdateFlags flags)
Definition fe_values.cc:49
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define AssertDimension(dim1, dim2)
TriaIterator< CellAccessor< dim, spacedim > > cell_iterator
Definition tria.h:1624
UpdateFlags
@ update_hessians
Second derivatives of shape functions.
@ update_values
Shape function values.
@ update_normal_vectors
Normal vectors.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
@ update_default
No update.
MappingQ< dim, spacedim > StaticMappingQ1< dim, spacedim >::mapping
Definition mapping_q1.h:101
constexpr types::geometric_orientation default_geometric_orientation
Definition types.h:350
STL namespace.
typename internal::ndarray::HelperArray< T, Ns... >::type ndarray
Definition ndarray.h:105
*  const unsigned int n_q_points