| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2020 - 2025 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
|
| 16 |
#ifndef dealii_vector_tools_boundary_templates_h |
| 17 |
#define dealii_vector_tools_boundary_templates_h |
| 18 |
|
| 19 |
#include <deal.II/base/qprojector.h> |
| 20 |
#include <deal.II/base/quadrature_lib.h> |
| 21 |
|
| 22 |
#include <deal.II/dofs/dof_tools.h> |
| 23 |
|
| 24 |
#include <deal.II/fe/fe_nedelec.h> |
| 25 |
#include <deal.II/fe/fe_nedelec_sz.h> |
| 26 |
#include <deal.II/fe/fe_nothing.h> |
| 27 |
#include <deal.II/fe/fe_raviart_thomas.h> |
| 28 |
#include <deal.II/fe/fe_system.h> |
| 29 |
|
| 30 |
#include <deal.II/hp/fe_values.h> |
| 31 |
#include <deal.II/hp/q_collection.h> |
| 32 |
|
| 33 |
#include <deal.II/lac/dynamic_sparsity_pattern.h> |
| 34 |
#include <deal.II/lac/precondition.h> |
| 35 |
#include <deal.II/lac/solver_cg.h> |
| 36 |
#include <deal.II/lac/solver_control.h> |
| 37 |
#include <deal.II/lac/sparse_matrix.h> |
| 38 |
#include <deal.II/lac/sparsity_pattern.h> |
| 39 |
|
| 40 |
#include <deal.II/numerics/matrix_tools.h> |
| 41 |
#include <deal.II/numerics/vector_tools_boundary.h> |
| 42 |
|
| 43 |
#include <limits> |
| 44 |
|
| 45 |
DEAL_II_NAMESPACE_OPEN |
| 46 |
|
| 47 |
namespace VectorTools |
| 48 |
{ |
| 49 |
// ----------- interpolate_boundary_values for std::map -------------------- |
| 50 |
|
| 51 |
namespace internal |
| 52 |
{ |
| 53 |
template <int dim, |
| 54 |
int spacedim, |
| 55 |
typename number, |
| 56 |
template <int, int> |
| 57 |
class M_or_MC> |
| 58 |
inline void |
| 59 |
do_interpolate_boundary_values( |
| 60 |
const M_or_MC<dim, spacedim> &mapping, |
| 61 |
const DoFHandler<dim, spacedim> &dof, |
| 62 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 63 |
&function_map, |
| 64 |
std::map<types::global_dof_index, number> &boundary_values, |
| 65 |
const ComponentMask &component_mask) |
| 66 |
{ |
| 67 |
Assert( |
| 68 |
component_mask.represents_n_components(dof.get_fe(0).n_components()), |
| 69 |
ExcMessage("The number of components in the mask has to be either " |
| 70 |
"zero or equal to the number of components in the finite " |
| 71 |
"element.")); |
| 72 |
|
| 73 |
|
| 74 |
// if for whatever reason we were passed an empty map, return |
| 75 |
// immediately |
| 76 |
if (function_map.empty()) |
| 77 |
return; |
| 78 |
|
| 79 |
Assert(function_map.find(numbers::internal_face_boundary_id) == |
| 80 |
function_map.end(), |
| 81 |
ExcMessage("You cannot specify the special boundary indicator " |
| 82 |
"for interior faces in your function map.")); |
| 83 |
|
| 84 |
const unsigned int n_components = dof.get_fe_collection().n_components(); |
| 85 |
for (typename std::map<types::boundary_id, |
| 86 |
const Function<spacedim, number> *>::const_iterator |
| 87 |
i = function_map.begin(); |
| 88 |
i != function_map.end(); |
| 89 |
++i) |
| 90 |
Assert(n_components == i->second->n_components, |
| 91 |
ExcDimensionMismatch(n_components, i->second->n_components)); |
| 92 |
|
| 93 |
|
| 94 |
// interpolate boundary values in 1d. in higher dimensions, we |
| 95 |
// use FEValues to figure out what to do on faces, but in 1d |
| 96 |
// faces are points and it is far easier to simply work on |
| 97 |
// individual vertices |
| 98 |
if (dim == 1) |
| 99 |
{ |
| 100 |
for (const auto &cell : dof.active_cell_iterators()) |
| 101 |
for (const unsigned int direction : cell->face_indices()) |
| 102 |
if (cell->at_boundary(direction) && |
| 103 |
(function_map.find(cell->face(direction)->boundary_id()) != |
| 104 |
function_map.end())) |
| 105 |
{ |
| 106 |
const Function<spacedim, number> &boundary_function = |
| 107 |
*function_map.find(cell->face(direction)->boundary_id()) |
| 108 |
->second; |
| 109 |
|
| 110 |
// get the FE corresponding to this cell |
| 111 |
const FiniteElement<dim, spacedim> &fe = cell->get_fe(); |
| 112 |
Assert(fe.n_components() == boundary_function.n_components, |
| 113 |
ExcDimensionMismatch(fe.n_components(), |
| 114 |
boundary_function.n_components)); |
| 115 |
|
| 116 |
Assert(component_mask.n_selected_components( |
| 117 |
fe.n_components()) > 0, |
| 118 |
ComponentMask::ExcNoComponentSelected()); |
| 119 |
|
| 120 |
// now set the value of the vertex degree of |
| 121 |
// freedom. setting also creates the entry in the |
| 122 |
// map if it did not exist beforehand |
| 123 |
// |
| 124 |
// save some time by requesting values only once for |
| 125 |
// each point, irrespective of the number of |
| 126 |
// components of the function |
| 127 |
Vector<number> function_values(fe.n_components()); |
| 128 |
if (fe.n_components() == 1) |
| 129 |
function_values(0) = |
| 130 |
boundary_function.value(cell->vertex(direction)); |
| 131 |
else |
| 132 |
boundary_function.vector_value(cell->vertex(direction), |
| 133 |
function_values); |
| 134 |
|
| 135 |
for (unsigned int i = 0; i < fe.n_dofs_per_vertex(); ++i) |
| 136 |
if (component_mask[fe.face_system_to_component_index( |
| 137 |
i, direction) |
| 138 |
.first]) |
| 139 |
boundary_values[cell->vertex_dof_index( |
| 140 |
direction, i, cell->active_fe_index())] = |
| 141 |
function_values( |
| 142 |
fe.face_system_to_component_index(i, direction) |
| 143 |
.first); |
| 144 |
} |
| 145 |
} |
| 146 |
else // dim > 1 |
| 147 |
{ |
| 148 |
const bool fe_is_system = (n_components != 1); |
| 149 |
|
| 150 |
// field to store the indices |
| 151 |
std::vector<types::global_dof_index> face_dofs; |
| 152 |
face_dofs.reserve(dof.get_fe_collection().max_dofs_per_face()); |
| 153 |
|
| 154 |
// array to store the values of the boundary function at the boundary |
| 155 |
// points. have two arrays for scalar and vector functions to use the |
| 156 |
// more efficient one respectively |
| 157 |
std::vector<number> dof_values_scalar; |
| 158 |
std::vector<Vector<number>> dof_values_system; |
| 159 |
dof_values_scalar.reserve( |
| 160 |
dof.get_fe_collection().max_dofs_per_face()); |
| 161 |
dof_values_system.reserve( |
| 162 |
dof.get_fe_collection().max_dofs_per_face()); |
| 163 |
|
| 164 |
// before we start with the loop over all cells create an hp::FEValues |
| 165 |
// object that holds the interpolation points of all finite elements |
| 166 |
// that may ever be in use |
| 167 |
const dealii::hp::FECollection<dim, spacedim> &finite_elements = |
| 168 |
dof.get_fe_collection(); |
| 169 |
std::vector<dealii::hp::QCollection<dim - 1>> q_collection( |
| 170 |
finite_elements.size()); |
| 171 |
for (unsigned int f = 0; f < finite_elements.size(); ++f) |
| 172 |
for (unsigned int face_no = 0; |
| 173 |
face_no < (finite_elements[f].n_unique_faces() == 1 ? |
| 174 |
1 : |
| 175 |
finite_elements[f].reference_cell().n_faces()); |
| 176 |
++face_no) |
| 177 |
{ |
| 178 |
const FiniteElement<dim, spacedim> &fe = finite_elements[f]; |
| 179 |
|
| 180 |
// generate a quadrature rule on the face from the unit support |
| 181 |
// points. this will be used to obtain the quadrature points on |
| 182 |
// the real cell's face |
| 183 |
// |
| 184 |
// to do this, we check whether the FE has support points on the |
| 185 |
// face at all: |
| 186 |
if (fe.has_face_support_points(face_no)) |
| 187 |
q_collection[f].push_back(Quadrature<dim - 1>( |
| 188 |
fe.get_unit_face_support_points(face_no))); |
| 189 |
else |
| 190 |
{ |
| 191 |
// if not, then we should try a more clever way. the idea is |
| 192 |
// that a finite element may not offer support points for |
| 193 |
// all its shape functions, but maybe only some. if it |
| 194 |
// offers support points for the components we are |
| 195 |
// interested in in this function, then that's fine. if not, |
| 196 |
// the function we call in the finite element will raise an |
| 197 |
// exception. the support points for the other shape |
| 198 |
// functions are left uninitialized (well, initialized by |
| 199 |
// the default constructor), since we don't need them |
| 200 |
// anyway. |
| 201 |
// |
| 202 |
// As a detour, we must make sure we only query |
| 203 |
// face_system_to_component_index if the index corresponds |
| 204 |
// to a primitive shape function. since we know that all the |
| 205 |
// components we are interested in are primitive (by the |
| 206 |
// above check), we can safely put such a check in front |
| 207 |
std::vector<Point<dim - 1>> unit_support_points( |
| 208 |
fe.n_dofs_per_face(face_no)); |
| 209 |
|
| 210 |
for (unsigned int i = 0; i < fe.n_dofs_per_face(face_no); |
| 211 |
++i) |
| 212 |
if (fe.is_primitive(fe.face_to_cell_index(i, face_no))) |
| 213 |
if (component_mask[fe.face_system_to_component_index( |
| 214 |
i, face_no) |
| 215 |
.first] == true) |
| 216 |
unit_support_points[i] = |
| 217 |
fe.unit_face_support_point(i, face_no); |
| 218 |
|
| 219 |
q_collection[f].push_back( |
| 220 |
Quadrature<dim - 1>(unit_support_points)); |
| 221 |
} |
| 222 |
} |
| 223 |
// now that we have a q_collection object with all the right |
| 224 |
// quadrature points, create an hp::FEFaceValues object that we can |
| 225 |
// use to evaluate the boundary values at |
| 226 |
const auto mapping_collection = |
| 227 |
dealii::hp::MappingCollection<dim, spacedim>(mapping); |
| 228 |
dealii::hp::FEFaceValues<dim, spacedim> x_fe_values( |
| 229 |
mapping_collection, |
| 230 |
finite_elements, |
| 231 |
q_collection, |
| 232 |
update_quadrature_points); |
| 233 |
|
| 234 |
for (const auto &cell : dof.active_cell_iterators()) |
| 235 |
if (!cell->is_artificial()) |
| 236 |
for (const unsigned int face_no : cell->face_indices()) |
| 237 |
{ |
| 238 |
const FiniteElement<dim, spacedim> &fe = cell->get_fe(); |
| 239 |
|
| 240 |
// we can presently deal only with primitive elements for |
| 241 |
// boundary values. this does not preclude us using |
| 242 |
// non-primitive elements in components that we aren't |
| 243 |
// interested in, however. make sure that all shape functions |
| 244 |
// that are non-zero for the components we are interested in, |
| 245 |
// are in fact primitive |
| 246 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 247 |
{ |
| 248 |
const ComponentMask &nonzero_component_array = |
| 249 |
fe.get_nonzero_components(i); |
| 250 |
for (unsigned int c = 0; c < n_components; ++c) |
| 251 |
if ((nonzero_component_array[c] == true) && |
| 252 |
(component_mask[c] == true)) |
| 253 |
Assert( |
| 254 |
fe.is_primitive(i), |
| 255 |
ExcMessage( |
| 256 |
"This function can only deal with requested boundary " |
| 257 |
"values that correspond to primitive (scalar) base " |
| 258 |
"elements. You may want to look up in the deal.II " |
| 259 |
"glossary what the term 'primitive' means." |
| 260 |
"\n\n" |
| 261 |
"There are alternative boundary value interpolation " |
| 262 |
"functions in namespace 'VectorTools' that you can " |
| 263 |
"use for non-primitive finite elements.")); |
| 264 |
} |
| 265 |
|
| 266 |
const typename DoFHandler<dim, spacedim>::face_iterator face = |
| 267 |
cell->face(face_no); |
| 268 |
const types::boundary_id boundary_component = |
| 269 |
face->boundary_id(); |
| 270 |
|
| 271 |
// see if this face is part of the boundaries for which we are |
| 272 |
// supposed to do something, and also see if the finite |
| 273 |
// element in use here has DoFs on the face at all |
| 274 |
if ((function_map.find(boundary_component) != |
| 275 |
function_map.end()) && |
| 276 |
(fe.n_dofs_per_face(face_no) > 0)) |
| 277 |
{ |
| 278 |
// face is of the right component |
| 279 |
x_fe_values.reinit(cell, face_no); |
| 280 |
const dealii::FEFaceValues<dim, spacedim> &fe_values = |
| 281 |
x_fe_values.get_present_fe_values(); |
| 282 |
|
| 283 |
// get indices, physical location and boundary values of |
| 284 |
// dofs on this face |
| 285 |
face_dofs.resize(fe.n_dofs_per_face(face_no)); |
| 286 |
face->get_dof_indices(face_dofs, cell->active_fe_index()); |
| 287 |
std::vector<Point<spacedim>> dof_locations = |
| 288 |
fe_values.get_quadrature_points(); |
| 289 |
dof_locations.resize(fe.n_dofs_per_face(face_no)); |
| 290 |
|
| 291 |
if (fe_is_system) |
| 292 |
{ |
| 293 |
dof_values_system.resize(fe.n_dofs_per_face(face_no), |
| 294 |
Vector<number>( |
| 295 |
fe.n_components())); |
| 296 |
|
| 297 |
function_map.find(boundary_component) |
| 298 |
->second->vector_value_list(dof_locations, |
| 299 |
dof_values_system); |
| 300 |
|
| 301 |
// enter those dofs into the list that match the |
| 302 |
// component signature. avoid the usual complication |
| 303 |
// that we can't just use *_system_to_component_index |
| 304 |
// for non-primitive FEs |
| 305 |
for (unsigned int i = 0; i < face_dofs.size(); ++i) |
| 306 |
{ |
| 307 |
unsigned int component; |
| 308 |
if (fe.is_primitive()) |
| 309 |
component = |
| 310 |
fe.face_system_to_component_index(i, face_no) |
| 311 |
.first; |
| 312 |
else |
| 313 |
{ |
| 314 |
// non-primitive case. make sure that this |
| 315 |
// particular shape function _is_ primitive, |
| 316 |
// and get at it's component. use usual trick |
| 317 |
// to transfer face dof index to cell dof |
| 318 |
// index |
| 319 |
const unsigned int cell_i = |
| 320 |
(dim == 1 ? |
| 321 |
i : |
| 322 |
(dim == 2 ? |
| 323 |
(i < 2 * fe.n_dofs_per_vertex() ? |
| 324 |
i : |
| 325 |
i + 2 * fe.n_dofs_per_vertex()) : |
| 326 |
(dim == 3 ? |
| 327 |
(i < 4 * fe.n_dofs_per_vertex() ? |
| 328 |
i : |
| 329 |
(i < 4 * fe.n_dofs_per_vertex() + |
| 330 |
4 * |
| 331 |
fe.n_dofs_per_line() ? |
| 332 |
i + |
| 333 |
4 * |
| 334 |
fe.n_dofs_per_vertex() : |
| 335 |
i + |
| 336 |
4 * |
| 337 |
fe.n_dofs_per_vertex() + |
| 338 |
8 * |
| 339 |
fe.n_dofs_per_line())) : |
| 340 |
numbers::invalid_unsigned_int))); |
| 341 |
Assert(cell_i < fe.n_dofs_per_cell(), |
| 342 |
ExcInternalError()); |
| 343 |
|
| 344 |
// make sure that if this is not a primitive |
| 345 |
// shape function, then all the corresponding |
| 346 |
// components in the mask are not set |
| 347 |
if (!fe.is_primitive(cell_i)) |
| 348 |
for (unsigned int c = 0; c < n_components; |
| 349 |
++c) |
| 350 |
if (fe.get_nonzero_components(cell_i)[c]) |
| 351 |
Assert(component_mask[c] == false, |
| 352 |
FETools::ExcFENotPrimitive()); |
| 353 |
|
| 354 |
// let's pick the first of possibly more than |
| 355 |
// one non-zero components. if shape function |
| 356 |
// is non-primitive, then we will ignore the |
| 357 |
// result in the following anyway, otherwise |
| 358 |
// there's only one non-zero component which |
| 359 |
// we will use |
| 360 |
component = fe.get_nonzero_components(cell_i) |
| 361 |
.first_selected_component(); |
| 362 |
} |
| 363 |
|
| 364 |
if (component_mask[component] == true) |
| 365 |
boundary_values[face_dofs[i]] = |
| 366 |
dof_values_system[i](component); |
| 367 |
} |
| 368 |
} |
| 369 |
else |
| 370 |
// FE has only one component, so save some computations |
| 371 |
{ |
| 372 |
// get only the one component that this function has |
| 373 |
dof_values_scalar.resize(fe.n_dofs_per_face(face_no)); |
| 374 |
function_map.find(boundary_component) |
| 375 |
->second->value_list(dof_locations, |
| 376 |
dof_values_scalar, |
| 377 |
0); |
| 378 |
|
| 379 |
// enter into list |
| 380 |
|
| 381 |
for (unsigned int i = 0; i < face_dofs.size(); ++i) |
| 382 |
boundary_values[face_dofs[i]] = |
| 383 |
dof_values_scalar[i]; |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
} |
| 388 |
} // end of interpolate_boundary_values |
| 389 |
} // namespace internal |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
template <int dim, int spacedim, typename number> |
| 394 |
void |
| 395 |
interpolate_boundary_values( |
| 396 |
const Mapping<dim, spacedim> &mapping, |
| 397 |
const DoFHandler<dim, spacedim> &dof, |
| 398 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 399 |
&function_map, |
| 400 |
std::map<types::global_dof_index, number> &boundary_values, |
| 401 |
const ComponentMask &component_mask_) |
| 402 |
{ |
| 403 |
internal::do_interpolate_boundary_values( |
| 404 |
mapping, dof, function_map, boundary_values, component_mask_); |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
template <int dim, int spacedim, typename number> |
| 410 |
void |
| 411 |
interpolate_boundary_values( |
| 412 |
const Mapping<dim, spacedim> &mapping, |
| 413 |
const DoFHandler<dim, spacedim> &dof, |
| 414 |
const types::boundary_id boundary_component, |
| 415 |
const Function<spacedim, number> &boundary_function, |
| 416 |
std::map<types::global_dof_index, number> &boundary_values, |
| 417 |
const ComponentMask &component_mask) |
| 418 |
{ |
| 419 |
std::map<types::boundary_id, const Function<spacedim, number> *> |
| 420 |
function_map = {{boundary_component, &boundary_function}}; |
| 421 |
interpolate_boundary_values( |
| 422 |
mapping, dof, function_map, boundary_values, component_mask); |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
template <int dim, int spacedim, typename number> |
| 427 |
void |
| 428 |
interpolate_boundary_values( |
| 429 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 430 |
const DoFHandler<dim, spacedim> &dof, |
| 431 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 432 |
&function_map, |
| 433 |
std::map<types::global_dof_index, number> &boundary_values, |
| 434 |
const ComponentMask &component_mask_) |
| 435 |
{ |
| 436 |
internal::do_interpolate_boundary_values( |
| 437 |
mapping, dof, function_map, boundary_values, component_mask_); |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
template <int dim, int spacedim, typename number> |
| 443 |
void |
| 444 |
interpolate_boundary_values( |
| 445 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 446 |
const DoFHandler<dim, spacedim> &dof, |
| 447 |
const types::boundary_id boundary_component, |
| 448 |
const Function<spacedim, number> &boundary_function, |
| 449 |
std::map<types::global_dof_index, number> &boundary_values, |
| 450 |
const ComponentMask &component_mask) |
| 451 |
{ |
| 452 |
std::map<types::boundary_id, const Function<spacedim, number> *> |
| 453 |
function_map = {{boundary_component, &boundary_function}}; |
| 454 |
interpolate_boundary_values( |
| 455 |
mapping, dof, function_map, boundary_values, component_mask); |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
template <int dim, int spacedim, typename number> |
| 461 |
void |
| 462 |
interpolate_boundary_values( |
| 463 |
const DoFHandler<dim, spacedim> &dof, |
| 464 |
const types::boundary_id boundary_component, |
| 465 |
const Function<spacedim, number> &boundary_function, |
| 466 |
std::map<types::global_dof_index, number> &boundary_values, |
| 467 |
const ComponentMask &component_mask) |
| 468 |
{ |
| 469 |
interpolate_boundary_values(get_default_linear_mapping( |
| 470 |
dof.get_triangulation()), |
| 471 |
dof, |
| 472 |
boundary_component, |
| 473 |
boundary_function, |
| 474 |
boundary_values, |
| 475 |
component_mask); |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
template <int dim, int spacedim, typename number> |
| 481 |
void |
| 482 |
interpolate_boundary_values( |
| 483 |
const DoFHandler<dim, spacedim> &dof, |
| 484 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 485 |
&function_map, |
| 486 |
std::map<types::global_dof_index, number> &boundary_values, |
| 487 |
const ComponentMask &component_mask) |
| 488 |
{ |
| 489 |
interpolate_boundary_values(get_default_linear_mapping( |
| 490 |
dof.get_triangulation()), |
| 491 |
dof, |
| 492 |
function_map, |
| 493 |
boundary_values, |
| 494 |
component_mask); |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
// ----------- interpolate_boundary_values for AffineConstraints |
| 500 |
// -------------- |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
template <int dim, int spacedim, typename number> |
| 505 |
void |
| 506 |
interpolate_boundary_values( |
| 507 |
const Mapping<dim, spacedim> &mapping, |
| 508 |
const DoFHandler<dim, spacedim> &dof, |
| 509 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 510 |
&function_map, |
| 511 |
AffineConstraints<number> &constraints, |
| 512 |
const ComponentMask &component_mask_) |
| 513 |
{ |
| 514 |
std::map<types::global_dof_index, number> boundary_values; |
| 515 |
interpolate_boundary_values( |
| 516 |
mapping, dof, function_map, boundary_values, component_mask_); |
| 517 |
for (const auto &boundary_value : boundary_values) |
| 518 |
{ |
| 519 |
if (constraints.can_store_line(boundary_value.first) && |
| 520 |
!constraints.is_constrained(boundary_value.first)) |
| 521 |
constraints.add_constraint(boundary_value.first, |
| 522 |
{}, |
| 523 |
boundary_value.second); |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
template <int dim, int spacedim, typename number> |
| 530 |
void |
| 531 |
interpolate_boundary_values( |
| 532 |
const Mapping<dim, spacedim> &mapping, |
| 533 |
const DoFHandler<dim, spacedim> &dof, |
| 534 |
const types::boundary_id boundary_component, |
| 535 |
const Function<spacedim, number> &boundary_function, |
| 536 |
AffineConstraints<number> &constraints, |
| 537 |
const ComponentMask &component_mask) |
| 538 |
{ |
| 539 |
std::map<types::boundary_id, const Function<spacedim, number> *> |
| 540 |
function_map = {{boundary_component, &boundary_function}}; |
| 541 |
interpolate_boundary_values( |
| 542 |
mapping, dof, function_map, constraints, component_mask); |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
template <int dim, int spacedim, typename number> |
| 548 |
void |
| 549 |
interpolate_boundary_values( |
| 550 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 551 |
const DoFHandler<dim, spacedim> &dof, |
| 552 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 553 |
&function_map, |
| 554 |
AffineConstraints<number> &constraints, |
| 555 |
const ComponentMask &component_mask_) |
| 556 |
{ |
| 557 |
std::map<types::global_dof_index, number> boundary_values; |
| 558 |
interpolate_boundary_values( |
| 559 |
mapping, dof, function_map, boundary_values, component_mask_); |
| 560 |
for (const auto &boundary_value : boundary_values) |
| 561 |
{ |
| 562 |
if (constraints.can_store_line(boundary_value.first) && |
| 563 |
!constraints.is_constrained(boundary_value.first)) |
| 564 |
constraints.add_constraint(boundary_value.first, |
| 565 |
{}, |
| 566 |
boundary_value.second); |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
template <int dim, int spacedim, typename number> |
| 573 |
void |
| 574 |
interpolate_boundary_values( |
| 575 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 576 |
const DoFHandler<dim, spacedim> &dof, |
| 577 |
const types::boundary_id boundary_component, |
| 578 |
const Function<spacedim, number> &boundary_function, |
| 579 |
AffineConstraints<number> &constraints, |
| 580 |
const ComponentMask &component_mask) |
| 581 |
{ |
| 582 |
std::map<types::boundary_id, const Function<spacedim, number> *> |
| 583 |
function_map = {{boundary_component, &boundary_function}}; |
| 584 |
interpolate_boundary_values( |
| 585 |
mapping, dof, function_map, constraints, component_mask); |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
template <int dim, int spacedim, typename number> |
| 591 |
void |
| 592 |
interpolate_boundary_values( |
| 593 |
const DoFHandler<dim, spacedim> &dof, |
| 594 |
const types::boundary_id boundary_component, |
| 595 |
const Function<spacedim, number> &boundary_function, |
| 596 |
AffineConstraints<number> &constraints, |
| 597 |
const ComponentMask &component_mask) |
| 598 |
{ |
| 599 |
interpolate_boundary_values(get_default_linear_mapping( |
| 600 |
dof.get_triangulation()), |
| 601 |
dof, |
| 602 |
boundary_component, |
| 603 |
boundary_function, |
| 604 |
constraints, |
| 605 |
component_mask); |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
template <int dim, int spacedim, typename number> |
| 611 |
void |
| 612 |
interpolate_boundary_values( |
| 613 |
const DoFHandler<dim, spacedim> &dof, |
| 614 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 615 |
&function_map, |
| 616 |
AffineConstraints<number> &constraints, |
| 617 |
const ComponentMask &component_mask) |
| 618 |
{ |
| 619 |
interpolate_boundary_values(get_default_linear_mapping( |
| 620 |
dof.get_triangulation()), |
| 621 |
dof, |
| 622 |
function_map, |
| 623 |
constraints, |
| 624 |
component_mask); |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
// -------- implementation for project_boundary_values with std::map -------- |
| 630 |
|
| 631 |
|
| 632 |
namespace internal |
| 633 |
{ |
| 634 |
// keep the first argument non-reference since we use it |
| 635 |
// with 1e-8 * number |
| 636 |
template <typename number1, typename number2> |
| 637 |
bool |
| 638 |
real_part_bigger_than(const number1 a, const number2 &b) |
| 639 |
{ |
| 640 |
return a > b; |
| 641 |
} |
| 642 |
|
| 643 |
template <typename number1, typename number2> |
| 644 |
bool |
| 645 |
real_part_bigger_than(const number1 a, const std::complex<number2> b) |
| 646 |
{ |
| 647 |
Assert(std::abs(b.imag()) <= 1e-15 * std::abs(b), ExcInternalError()); |
| 648 |
return a > b.real(); |
| 649 |
} |
| 650 |
|
| 651 |
template <typename number1, typename number2> |
| 652 |
bool |
| 653 |
real_part_bigger_than(const std::complex<number1> a, const number2 b) |
| 654 |
{ |
| 655 |
Assert(std::abs(a.imag()) <= 1e-15 * std::abs(a), ExcInternalError()); |
| 656 |
return a.real() > b; |
| 657 |
} |
| 658 |
|
| 659 |
template <typename number1, typename number2> |
| 660 |
bool |
| 661 |
real_part_bigger_than(const std::complex<number1> a, |
| 662 |
const std::complex<number2> b) |
| 663 |
{ |
| 664 |
Assert(std::abs(a.imag()) <= 1e-15 * std::abs(a), ExcInternalError()); |
| 665 |
Assert(std::abs(b.imag()) <= 1e-15 * std::abs(b), ExcInternalError()); |
| 666 |
return a.real() > b.real(); |
| 667 |
} |
| 668 |
|
| 669 |
// this function is needed to get an idea where |
| 670 |
// rhs.norm_sqr() is too small for a given type. |
| 671 |
template <typename number> |
| 672 |
number |
| 673 |
min_number(const number & /*dummy*/) |
| 674 |
{ |
| 675 |
return std::numeric_limits<number>::min(); |
| 676 |
} |
| 677 |
|
| 678 |
// Sine rhs.norm_sqr() is non-negative real, in complex case we |
| 679 |
// take the numeric limits of the underlying type used in std::complex<>. |
| 680 |
template <typename number> |
| 681 |
number |
| 682 |
min_number(const std::complex<number> & /*dummy*/) |
| 683 |
{ |
| 684 |
return std::numeric_limits<number>::min(); |
| 685 |
} |
| 686 |
|
| 687 |
template <int dim, |
| 688 |
int spacedim, |
| 689 |
template <int, int> |
| 690 |
class M_or_MC, |
| 691 |
template <int> |
| 692 |
class Q_or_QC, |
| 693 |
typename number> |
| 694 |
void |
| 695 |
do_project_boundary_values( |
| 696 |
const M_or_MC<dim, spacedim> &mapping, |
| 697 |
const DoFHandler<dim, spacedim> &dof, |
| 698 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 699 |
&boundary_functions, |
| 700 |
const Q_or_QC<dim - 1> &q, |
| 701 |
std::map<types::global_dof_index, number> &boundary_values, |
| 702 |
std::vector<unsigned int> component_mapping) |
| 703 |
{ |
| 704 |
// in 1d, projection onto the 0d end points == interpolation |
| 705 |
if (dim == 1) |
| 706 |
{ |
| 707 |
Assert(component_mapping.empty(), ExcNotImplemented()); |
| 708 |
interpolate_boundary_values( |
| 709 |
mapping, dof, boundary_functions, boundary_values, ComponentMask()); |
| 710 |
return; |
| 711 |
} |
| 712 |
|
| 713 |
// TODO:[?] In project_boundary_values, no condensation of sparsity |
| 714 |
// structures, matrices and right hand sides or distribution of |
| 715 |
// solution vectors is performed. This is ok for dim<3 because then |
| 716 |
// there are no constrained nodes on the boundary, but is not |
| 717 |
// acceptable for higher dimensions. Fix this. |
| 718 |
|
| 719 |
if (component_mapping.empty()) |
| 720 |
{ |
| 721 |
AssertDimension(dof.get_fe(0).n_components(), |
| 722 |
boundary_functions.begin()->second->n_components); |
| 723 |
// I still do not see why i |
| 724 |
// should create another copy |
| 725 |
// here |
| 726 |
component_mapping.resize(dof.get_fe(0).n_components()); |
| 727 |
for (unsigned int i = 0; i < component_mapping.size(); ++i) |
| 728 |
component_mapping[i] = i; |
| 729 |
} |
| 730 |
else |
| 731 |
AssertDimension(dof.get_fe(0).n_components(), component_mapping.size()); |
| 732 |
|
| 733 |
std::vector<types::global_dof_index> dof_to_boundary_mapping; |
| 734 |
std::set<types::boundary_id> selected_boundary_components; |
| 735 |
for (typename std::map<types::boundary_id, |
| 736 |
const Function<spacedim, number> *>::const_iterator |
| 737 |
i = boundary_functions.begin(); |
| 738 |
i != boundary_functions.end(); |
| 739 |
++i) |
| 740 |
selected_boundary_components.insert(i->first); |
| 741 |
|
| 742 |
DoFTools::map_dof_to_boundary_indices(dof, |
| 743 |
selected_boundary_components, |
| 744 |
dof_to_boundary_mapping); |
| 745 |
|
| 746 |
// Done if no degrees of freedom on the boundary |
| 747 |
if (dof.n_boundary_dofs(boundary_functions) == 0) |
| 748 |
return; |
| 749 |
|
| 750 |
// set up sparsity structure |
| 751 |
DynamicSparsityPattern dsp(dof.n_boundary_dofs(boundary_functions), |
| 752 |
dof.n_boundary_dofs(boundary_functions)); |
| 753 |
DoFTools::make_boundary_sparsity_pattern(dof, |
| 754 |
boundary_functions, |
| 755 |
dof_to_boundary_mapping, |
| 756 |
dsp); |
| 757 |
SparsityPattern sparsity; |
| 758 |
sparsity.copy_from(dsp); |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
// note: for three or more dimensions, there |
| 763 |
// may be constrained nodes on the boundary |
| 764 |
// in this case the boundary mass matrix has |
| 765 |
// to be condensed and the solution is to |
| 766 |
// be distributed afterwards, which is not |
| 767 |
// yet implemented. The reason for this is |
| 768 |
// that we cannot simply use the condense |
| 769 |
// family of functions, since the matrices |
| 770 |
// and vectors do not use the global |
| 771 |
// numbering but rather the boundary |
| 772 |
// numbering, i.e. the condense function |
| 773 |
// needs to use another indirection. There |
| 774 |
// should be not many technical problems, |
| 775 |
// but it needs to be implemented |
| 776 |
if (dim >= 3) |
| 777 |
{ |
| 778 |
if constexpr (running_in_debug_mode()) |
| 779 |
{ |
| 780 |
// Assert that there are no hanging nodes at the boundary |
| 781 |
int level = -1; |
| 782 |
for (const auto &cell : dof.active_cell_iterators()) |
| 783 |
for (auto f : cell->face_indices()) |
| 784 |
{ |
| 785 |
if (cell->at_boundary(f)) |
| 786 |
{ |
| 787 |
if (level == -1) |
| 788 |
level = cell->level(); |
| 789 |
else |
| 790 |
{ |
| 791 |
Assert( |
| 792 |
level == cell->level(), |
| 793 |
ExcMessage( |
| 794 |
"The mesh you use in projecting boundary values " |
| 795 |
"has hanging nodes at the boundary. This would require " |
| 796 |
"dealing with hanging node constraints when solving " |
| 797 |
"the linear system on the boundary, but this is not " |
| 798 |
"currently implemented.")); |
| 799 |
} |
| 800 |
} |
| 801 |
} |
| 802 |
} |
| 803 |
} |
| 804 |
sparsity.compress(); |
| 805 |
|
| 806 |
|
| 807 |
// make mass matrix and right hand side |
| 808 |
SparseMatrix<number> mass_matrix(sparsity); |
| 809 |
Vector<number> rhs(sparsity.n_rows()); |
| 810 |
|
| 811 |
|
| 812 |
MatrixCreator::create_boundary_mass_matrix( |
| 813 |
mapping, |
| 814 |
dof, |
| 815 |
q, |
| 816 |
mass_matrix, |
| 817 |
boundary_functions, |
| 818 |
rhs, |
| 819 |
dof_to_boundary_mapping, |
| 820 |
static_cast<const Function<spacedim, number> *>(nullptr), |
| 821 |
component_mapping); |
| 822 |
|
| 823 |
Vector<number> boundary_projection(rhs.size()); |
| 824 |
|
| 825 |
// cannot reduce residual in a useful way if we are close to the square |
| 826 |
// root of the minimal double value |
| 827 |
if (rhs.norm_sqr() < 1e28 * min_number(number())) |
| 828 |
boundary_projection = 0; |
| 829 |
else |
| 830 |
{ |
| 831 |
// Allow for a maximum of 5*n steps to reduce the residual by 10^-12. |
| 832 |
// n steps may not be sufficient, since roundoff errors may accumulate |
| 833 |
// for badly conditioned matrices |
| 834 |
ReductionControl control(5 * rhs.size(), 0., 1e-12, false, false); |
| 835 |
GrowingVectorMemory<Vector<number>> memory; |
| 836 |
SolverCG<Vector<number>> cg(control, memory); |
| 837 |
|
| 838 |
PreconditionSSOR<SparseMatrix<number>> prec; |
| 839 |
prec.initialize(mass_matrix, 1.2); |
| 840 |
|
| 841 |
cg.solve(mass_matrix, boundary_projection, rhs, prec); |
| 842 |
} |
| 843 |
// fill in boundary values |
| 844 |
for (unsigned int i = 0; i < dof_to_boundary_mapping.size(); ++i) |
| 845 |
if (dof_to_boundary_mapping[i] != numbers::invalid_dof_index) |
| 846 |
{ |
| 847 |
AssertIsFinite(boundary_projection(dof_to_boundary_mapping[i])); |
| 848 |
|
| 849 |
// this dof is on one of the |
| 850 |
// interesting boundary parts |
| 851 |
// |
| 852 |
// remember: i is the global dof |
| 853 |
// number, dof_to_boundary_mapping[i] |
| 854 |
// is the number on the boundary and |
| 855 |
// thus in the solution vector |
| 856 |
boundary_values[i] = |
| 857 |
boundary_projection(dof_to_boundary_mapping[i]); |
| 858 |
} |
| 859 |
} |
| 860 |
} // namespace internal |
| 861 |
|
| 862 |
template <int dim, int spacedim, typename number> |
| 863 |
void |
| 864 |
project_boundary_values( |
| 865 |
const Mapping<dim, spacedim> &mapping, |
| 866 |
const DoFHandler<dim, spacedim> &dof, |
| 867 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 868 |
&boundary_functions, |
| 869 |
const Quadrature<dim - 1> &q, |
| 870 |
std::map<types::global_dof_index, number> &boundary_values, |
| 871 |
std::vector<unsigned int> component_mapping) |
| 872 |
{ |
| 873 |
internal::do_project_boundary_values( |
| 874 |
mapping, dof, boundary_functions, q, boundary_values, component_mapping); |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
template <int dim, int spacedim, typename number> |
| 880 |
void |
| 881 |
project_boundary_values( |
| 882 |
const DoFHandler<dim, spacedim> &dof, |
| 883 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 884 |
&boundary_functions, |
| 885 |
const Quadrature<dim - 1> &q, |
| 886 |
std::map<types::global_dof_index, number> &boundary_values, |
| 887 |
std::vector<unsigned int> component_mapping) |
| 888 |
{ |
| 889 |
project_boundary_values(get_default_linear_mapping(dof.get_triangulation()), |
| 890 |
dof, |
| 891 |
boundary_functions, |
| 892 |
q, |
| 893 |
boundary_values, |
| 894 |
component_mapping); |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
template <int dim, int spacedim, typename number> |
| 900 |
void |
| 901 |
project_boundary_values( |
| 902 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 903 |
const DoFHandler<dim, spacedim> &dof, |
| 904 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 905 |
&boundary_functions, |
| 906 |
const hp::QCollection<dim - 1> &q, |
| 907 |
std::map<types::global_dof_index, number> &boundary_values, |
| 908 |
std::vector<unsigned int> component_mapping) |
| 909 |
{ |
| 910 |
internal::do_project_boundary_values( |
| 911 |
mapping, dof, boundary_functions, q, boundary_values, component_mapping); |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
template <int dim, int spacedim, typename number> |
| 917 |
void |
| 918 |
project_boundary_values( |
| 919 |
const DoFHandler<dim, spacedim> &dof, |
| 920 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 921 |
&boundary_function, |
| 922 |
const hp::QCollection<dim - 1> &q, |
| 923 |
std::map<types::global_dof_index, number> &boundary_values, |
| 924 |
std::vector<unsigned int> component_mapping) |
| 925 |
{ |
| 926 |
project_boundary_values( |
| 927 |
hp::StaticMappingQ1<dim, spacedim>::mapping_collection, |
| 928 |
dof, |
| 929 |
boundary_function, |
| 930 |
q, |
| 931 |
boundary_values, |
| 932 |
component_mapping); |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
// ---- implementation for project_boundary_values with AffineConstraints ---- |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
template <int dim, int spacedim, typename number> |
| 941 |
void |
| 942 |
project_boundary_values( |
| 943 |
const Mapping<dim, spacedim> &mapping, |
| 944 |
const DoFHandler<dim, spacedim> &dof, |
| 945 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 946 |
&boundary_functions, |
| 947 |
const Quadrature<dim - 1> &q, |
| 948 |
AffineConstraints<number> &constraints, |
| 949 |
std::vector<unsigned int> component_mapping) |
| 950 |
{ |
| 951 |
std::map<types::global_dof_index, number> boundary_values; |
| 952 |
project_boundary_values( |
| 953 |
mapping, dof, boundary_functions, q, boundary_values, component_mapping); |
| 954 |
|
| 955 |
for (const auto &boundary_value : boundary_values) |
| 956 |
{ |
| 957 |
if (!constraints.is_constrained(boundary_value.first)) |
| 958 |
constraints.add_constraint(boundary_value.first, |
| 959 |
{}, |
| 960 |
boundary_value.second); |
| 961 |
} |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
template <int dim, int spacedim, typename number> |
| 967 |
void |
| 968 |
project_boundary_values( |
| 969 |
const DoFHandler<dim, spacedim> &dof, |
| 970 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 971 |
&boundary_functions, |
| 972 |
const Quadrature<dim - 1> &q, |
| 973 |
AffineConstraints<number> &constraints, |
| 974 |
std::vector<unsigned int> component_mapping) |
| 975 |
{ |
| 976 |
project_boundary_values(get_default_linear_mapping(dof.get_triangulation()), |
| 977 |
dof, |
| 978 |
boundary_functions, |
| 979 |
q, |
| 980 |
constraints, |
| 981 |
component_mapping); |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
namespace internals |
| 986 |
{ |
| 987 |
template <int dim, typename cell_iterator, typename number> |
| 988 |
std::enable_if_t<dim == 3> |
| 989 |
compute_edge_projection_l2(const cell_iterator &cell, |
| 990 |
const unsigned int face, |
| 991 |
const unsigned int line, |
| 992 |
hp::FEValues<dim> &hp_fe_values, |
| 993 |
const Function<dim, number> &boundary_function, |
| 994 |
const unsigned int first_vector_component, |
| 995 |
std::vector<number> &dof_values, |
| 996 |
std::vector<bool> &dofs_processed) |
| 997 |
{ |
| 998 |
// This function computes the L2-projection of the given |
| 999 |
// boundary function on 3d edges and returns the constraints |
| 1000 |
// associated with the edge functions for the given cell. |
| 1001 |
// |
| 1002 |
// In the context of this function, by associated DoFs we mean: |
| 1003 |
// the DoFs corresponding to the group of components making up the vector |
| 1004 |
// with first component first_vector_component (length dim). |
| 1005 |
const FiniteElement<dim> &fe = cell->get_fe(); |
| 1006 |
|
| 1007 |
// reinit for this cell, face and line. |
| 1008 |
hp_fe_values.reinit(cell, |
| 1009 |
(cell->active_fe_index() * cell->n_faces() + face) * |
| 1010 |
GeometryInfo<dim>::lines_per_face + |
| 1011 |
line); |
| 1012 |
|
| 1013 |
// Initialize the required objects. |
| 1014 |
const FEValues<dim> &fe_values = hp_fe_values.get_present_fe_values(); |
| 1015 |
|
| 1016 |
const std::vector<Point<dim>> &quadrature_points = |
| 1017 |
fe_values.get_quadrature_points(); |
| 1018 |
std::vector<Vector<number>> values(fe_values.n_quadrature_points, |
| 1019 |
Vector<number>(fe.n_components())); |
| 1020 |
|
| 1021 |
// Get boundary function values |
| 1022 |
// at quadrature points. |
| 1023 |
AssertDimension(boundary_function.n_components, fe.n_components()); |
| 1024 |
boundary_function.vector_value_list(quadrature_points, values); |
| 1025 |
|
| 1026 |
// Find the group of vector components we want to project onto |
| 1027 |
// (dim of them, starting at first_vector_component) within the |
| 1028 |
// overall finite element (which may be an FESystem). |
| 1029 |
std::pair<unsigned int, unsigned int> base_indices(0, 0); |
| 1030 |
if (dynamic_cast<const FESystem<dim> *>(&fe) != nullptr) |
| 1031 |
{ |
| 1032 |
unsigned int fe_index = 0; |
| 1033 |
unsigned int fe_index_old = 0; |
| 1034 |
unsigned int i = 0; |
| 1035 |
|
| 1036 |
// Find base element: |
| 1037 |
// base_indices.first |
| 1038 |
// |
| 1039 |
// Then select which copy of that base element |
| 1040 |
// [ each copy is of length |
| 1041 |
// fe.base_element(base_indices.first).n_components() ] corresponds to |
| 1042 |
// first_vector_component: base_index.second |
| 1043 |
for (; i < fe.n_base_elements(); ++i) |
| 1044 |
{ |
| 1045 |
fe_index_old = fe_index; |
| 1046 |
fe_index += |
| 1047 |
fe.element_multiplicity(i) * fe.base_element(i).n_components(); |
| 1048 |
|
| 1049 |
if (fe_index > first_vector_component) |
| 1050 |
break; |
| 1051 |
} |
| 1052 |
|
| 1053 |
base_indices.first = i; |
| 1054 |
base_indices.second = (first_vector_component - fe_index_old) / |
| 1055 |
fe.base_element(i).n_components(); |
| 1056 |
} |
| 1057 |
else |
| 1058 |
// The only other element we know how to deal with (so far) is |
| 1059 |
// FE_Nedelec, which has one base element and one copy of it |
| 1060 |
// (with 3 components). In that case, the values of |
| 1061 |
// 'base_indices' as initialized above are correct. |
| 1062 |
Assert((dynamic_cast<const FE_Nedelec<dim> *>(&fe) != nullptr) || |
| 1063 |
(dynamic_cast<const FE_NedelecSZ<dim> *>(&fe) != nullptr), |
| 1064 |
ExcNotImplemented()); |
| 1065 |
|
| 1066 |
|
| 1067 |
// Store the 'degree' of the Nedelec element as fe.degree-1. For |
| 1068 |
// Nedelec elements, FE_Nedelec<dim>(0) returns fe.degree = 1 |
| 1069 |
// because fe.degree stores the *polynomial* degree, not the |
| 1070 |
// degree of the element (which is typically defined based on |
| 1071 |
// the largest polynomial space that is *complete* within the |
| 1072 |
// finite element). |
| 1073 |
const unsigned int degree = |
| 1074 |
fe.base_element(base_indices.first).degree - 1; |
| 1075 |
|
| 1076 |
// Find DoFs we want to constrain: There are |
| 1077 |
// fe.base_element(base_indices.first).dofs_per_line DoFs |
| 1078 |
// associated with the given line on the given face on the given |
| 1079 |
// cell. |
| 1080 |
// |
| 1081 |
// We need to know which of these DoFs (there are degree+1 of interest) |
| 1082 |
// are associated with the components given by first_vector_component. |
| 1083 |
// Then we can make a map from the associated line DoFs to the face DoFs. |
| 1084 |
// |
| 1085 |
// For a single FE_Nedelec<3> element this is simple: |
| 1086 |
// We know the ordering of local DoFs goes |
| 1087 |
// lines -> faces -> cells |
| 1088 |
// |
| 1089 |
// For a set of FESystem<3> elements we need to pick out the matching base |
| 1090 |
// element and the index within this ordering. |
| 1091 |
// |
| 1092 |
// We call the map associated_edge_dof_to_face_dof |
| 1093 |
std::vector<unsigned int> associated_edge_dof_to_face_dof( |
| 1094 |
degree + 1, numbers::invalid_unsigned_int); |
| 1095 |
|
| 1096 |
// Lowest DoF in the base element allowed for this edge: |
| 1097 |
const unsigned int lower_bound = |
| 1098 |
fe.base_element(base_indices.first) |
| 1099 |
.face_to_cell_index(line * (degree + 1), face); |
| 1100 |
// Highest DoF in the base element allowed for this edge: |
| 1101 |
const unsigned int upper_bound = |
| 1102 |
fe.base_element(base_indices.first) |
| 1103 |
.face_to_cell_index((line + 1) * (degree + 1) - 1, face); |
| 1104 |
|
| 1105 |
unsigned int associated_edge_dof_index = 0; |
| 1106 |
for (unsigned int line_dof_idx = 0; line_dof_idx < fe.n_dofs_per_line(); |
| 1107 |
++line_dof_idx) |
| 1108 |
{ |
| 1109 |
// For each DoF associated with the (interior of) the line, we need |
| 1110 |
// to figure out which base element it belongs to and then if |
| 1111 |
// that's the correct base element. This is complicated by the |
| 1112 |
// fact that the FiniteElement class has functions that translate |
| 1113 |
// from face to cell, but not from edge to cell index systems. So |
| 1114 |
// we have to do that step by step. |
| 1115 |
// |
| 1116 |
// DoFs on a face in 3d are numbered in order by vertices then lines |
| 1117 |
// then faces. |
| 1118 |
// i.e. line 0 has degree+1 dofs numbered 0,..,degree |
| 1119 |
// line 1 has degree+1 dofs numbered (degree+1),..,2*(degree+1) |
| 1120 |
// and so on. |
| 1121 |
|
| 1122 |
const unsigned int face_dof_idx = |
| 1123 |
GeometryInfo<dim>::vertices_per_face * fe.n_dofs_per_vertex() + |
| 1124 |
line * fe.n_dofs_per_line() + line_dof_idx; |
| 1125 |
|
| 1126 |
// Note, assuming that the edge orientations are "standard", i.e., |
| 1127 |
// cell->line_orientation(line) = |
| 1128 |
// numbers::default_geometric_orientation |
| 1129 |
Assert(cell->line_orientation(line) == |
| 1130 |
numbers::default_geometric_orientation, |
| 1131 |
ExcMessage("Edge orientation does not meet expectation.")); |
| 1132 |
// Next, translate from face to cell. Note, this might be assuming |
| 1133 |
// that the edge orientations are "standard" |
| 1134 |
const unsigned int cell_dof_idx = |
| 1135 |
fe.face_to_cell_index(face_dof_idx, face); |
| 1136 |
|
| 1137 |
// Check that this cell_idx belongs to the correct base_element, |
| 1138 |
// component and line. We do this for each of the supported elements |
| 1139 |
// separately |
| 1140 |
bool dof_is_of_interest = false; |
| 1141 |
if (dynamic_cast<const FESystem<dim> *>(&fe) != nullptr) |
| 1142 |
{ |
| 1143 |
dof_is_of_interest = |
| 1144 |
(fe.system_to_base_index(cell_dof_idx).first == base_indices) && |
| 1145 |
(lower_bound <= fe.system_to_base_index(cell_dof_idx).second) && |
| 1146 |
(fe.system_to_base_index(cell_dof_idx).second <= upper_bound); |
| 1147 |
} |
| 1148 |
else if ((dynamic_cast<const FE_Nedelec<dim> *>(&fe) != nullptr) || |
| 1149 |
(dynamic_cast<const FE_NedelecSZ<dim> *>(&fe) != nullptr)) |
| 1150 |
{ |
| 1151 |
Assert((line * (degree + 1) <= face_dof_idx) && |
| 1152 |
(face_dof_idx < (line + 1) * (degree + 1)), |
| 1153 |
ExcInternalError()); |
| 1154 |
dof_is_of_interest = true; |
| 1155 |
} |
| 1156 |
else |
| 1157 |
DEAL_II_NOT_IMPLEMENTED(); |
| 1158 |
|
| 1159 |
if (dof_is_of_interest) |
| 1160 |
{ |
| 1161 |
associated_edge_dof_to_face_dof[associated_edge_dof_index] = |
| 1162 |
face_dof_idx; |
| 1163 |
++associated_edge_dof_index; |
| 1164 |
} |
| 1165 |
} |
| 1166 |
// Sanity check: |
| 1167 |
const unsigned int n_associated_edge_dofs = associated_edge_dof_index; |
| 1168 |
Assert(n_associated_edge_dofs == degree + 1, |
| 1169 |
ExcMessage("Error: Unexpected number of 3d edge DoFs")); |
| 1170 |
|
| 1171 |
// Matrix and RHS vectors to store linear system: |
| 1172 |
// We have (degree+1) basis functions for an edge |
| 1173 |
FullMatrix<number> edge_matrix(degree + 1, degree + 1); |
| 1174 |
FullMatrix<number> edge_matrix_inv(degree + 1, degree + 1); |
| 1175 |
Vector<number> edge_rhs(degree + 1); |
| 1176 |
Vector<number> edge_solution(degree + 1); |
| 1177 |
|
| 1178 |
const FEValuesExtractors::Vector vec(first_vector_component); |
| 1179 |
|
| 1180 |
// coordinate directions of |
| 1181 |
// the edges of the face. |
| 1182 |
const unsigned int |
| 1183 |
edge_coordinate_direction[GeometryInfo<dim>::faces_per_cell] |
| 1184 |
[GeometryInfo<dim>::lines_per_face] = { |
| 1185 |
{2, 2, 1, 1}, |
| 1186 |
{2, 2, 1, 1}, |
| 1187 |
{0, 0, 2, 2}, |
| 1188 |
{0, 0, 2, 2}, |
| 1189 |
{1, 1, 0, 0}, |
| 1190 |
{1, 1, 0, 0}}; |
| 1191 |
|
| 1192 |
const double tol = |
| 1193 |
0.5 * cell->face(face)->line(line)->diameter() / fe.degree; |
| 1194 |
const std::vector<Point<dim>> &reference_quadrature_points = |
| 1195 |
fe_values.get_quadrature().get_points(); |
| 1196 |
|
| 1197 |
// Project the boundary function onto the shape functions for this edge |
| 1198 |
// and set up a linear system of equations to get the values for the DoFs |
| 1199 |
// associated with this edge. |
| 1200 |
for (unsigned int q_point = 0; q_point < fe_values.n_quadrature_points; |
| 1201 |
++q_point) |
| 1202 |
{ |
| 1203 |
// Compute the tangential |
| 1204 |
// of the edge at |
| 1205 |
// the quadrature point. |
| 1206 |
Point<dim> shifted_reference_point_1 = |
| 1207 |
reference_quadrature_points[q_point]; |
| 1208 |
Point<dim> shifted_reference_point_2 = |
| 1209 |
reference_quadrature_points[q_point]; |
| 1210 |
|
| 1211 |
shifted_reference_point_1[edge_coordinate_direction[face][line]] += |
| 1212 |
tol; |
| 1213 |
shifted_reference_point_2[edge_coordinate_direction[face][line]] -= |
| 1214 |
tol; |
| 1215 |
Tensor<1, dim> tangential = |
| 1216 |
(0.5 * |
| 1217 |
(fe_values.get_mapping().transform_unit_to_real_cell( |
| 1218 |
cell, shifted_reference_point_1) - |
| 1219 |
fe_values.get_mapping().transform_unit_to_real_cell( |
| 1220 |
cell, shifted_reference_point_2)) / |
| 1221 |
tol); |
| 1222 |
tangential /= tangential.norm(); |
| 1223 |
|
| 1224 |
// Compute the entries of the linear system |
| 1225 |
// Note the system is symmetric so we could only compute the |
| 1226 |
// lower/upper triangle. |
| 1227 |
// |
| 1228 |
// The matrix entries are |
| 1229 |
// \int_{edge} |
| 1230 |
// (tangential*edge_shape_function_i)*(tangential*edge_shape_function_j) |
| 1231 |
// dS |
| 1232 |
// |
| 1233 |
// The RHS entries are: |
| 1234 |
// \int_{edge} |
| 1235 |
// (tangential*boundary_value)*(tangential*edge_shape_function_i) dS. |
| 1236 |
for (unsigned int j = 0; j < n_associated_edge_dofs; ++j) |
| 1237 |
{ |
| 1238 |
const unsigned int j_face_idx = |
| 1239 |
associated_edge_dof_to_face_dof[j]; |
| 1240 |
const unsigned int j_cell_idx = |
| 1241 |
fe.face_to_cell_index(j_face_idx, face); |
| 1242 |
for (unsigned int i = 0; i < n_associated_edge_dofs; ++i) |
| 1243 |
{ |
| 1244 |
const unsigned int i_face_idx = |
| 1245 |
associated_edge_dof_to_face_dof[i]; |
| 1246 |
const unsigned int i_cell_idx = |
| 1247 |
fe.face_to_cell_index(i_face_idx, face); |
| 1248 |
|
| 1249 |
edge_matrix(i, j) += |
| 1250 |
fe_values.JxW(q_point) * |
| 1251 |
(fe_values[vec].value(i_cell_idx, q_point) * tangential) * |
| 1252 |
(fe_values[vec].value(j_cell_idx, q_point) * tangential); |
| 1253 |
} |
| 1254 |
// Compute the RHS entries: |
| 1255 |
edge_rhs(j) += |
| 1256 |
fe_values.JxW(q_point) * |
| 1257 |
(values[q_point](first_vector_component) * tangential[0] + |
| 1258 |
values[q_point](first_vector_component + 1) * tangential[1] + |
| 1259 |
values[q_point](first_vector_component + 2) * tangential[2]) * |
| 1260 |
(fe_values[vec].value(j_cell_idx, q_point) * tangential); |
| 1261 |
} |
| 1262 |
} |
| 1263 |
|
| 1264 |
// Invert linear system |
| 1265 |
edge_matrix_inv.invert(edge_matrix); |
| 1266 |
edge_matrix_inv.vmult(edge_solution, edge_rhs); |
| 1267 |
|
| 1268 |
// Store computed DoFs |
| 1269 |
for (unsigned int i = 0; i < n_associated_edge_dofs; ++i) |
| 1270 |
{ |
| 1271 |
dof_values[associated_edge_dof_to_face_dof[i]] = edge_solution(i); |
| 1272 |
dofs_processed[associated_edge_dof_to_face_dof[i]] = true; |
| 1273 |
} |
| 1274 |
} |
| 1275 |
|
| 1276 |
|
| 1277 |
template <int dim, typename cell_iterator, typename number> |
| 1278 |
std::enable_if_t<dim != 3> |
| 1279 |
compute_edge_projection_l2(const cell_iterator &, |
| 1280 |
const unsigned int, |
| 1281 |
const unsigned int, |
| 1282 |
hp::FEValues<dim> &, |
| 1283 |
const Function<dim, number> &, |
| 1284 |
const unsigned int, |
| 1285 |
std::vector<number> &, |
| 1286 |
std::vector<bool> &) |
| 1287 |
{ |
| 1288 |
// dummy implementation of above function |
| 1289 |
// for all other dimensions |
| 1290 |
DEAL_II_ASSERT_UNREACHABLE(); |
| 1291 |
} |
| 1292 |
|
| 1293 |
|
| 1294 |
template <int dim, typename cell_iterator, typename number> |
| 1295 |
void |
| 1296 |
compute_face_projection_curl_conforming_l2( |
| 1297 |
const cell_iterator &cell, |
| 1298 |
const unsigned int face, |
| 1299 |
hp::FEFaceValues<dim> &hp_fe_face_values, |
| 1300 |
const Function<dim, number> &boundary_function, |
| 1301 |
const unsigned int first_vector_component, |
| 1302 |
std::vector<number> &dof_values, |
| 1303 |
std::vector<bool> &dofs_processed) |
| 1304 |
{ |
| 1305 |
// This function computes the L2-projection of the boundary |
| 1306 |
// function on the interior of faces only. In 3d, this should only be |
| 1307 |
// called after first calling compute_edge_projection_l2, as it relies on |
| 1308 |
// edge constraints which are found. |
| 1309 |
|
| 1310 |
// In the context of this function, by associated DoFs we mean: |
| 1311 |
// the DoFs corresponding to the group of components making up the vector |
| 1312 |
// with first component first_vector_component (with total components |
| 1313 |
// dim). |
| 1314 |
|
| 1315 |
// Copy to the standard FEFaceValues object: |
| 1316 |
hp_fe_face_values.reinit(cell, face); |
| 1317 |
const FEFaceValues<dim> &fe_face_values = |
| 1318 |
hp_fe_face_values.get_present_fe_values(); |
| 1319 |
|
| 1320 |
// Initialize the required objects. |
| 1321 |
const FiniteElement<dim> &fe = cell->get_fe(); |
| 1322 |
const std::vector<Point<dim>> &quadrature_points = |
| 1323 |
fe_face_values.get_quadrature_points(); |
| 1324 |
|
| 1325 |
std::vector<Vector<number>> values(fe_face_values.n_quadrature_points, |
| 1326 |
Vector<number>(fe.n_components())); |
| 1327 |
|
| 1328 |
// Get boundary function values at quadrature points. |
| 1329 |
AssertDimension(boundary_function.n_components, fe.n_components()); |
| 1330 |
boundary_function.vector_value_list(quadrature_points, values); |
| 1331 |
|
| 1332 |
// Find where the group of vector components (dim of them, |
| 1333 |
// starting at first_vector_component) are within an FESystem. |
| 1334 |
// |
| 1335 |
// If not using FESystem then must be using FE_Nedelec, |
| 1336 |
// which has one base element and one copy of it (with 3 components). |
| 1337 |
std::pair<unsigned int, unsigned int> base_indices(0, 0); |
| 1338 |
if (dynamic_cast<const FESystem<dim> *>(&fe) != nullptr) |
| 1339 |
{ |
| 1340 |
unsigned int fe_index = 0; |
| 1341 |
unsigned int fe_index_old = 0; |
| 1342 |
unsigned int i = 0; |
| 1343 |
|
| 1344 |
// Find base element: |
| 1345 |
// base_indices.first |
| 1346 |
// |
| 1347 |
// Then select which copy of that base element |
| 1348 |
// [ each copy is of length |
| 1349 |
// fe.base_element(base_indices.first).n_components() ] corresponds to |
| 1350 |
// first_vector_component: base_index.second |
| 1351 |
for (; i < fe.n_base_elements(); ++i) |
| 1352 |
{ |
| 1353 |
fe_index_old = fe_index; |
| 1354 |
fe_index += |
| 1355 |
fe.element_multiplicity(i) * fe.base_element(i).n_components(); |
| 1356 |
|
| 1357 |
if (fe_index > first_vector_component) |
| 1358 |
break; |
| 1359 |
} |
| 1360 |
base_indices.first = i; |
| 1361 |
base_indices.second = (first_vector_component - fe_index_old) / |
| 1362 |
fe.base_element(i).n_components(); |
| 1363 |
} |
| 1364 |
else |
| 1365 |
{ |
| 1366 |
// Assert that the FE is in fact an FE_Nedelec, so that the default |
| 1367 |
// base_indices == (0,0) is correct. |
| 1368 |
Assert((dynamic_cast<const FE_Nedelec<dim> *>(&fe) != nullptr) || |
| 1369 |
(dynamic_cast<const FE_NedelecSZ<dim> *>(&fe) != nullptr), |
| 1370 |
ExcNotImplemented()); |
| 1371 |
} |
| 1372 |
const unsigned int degree = |
| 1373 |
fe.base_element(base_indices.first).degree - 1; |
| 1374 |
|
| 1375 |
switch (dim) |
| 1376 |
{ |
| 1377 |
case 2: |
| 1378 |
// NOTE: This is very similar to compute_edge_projection as used in |
| 1379 |
// 3d, |
| 1380 |
// and contains a lot of overlap with that function. |
| 1381 |
{ |
| 1382 |
// Find the DoFs we want to constrain. There are degree+1 in |
| 1383 |
// total. Create a map from these to the face index Note: |
| 1384 |
// - for a single FE_Nedelec<2> element this is |
| 1385 |
// simply 0 to fe.dofs_per_face |
| 1386 |
// - for FESystem<2> this just requires matching the |
| 1387 |
// base element, fe.system_to_base_index.first.first |
| 1388 |
// and the copy of the base element we're interested |
| 1389 |
// in, fe.system_to_base_index.first.second |
| 1390 |
std::vector<unsigned int> associated_edge_dof_to_face_dof(degree + |
| 1391 |
1); |
| 1392 |
|
| 1393 |
unsigned int associated_edge_dof_index = 0; |
| 1394 |
for (unsigned int face_idx = 0; |
| 1395 |
face_idx < fe.n_dofs_per_face(face); |
| 1396 |
++face_idx) |
| 1397 |
{ |
| 1398 |
const unsigned int cell_idx = |
| 1399 |
fe.face_to_cell_index(face_idx, face); |
| 1400 |
if (((dynamic_cast<const FESystem<dim> *>(&fe) != nullptr) && |
| 1401 |
(fe.system_to_base_index(cell_idx).first == |
| 1402 |
base_indices)) || |
| 1403 |
(dynamic_cast<const FE_Nedelec<dim> *>(&fe) != nullptr) || |
| 1404 |
(dynamic_cast<const FE_NedelecSZ<dim> *>(&fe) != nullptr)) |
| 1405 |
{ |
| 1406 |
associated_edge_dof_to_face_dof |
| 1407 |
[associated_edge_dof_index] = face_idx; |
| 1408 |
++associated_edge_dof_index; |
| 1409 |
} |
| 1410 |
} |
| 1411 |
// Sanity check: |
| 1412 |
const unsigned int associated_edge_dofs = |
| 1413 |
associated_edge_dof_index; |
| 1414 |
Assert(associated_edge_dofs == degree + 1, |
| 1415 |
ExcMessage("Error: Unexpected number of 2d edge DoFs")); |
| 1416 |
|
| 1417 |
// Matrix and RHS vectors to store: |
| 1418 |
// We have (degree+1) edge basis functions |
| 1419 |
FullMatrix<number> edge_matrix(degree + 1, degree + 1); |
| 1420 |
FullMatrix<number> edge_matrix_inv(degree + 1, degree + 1); |
| 1421 |
Vector<number> edge_rhs(degree + 1); |
| 1422 |
Vector<number> edge_solution(degree + 1); |
| 1423 |
|
| 1424 |
const FEValuesExtractors::Vector vec(first_vector_component); |
| 1425 |
|
| 1426 |
// Project the boundary function onto the shape functions for this |
| 1427 |
// edge and set up a linear system of equations to get the values |
| 1428 |
// for the DoFs associated with this edge. |
| 1429 |
for (unsigned int q_point = 0; |
| 1430 |
q_point < fe_face_values.n_quadrature_points; |
| 1431 |
++q_point) |
| 1432 |
{ |
| 1433 |
// Compute the entries of the linear system |
| 1434 |
// Note the system is symmetric so we could only compute the |
| 1435 |
// lower/upper triangle. |
| 1436 |
// |
| 1437 |
// The matrix entries are |
| 1438 |
// \int_{edge} (tangential * edge_shape_function_i) * |
| 1439 |
// (tangential * edge_shape_function_j) dS |
| 1440 |
// |
| 1441 |
// The RHS entries are: |
| 1442 |
// \int_{edge} (tangential* boundary_value) * (tangential * |
| 1443 |
// edge_shape_function_i) dS. |
| 1444 |
// |
| 1445 |
// In 2d, tangential*vector is equivalent to |
| 1446 |
// cross_product_3d(normal, vector), so we use this instead. |
| 1447 |
// This avoids possible issues with the computation of the |
| 1448 |
// tangent. |
| 1449 |
|
| 1450 |
// Store the normal at this quad point: |
| 1451 |
Tensor<1, dim> normal_at_q_point = |
| 1452 |
fe_face_values.normal_vector(q_point); |
| 1453 |
for (unsigned int j = 0; j < associated_edge_dofs; ++j) |
| 1454 |
{ |
| 1455 |
const unsigned int j_face_idx = |
| 1456 |
associated_edge_dof_to_face_dof[j]; |
| 1457 |
const unsigned int j_cell_idx = |
| 1458 |
fe.face_to_cell_index(j_face_idx, face); |
| 1459 |
|
| 1460 |
Tensor<1, dim> phi_j = |
| 1461 |
fe_face_values[vec].value(j_cell_idx, q_point); |
| 1462 |
for (unsigned int i = 0; i < associated_edge_dofs; ++i) |
| 1463 |
{ |
| 1464 |
const unsigned int i_face_idx = |
| 1465 |
associated_edge_dof_to_face_dof[i]; |
| 1466 |
const unsigned int i_cell_idx = |
| 1467 |
fe.face_to_cell_index(i_face_idx, face); |
| 1468 |
|
| 1469 |
Tensor<1, dim> phi_i = |
| 1470 |
fe_face_values[vec].value(i_cell_idx, q_point); |
| 1471 |
|
| 1472 |
// Using n cross phi |
| 1473 |
edge_matrix(i, j) += |
| 1474 |
fe_face_values.JxW(q_point) * |
| 1475 |
((phi_i[1] * normal_at_q_point[0] - |
| 1476 |
phi_i[0] * normal_at_q_point[1]) * |
| 1477 |
(phi_j[1] * normal_at_q_point[0] - |
| 1478 |
phi_j[0] * normal_at_q_point[1])); |
| 1479 |
} |
| 1480 |
// Using n cross phi |
| 1481 |
edge_rhs(j) += |
| 1482 |
fe_face_values.JxW(q_point) * |
| 1483 |
((values[q_point](first_vector_component + 1) * |
| 1484 |
normal_at_q_point[0] - |
| 1485 |
values[q_point](first_vector_component) * |
| 1486 |
normal_at_q_point[1]) * |
| 1487 |
(phi_j[1] * normal_at_q_point[0] - |
| 1488 |
phi_j[0] * normal_at_q_point[1])); |
| 1489 |
} |
| 1490 |
} |
| 1491 |
|
| 1492 |
// Invert linear system |
| 1493 |
edge_matrix_inv.invert(edge_matrix); |
| 1494 |
edge_matrix_inv.vmult(edge_solution, edge_rhs); |
| 1495 |
|
| 1496 |
// Store computed DoFs |
| 1497 |
for (unsigned int associated_edge_dof_index = 0; |
| 1498 |
associated_edge_dof_index < associated_edge_dofs; |
| 1499 |
++associated_edge_dof_index) |
| 1500 |
{ |
| 1501 |
dof_values[associated_edge_dof_to_face_dof |
| 1502 |
[associated_edge_dof_index]] = |
| 1503 |
edge_solution(associated_edge_dof_index); |
| 1504 |
dofs_processed[associated_edge_dof_to_face_dof |
| 1505 |
[associated_edge_dof_index]] = true; |
| 1506 |
} |
| 1507 |
break; |
| 1508 |
} |
| 1509 |
|
| 1510 |
case 3: |
| 1511 |
{ |
| 1512 |
const FEValuesExtractors::Vector vec(first_vector_component); |
| 1513 |
|
| 1514 |
// First group DoFs associated with edges which we already know. |
| 1515 |
// Sort these into groups of dofs (0 -> degree+1 of them) by each |
| 1516 |
// edge. This will help when computing the residual for the face |
| 1517 |
// projections. |
| 1518 |
// |
| 1519 |
// This matches with the search done in compute_edge_projection. |
| 1520 |
const unsigned int lines_per_face = |
| 1521 |
GeometryInfo<dim>::lines_per_face; |
| 1522 |
std::vector<std::vector<unsigned int>> |
| 1523 |
associated_edge_dof_to_face_dof( |
| 1524 |
lines_per_face, std::vector<unsigned int>(degree + 1)); |
| 1525 |
std::vector<unsigned int> associated_edge_dofs(lines_per_face); |
| 1526 |
|
| 1527 |
for (unsigned int line = 0; line < lines_per_face; ++line) |
| 1528 |
{ |
| 1529 |
// Lowest DoF in the base element allowed for this edge: |
| 1530 |
const unsigned int lower_bound = |
| 1531 |
fe.base_element(base_indices.first) |
| 1532 |
.face_to_cell_index(line * (degree + 1), face); |
| 1533 |
// Highest DoF in the base element allowed for this edge: |
| 1534 |
const unsigned int upper_bound = |
| 1535 |
fe.base_element(base_indices.first) |
| 1536 |
.face_to_cell_index((line + 1) * (degree + 1) - 1, face); |
| 1537 |
unsigned int associated_edge_dof_index = 0; |
| 1538 |
|
| 1539 |
for (unsigned int line_dof_idx = 0; |
| 1540 |
line_dof_idx < fe.n_dofs_per_line(); |
| 1541 |
++line_dof_idx) |
| 1542 |
{ |
| 1543 |
// For each DoF associated with the (interior of) the |
| 1544 |
// line, we need to figure out which base element it |
| 1545 |
// belongs to and then if that's the correct base element. |
| 1546 |
// This is complicated by the fact that the FiniteElement |
| 1547 |
// class has functions that translate from face to cell, |
| 1548 |
// but not from edge to cell index systems. So we have to |
| 1549 |
// do that step by step. |
| 1550 |
// |
| 1551 |
// DoFs on a face in 3d are numbered in order by vertices |
| 1552 |
// then lines then faces. i.e. line 0 has degree+1 dofs |
| 1553 |
// numbered 0,..,degree |
| 1554 |
// line 1 has degree+1 dofs numbered |
| 1555 |
// (degree+1),..,2*(degree+1) and so on. |
| 1556 |
const unsigned int face_dof_idx = |
| 1557 |
GeometryInfo<dim>::vertices_per_face * |
| 1558 |
fe.n_dofs_per_vertex() + |
| 1559 |
line * fe.n_dofs_per_line() + line_dof_idx; |
| 1560 |
|
| 1561 |
// Next, translate from face to cell. Note, this might be |
| 1562 |
// assuming that the edge orientations are "standard" |
| 1563 |
const unsigned int cell_dof_idx = |
| 1564 |
fe.face_to_cell_index(face_dof_idx, face); |
| 1565 |
|
| 1566 |
// Check that this cell_idx belongs to the correct |
| 1567 |
// base_element, component and line. We do this for each |
| 1568 |
// of the supported elements separately |
| 1569 |
bool dof_is_of_interest = false; |
| 1570 |
if (dynamic_cast<const FESystem<dim> *>(&fe) != nullptr) |
| 1571 |
{ |
| 1572 |
dof_is_of_interest = |
| 1573 |
(fe.system_to_base_index(cell_dof_idx).first == |
| 1574 |
base_indices) && |
| 1575 |
(lower_bound <= |
| 1576 |
fe.system_to_base_index(cell_dof_idx).second) && |
| 1577 |
(fe.system_to_base_index(cell_dof_idx).second <= |
| 1578 |
upper_bound); |
| 1579 |
} |
| 1580 |
else if ((dynamic_cast<const FE_Nedelec<dim> *>(&fe) != |
| 1581 |
nullptr) || |
| 1582 |
(dynamic_cast<const FE_NedelecSZ<dim> *>(&fe) != |
| 1583 |
nullptr)) |
| 1584 |
{ |
| 1585 |
Assert((line * (degree + 1) <= face_dof_idx) && |
| 1586 |
(face_dof_idx < (line + 1) * (degree + 1)), |
| 1587 |
ExcInternalError()); |
| 1588 |
dof_is_of_interest = true; |
| 1589 |
} |
| 1590 |
else |
| 1591 |
DEAL_II_NOT_IMPLEMENTED(); |
| 1592 |
|
| 1593 |
if (dof_is_of_interest) |
| 1594 |
{ |
| 1595 |
associated_edge_dof_to_face_dof |
| 1596 |
[line][associated_edge_dof_index] = face_dof_idx; |
| 1597 |
++associated_edge_dof_index; |
| 1598 |
} |
| 1599 |
} |
| 1600 |
// Sanity check: |
| 1601 |
associated_edge_dofs[line] = associated_edge_dof_index; |
| 1602 |
Assert(associated_edge_dofs[line] == degree + 1, |
| 1603 |
ExcInternalError()); |
| 1604 |
} |
| 1605 |
|
| 1606 |
// Next find the face DoFs associated with the vector components |
| 1607 |
// we're interested in. There are 2*degree*(degree+1) DoFs |
| 1608 |
// associated with the interior of each face (not including |
| 1609 |
// edges!). |
| 1610 |
// |
| 1611 |
// Create a map mapping from the consecutively numbered |
| 1612 |
// associated_dofs to the face DoF (which can be transferred to a |
| 1613 |
// local cell index). |
| 1614 |
// |
| 1615 |
// For FE_Nedelec<3> we just need to have a face numbering greater |
| 1616 |
// than the number of edge DoFs (=lines_per_face*(degree+1). |
| 1617 |
// |
| 1618 |
// For FESystem<3> we need to base the base_indices (base element |
| 1619 |
// and copy within that base element) and ensure we're above the |
| 1620 |
// number of edge DoFs within that base element. |
| 1621 |
std::vector<unsigned int> associated_face_dof_to_face_dof( |
| 1622 |
2 * degree * (degree + 1)); |
| 1623 |
|
| 1624 |
// Loop over these quad-interior dofs. |
| 1625 |
unsigned int associated_face_dof_index = 0; |
| 1626 |
for (unsigned int quad_dof_idx = 0; |
| 1627 |
quad_dof_idx < fe.n_dofs_per_quad(face); |
| 1628 |
++quad_dof_idx) |
| 1629 |
{ |
| 1630 |
const unsigned int face_idx = |
| 1631 |
GeometryInfo<dim>::vertices_per_face * |
| 1632 |
fe.n_dofs_per_vertex() + |
| 1633 |
lines_per_face * fe.n_dofs_per_line() + quad_dof_idx; |
| 1634 |
const unsigned int cell_idx = |
| 1635 |
fe.face_to_cell_index(face_idx, face); |
| 1636 |
if (((dynamic_cast<const FESystem<dim> *>(&fe) != nullptr) && |
| 1637 |
(fe.system_to_base_index(cell_idx).first == |
| 1638 |
base_indices)) || |
| 1639 |
(dynamic_cast<const FE_Nedelec<dim> *>(&fe) != nullptr) || |
| 1640 |
(dynamic_cast<const FE_NedelecSZ<dim> *>(&fe) != nullptr)) |
| 1641 |
{ |
| 1642 |
AssertIndexRange(associated_face_dof_index, |
| 1643 |
associated_face_dof_to_face_dof.size()); |
| 1644 |
associated_face_dof_to_face_dof |
| 1645 |
[associated_face_dof_index] = face_idx; |
| 1646 |
++associated_face_dof_index; |
| 1647 |
} |
| 1648 |
} |
| 1649 |
// Sanity check: |
| 1650 |
const unsigned int associated_face_dofs = |
| 1651 |
associated_face_dof_index; |
| 1652 |
Assert(associated_face_dofs == 2 * degree * (degree + 1), |
| 1653 |
ExcMessage("Error: Unexpected number of 3d face DoFs")); |
| 1654 |
|
| 1655 |
// Storage for the linear system. |
| 1656 |
// There are 2*degree*(degree+1) DoFs associated with a face in |
| 1657 |
// 3d. Note this doesn't include the DoFs associated with edges on |
| 1658 |
// that face. |
| 1659 |
FullMatrix<number> face_matrix(2 * degree * (degree + 1)); |
| 1660 |
FullMatrix<number> face_matrix_inv(2 * degree * (degree + 1)); |
| 1661 |
Vector<number> face_rhs(2 * degree * (degree + 1)); |
| 1662 |
Vector<number> face_solution(2 * degree * (degree + 1)); |
| 1663 |
|
| 1664 |
// Project the boundary function onto the shape functions for this |
| 1665 |
// face and set up a linear system of equations to get the values |
| 1666 |
// for the DoFs associated with this face. We also must include |
| 1667 |
// the residuals from the shape functions associated with edges. |
| 1668 |
Tensor<1, dim, number> tmp; |
| 1669 |
Tensor<1, dim> cross_product_i; |
| 1670 |
Tensor<1, dim> cross_product_j; |
| 1671 |
Tensor<1, dim, number> cross_product_rhs; |
| 1672 |
|
| 1673 |
// Loop to construct face linear system. |
| 1674 |
for (unsigned int q_point = 0; |
| 1675 |
q_point < fe_face_values.n_quadrature_points; |
| 1676 |
++q_point) |
| 1677 |
{ |
| 1678 |
// First calculate the residual from the edge functions |
| 1679 |
// store the result in tmp. |
| 1680 |
// |
| 1681 |
// Edge_residual = |
| 1682 |
// boundary_value - ( |
| 1683 |
// \sum_(edges on face) |
| 1684 |
// \sum_(DoFs on edge) |
| 1685 |
// edge_dof_value*edge_shape_function |
| 1686 |
// ) |
| 1687 |
for (unsigned int d = 0; d < dim; ++d) |
| 1688 |
{ |
| 1689 |
tmp[d] = 0.0; |
| 1690 |
} |
| 1691 |
for (unsigned int line = 0; line < lines_per_face; ++line) |
| 1692 |
{ |
| 1693 |
for (unsigned int associated_edge_dof = 0; |
| 1694 |
associated_edge_dof < associated_edge_dofs[line]; |
| 1695 |
++associated_edge_dof) |
| 1696 |
{ |
| 1697 |
const unsigned int face_idx = |
| 1698 |
associated_edge_dof_to_face_dof |
| 1699 |
[line][associated_edge_dof]; |
| 1700 |
const unsigned int cell_idx = |
| 1701 |
fe.face_to_cell_index(face_idx, face); |
| 1702 |
tmp -= dof_values[face_idx] * |
| 1703 |
fe_face_values[vec].value(cell_idx, q_point); |
| 1704 |
} |
| 1705 |
} |
| 1706 |
|
| 1707 |
for (unsigned int d = 0; d < dim; ++d) |
| 1708 |
{ |
| 1709 |
tmp[d] += values[q_point](first_vector_component + d); |
| 1710 |
} |
| 1711 |
|
| 1712 |
// Tensor of normal vector on the face at q_point; |
| 1713 |
const Tensor<1, dim> &normal_vector = |
| 1714 |
fe_face_values.normal_vector(q_point); |
| 1715 |
|
| 1716 |
// Now compute the linear system: |
| 1717 |
// On a face: |
| 1718 |
// The matrix entries are: |
| 1719 |
// \int_{face} (n x face_shape_function_i) \cdot ( n x |
| 1720 |
// face_shape_function_j) dS |
| 1721 |
// |
| 1722 |
// The RHS entries are: |
| 1723 |
// \int_{face} (n x (Edge_residual) \cdot (n x |
| 1724 |
// face_shape_function_i) dS |
| 1725 |
|
| 1726 |
for (unsigned int j = 0; j < associated_face_dofs; ++j) |
| 1727 |
{ |
| 1728 |
const unsigned int j_face_idx = |
| 1729 |
associated_face_dof_to_face_dof[j]; |
| 1730 |
const unsigned int cell_j = |
| 1731 |
fe.face_to_cell_index(j_face_idx, face); |
| 1732 |
|
| 1733 |
cross_product_j = |
| 1734 |
cross_product_3d(normal_vector, |
| 1735 |
fe_face_values[vec].value(cell_j, |
| 1736 |
q_point)); |
| 1737 |
|
| 1738 |
for (unsigned int i = 0; i < associated_face_dofs; ++i) |
| 1739 |
{ |
| 1740 |
const unsigned int i_face_idx = |
| 1741 |
associated_face_dof_to_face_dof[i]; |
| 1742 |
const unsigned int cell_i = |
| 1743 |
fe.face_to_cell_index(i_face_idx, face); |
| 1744 |
cross_product_i = cross_product_3d( |
| 1745 |
normal_vector, |
| 1746 |
fe_face_values[vec].value(cell_i, q_point)); |
| 1747 |
|
| 1748 |
face_matrix(i, j) += fe_face_values.JxW(q_point) * |
| 1749 |
cross_product_i * |
| 1750 |
cross_product_j; |
| 1751 |
} |
| 1752 |
// compute rhs |
| 1753 |
cross_product_rhs = cross_product_3d(normal_vector, tmp); |
| 1754 |
face_rhs(j) += fe_face_values.JxW(q_point) * |
| 1755 |
cross_product_rhs * cross_product_j; |
| 1756 |
} |
| 1757 |
} |
| 1758 |
|
| 1759 |
// Solve linear system: |
| 1760 |
if (associated_face_dofs > 0) |
| 1761 |
{ |
| 1762 |
face_matrix_inv.invert(face_matrix); |
| 1763 |
face_matrix_inv.vmult(face_solution, face_rhs); |
| 1764 |
} |
| 1765 |
|
| 1766 |
// Store computed DoFs: |
| 1767 |
for (unsigned int associated_face_dof = 0; |
| 1768 |
associated_face_dof < associated_face_dofs; |
| 1769 |
++associated_face_dof) |
| 1770 |
{ |
| 1771 |
dof_values |
| 1772 |
[associated_face_dof_to_face_dof[associated_face_dof]] = |
| 1773 |
face_solution(associated_face_dof); |
| 1774 |
dofs_processed |
| 1775 |
[associated_face_dof_to_face_dof[associated_face_dof]] = |
| 1776 |
true; |
| 1777 |
} |
| 1778 |
break; |
| 1779 |
} |
| 1780 |
default: |
| 1781 |
DEAL_II_NOT_IMPLEMENTED(); |
| 1782 |
} |
| 1783 |
} |
| 1784 |
|
| 1785 |
template <int dim, int spacedim, typename number> |
| 1786 |
void |
| 1787 |
compute_project_boundary_values_curl_conforming_l2( |
| 1788 |
const DoFHandler<dim, spacedim> &dof_handler, |
| 1789 |
const unsigned int first_vector_component, |
| 1790 |
const Function<dim, number> &boundary_function, |
| 1791 |
const types::boundary_id boundary_component, |
| 1792 |
AffineConstraints<number> &constraints, |
| 1793 |
const hp::MappingCollection<dim, dim> &mapping_collection) |
| 1794 |
{ |
| 1795 |
// L2-projection based interpolation formed in one (in 2d) or two (in 3d) |
| 1796 |
// steps. |
| 1797 |
// |
| 1798 |
// In 2d we only need to constrain edge DoFs. |
| 1799 |
// |
| 1800 |
// In 3d we need to constrain both edge and face DoFs. This is done in two |
| 1801 |
// parts. |
| 1802 |
// |
| 1803 |
// For edges, since the face shape functions are zero here ("bubble |
| 1804 |
// functions"), we project the tangential component of the boundary |
| 1805 |
// function and compute the L2-projection. This returns the values for the |
| 1806 |
// DoFs associated with each edge shape function. In 3d, this is computed |
| 1807 |
// by internals::compute_edge_projection_l2, in 2d, it is handled by |
| 1808 |
// compute_face_projection_curl_conforming_l2. |
| 1809 |
// |
| 1810 |
// For faces we compute the residual of the boundary function which is |
| 1811 |
// satisfied by the edge shape functions alone. Which can then be used to |
| 1812 |
// calculate the remaining face DoF values via a projection which leads to |
| 1813 |
// a linear system to solve. This is handled by |
| 1814 |
// compute_face_projection_curl_conforming_l2 |
| 1815 |
// |
| 1816 |
// For details see (for example) section 4.2: |
| 1817 |
// Electromagnetic scattering simulation using an H (curl) conforming hp- |
| 1818 |
// finite element method in three dimensions, PD Ledger, K Morgan, O |
| 1819 |
// Hassan, Int. J. Num. Meth. Fluids, Volume 53, Issue 8, pages |
| 1820 |
// 1267-1296, 20 March 2007: |
| 1821 |
// http://onlinelibrary.wiley.com/doi/10.1002/fld.1223/abstract |
| 1822 |
|
| 1823 |
// Create hp-FEcollection, dof_handler can be either hp- or standard type. |
| 1824 |
// From here on we can treat it like a hp-namespace object. |
| 1825 |
const hp::FECollection<dim> &fe_collection( |
| 1826 |
dof_handler.get_fe_collection()); |
| 1827 |
|
| 1828 |
// Create face quadrature collection |
| 1829 |
hp::QCollection<dim - 1> face_quadrature_collection; |
| 1830 |
for (unsigned int i = 0; i < fe_collection.size(); ++i) |
| 1831 |
{ |
| 1832 |
const QGauss<dim - 1> reference_face_quadrature( |
| 1833 |
2 * fe_collection[i].degree + 1); |
| 1834 |
face_quadrature_collection.push_back(reference_face_quadrature); |
| 1835 |
} |
| 1836 |
|
| 1837 |
hp::FEFaceValues<dim> fe_face_values(mapping_collection, |
| 1838 |
fe_collection, |
| 1839 |
face_quadrature_collection, |
| 1840 |
update_values | |
| 1841 |
update_quadrature_points | |
| 1842 |
update_normal_vectors | |
| 1843 |
update_JxW_values); |
| 1844 |
|
| 1845 |
// Storage for dof values found and whether they have been processed: |
| 1846 |
std::vector<bool> dofs_processed; |
| 1847 |
std::vector<number> dof_values; |
| 1848 |
std::vector<types::global_dof_index> face_dof_indices; |
| 1849 |
|
| 1850 |
switch (dim) |
| 1851 |
{ |
| 1852 |
case 2: |
| 1853 |
{ |
| 1854 |
for (const auto &cell : dof_handler.active_cell_iterators()) |
| 1855 |
{ |
| 1856 |
if (cell->at_boundary() && cell->is_locally_owned()) |
| 1857 |
{ |
| 1858 |
for (const unsigned int face : cell->face_indices()) |
| 1859 |
{ |
| 1860 |
if (cell->face(face)->boundary_id() == |
| 1861 |
boundary_component) |
| 1862 |
{ |
| 1863 |
const FiniteElement<dim> &fe = cell->get_fe(); |
| 1864 |
|
| 1865 |
// If the FE is an FE_Nothing object there is no |
| 1866 |
// work to do |
| 1867 |
if (dynamic_cast<const FE_Nothing<dim> *>(&fe) != |
| 1868 |
nullptr) |
| 1869 |
{ |
| 1870 |
return; |
| 1871 |
} |
| 1872 |
|
| 1873 |
// This is only implemented for FE_Nedelec |
| 1874 |
// elements. If the FE is a FESystem we cannot |
| 1875 |
// check this. |
| 1876 |
if (dynamic_cast<const FESystem<dim> *>(&fe) == |
| 1877 |
nullptr) |
| 1878 |
{ |
| 1879 |
AssertThrow( |
| 1880 |
(dynamic_cast<const FE_Nedelec<dim> *>( |
| 1881 |
&fe) != nullptr) || |
| 1882 |
(dynamic_cast<const FE_NedelecSZ<dim> *>( |
| 1883 |
&fe) != nullptr), |
| 1884 |
typename FiniteElement< |
| 1885 |
dim>::ExcInterpolationNotImplemented()); |
| 1886 |
} |
| 1887 |
|
| 1888 |
const unsigned int dofs_per_face = |
| 1889 |
fe.n_dofs_per_face(face); |
| 1890 |
|
| 1891 |
dofs_processed.resize(dofs_per_face); |
| 1892 |
dof_values.resize(dofs_per_face); |
| 1893 |
|
| 1894 |
for (unsigned int dof = 0; dof < dofs_per_face; |
| 1895 |
++dof) |
| 1896 |
{ |
| 1897 |
dof_values[dof] = 0.0; |
| 1898 |
dofs_processed[dof] = false; |
| 1899 |
} |
| 1900 |
|
| 1901 |
// Compute the projection of the boundary function |
| 1902 |
// on the edge. In 2d this is all that's required. |
| 1903 |
compute_face_projection_curl_conforming_l2( |
| 1904 |
cell, |
| 1905 |
face, |
| 1906 |
fe_face_values, |
| 1907 |
boundary_function, |
| 1908 |
first_vector_component, |
| 1909 |
dof_values, |
| 1910 |
dofs_processed); |
| 1911 |
|
| 1912 |
// store the local->global map: |
| 1913 |
face_dof_indices.resize(dofs_per_face); |
| 1914 |
cell->face(face)->get_dof_indices( |
| 1915 |
face_dof_indices, cell->active_fe_index()); |
| 1916 |
|
| 1917 |
// Add the computed constraints to the |
| 1918 |
// AffineConstraints object, assuming the degree |
| 1919 |
// of freedom is not already constrained. |
| 1920 |
for (unsigned int dof = 0; dof < dofs_per_face; |
| 1921 |
++dof) |
| 1922 |
{ |
| 1923 |
if (dofs_processed[dof] && |
| 1924 |
constraints.can_store_line( |
| 1925 |
face_dof_indices[dof]) && |
| 1926 |
!(constraints.is_constrained( |
| 1927 |
face_dof_indices[dof]))) |
| 1928 |
constraints.add_constraint( |
| 1929 |
face_dof_indices[dof], |
| 1930 |
{}, |
| 1931 |
(std::abs(dof_values[dof]) > 1e-13 ? |
| 1932 |
dof_values[dof] : |
| 1933 |
0)); |
| 1934 |
} |
| 1935 |
} |
| 1936 |
} |
| 1937 |
} |
| 1938 |
} |
| 1939 |
break; |
| 1940 |
} |
| 1941 |
|
| 1942 |
case 3: |
| 1943 |
{ |
| 1944 |
hp::QCollection<dim> edge_quadrature_collection; |
| 1945 |
|
| 1946 |
// Create equivalent of FEEdgeValues: |
| 1947 |
for (unsigned int i = 0; i < fe_collection.size(); ++i) |
| 1948 |
{ |
| 1949 |
const QGauss<dim - 2> reference_edge_quadrature( |
| 1950 |
2 * fe_collection[i].degree + 1); |
| 1951 |
for (const unsigned int face : |
| 1952 |
GeometryInfo<dim>::face_indices()) |
| 1953 |
{ |
| 1954 |
for (unsigned int line = 0; |
| 1955 |
line < GeometryInfo<dim>::lines_per_face; |
| 1956 |
++line) |
| 1957 |
{ |
| 1958 |
edge_quadrature_collection.push_back( |
| 1959 |
QProjector<dim>::project_to_face( |
| 1960 |
ReferenceCells::get_hypercube<dim>(), |
| 1961 |
QProjector<dim - 1>::project_to_face( |
| 1962 |
ReferenceCells::get_hypercube<dim - 1>(), |
| 1963 |
reference_edge_quadrature, |
| 1964 |
line, |
| 1965 |
numbers::default_geometric_orientation), |
| 1966 |
face, |
| 1967 |
numbers::default_geometric_orientation)); |
| 1968 |
} |
| 1969 |
} |
| 1970 |
} |
| 1971 |
|
| 1972 |
hp::FEValues<dim> fe_edge_values(mapping_collection, |
| 1973 |
fe_collection, |
| 1974 |
edge_quadrature_collection, |
| 1975 |
update_jacobians | |
| 1976 |
update_JxW_values | |
| 1977 |
update_quadrature_points | |
| 1978 |
update_values); |
| 1979 |
|
| 1980 |
for (const auto &cell : dof_handler.active_cell_iterators()) |
| 1981 |
{ |
| 1982 |
if (cell->at_boundary() && cell->is_locally_owned()) |
| 1983 |
{ |
| 1984 |
const FiniteElement<dim> &fe = cell->get_fe(); |
| 1985 |
for (const unsigned int face : cell->face_indices()) |
| 1986 |
{ |
| 1987 |
if (cell->face(face)->boundary_id() == |
| 1988 |
boundary_component) |
| 1989 |
{ |
| 1990 |
// If the FE is an FE_Nothing object there is no |
| 1991 |
// work to do |
| 1992 |
if (dynamic_cast<const FE_Nothing<dim> *>(&fe) != |
| 1993 |
nullptr) |
| 1994 |
{ |
| 1995 |
return; |
| 1996 |
} |
| 1997 |
|
| 1998 |
// This is only implemented for FE_Nedelec |
| 1999 |
// elements. If the FE is a FESystem we cannot |
| 2000 |
// check this. |
| 2001 |
if (dynamic_cast<const FESystem<dim> *>(&fe) == |
| 2002 |
nullptr) |
| 2003 |
{ |
| 2004 |
AssertThrow( |
| 2005 |
(dynamic_cast<const FE_Nedelec<dim> *>( |
| 2006 |
&fe) != nullptr) || |
| 2007 |
(dynamic_cast<const FE_NedelecSZ<dim> *>( |
| 2008 |
&fe) != nullptr), |
| 2009 |
typename FiniteElement< |
| 2010 |
dim>::ExcInterpolationNotImplemented()); |
| 2011 |
} |
| 2012 |
|
| 2013 |
const unsigned int superdegree = fe.degree; |
| 2014 |
const unsigned int degree = superdegree - 1; |
| 2015 |
const unsigned int dofs_per_face = |
| 2016 |
fe.n_dofs_per_face(face); |
| 2017 |
|
| 2018 |
dofs_processed.resize(dofs_per_face); |
| 2019 |
dof_values.resize(dofs_per_face); |
| 2020 |
for (unsigned int dof = 0; dof < dofs_per_face; |
| 2021 |
++dof) |
| 2022 |
{ |
| 2023 |
dof_values[dof] = 0.0; |
| 2024 |
dofs_processed[dof] = false; |
| 2025 |
} |
| 2026 |
|
| 2027 |
// First compute the projection on the edges. |
| 2028 |
for (unsigned int line = 0; |
| 2029 |
line < cell->face(face)->n_lines(); |
| 2030 |
++line) |
| 2031 |
{ |
| 2032 |
compute_edge_projection_l2( |
| 2033 |
cell, |
| 2034 |
face, |
| 2035 |
line, |
| 2036 |
fe_edge_values, |
| 2037 |
boundary_function, |
| 2038 |
first_vector_component, |
| 2039 |
dof_values, |
| 2040 |
dofs_processed); |
| 2041 |
} |
| 2042 |
|
| 2043 |
// If there are higher order shape functions, then |
| 2044 |
// we still need to compute the face projection |
| 2045 |
if (degree > 0) |
| 2046 |
{ |
| 2047 |
compute_face_projection_curl_conforming_l2( |
| 2048 |
cell, |
| 2049 |
face, |
| 2050 |
fe_face_values, |
| 2051 |
boundary_function, |
| 2052 |
first_vector_component, |
| 2053 |
dof_values, |
| 2054 |
dofs_processed); |
| 2055 |
} |
| 2056 |
|
| 2057 |
// Store the computed values in the global vector. |
| 2058 |
face_dof_indices.resize(dofs_per_face); |
| 2059 |
cell->face(face)->get_dof_indices( |
| 2060 |
face_dof_indices, cell->active_fe_index()); |
| 2061 |
|
| 2062 |
for (unsigned int dof = 0; dof < dofs_per_face; |
| 2063 |
++dof) |
| 2064 |
{ |
| 2065 |
if (dofs_processed[dof] && |
| 2066 |
constraints.can_store_line( |
| 2067 |
face_dof_indices[dof]) && |
| 2068 |
!(constraints.is_constrained( |
| 2069 |
face_dof_indices[dof]))) |
| 2070 |
constraints.add_constraint( |
| 2071 |
face_dof_indices[dof], |
| 2072 |
{}, |
| 2073 |
(std::abs(dof_values[dof]) > 1e-13 ? |
| 2074 |
dof_values[dof] : |
| 2075 |
0)); |
| 2076 |
} |
| 2077 |
} |
| 2078 |
} |
| 2079 |
} |
| 2080 |
} |
| 2081 |
break; |
| 2082 |
} |
| 2083 |
default: |
| 2084 |
DEAL_II_NOT_IMPLEMENTED(); |
| 2085 |
} |
| 2086 |
} |
| 2087 |
|
| 2088 |
} // namespace internals |
| 2089 |
|
| 2090 |
|
| 2091 |
template <int dim, typename number> |
| 2092 |
void |
| 2093 |
project_boundary_values_curl_conforming_l2( |
| 2094 |
const DoFHandler<dim> &dof_handler, |
| 2095 |
const unsigned int first_vector_component, |
| 2096 |
const Function<dim, number> &boundary_function, |
| 2097 |
const types::boundary_id boundary_component, |
| 2098 |
AffineConstraints<number> &constraints, |
| 2099 |
const Mapping<dim> &mapping) |
| 2100 |
{ |
| 2101 |
// non-hp-version - calls the internal |
| 2102 |
// compute_project_boundary_values_curl_conforming_l2() function |
| 2103 |
// above after recasting the mapping. |
| 2104 |
|
| 2105 |
const hp::MappingCollection<dim> mapping_collection(mapping); |
| 2106 |
internals::compute_project_boundary_values_curl_conforming_l2( |
| 2107 |
dof_handler, |
| 2108 |
first_vector_component, |
| 2109 |
boundary_function, |
| 2110 |
boundary_component, |
| 2111 |
constraints, |
| 2112 |
mapping_collection); |
| 2113 |
} |
| 2114 |
|
| 2115 |
template <int dim, typename number> |
| 2116 |
void |
| 2117 |
project_boundary_values_curl_conforming_l2( |
| 2118 |
const DoFHandler<dim> &dof_handler, |
| 2119 |
const unsigned int first_vector_component, |
| 2120 |
const Function<dim, number> &boundary_function, |
| 2121 |
const types::boundary_id boundary_component, |
| 2122 |
AffineConstraints<number> &constraints, |
| 2123 |
const hp::MappingCollection<dim, dim> &mapping_collection) |
| 2124 |
{ |
| 2125 |
// hp-version - calls the internal |
| 2126 |
// compute_project_boundary_values_curl_conforming_l2() function above. |
| 2127 |
internals::compute_project_boundary_values_curl_conforming_l2( |
| 2128 |
dof_handler, |
| 2129 |
first_vector_component, |
| 2130 |
boundary_function, |
| 2131 |
boundary_component, |
| 2132 |
constraints, |
| 2133 |
mapping_collection); |
| 2134 |
} |
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
namespace internals |
| 2139 |
{ |
| 2140 |
// This function computes the projection of the boundary function on the |
| 2141 |
// boundary in 2d. |
| 2142 |
template <typename cell_iterator, typename number, typename number2> |
| 2143 |
void |
| 2144 |
compute_face_projection_div_conforming( |
| 2145 |
const cell_iterator &cell, |
| 2146 |
const unsigned int face, |
| 2147 |
const FEFaceValues<2> &fe_values, |
| 2148 |
const unsigned int first_vector_component, |
| 2149 |
const Function<2, number2> &boundary_function, |
| 2150 |
const std::vector<DerivativeForm<1, 2, 2>> &jacobians, |
| 2151 |
AffineConstraints<number> &constraints) |
| 2152 |
{ |
| 2153 |
// Compute the integral over the product of the normal components of |
| 2154 |
// the boundary function times the normal components of the shape |
| 2155 |
// functions supported on the boundary. |
| 2156 |
const FEValuesExtractors::Vector vec(first_vector_component); |
| 2157 |
const FiniteElement<2> &fe = cell->get_fe(); |
| 2158 |
const std::vector<Tensor<1, 2>> &normals = fe_values.get_normal_vectors(); |
| 2159 |
const unsigned int |
| 2160 |
face_coordinate_direction[GeometryInfo<2>::faces_per_cell] = {1, |
| 2161 |
1, |
| 2162 |
0, |
| 2163 |
0}; |
| 2164 |
std::vector<Vector<number2>> values(fe_values.n_quadrature_points, |
| 2165 |
Vector<number2>(2)); |
| 2166 |
Vector<number2> dof_values(fe.n_dofs_per_face(face)); |
| 2167 |
|
| 2168 |
// Get the values of the boundary function at the quadrature points. |
| 2169 |
{ |
| 2170 |
const std::vector<Point<2>> &quadrature_points = |
| 2171 |
fe_values.get_quadrature_points(); |
| 2172 |
|
| 2173 |
boundary_function.vector_value_list(quadrature_points, values); |
| 2174 |
} |
| 2175 |
|
| 2176 |
for (unsigned int q_point = 0; q_point < fe_values.n_quadrature_points; |
| 2177 |
++q_point) |
| 2178 |
{ |
| 2179 |
number2 tmp = 0.0; |
| 2180 |
|
| 2181 |
for (unsigned int d = 0; d < 2; ++d) |
| 2182 |
tmp += normals[q_point][d] * values[q_point](d); |
| 2183 |
|
| 2184 |
tmp *= |
| 2185 |
fe_values.JxW(q_point) * |
| 2186 |
std::sqrt(jacobians[q_point][0][face_coordinate_direction[face]] * |
| 2187 |
jacobians[q_point][0][face_coordinate_direction[face]] + |
| 2188 |
jacobians[q_point][1][face_coordinate_direction[face]] * |
| 2189 |
jacobians[q_point][1][face_coordinate_direction[face]]); |
| 2190 |
|
| 2191 |
for (unsigned int i = 0; i < fe.n_dofs_per_face(face); ++i) |
| 2192 |
dof_values(i) += |
| 2193 |
tmp * (normals[q_point] * |
| 2194 |
fe_values[vec].value( |
| 2195 |
fe.face_to_cell_index( |
| 2196 |
i, face, cell->combined_face_orientation(face)), |
| 2197 |
q_point)); |
| 2198 |
} |
| 2199 |
|
| 2200 |
std::vector<types::global_dof_index> face_dof_indices( |
| 2201 |
fe.n_dofs_per_face(face)); |
| 2202 |
|
| 2203 |
cell->face(face)->get_dof_indices(face_dof_indices, |
| 2204 |
cell->active_fe_index()); |
| 2205 |
|
| 2206 |
// Copy the computed values in the AffineConstraints only, if the degree |
| 2207 |
// of freedom is not already constrained. |
| 2208 |
for (unsigned int i = 0; i < fe.n_dofs_per_face(face); ++i) |
| 2209 |
if (!(constraints.is_constrained(face_dof_indices[i])) && |
| 2210 |
fe.get_nonzero_components(fe.face_to_cell_index( |
| 2211 |
i, |
| 2212 |
face, |
| 2213 |
cell->combined_face_orientation(face)))[first_vector_component]) |
| 2214 |
constraints.add_constraint(face_dof_indices[i], |
| 2215 |
{}, |
| 2216 |
(std::abs(dof_values[i]) > 1e-14 ? |
| 2217 |
dof_values[i] : |
| 2218 |
0)); |
| 2219 |
} |
| 2220 |
|
| 2221 |
// dummy implementation of above function for all other dimensions |
| 2222 |
template <int dim, |
| 2223 |
typename cell_iterator, |
| 2224 |
typename number, |
| 2225 |
typename number2> |
| 2226 |
void |
| 2227 |
compute_face_projection_div_conforming( |
| 2228 |
const cell_iterator &, |
| 2229 |
const unsigned int, |
| 2230 |
const FEFaceValues<dim> &, |
| 2231 |
const unsigned int, |
| 2232 |
const Function<dim, number2> &, |
| 2233 |
const std::vector<DerivativeForm<1, dim, dim>> &, |
| 2234 |
AffineConstraints<number> &) |
| 2235 |
{ |
| 2236 |
DEAL_II_NOT_IMPLEMENTED(); |
| 2237 |
} |
| 2238 |
|
| 2239 |
// This function computes the projection of the boundary function on the |
| 2240 |
// boundary in 3d. |
| 2241 |
template <typename cell_iterator, typename number, typename number2> |
| 2242 |
void |
| 2243 |
compute_face_projection_div_conforming( |
| 2244 |
const cell_iterator &cell, |
| 2245 |
const unsigned int face, |
| 2246 |
const FEFaceValues<3> &fe_values, |
| 2247 |
const unsigned int first_vector_component, |
| 2248 |
const Function<3, number2> &boundary_function, |
| 2249 |
const std::vector<DerivativeForm<1, 3, 3>> &jacobians, |
| 2250 |
std::vector<number> &dof_values, |
| 2251 |
std::vector<types::global_dof_index> &projected_dofs) |
| 2252 |
{ |
| 2253 |
// Compute the integral over the product of the normal components of |
| 2254 |
// the boundary function times the normal components of the shape |
| 2255 |
// functions supported on the boundary. |
| 2256 |
const FEValuesExtractors::Vector vec(first_vector_component); |
| 2257 |
const FiniteElement<3> &fe = cell->get_fe(); |
| 2258 |
const std::vector<Tensor<1, 3>> &normals = fe_values.get_normal_vectors(); |
| 2259 |
const unsigned int |
| 2260 |
face_coordinate_directions[GeometryInfo<3>::faces_per_cell][2] = { |
| 2261 |
{1, 2}, {1, 2}, {2, 0}, {2, 0}, {0, 1}, {0, 1}}; |
| 2262 |
std::vector<Vector<number2>> values(fe_values.n_quadrature_points, |
| 2263 |
Vector<number2>(3)); |
| 2264 |
Vector<number2> dof_values_local(fe.n_dofs_per_face(face)); |
| 2265 |
|
| 2266 |
{ |
| 2267 |
const std::vector<Point<3>> &quadrature_points = |
| 2268 |
fe_values.get_quadrature_points(); |
| 2269 |
|
| 2270 |
boundary_function.vector_value_list(quadrature_points, values); |
| 2271 |
} |
| 2272 |
|
| 2273 |
for (unsigned int q_point = 0; q_point < fe_values.n_quadrature_points; |
| 2274 |
++q_point) |
| 2275 |
{ |
| 2276 |
number2 tmp = 0.0; |
| 2277 |
|
| 2278 |
for (unsigned int d = 0; d < 3; ++d) |
| 2279 |
tmp += normals[q_point][d] * values[q_point](d); |
| 2280 |
|
| 2281 |
tmp *= |
| 2282 |
fe_values.JxW(q_point) * |
| 2283 |
std::sqrt( |
| 2284 |
(jacobians[q_point][0][face_coordinate_directions[face][0]] * |
| 2285 |
jacobians[q_point][0][face_coordinate_directions[face][0]] + |
| 2286 |
jacobians[q_point][1][face_coordinate_directions[face][0]] * |
| 2287 |
jacobians[q_point][1][face_coordinate_directions[face][0]] + |
| 2288 |
jacobians[q_point][2][face_coordinate_directions[face][0]] * |
| 2289 |
jacobians[q_point][2][face_coordinate_directions[face][0]]) * |
| 2290 |
(jacobians[q_point][0][face_coordinate_directions[face][1]] * |
| 2291 |
jacobians[q_point][0][face_coordinate_directions[face][1]] + |
| 2292 |
jacobians[q_point][1][face_coordinate_directions[face][1]] * |
| 2293 |
jacobians[q_point][1][face_coordinate_directions[face][1]] + |
| 2294 |
jacobians[q_point][2][face_coordinate_directions[face][1]] * |
| 2295 |
jacobians[q_point][2][face_coordinate_directions[face][1]])); |
| 2296 |
|
| 2297 |
for (unsigned int i = 0; i < fe.n_dofs_per_face(face); ++i) |
| 2298 |
dof_values_local(i) += |
| 2299 |
tmp * (normals[q_point] * |
| 2300 |
fe_values[vec].value( |
| 2301 |
fe.face_to_cell_index( |
| 2302 |
i, face, cell->combined_face_orientation(face)), |
| 2303 |
q_point)); |
| 2304 |
} |
| 2305 |
|
| 2306 |
std::vector<types::global_dof_index> face_dof_indices( |
| 2307 |
fe.n_dofs_per_face(face)); |
| 2308 |
|
| 2309 |
cell->face(face)->get_dof_indices(face_dof_indices, |
| 2310 |
cell->active_fe_index()); |
| 2311 |
|
| 2312 |
for (unsigned int i = 0; i < fe.n_dofs_per_face(face); ++i) |
| 2313 |
if (projected_dofs[face_dof_indices[i]] < fe.degree && |
| 2314 |
fe.get_nonzero_components(fe.face_to_cell_index( |
| 2315 |
i, |
| 2316 |
face, |
| 2317 |
cell->combined_face_orientation(face)))[first_vector_component]) |
| 2318 |
{ |
| 2319 |
dof_values[face_dof_indices[i]] = dof_values_local(i); |
| 2320 |
projected_dofs[face_dof_indices[i]] = fe.degree; |
| 2321 |
} |
| 2322 |
} |
| 2323 |
|
| 2324 |
// dummy implementation of above |
| 2325 |
// function for all other |
| 2326 |
// dimensions |
| 2327 |
template <int dim, |
| 2328 |
typename cell_iterator, |
| 2329 |
typename number, |
| 2330 |
typename number2> |
| 2331 |
void |
| 2332 |
compute_face_projection_div_conforming( |
| 2333 |
const cell_iterator &, |
| 2334 |
const unsigned int, |
| 2335 |
const FEFaceValues<dim> &, |
| 2336 |
const unsigned int, |
| 2337 |
const Function<dim, number2> &, |
| 2338 |
const std::vector<DerivativeForm<1, dim, dim>> &, |
| 2339 |
std::vector<number> &, |
| 2340 |
std::vector<types::global_dof_index> &) |
| 2341 |
{ |
| 2342 |
DEAL_II_NOT_IMPLEMENTED(); |
| 2343 |
} |
| 2344 |
} // namespace internals |
| 2345 |
|
| 2346 |
|
| 2347 |
template <int dim, typename number, typename number2> |
| 2348 |
void |
| 2349 |
project_boundary_values_div_conforming( |
| 2350 |
const DoFHandler<dim> &dof_handler, |
| 2351 |
const unsigned int first_vector_component, |
| 2352 |
const Function<dim, number2> &boundary_function, |
| 2353 |
const types::boundary_id boundary_component, |
| 2354 |
AffineConstraints<number> &constraints, |
| 2355 |
const Mapping<dim> &mapping) |
| 2356 |
{ |
| 2357 |
const unsigned int spacedim = dim; |
| 2358 |
// Interpolate the normal components |
| 2359 |
// of the boundary functions. Since |
| 2360 |
// the Raviart-Thomas elements are |
| 2361 |
// constructed from a Lagrangian |
| 2362 |
// basis, it suffices to compute |
| 2363 |
// the integral over the product |
| 2364 |
// of the normal components of the |
| 2365 |
// boundary function times the |
| 2366 |
// normal components of the shape |
| 2367 |
// functions supported on the |
| 2368 |
// boundary. |
| 2369 |
const FiniteElement<dim> &fe = dof_handler.get_fe(); |
| 2370 |
QGauss<dim - 1> face_quadrature(fe.degree + 1); |
| 2371 |
FEFaceValues<dim> fe_face_values(mapping, |
| 2372 |
fe, |
| 2373 |
face_quadrature, |
| 2374 |
update_JxW_values | update_normal_vectors | |
| 2375 |
update_quadrature_points | |
| 2376 |
update_values); |
| 2377 |
hp::FECollection<dim> fe_collection(fe); |
| 2378 |
const hp::MappingCollection<dim> mapping_collection(mapping); |
| 2379 |
hp::QCollection<dim> quadrature_collection; |
| 2380 |
|
| 2381 |
for (const unsigned int face : GeometryInfo<dim>::face_indices()) |
| 2382 |
quadrature_collection.push_back(QProjector<dim>::project_to_face( |
| 2383 |
ReferenceCells::get_hypercube<dim>(), |
| 2384 |
face_quadrature, |
| 2385 |
face, |
| 2386 |
numbers::default_geometric_orientation)); |
| 2387 |
|
| 2388 |
hp::FEValues<dim> fe_values(mapping_collection, |
| 2389 |
fe_collection, |
| 2390 |
quadrature_collection, |
| 2391 |
update_jacobians); |
| 2392 |
|
| 2393 |
switch (dim) |
| 2394 |
{ |
| 2395 |
case 2: |
| 2396 |
{ |
| 2397 |
for (const auto &cell : dof_handler.active_cell_iterators()) |
| 2398 |
if (cell->at_boundary() && cell->is_locally_owned()) |
| 2399 |
for (const unsigned int face : cell->face_indices()) |
| 2400 |
if (cell->face(face)->boundary_id() == boundary_component) |
| 2401 |
{ |
| 2402 |
const FiniteElement<dim> &fe = cell->get_fe(); |
| 2403 |
|
| 2404 |
// if the FE is a |
| 2405 |
// FE_Nothing object |
| 2406 |
// there is no work to |
| 2407 |
// do |
| 2408 |
if (dynamic_cast<const FE_Nothing<dim> *>(&fe) != nullptr) |
| 2409 |
return; |
| 2410 |
|
| 2411 |
// This is only |
| 2412 |
// implemented, if the |
| 2413 |
// FE is a Raviart-Thomas |
| 2414 |
// element. If the FE is |
| 2415 |
// a FESystem we cannot |
| 2416 |
// check this. |
| 2417 |
if (dynamic_cast<const FESystem<dim> *>(&fe) == nullptr) |
| 2418 |
{ |
| 2419 |
AssertThrow( |
| 2420 |
dynamic_cast<const FE_RaviartThomas<dim> *>(&fe) != |
| 2421 |
nullptr || |
| 2422 |
dynamic_cast<const FE_RaviartThomasNodal<dim> *>( |
| 2423 |
&fe) != nullptr, |
| 2424 |
typename FiniteElement< |
| 2425 |
dim>::ExcInterpolationNotImplemented()); |
| 2426 |
} |
| 2427 |
|
| 2428 |
fe_values.reinit(cell, |
| 2429 |
face + cell->active_fe_index() * |
| 2430 |
cell->n_faces()); |
| 2431 |
|
| 2432 |
const std::vector<DerivativeForm<1, dim, spacedim>> |
| 2433 |
&jacobians = |
| 2434 |
fe_values.get_present_fe_values().get_jacobians(); |
| 2435 |
|
| 2436 |
fe_face_values.reinit(cell, face); |
| 2437 |
internals::compute_face_projection_div_conforming( |
| 2438 |
cell, |
| 2439 |
face, |
| 2440 |
fe_face_values, |
| 2441 |
first_vector_component, |
| 2442 |
boundary_function, |
| 2443 |
jacobians, |
| 2444 |
constraints); |
| 2445 |
} |
| 2446 |
|
| 2447 |
break; |
| 2448 |
} |
| 2449 |
|
| 2450 |
case 3: |
| 2451 |
{ |
| 2452 |
// In three dimensions the edges between two faces are treated |
| 2453 |
// twice. Therefore we store the computed values in a vector |
| 2454 |
// and copy them over in the AffineConstraints after all values |
| 2455 |
// have been computed. If we have two values for one edge, we |
| 2456 |
// choose the one, which was computed with the higher order |
| 2457 |
// element. If both elements are of the same order, we just |
| 2458 |
// keep the first value and do not compute a second one. |
| 2459 |
const unsigned int n_dofs = dof_handler.n_dofs(); |
| 2460 |
std::vector<double> dof_values(n_dofs); |
| 2461 |
std::vector<types::global_dof_index> projected_dofs(n_dofs); |
| 2462 |
|
| 2463 |
for (unsigned int dof = 0; dof < n_dofs; ++dof) |
| 2464 |
projected_dofs[dof] = 0; |
| 2465 |
|
| 2466 |
for (const auto &cell : dof_handler.active_cell_iterators()) |
| 2467 |
if (cell->at_boundary() && cell->is_locally_owned()) |
| 2468 |
for (const unsigned int face : cell->face_indices()) |
| 2469 |
if (cell->face(face)->boundary_id() == boundary_component) |
| 2470 |
{ |
| 2471 |
// This is only implemented, if the FE is a |
| 2472 |
// Raviart-Thomas element. If the FE is a FESystem we |
| 2473 |
// cannot check this. |
| 2474 |
if (dynamic_cast<const FESystem<dim> *>(&fe) == nullptr) |
| 2475 |
{ |
| 2476 |
AssertThrow( |
| 2477 |
dynamic_cast<const FE_RaviartThomas<dim> *>(&fe) != |
| 2478 |
nullptr || |
| 2479 |
dynamic_cast<const FE_RaviartThomasNodal<dim> *>( |
| 2480 |
&fe) != nullptr, |
| 2481 |
typename FiniteElement< |
| 2482 |
dim>::ExcInterpolationNotImplemented()); |
| 2483 |
} |
| 2484 |
|
| 2485 |
fe_values.reinit(cell, |
| 2486 |
face + cell->active_fe_index() * |
| 2487 |
cell->n_faces()); |
| 2488 |
|
| 2489 |
const std::vector<DerivativeForm<1, dim, spacedim>> |
| 2490 |
&jacobians = |
| 2491 |
fe_values.get_present_fe_values().get_jacobians(); |
| 2492 |
|
| 2493 |
fe_face_values.reinit(cell, face); |
| 2494 |
internals::compute_face_projection_div_conforming( |
| 2495 |
cell, |
| 2496 |
face, |
| 2497 |
fe_face_values, |
| 2498 |
first_vector_component, |
| 2499 |
boundary_function, |
| 2500 |
jacobians, |
| 2501 |
dof_values, |
| 2502 |
projected_dofs); |
| 2503 |
} |
| 2504 |
|
| 2505 |
for (unsigned int dof = 0; dof < n_dofs; ++dof) |
| 2506 |
if ((projected_dofs[dof] != 0) && |
| 2507 |
!(constraints.is_constrained(dof))) |
| 2508 |
constraints.add_constraint(dof, |
| 2509 |
{}, |
| 2510 |
(std::abs(dof_values[dof]) > 1e-14 ? |
| 2511 |
dof_values[dof] : |
| 2512 |
0)); |
| 2513 |
|
| 2514 |
break; |
| 2515 |
} |
| 2516 |
|
| 2517 |
default: |
| 2518 |
DEAL_II_NOT_IMPLEMENTED(); |
| 2519 |
} |
| 2520 |
} |
| 2521 |
|
| 2522 |
|
| 2523 |
template <int dim, typename number, typename number2> |
| 2524 |
void |
| 2525 |
project_boundary_values_div_conforming( |
| 2526 |
const DoFHandler<dim> &dof_handler, |
| 2527 |
const unsigned int first_vector_component, |
| 2528 |
const Function<dim, number2> &boundary_function, |
| 2529 |
const types::boundary_id boundary_component, |
| 2530 |
AffineConstraints<number> &constraints, |
| 2531 |
const hp::MappingCollection<dim, dim> &mapping_collection) |
| 2532 |
{ |
| 2533 |
const unsigned int spacedim = dim; |
| 2534 |
const hp::FECollection<dim> &fe_collection = |
| 2535 |
dof_handler.get_fe_collection(); |
| 2536 |
hp::QCollection<dim - 1> face_quadrature_collection; |
| 2537 |
hp::QCollection<dim> quadrature_collection; |
| 2538 |
|
| 2539 |
for (unsigned int i = 0; i < fe_collection.size(); ++i) |
| 2540 |
{ |
| 2541 |
const QGauss<dim - 1> quadrature(fe_collection[i].degree + 1); |
| 2542 |
|
| 2543 |
face_quadrature_collection.push_back(quadrature); |
| 2544 |
|
| 2545 |
for (const unsigned int face : GeometryInfo<dim>::face_indices()) |
| 2546 |
quadrature_collection.push_back(QProjector<dim>::project_to_face( |
| 2547 |
ReferenceCells::get_hypercube<dim>(), |
| 2548 |
quadrature, |
| 2549 |
face, |
| 2550 |
numbers::default_geometric_orientation)); |
| 2551 |
} |
| 2552 |
|
| 2553 |
hp::FEFaceValues<dim> fe_face_values(mapping_collection, |
| 2554 |
fe_collection, |
| 2555 |
face_quadrature_collection, |
| 2556 |
update_JxW_values | |
| 2557 |
update_normal_vectors | |
| 2558 |
update_quadrature_points | |
| 2559 |
update_values); |
| 2560 |
hp::FEValues<dim> fe_values(mapping_collection, |
| 2561 |
fe_collection, |
| 2562 |
quadrature_collection, |
| 2563 |
update_jacobians); |
| 2564 |
|
| 2565 |
switch (dim) |
| 2566 |
{ |
| 2567 |
case 2: |
| 2568 |
{ |
| 2569 |
for (const auto &cell : dof_handler.active_cell_iterators()) |
| 2570 |
if (cell->at_boundary() && cell->is_locally_owned()) |
| 2571 |
for (const unsigned int face : cell->face_indices()) |
| 2572 |
if (cell->face(face)->boundary_id() == boundary_component) |
| 2573 |
{ |
| 2574 |
// This is only |
| 2575 |
// implemented, if the |
| 2576 |
// FE is a Raviart-Thomas |
| 2577 |
// element. If the FE is |
| 2578 |
// a FESystem we cannot |
| 2579 |
// check this. |
| 2580 |
if (dynamic_cast<const FESystem<dim> *>( |
| 2581 |
&cell->get_fe()) == nullptr) |
| 2582 |
{ |
| 2583 |
AssertThrow( |
| 2584 |
dynamic_cast<const FE_RaviartThomas<dim> *>( |
| 2585 |
&cell->get_fe()) != nullptr || |
| 2586 |
dynamic_cast<const FE_RaviartThomasNodal<dim> *>( |
| 2587 |
&cell->get_fe()) != nullptr, |
| 2588 |
typename FiniteElement< |
| 2589 |
dim>::ExcInterpolationNotImplemented()); |
| 2590 |
} |
| 2591 |
|
| 2592 |
fe_values.reinit(cell, |
| 2593 |
face + cell->active_fe_index() * |
| 2594 |
cell->n_faces()); |
| 2595 |
|
| 2596 |
const std::vector<DerivativeForm<1, dim, spacedim>> |
| 2597 |
&jacobians = |
| 2598 |
fe_values.get_present_fe_values().get_jacobians(); |
| 2599 |
|
| 2600 |
fe_face_values.reinit(cell, face); |
| 2601 |
internals::compute_face_projection_div_conforming( |
| 2602 |
cell, |
| 2603 |
face, |
| 2604 |
fe_face_values.get_present_fe_values(), |
| 2605 |
first_vector_component, |
| 2606 |
boundary_function, |
| 2607 |
jacobians, |
| 2608 |
constraints); |
| 2609 |
} |
| 2610 |
|
| 2611 |
break; |
| 2612 |
} |
| 2613 |
|
| 2614 |
case 3: |
| 2615 |
{ |
| 2616 |
const unsigned int n_dofs = dof_handler.n_dofs(); |
| 2617 |
std::vector<number2> dof_values(n_dofs); |
| 2618 |
std::vector<types::global_dof_index> projected_dofs(n_dofs); |
| 2619 |
|
| 2620 |
for (unsigned int dof = 0; dof < n_dofs; ++dof) |
| 2621 |
projected_dofs[dof] = 0; |
| 2622 |
|
| 2623 |
for (const auto &cell : dof_handler.active_cell_iterators()) |
| 2624 |
if (cell->at_boundary() && cell->is_locally_owned()) |
| 2625 |
for (const unsigned int face : cell->face_indices()) |
| 2626 |
if (cell->face(face)->boundary_id() == boundary_component) |
| 2627 |
{ |
| 2628 |
// This is only |
| 2629 |
// implemented, if the |
| 2630 |
// FE is a Raviart-Thomas |
| 2631 |
// element. If the FE is |
| 2632 |
// a FESystem we cannot |
| 2633 |
// check this. |
| 2634 |
if (dynamic_cast<const FESystem<dim> *>( |
| 2635 |
&cell->get_fe()) == nullptr) |
| 2636 |
{ |
| 2637 |
AssertThrow( |
| 2638 |
dynamic_cast<const FE_RaviartThomas<dim> *>( |
| 2639 |
&cell->get_fe()) != nullptr || |
| 2640 |
dynamic_cast<const FE_RaviartThomasNodal<dim> *>( |
| 2641 |
&cell->get_fe()) != nullptr, |
| 2642 |
typename FiniteElement< |
| 2643 |
dim>::ExcInterpolationNotImplemented()); |
| 2644 |
} |
| 2645 |
|
| 2646 |
fe_values.reinit(cell, |
| 2647 |
face + cell->active_fe_index() * |
| 2648 |
cell->n_faces()); |
| 2649 |
|
| 2650 |
const std::vector<DerivativeForm<1, dim, spacedim>> |
| 2651 |
&jacobians = |
| 2652 |
fe_values.get_present_fe_values().get_jacobians(); |
| 2653 |
|
| 2654 |
fe_face_values.reinit(cell, face); |
| 2655 |
internals::compute_face_projection_div_conforming( |
| 2656 |
cell, |
| 2657 |
face, |
| 2658 |
fe_face_values.get_present_fe_values(), |
| 2659 |
first_vector_component, |
| 2660 |
boundary_function, |
| 2661 |
jacobians, |
| 2662 |
dof_values, |
| 2663 |
projected_dofs); |
| 2664 |
} |
| 2665 |
|
| 2666 |
for (unsigned int dof = 0; dof < n_dofs; ++dof) |
| 2667 |
if ((projected_dofs[dof] != 0) && |
| 2668 |
!(constraints.is_constrained(dof))) |
| 2669 |
constraints.add_constraint(dof, |
| 2670 |
{}, |
| 2671 |
(std::abs(dof_values[dof]) > 1e-14 ? |
| 2672 |
dof_values[dof] : |
| 2673 |
0)); |
| 2674 |
|
| 2675 |
break; |
| 2676 |
} |
| 2677 |
|
| 2678 |
default: |
| 2679 |
DEAL_II_NOT_IMPLEMENTED(); |
| 2680 |
} |
| 2681 |
} |
| 2682 |
} // namespace VectorTools |
| 2683 |
|
| 2684 |
DEAL_II_NAMESPACE_CLOSE |
| 2685 |
|
| 2686 |
#endif // dealii_vector_tools_boundary_templates_h |