Reference documentation for deal.II version 9.1.0-pre
fe_p1nc.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2015 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/std_cxx14/memory.h>
18 
19 #include <deal.II/fe/fe_p1nc.h>
20 
21 DEAL_II_NAMESPACE_OPEN
22 
23 
25  : FiniteElement<2, 2>(
26  FiniteElementData<2>(get_dpo_vector(), 1, 1, FiniteElementData<2>::L2),
27  std::vector<bool>(1, false),
28  std::vector<ComponentMask>(4, ComponentMask(1, true)))
29 {
30  // face support points: 2 end vertices
31  unit_face_support_points.resize(2);
32  unit_face_support_points[0][0] = 0.0;
33  unit_face_support_points[1][0] = 1.0;
34 
35  // initialize constraints matrix
37 }
38 
39 
40 
41 std::string
43 {
44  return "FE_P1NC";
45 }
46 
47 
48 
51 {
53 
54  if (flags & update_values)
55  out |= update_values | update_quadrature_points;
56  if (flags & update_gradients)
57  out |= update_gradients;
58  if (flags & update_cell_normal_vectors)
59  out |= update_cell_normal_vectors | update_JxW_values;
60  if (flags & update_hessians)
61  out |= update_hessians;
62 
63  return out;
64 }
65 
66 
67 
68 std::unique_ptr<FiniteElement<2, 2>>
70 {
71  return std_cxx14::make_unique<FE_P1NC>(*this);
72 }
73 
74 
75 
76 std::vector<unsigned int>
78 {
79  std::vector<unsigned int> dpo(3);
80  dpo[0] = 1; // dofs per object: vertex
81  dpo[1] = 0; // line
82  dpo[2] = 0; // quad
83  return dpo;
84 }
85 
86 
87 
88 std::array<std::array<double, 3>, 4>
91 {
92  // edge midpoints
93  const Point<2> mpt[4] = {(cell->vertex(0) + cell->vertex(2)) / 2,
94  (cell->vertex(1) + cell->vertex(3)) / 2,
95  (cell->vertex(0) + cell->vertex(1)) / 2,
96  (cell->vertex(2) + cell->vertex(3)) / 2};
97 
98  // center point
99  const Point<2> cpt =
100  (cell->vertex(0) + cell->vertex(1) + cell->vertex(2) + cell->vertex(3)) / 4;
101 
102  const double det = (mpt[0](0) - mpt[1](0)) * (mpt[2](1) - mpt[3](1)) -
103  (mpt[2](0) - mpt[3](0)) * (mpt[0](1) - mpt[1](1));
104 
105  std::array<std::array<double, 3>, 4> coeffs;
106  coeffs[0][0] =
107  ((mpt[2](1) - mpt[3](1)) * (0.5) - (mpt[0](1) - mpt[1](1)) * (0.5)) / det;
108  coeffs[1][0] =
109  ((mpt[2](1) - mpt[3](1)) * (-0.5) - (mpt[0](1) - mpt[1](1)) * (0.5)) / det;
110  coeffs[2][0] =
111  ((mpt[2](1) - mpt[3](1)) * (0.5) - (mpt[0](1) - mpt[1](1)) * (-0.5)) / det;
112  coeffs[3][0] =
113  ((mpt[2](1) - mpt[3](1)) * (-0.5) - (mpt[0](1) - mpt[1](1)) * (-0.5)) / det;
114 
115  coeffs[0][1] =
116  (-(mpt[2](0) - mpt[3](0)) * (0.5) + (mpt[0](0) - mpt[1](0)) * (0.5)) / det;
117  coeffs[1][1] =
118  (-(mpt[2](0) - mpt[3](0)) * (-0.5) + (mpt[0](0) - mpt[1](0)) * (0.5)) / det;
119  coeffs[2][1] =
120  (-(mpt[2](0) - mpt[3](0)) * (0.5) + (mpt[0](0) - mpt[1](0)) * (-0.5)) / det;
121  coeffs[3][1] =
122  (-(mpt[2](0) - mpt[3](0)) * (-0.5) + (mpt[0](0) - mpt[1](0)) * (-0.5)) /
123  det;
124 
125  coeffs[0][2] = 0.25 - cpt(0) * coeffs[0][0] - cpt(1) * coeffs[0][1];
126  coeffs[1][2] = 0.25 - cpt(0) * coeffs[1][0] - cpt(1) * coeffs[1][1];
127  coeffs[2][2] = 0.25 - cpt(0) * coeffs[2][0] - cpt(1) * coeffs[2][1];
128  coeffs[3][2] = 0.25 - cpt(0) * coeffs[3][0] - cpt(1) * coeffs[3][1];
129 
130  return coeffs;
131 }
132 
133 
134 
135 std::unique_ptr<FiniteElement<2, 2>::InternalDataBase>
137  const UpdateFlags update_flags,
138  const Mapping<2, 2> &,
139  const Quadrature<2> &quadrature,
141  &output_data) const
142 {
143  auto data = std_cxx14::make_unique<FiniteElement<2, 2>::InternalDataBase>();
144 
145  data->update_each = requires_update_flags(update_flags);
146 
147  const unsigned int n_q_points = quadrature.size();
148  output_data.initialize(n_q_points, FE_P1NC(), data->update_each);
149 
150  // this is a linear element, so its second derivatives are zero
151  if (data->update_each & update_hessians)
152  output_data.shape_hessians.fill(Tensor<2, 2>());
153 
154  return data;
155 }
156 
157 
158 
159 std::unique_ptr<FiniteElement<2, 2>::InternalDataBase>
160 FE_P1NC::get_face_data(
161  const UpdateFlags update_flags,
162  const Mapping<2, 2> &,
163  const Quadrature<1> &quadrature,
165  &output_data) const
166 {
167  auto data = std_cxx14::make_unique<FiniteElement<2, 2>::InternalDataBase>();
168 
169  data->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->update_each);
173 
174  // this is a linear element, so its second derivatives are zero
175  if (data->update_each & update_hessians)
176  output_data.shape_hessians.fill(Tensor<2, 2>());
177 
178  return data;
179 }
180 
181 
182 
183 std::unique_ptr<FiniteElement<2, 2>::InternalDataBase>
184 FE_P1NC::get_subface_data(
185  const UpdateFlags update_flags,
186  const Mapping<2, 2> &,
187  const Quadrature<1> &quadrature,
189  &output_data) const
190 {
191  auto data = std_cxx14::make_unique<FiniteElement<2, 2>::InternalDataBase>();
192 
193  data->update_each = requires_update_flags(update_flags);
194 
195  const unsigned int n_q_points = quadrature.size();
196  output_data.initialize(n_q_points, FE_P1NC(), data->update_each);
197 
198  // this is a linear element, so its second derivatives are zero
199  if (data->update_each & update_hessians)
200  output_data.shape_hessians.fill(Tensor<2, 2>());
201 
202  return data;
203 }
204 
205 
206 
207 void
211  const Quadrature<2> &,
212  const Mapping<2, 2> &,
215  & mapping_data,
216  const FiniteElement<2, 2>::InternalDataBase &fe_internal,
218  const
219 {
220  const UpdateFlags flags(fe_internal.update_each);
221 
222  const unsigned int n_q_points = mapping_data.quadrature_points.size();
223 
224  // linear shape functions
225  std::array<std::array<double, 3>, 4> coeffs =
227 
228  // compute on the cell
229  if (flags & update_values)
230  for (unsigned int i = 0; i < n_q_points; ++i)
231  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
232  output_data.shape_values[k][i] =
233  (coeffs[k][0] * mapping_data.quadrature_points[i](0) +
234  coeffs[k][1] * mapping_data.quadrature_points[i](1) + coeffs[k][2]);
235 
236  if (flags & update_gradients)
237  for (unsigned int i = 0; i < n_q_points; ++i)
238  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
239  output_data.shape_gradients[k][i] =
240  Point<2>(coeffs[k][0], coeffs[k][1]);
241 }
242 
243 
244 
245 void
248  const unsigned int face_no,
249  const Quadrature<1> & quadrature,
250  const Mapping<2, 2> & mapping,
252  const ::internal::FEValuesImplementation::MappingRelatedData<2, 2> &,
253  const InternalDataBase &fe_internal,
255  &output_data) const
256 {
257  const UpdateFlags flags(fe_internal.update_each);
258 
259  // linear shape functions
260  const std::array<std::array<double, 3>, 4> coeffs =
262 
263  // compute on the face
264  const Quadrature<2> quadrature_on_face =
265  QProjector<2>::project_to_face(quadrature, face_no);
266 
267  if (flags & update_values)
268  for (unsigned int i = 0; i < quadrature_on_face.size(); ++i)
269  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
270  {
271  const Point<2> quadrature_point =
272  mapping.transform_unit_to_real_cell(cell,
273  quadrature_on_face.point(i));
274 
275  output_data.shape_values[k][i] =
276  (coeffs[k][0] * quadrature_point(0) +
277  coeffs[k][1] * quadrature_point(1) + coeffs[k][2]);
278  }
279 
280  if (flags & update_gradients)
281  for (unsigned int i = 0; i < quadrature_on_face.size(); ++i)
282  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
283  output_data.shape_gradients[k][i] =
284  Point<2>(coeffs[k][0], coeffs[k][1]);
285 }
286 
287 
288 
289 void
292  const unsigned int face_no,
293  const unsigned int sub_no,
294  const Quadrature<1> & quadrature,
295  const Mapping<2, 2> & mapping,
297  const ::internal::FEValuesImplementation::MappingRelatedData<2, 2> &,
298  const InternalDataBase &fe_internal,
300  &output_data) const
301 {
302  const UpdateFlags flags(fe_internal.update_each);
303 
304  // linear shape functions
305  const std::array<std::array<double, 3>, 4> coeffs =
307 
308  // compute on the subface
309  const Quadrature<2> quadrature_on_subface =
310  QProjector<2>::project_to_subface(quadrature, face_no, sub_no);
311 
312  if (flags & update_values)
313  for (unsigned int i = 0; i < quadrature_on_subface.size(); ++i)
314  {
315  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
316  {
317  const Point<2> quadrature_point =
319  cell, quadrature_on_subface.point(i));
320 
321  output_data.shape_values[k][i] =
322  (coeffs[k][0] * quadrature_point(0) +
323  coeffs[k][1] * quadrature_point(1) + coeffs[k][2]);
324  }
325  }
326 
327  if (flags & update_gradients)
328  for (unsigned int i = 0; i < quadrature_on_subface.size(); ++i)
329  for (unsigned int k = 0; k < this->dofs_per_cell; ++k)
330  output_data.shape_gradients[k][i] =
331  Point<2>(coeffs[k][0], coeffs[k][1]);
332 }
333 
334 
335 
336 void
338 {
339  // coefficient relation between children and mother
340  interface_constraints.TableBase<2, double>::reinit(
342 
343  interface_constraints(0, 0) = 0.5;
344  interface_constraints(0, 1) = 0.5;
345 }
346 
347 
348 DEAL_II_NAMESPACE_CLOSE
Transformed quadrature weights.
Shape function values.
FE_P1NC()
Definition: fe_p1nc.cc:24
FullMatrix< double > interface_constraints
Definition: fe.h:2445
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:136
std::vector< Point< dim-1 > > unit_face_support_points
Definition: fe.h:2464
STL namespace.
Transformed quadrature points.
TableIndices< 2 > interface_constraints_size() const
virtual void fill_fe_face_values(const Triangulation< 2, 2 >::cell_iterator &cell, const unsigned int face_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:246
const Point< dim > & point(const unsigned int i) const
virtual std::unique_ptr< FiniteElement< 2, 2 > > clone() const override
Definition: fe_p1nc.cc:69
static std::vector< unsigned int > get_dpo_vector()
Definition: fe_p1nc.cc:77
unsigned int size() const
No update.
virtual UpdateFlags requires_update_flags(const UpdateFlags flags) const override
Definition: fe_p1nc.cc:50
static std::array< std::array< double, 3 >, 4 > get_linear_shape_coefficients(const Triangulation< 2, 2 >::cell_iterator &cell)
Definition: fe_p1nc.cc:89
UpdateFlags
Abstract base class for mapping classes.
Definition: dof_tools.h:57
virtual std::string get_name() const override
Definition: fe_p1nc.cc:42
void initialize(const unsigned int n_quadrature_points, const FiniteElement< dim, spacedim > &fe, const UpdateFlags flags)
Definition: fe_values.cc:3086
Second derivatives of shape functions.
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:290
const unsigned int dofs_per_cell
Definition: fe_base.h:297
std::vector< Point< spacedim > > quadrature_points
static void project_to_subface(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 SubQuadrature &quadrature, const unsigned int face_no, std::vector< Point< dim >> &q_points)
Definition: mpi.h:55
Shape function gradients.
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:208
void initialize_constraints()
Definition: fe_p1nc.cc:337
virtual Point< spacedim > transform_unit_to_real_cell(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const Point< dim > &p) const =0