| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2000 - 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 |
#ifndef dealii_fe_tools_templates_H |
| 16 |
#define dealii_fe_tools_templates_H |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/index_set.h> |
| 22 |
#include <deal.II/base/qprojector.h> |
| 23 |
#include <deal.II/base/quadrature_lib.h> |
| 24 |
#include <deal.II/base/utilities.h> |
| 25 |
|
| 26 |
#include <deal.II/dofs/dof_accessor.h> |
| 27 |
#include <deal.II/dofs/dof_handler.h> |
| 28 |
#include <deal.II/dofs/dof_tools.h> |
| 29 |
|
| 30 |
#include <deal.II/fe/fe.h> |
| 31 |
#include <deal.II/fe/fe_abf.h> |
| 32 |
#include <deal.II/fe/fe_bdm.h> |
| 33 |
#include <deal.II/fe/fe_bernstein.h> |
| 34 |
#include <deal.II/fe/fe_dg_vector.h> |
| 35 |
#include <deal.II/fe/fe_dgp.h> |
| 36 |
#include <deal.II/fe/fe_dgp_monomial.h> |
| 37 |
#include <deal.II/fe/fe_dgp_nonparametric.h> |
| 38 |
#include <deal.II/fe/fe_dgq.h> |
| 39 |
#include <deal.II/fe/fe_face.h> |
| 40 |
#include <deal.II/fe/fe_nedelec.h> |
| 41 |
#include <deal.II/fe/fe_nedelec_sz.h> |
| 42 |
#include <deal.II/fe/fe_nothing.h> |
| 43 |
#include <deal.II/fe/fe_pyramid_p.h> |
| 44 |
#include <deal.II/fe/fe_q.h> |
| 45 |
#include <deal.II/fe/fe_q_bubbles.h> |
| 46 |
#include <deal.II/fe/fe_q_dg0.h> |
| 47 |
#include <deal.II/fe/fe_q_hierarchical.h> |
| 48 |
#include <deal.II/fe/fe_q_iso_q1.h> |
| 49 |
#include <deal.II/fe/fe_rannacher_turek.h> |
| 50 |
#include <deal.II/fe/fe_raviart_thomas.h> |
| 51 |
#include <deal.II/fe/fe_rt_bubbles.h> |
| 52 |
#include <deal.II/fe/fe_simplex_p.h> |
| 53 |
#include <deal.II/fe/fe_simplex_p_bubbles.h> |
| 54 |
#include <deal.II/fe/fe_system.h> |
| 55 |
#include <deal.II/fe/fe_tools.h> |
| 56 |
#include <deal.II/fe/fe_values.h> |
| 57 |
#include <deal.II/fe/fe_wedge_p.h> |
| 58 |
#include <deal.II/fe/mapping_cartesian.h> |
| 59 |
|
| 60 |
#include <deal.II/grid/grid_generator.h> |
| 61 |
#include <deal.II/grid/tria.h> |
| 62 |
#include <deal.II/grid/tria_iterator.h> |
| 63 |
|
| 64 |
#include <deal.II/lac/full_matrix.h> |
| 65 |
#include <deal.II/lac/householder.h> |
| 66 |
|
| 67 |
#include <cctype> |
| 68 |
#include <iostream> |
| 69 |
#include <memory> |
| 70 |
#include <shared_mutex> |
| 71 |
|
| 72 |
|
| 73 |
DEAL_II_NAMESPACE_OPEN |
| 74 |
|
| 75 |
namespace FETools |
| 76 |
{ |
| 77 |
namespace Compositing |
| 78 |
{ |
| 79 |
template <int dim, int spacedim> |
| 80 |
FiniteElementData<dim> |
| 81 |
multiply_dof_numbers( |
| 82 |
const std::vector<const FiniteElement<dim, spacedim> *> &fes, |
| 83 |
const std::vector<unsigned int> &multiplicities, |
| 84 |
const bool do_tensor_product) |
| 85 |
{ |
| 86 |
AssertDimension(fes.size(), multiplicities.size()); |
| 87 |
|
| 88 |
dealii::internal::GenericDoFsPerObject dpo; |
| 89 |
|
| 90 |
std::vector<dealii::internal::GenericDoFsPerObject> dpos_in(fes.size()); |
| 91 |
|
| 92 |
for (unsigned int i = 0; i < fes.size(); ++i) |
| 93 |
if (multiplicities[i] > 0) |
| 94 |
dpos_in[i] = |
| 95 |
dealii::internal::GenericDoFsPerObject::generate(*fes[i]); |
| 96 |
|
| 97 |
// helper function to fill a vector of GenericDoFsPerObject |
| 98 |
// according to multiplicities |
| 99 |
const auto fill_dpo_vector = |
| 100 |
[&](const std::function<std::vector<std::vector<unsigned int>> &( |
| 101 |
dealii::internal::GenericDoFsPerObject &)> &get_vector) { |
| 102 |
auto &vector_dst = get_vector(dpo); |
| 103 |
|
| 104 |
// allocate memory |
| 105 |
for (unsigned int i = 0; i < fes.size(); ++i) |
| 106 |
if (multiplicities[i] > 0) |
| 107 |
{ |
| 108 |
const auto &vector_src = get_vector(dpos_in[i]); |
| 109 |
|
| 110 |
vector_dst.resize(vector_src.size()); |
| 111 |
|
| 112 |
for (unsigned int j = 0; j < vector_src.size(); ++j) |
| 113 |
vector_dst[j].assign(vector_src[j].size(), 0); |
| 114 |
|
| 115 |
break; |
| 116 |
} |
| 117 |
|
| 118 |
// fill vector according to multiplicities |
| 119 |
for (unsigned int i = 0; i < fes.size(); ++i) |
| 120 |
if (multiplicities[i] > 0) |
| 121 |
{ |
| 122 |
const auto &vector_src = get_vector(dpos_in[i]); |
| 123 |
|
| 124 |
for (unsigned int j = 0; j < vector_src.size(); ++j) |
| 125 |
for (unsigned int k = 0; k < vector_src[j].size(); ++k) |
| 126 |
vector_dst[j][k] += vector_src[j][k] * multiplicities[i]; |
| 127 |
} |
| 128 |
}; |
| 129 |
|
| 130 |
// go through each field of GenericDoFsPerObject |
| 131 |
fill_dpo_vector( |
| 132 |
[](auto &dpo) -> std::vector<std::vector<unsigned int>> & { |
| 133 |
return dpo.dofs_per_object_exclusive; |
| 134 |
}); |
| 135 |
fill_dpo_vector( |
| 136 |
[](auto &dpo) -> std::vector<std::vector<unsigned int>> & { |
| 137 |
return dpo.dofs_per_object_inclusive; |
| 138 |
}); |
| 139 |
fill_dpo_vector( |
| 140 |
[](auto &dpo) -> std::vector<std::vector<unsigned int>> & { |
| 141 |
return dpo.object_index; |
| 142 |
}); |
| 143 |
fill_dpo_vector( |
| 144 |
[](auto &dpo) -> std::vector<std::vector<unsigned int>> & { |
| 145 |
return dpo.first_object_index_on_face; |
| 146 |
}); |
| 147 |
|
| 148 |
const unsigned int n_components = fes[0]->n_components(); |
| 149 |
unsigned int multiplied_n_components = 0; |
| 150 |
unsigned int degree = 0; // degree is the maximal degree of the components |
| 151 |
|
| 152 |
for (unsigned int i = 0; i < fes.size(); ++i) |
| 153 |
{ |
| 154 |
Assert(do_tensor_product || (n_components == fes[i]->n_components()), |
| 155 |
ExcDimensionMismatch(n_components, fes[i]->n_components())); |
| 156 |
|
| 157 |
multiplied_n_components += fes[i]->n_components() * multiplicities[i]; |
| 158 |
|
| 159 |
if (multiplicities[i] > 0) |
| 160 |
degree = std::max(degree, fes[i]->tensor_degree()); |
| 161 |
} |
| 162 |
|
| 163 |
// assume conformity of the first finite element and then take away |
| 164 |
// bits as indicated by the base elements. if all multiplicities |
| 165 |
// happen to be zero, then it doesn't matter what we set it to. |
| 166 |
typename FiniteElementData<dim>::Conformity total_conformity = |
| 167 |
typename FiniteElementData<dim>::Conformity(); |
| 168 |
{ |
| 169 |
unsigned int index = 0; |
| 170 |
for (index = 0; index < fes.size(); ++index) |
| 171 |
if (multiplicities[index] > 0) |
| 172 |
{ |
| 173 |
total_conformity = fes[index]->conforming_space; |
| 174 |
break; |
| 175 |
} |
| 176 |
|
| 177 |
for (; index < fes.size(); ++index) |
| 178 |
if (multiplicities[index] > 0) |
| 179 |
total_conformity = typename FiniteElementData<dim>::Conformity( |
| 180 |
total_conformity & fes[index]->conforming_space); |
| 181 |
} |
| 182 |
|
| 183 |
BlockIndices block_indices(0, 0); |
| 184 |
|
| 185 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 186 |
for (unsigned int m = 0; m < multiplicities[base]; ++m) |
| 187 |
block_indices.push_back(fes[base]->n_dofs_per_cell()); |
| 188 |
|
| 189 |
const ReferenceCell reference_cell = fes.front()->reference_cell(); |
| 190 |
Assert(std::all_of(fes.begin(), |
| 191 |
fes.end(), |
| 192 |
[reference_cell]( |
| 193 |
const FiniteElement<dim, spacedim> *fe) { |
| 194 |
return fe->reference_cell() == reference_cell; |
| 195 |
}), |
| 196 |
ExcMessage("You cannot combine finite elements defined on " |
| 197 |
"different reference cells into a combined element " |
| 198 |
"such as an FESystem or FE_Enriched object.")); |
| 199 |
return FiniteElementData<dim>(dpo, |
| 200 |
reference_cell, |
| 201 |
(do_tensor_product ? |
| 202 |
multiplied_n_components : |
| 203 |
n_components), |
| 204 |
degree, |
| 205 |
total_conformity, |
| 206 |
block_indices); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
template <int dim, int spacedim> |
| 212 |
FiniteElementData<dim> |
| 213 |
multiply_dof_numbers(const FiniteElement<dim, spacedim> *fe1, |
| 214 |
const unsigned int N1, |
| 215 |
const FiniteElement<dim, spacedim> *fe2, |
| 216 |
const unsigned int N2, |
| 217 |
const FiniteElement<dim, spacedim> *fe3, |
| 218 |
const unsigned int N3, |
| 219 |
const FiniteElement<dim, spacedim> *fe4, |
| 220 |
const unsigned int N4, |
| 221 |
const FiniteElement<dim, spacedim> *fe5, |
| 222 |
const unsigned int N5) |
| 223 |
{ |
| 224 |
std::vector<const FiniteElement<dim, spacedim> *> fe_list = { |
| 225 |
fe1, fe2, fe3, fe4, fe5}; |
| 226 |
std::vector<unsigned int> multiplicities = {N1, N2, N3, N4, N5}; |
| 227 |
|
| 228 |
// This function is occasionally called with nullptr values for the |
| 229 |
// finite elements. Drop those again. |
| 230 |
while ((fe_list.size() > 0) && (fe_list.back() == nullptr)) |
| 231 |
{ |
| 232 |
Assert(multiplicities.back() == 0, ExcInternalError()); |
| 233 |
fe_list.pop_back(); |
| 234 |
multiplicities.pop_back(); |
| 235 |
} |
| 236 |
|
| 237 |
return multiply_dof_numbers(fe_list, multiplicities); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
template <int dim, int spacedim> |
| 243 |
std::vector<bool> |
| 244 |
compute_restriction_is_additive_flags( |
| 245 |
const std::vector<const FiniteElement<dim, spacedim> *> &fes, |
| 246 |
const std::vector<unsigned int> &multiplicities) |
| 247 |
{ |
| 248 |
AssertDimension(fes.size(), multiplicities.size()); |
| 249 |
|
| 250 |
const ReferenceCell reference_cell = fes.front()->reference_cell(); |
| 251 |
Assert(std::all_of(fes.begin(), |
| 252 |
fes.end(), |
| 253 |
[reference_cell]( |
| 254 |
const FiniteElement<dim, spacedim> *fe) { |
| 255 |
return fe->reference_cell() == reference_cell; |
| 256 |
}), |
| 257 |
ExcMessage("You cannot combine finite elements defined on " |
| 258 |
"different reference cells into a combined element " |
| 259 |
"such as an FESystem or FE_Enriched object.")); |
| 260 |
|
| 261 |
// first count the number of dofs and components that will emerge from the |
| 262 |
// given FEs |
| 263 |
unsigned int n_shape_functions = 0; |
| 264 |
for (unsigned int i = 0; i < fes.size(); ++i) |
| 265 |
n_shape_functions += fes[i]->n_dofs_per_cell() * multiplicities[i]; |
| 266 |
|
| 267 |
// generate the array that will hold the output |
| 268 |
std::vector<bool> retval(n_shape_functions, false); |
| 269 |
|
| 270 |
// finally go through all the shape functions of the base elements, and |
| 271 |
// copy their flags. this somehow copies the code in build_cell_table, |
| 272 |
// which is not nice as it uses too much implicit knowledge about the |
| 273 |
// layout of the individual bases in the composed FE, but there seems no |
| 274 |
// way around... |
| 275 |
// |
| 276 |
// for each shape function, copy the flags from the base element to this |
| 277 |
// one, taking into account multiplicities, and other complications |
| 278 |
unsigned int total_index = 0; |
| 279 |
for (const unsigned int vertex_number : reference_cell.vertex_indices()) |
| 280 |
{ |
| 281 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 282 |
for (unsigned int m = 0; m < multiplicities[base]; ++m) |
| 283 |
for (unsigned int local_index = 0; |
| 284 |
local_index < fes[base]->n_dofs_per_vertex(); |
| 285 |
++local_index, ++total_index) |
| 286 |
{ |
| 287 |
const unsigned int index_in_base = |
| 288 |
(fes[base]->n_dofs_per_vertex() * vertex_number + |
| 289 |
local_index); |
| 290 |
|
| 291 |
Assert(index_in_base < fes[base]->n_dofs_per_cell(), |
| 292 |
ExcInternalError()); |
| 293 |
retval[total_index] = |
| 294 |
fes[base]->restriction_is_additive(index_in_base); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
// 2. Lines |
| 299 |
for (const unsigned int line_number : reference_cell.line_indices()) |
| 300 |
{ |
| 301 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 302 |
for (unsigned int m = 0; m < multiplicities[base]; ++m) |
| 303 |
for (unsigned int local_index = 0; |
| 304 |
local_index < fes[base]->n_dofs_per_line(); |
| 305 |
++local_index, ++total_index) |
| 306 |
{ |
| 307 |
const unsigned int index_in_base = |
| 308 |
(fes[base]->n_dofs_per_line() * line_number + local_index + |
| 309 |
fes[base]->get_first_line_index()); |
| 310 |
|
| 311 |
Assert(index_in_base < fes[base]->n_dofs_per_cell(), |
| 312 |
ExcInternalError()); |
| 313 |
retval[total_index] = |
| 314 |
fes[base]->restriction_is_additive(index_in_base); |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
// 3. Quads |
| 319 |
for (unsigned int quad_number = 0; |
| 320 |
quad_number < |
| 321 |
(dim == 2 ? 1 : (dim == 3 ? reference_cell.n_faces() : 0)); |
| 322 |
++quad_number) |
| 323 |
{ |
| 324 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 325 |
for (unsigned int m = 0; m < multiplicities[base]; ++m) |
| 326 |
for (unsigned int local_index = 0; |
| 327 |
local_index < fes[base]->n_dofs_per_quad(quad_number); |
| 328 |
++local_index, ++total_index) |
| 329 |
{ |
| 330 |
const unsigned int index_in_base = |
| 331 |
local_index + fes[base]->get_first_quad_index(quad_number); |
| 332 |
|
| 333 |
Assert(index_in_base < fes[base]->n_dofs_per_cell(), |
| 334 |
ExcInternalError()); |
| 335 |
retval[total_index] = |
| 336 |
fes[base]->restriction_is_additive(index_in_base); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
// 4. Hexes |
| 341 |
if (dim == 3) |
| 342 |
{ |
| 343 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 344 |
for (unsigned int m = 0; m < multiplicities[base]; ++m) |
| 345 |
for (unsigned int local_index = 0; |
| 346 |
local_index < fes[base]->n_dofs_per_hex(); |
| 347 |
++local_index, ++total_index) |
| 348 |
{ |
| 349 |
const unsigned int index_in_base = |
| 350 |
local_index + fes[base]->get_first_hex_index(); |
| 351 |
|
| 352 |
Assert(index_in_base < fes[base]->n_dofs_per_cell(), |
| 353 |
ExcInternalError()); |
| 354 |
retval[total_index] = |
| 355 |
fes[base]->restriction_is_additive(index_in_base); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
Assert(total_index == n_shape_functions, ExcInternalError()); |
| 360 |
|
| 361 |
return retval; |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
/** |
| 367 |
* Take a @p FiniteElement object |
| 368 |
* and return an boolean vector including the @p |
| 369 |
* restriction_is_additive_flags of the mixed element consisting of @p N |
| 370 |
* elements of the sub-element @p fe. |
| 371 |
*/ |
| 372 |
template <int dim, int spacedim> |
| 373 |
std::vector<bool> |
| 374 |
compute_restriction_is_additive_flags( |
| 375 |
const FiniteElement<dim, spacedim> *fe1, |
| 376 |
const unsigned int N1, |
| 377 |
const FiniteElement<dim, spacedim> *fe2, |
| 378 |
const unsigned int N2, |
| 379 |
const FiniteElement<dim, spacedim> *fe3, |
| 380 |
const unsigned int N3, |
| 381 |
const FiniteElement<dim, spacedim> *fe4, |
| 382 |
const unsigned int N4, |
| 383 |
const FiniteElement<dim, spacedim> *fe5, |
| 384 |
const unsigned int N5) |
| 385 |
{ |
| 386 |
std::vector<const FiniteElement<dim, spacedim> *> fe_list = { |
| 387 |
fe1, fe2, fe3, fe4, fe5}; |
| 388 |
std::vector<unsigned int> multiplicities = {N1, N2, N3, N4, N5}; |
| 389 |
|
| 390 |
// This function is occasionally called with nullptr values for the |
| 391 |
// finite elements. Drop those again. |
| 392 |
while ((fe_list.size() > 0) && (fe_list.back() == nullptr)) |
| 393 |
{ |
| 394 |
Assert(multiplicities.back() == 0, ExcInternalError()); |
| 395 |
fe_list.pop_back(); |
| 396 |
multiplicities.pop_back(); |
| 397 |
} |
| 398 |
|
| 399 |
return compute_restriction_is_additive_flags(fe_list, multiplicities); |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
template <int dim, int spacedim> |
| 405 |
std::vector<ComponentMask> |
| 406 |
compute_nonzero_components( |
| 407 |
const std::vector<const FiniteElement<dim, spacedim> *> &fes, |
| 408 |
const std::vector<unsigned int> &multiplicities, |
| 409 |
const bool do_tensor_product) |
| 410 |
{ |
| 411 |
AssertDimension(fes.size(), multiplicities.size()); |
| 412 |
Assert( |
| 413 |
fes.size() > 0, |
| 414 |
ExcMessage( |
| 415 |
"This function only makes sense if at least one FiniteElement is provided.")); |
| 416 |
|
| 417 |
const ReferenceCell reference_cell = fes.front()->reference_cell(); |
| 418 |
Assert(std::all_of(fes.begin(), |
| 419 |
fes.end(), |
| 420 |
[reference_cell]( |
| 421 |
const FiniteElement<dim, spacedim> *fe) { |
| 422 |
return fe->reference_cell() == reference_cell; |
| 423 |
}), |
| 424 |
ExcMessage("You cannot combine finite elements defined on " |
| 425 |
"different reference cells into a combined element " |
| 426 |
"such as an FESystem or FE_Enriched object.")); |
| 427 |
|
| 428 |
// first count the number of dofs and components that will emerge from the |
| 429 |
// given FEs |
| 430 |
unsigned int n_shape_functions = 0; |
| 431 |
for (unsigned int i = 0; i < fes.size(); ++i) |
| 432 |
n_shape_functions += fes[i]->n_dofs_per_cell() * multiplicities[i]; |
| 433 |
|
| 434 |
unsigned int n_components = 0; |
| 435 |
if (do_tensor_product) |
| 436 |
{ |
| 437 |
for (unsigned int i = 0; i < fes.size(); ++i) |
| 438 |
n_components += fes[i]->n_components() * multiplicities[i]; |
| 439 |
} |
| 440 |
else |
| 441 |
{ |
| 442 |
n_components = fes[0]->n_components(); |
| 443 |
|
| 444 |
// Now check that all FEs have the same number of components: |
| 445 |
for (unsigned int i = 0; i < fes.size(); ++i) |
| 446 |
Assert(n_components == fes[i]->n_components(), |
| 447 |
ExcDimensionMismatch(n_components, fes[i]->n_components())); |
| 448 |
} |
| 449 |
|
| 450 |
// generate the array that will hold the output |
| 451 |
std::vector<std::vector<bool>> retval(n_shape_functions, |
| 452 |
std::vector<bool>(n_components, |
| 453 |
false)); |
| 454 |
|
| 455 |
// finally go through all the shape functions of the base elements, and |
| 456 |
// copy their flags. this somehow copies the code in build_cell_table, |
| 457 |
// which is not nice as it uses too much implicit knowledge about the |
| 458 |
// layout of the individual bases in the composed FE, but there seems no |
| 459 |
// way around... |
| 460 |
// |
| 461 |
// for each shape function, copy the non-zero flags from the base element |
| 462 |
// to this one, taking into account multiplicities, multiple components in |
| 463 |
// base elements, and other complications |
| 464 |
unsigned int total_index = 0; |
| 465 |
for (const unsigned int vertex_number : reference_cell.vertex_indices()) |
| 466 |
{ |
| 467 |
unsigned int comp_start = 0; |
| 468 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 469 |
for (unsigned int m = 0; m < multiplicities[base]; |
| 470 |
++m, |
| 471 |
comp_start += |
| 472 |
fes[base]->n_components() * do_tensor_product) |
| 473 |
for (unsigned int local_index = 0; |
| 474 |
local_index < fes[base]->n_dofs_per_vertex(); |
| 475 |
++local_index, ++total_index) |
| 476 |
{ |
| 477 |
const unsigned int index_in_base = |
| 478 |
(fes[base]->n_dofs_per_vertex() * vertex_number + |
| 479 |
local_index); |
| 480 |
|
| 481 |
Assert(comp_start + fes[base]->n_components() <= |
| 482 |
retval[total_index].size(), |
| 483 |
ExcInternalError()); |
| 484 |
for (unsigned int c = 0; c < fes[base]->n_components(); ++c) |
| 485 |
{ |
| 486 |
Assert(c < fes[base] |
| 487 |
->get_nonzero_components(index_in_base) |
| 488 |
.size(), |
| 489 |
ExcInternalError()); |
| 490 |
retval[total_index][comp_start + c] = |
| 491 |
fes[base]->get_nonzero_components(index_in_base)[c]; |
| 492 |
} |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
// 2. Lines |
| 497 |
for (const unsigned int line_number : reference_cell.line_indices()) |
| 498 |
{ |
| 499 |
unsigned int comp_start = 0; |
| 500 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 501 |
for (unsigned int m = 0; m < multiplicities[base]; |
| 502 |
++m, |
| 503 |
comp_start += |
| 504 |
fes[base]->n_components() * do_tensor_product) |
| 505 |
for (unsigned int local_index = 0; |
| 506 |
local_index < fes[base]->n_dofs_per_line(); |
| 507 |
++local_index, ++total_index) |
| 508 |
{ |
| 509 |
const unsigned int index_in_base = |
| 510 |
(fes[base]->n_dofs_per_line() * line_number + local_index + |
| 511 |
fes[base]->get_first_line_index()); |
| 512 |
|
| 513 |
Assert(comp_start + fes[base]->n_components() <= |
| 514 |
retval[total_index].size(), |
| 515 |
ExcInternalError()); |
| 516 |
for (unsigned int c = 0; c < fes[base]->n_components(); ++c) |
| 517 |
{ |
| 518 |
Assert(c < fes[base] |
| 519 |
->get_nonzero_components(index_in_base) |
| 520 |
.size(), |
| 521 |
ExcInternalError()); |
| 522 |
retval[total_index][comp_start + c] = |
| 523 |
fes[base]->get_nonzero_components(index_in_base)[c]; |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
// 3. Quads |
| 529 |
for (unsigned int quad_number = 0; |
| 530 |
quad_number < |
| 531 |
(dim == 2 ? 1 : (dim == 3 ? reference_cell.n_faces() : 0)); |
| 532 |
++quad_number) |
| 533 |
{ |
| 534 |
unsigned int comp_start = 0; |
| 535 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 536 |
for (unsigned int m = 0; m < multiplicities[base]; |
| 537 |
++m, |
| 538 |
comp_start += |
| 539 |
fes[base]->n_components() * do_tensor_product) |
| 540 |
for (unsigned int local_index = 0; |
| 541 |
local_index < fes[base]->n_dofs_per_quad(quad_number); |
| 542 |
++local_index, ++total_index) |
| 543 |
{ |
| 544 |
const unsigned int index_in_base = |
| 545 |
local_index + fes[base]->get_first_quad_index(quad_number); |
| 546 |
|
| 547 |
Assert(comp_start + fes[base]->n_components() <= |
| 548 |
retval[total_index].size(), |
| 549 |
ExcInternalError()); |
| 550 |
for (unsigned int c = 0; c < fes[base]->n_components(); ++c) |
| 551 |
{ |
| 552 |
Assert(c < fes[base] |
| 553 |
->get_nonzero_components(index_in_base) |
| 554 |
.size(), |
| 555 |
ExcInternalError()); |
| 556 |
retval[total_index][comp_start + c] = |
| 557 |
fes[base]->get_nonzero_components(index_in_base)[c]; |
| 558 |
} |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
// 4. Hexes |
| 563 |
if (dim == 3) |
| 564 |
{ |
| 565 |
unsigned int comp_start = 0; |
| 566 |
for (unsigned int base = 0; base < fes.size(); ++base) |
| 567 |
for (unsigned int m = 0; m < multiplicities[base]; |
| 568 |
++m, |
| 569 |
comp_start += |
| 570 |
fes[base]->n_components() * do_tensor_product) |
| 571 |
for (unsigned int local_index = 0; |
| 572 |
local_index < fes[base]->n_dofs_per_hex(); |
| 573 |
++local_index, ++total_index) |
| 574 |
{ |
| 575 |
const unsigned int index_in_base = |
| 576 |
local_index + fes[base]->get_first_hex_index(); |
| 577 |
|
| 578 |
Assert(comp_start + fes[base]->n_components() <= |
| 579 |
retval[total_index].size(), |
| 580 |
ExcInternalError()); |
| 581 |
for (unsigned int c = 0; c < fes[base]->n_components(); ++c) |
| 582 |
{ |
| 583 |
Assert(c < fes[base] |
| 584 |
->get_nonzero_components(index_in_base) |
| 585 |
.size(), |
| 586 |
ExcInternalError()); |
| 587 |
retval[total_index][comp_start + c] = |
| 588 |
fes[base]->get_nonzero_components(index_in_base)[c]; |
| 589 |
} |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
Assert(total_index == n_shape_functions, ExcInternalError()); |
| 594 |
|
| 595 |
// now copy the vector<vector<bool> > into a vector<ComponentMask>. |
| 596 |
// this appears complicated but we do it this way since it's just |
| 597 |
// awkward to generate ComponentMasks directly and so we need the |
| 598 |
// recourse of the inner vector<bool> anyway. |
| 599 |
std::vector<ComponentMask> xretval(retval.size()); |
| 600 |
for (unsigned int i = 0; i < retval.size(); ++i) |
| 601 |
xretval[i] = ComponentMask(retval[i]); |
| 602 |
return xretval; |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
/** |
| 608 |
* Compute the non-zero vector components of a composed finite element. |
| 609 |
*/ |
| 610 |
template <int dim, int spacedim> |
| 611 |
std::vector<ComponentMask> |
| 612 |
compute_nonzero_components(const FiniteElement<dim, spacedim> *fe1, |
| 613 |
const unsigned int N1, |
| 614 |
const FiniteElement<dim, spacedim> *fe2, |
| 615 |
const unsigned int N2, |
| 616 |
const FiniteElement<dim, spacedim> *fe3, |
| 617 |
const unsigned int N3, |
| 618 |
const FiniteElement<dim, spacedim> *fe4, |
| 619 |
const unsigned int N4, |
| 620 |
const FiniteElement<dim, spacedim> *fe5, |
| 621 |
const unsigned int N5, |
| 622 |
const bool do_tensor_product) |
| 623 |
{ |
| 624 |
std::vector<const FiniteElement<dim, spacedim> *> fe_list = { |
| 625 |
fe1, fe2, fe3, fe4, fe5}; |
| 626 |
std::vector<unsigned int> multiplicities = {N1, N2, N3, N4, N5}; |
| 627 |
|
| 628 |
// This function is occasionally called with nullptr values for the |
| 629 |
// finite elements. Drop those again. |
| 630 |
while ((fe_list.size() > 0) && (fe_list.back() == nullptr)) |
| 631 |
{ |
| 632 |
Assert(multiplicities.back() == 0, ExcInternalError()); |
| 633 |
fe_list.pop_back(); |
| 634 |
multiplicities.pop_back(); |
| 635 |
} |
| 636 |
|
| 637 |
return compute_nonzero_components(fe_list, |
| 638 |
multiplicities, |
| 639 |
do_tensor_product); |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
template <int dim, int spacedim> |
| 645 |
void |
| 646 |
build_cell_tables( |
| 647 |
std::vector<std::pair<std::pair<unsigned int, unsigned int>, |
| 648 |
unsigned int>> &system_to_base_table, |
| 649 |
std::vector<std::pair<unsigned int, unsigned int>> |
| 650 |
&system_to_component_table, |
| 651 |
std::vector<std::pair<std::pair<unsigned int, unsigned int>, |
| 652 |
unsigned int>> &component_to_base_table, |
| 653 |
const FiniteElement<dim, spacedim> &fe, |
| 654 |
const bool do_tensor_product) |
| 655 |
{ |
| 656 |
unsigned int total_index = 0; |
| 657 |
|
| 658 |
if (do_tensor_product) |
| 659 |
{ |
| 660 |
for (unsigned int base = 0; base < fe.n_base_elements(); ++base) |
| 661 |
for (unsigned int m = 0; m < fe.element_multiplicity(base); ++m) |
| 662 |
{ |
| 663 |
for (unsigned int k = 0; |
| 664 |
k < fe.base_element(base).n_components(); |
| 665 |
++k) |
| 666 |
component_to_base_table[total_index++] = |
| 667 |
std::make_pair(std::make_pair(base, k), m); |
| 668 |
} |
| 669 |
Assert(total_index == component_to_base_table.size(), |
| 670 |
ExcInternalError()); |
| 671 |
} |
| 672 |
else |
| 673 |
{ |
| 674 |
// The base element establishing a component does not make sense in |
| 675 |
// this case. Set up to something meaningless: |
| 676 |
std::fill( |
| 677 |
component_to_base_table.begin(), |
| 678 |
component_to_base_table.end(), |
| 679 |
std::make_pair(std::make_pair(numbers::invalid_unsigned_int, |
| 680 |
numbers::invalid_unsigned_int), |
| 681 |
numbers::invalid_unsigned_int)); |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
// Initialize index tables. Multi-component base elements have to be |
| 686 |
// thought of. For non-primitive shape functions, have a special invalid |
| 687 |
// index. |
| 688 |
const std::pair<unsigned int, unsigned int> non_primitive_index( |
| 689 |
numbers::invalid_unsigned_int, numbers::invalid_unsigned_int); |
| 690 |
|
| 691 |
// First enumerate vertex indices, where we first enumerate all indices on |
| 692 |
// the first vertex in the order of the base elements, then of the second |
| 693 |
// vertex, etc |
| 694 |
total_index = 0; |
| 695 |
for (const unsigned int vertex_number : |
| 696 |
fe.reference_cell().vertex_indices()) |
| 697 |
{ |
| 698 |
unsigned int comp_start = 0; |
| 699 |
for (unsigned int base = 0; base < fe.n_base_elements(); ++base) |
| 700 |
for (unsigned int m = 0; m < fe.element_multiplicity(base); |
| 701 |
++m, |
| 702 |
comp_start += |
| 703 |
fe.base_element(base).n_components() * |
| 704 |
do_tensor_product) |
| 705 |
for (unsigned int local_index = 0; |
| 706 |
local_index < fe.base_element(base).n_dofs_per_vertex(); |
| 707 |
++local_index, ++total_index) |
| 708 |
{ |
| 709 |
const unsigned int index_in_base = |
| 710 |
(fe.base_element(base).n_dofs_per_vertex() * vertex_number + |
| 711 |
local_index); |
| 712 |
|
| 713 |
system_to_base_table[total_index] = |
| 714 |
std::make_pair(std::make_pair(base, m), index_in_base); |
| 715 |
|
| 716 |
if (fe.base_element(base).is_primitive(index_in_base)) |
| 717 |
{ |
| 718 |
const unsigned int comp_in_base = |
| 719 |
fe.base_element(base) |
| 720 |
.system_to_component_index(index_in_base) |
| 721 |
.first; |
| 722 |
const unsigned int comp = comp_start + comp_in_base; |
| 723 |
const unsigned int index_in_comp = |
| 724 |
fe.base_element(base) |
| 725 |
.system_to_component_index(index_in_base) |
| 726 |
.second; |
| 727 |
system_to_component_table[total_index] = |
| 728 |
std::make_pair(comp, index_in_comp); |
| 729 |
} |
| 730 |
else |
| 731 |
system_to_component_table[total_index] = |
| 732 |
non_primitive_index; |
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
// 2. Lines |
| 737 |
for (const unsigned int line_number : fe.reference_cell().line_indices()) |
| 738 |
{ |
| 739 |
unsigned int comp_start = 0; |
| 740 |
for (unsigned int base = 0; base < fe.n_base_elements(); ++base) |
| 741 |
for (unsigned int m = 0; m < fe.element_multiplicity(base); |
| 742 |
++m, |
| 743 |
comp_start += |
| 744 |
fe.base_element(base).n_components() * |
| 745 |
do_tensor_product) |
| 746 |
for (unsigned int local_index = 0; |
| 747 |
local_index < fe.base_element(base).n_dofs_per_line(); |
| 748 |
++local_index, ++total_index) |
| 749 |
{ |
| 750 |
const unsigned int index_in_base = |
| 751 |
(fe.base_element(base).n_dofs_per_line() * line_number + |
| 752 |
local_index + |
| 753 |
fe.base_element(base).get_first_line_index()); |
| 754 |
|
| 755 |
system_to_base_table[total_index] = |
| 756 |
std::make_pair(std::make_pair(base, m), index_in_base); |
| 757 |
|
| 758 |
if (fe.base_element(base).is_primitive(index_in_base)) |
| 759 |
{ |
| 760 |
const unsigned int comp_in_base = |
| 761 |
fe.base_element(base) |
| 762 |
.system_to_component_index(index_in_base) |
| 763 |
.first; |
| 764 |
const unsigned int comp = comp_start + comp_in_base; |
| 765 |
const unsigned int index_in_comp = |
| 766 |
fe.base_element(base) |
| 767 |
.system_to_component_index(index_in_base) |
| 768 |
.second; |
| 769 |
system_to_component_table[total_index] = |
| 770 |
std::make_pair(comp, index_in_comp); |
| 771 |
} |
| 772 |
else |
| 773 |
system_to_component_table[total_index] = |
| 774 |
non_primitive_index; |
| 775 |
} |
| 776 |
} |
| 777 |
|
| 778 |
// 3. Quads |
| 779 |
for (unsigned int quad_number = 0; |
| 780 |
quad_number < |
| 781 |
(dim == 2 ? 1 : (dim == 3 ? fe.reference_cell().n_faces() : 0)); |
| 782 |
++quad_number) |
| 783 |
{ |
| 784 |
unsigned int comp_start = 0; |
| 785 |
for (unsigned int base = 0; base < fe.n_base_elements(); ++base) |
| 786 |
for (unsigned int m = 0; m < fe.element_multiplicity(base); |
| 787 |
++m, |
| 788 |
comp_start += |
| 789 |
fe.base_element(base).n_components() * |
| 790 |
do_tensor_product) |
| 791 |
for (unsigned int local_index = 0; |
| 792 |
local_index < |
| 793 |
fe.base_element(base).n_dofs_per_quad(quad_number); |
| 794 |
++local_index, ++total_index) |
| 795 |
{ |
| 796 |
const unsigned int index_in_base = |
| 797 |
local_index + |
| 798 |
fe.base_element(base).get_first_quad_index(quad_number); |
| 799 |
|
| 800 |
system_to_base_table[total_index] = |
| 801 |
std::make_pair(std::make_pair(base, m), index_in_base); |
| 802 |
|
| 803 |
if (fe.base_element(base).is_primitive(index_in_base)) |
| 804 |
{ |
| 805 |
const unsigned int comp_in_base = |
| 806 |
fe.base_element(base) |
| 807 |
.system_to_component_index(index_in_base) |
| 808 |
.first; |
| 809 |
const unsigned int comp = comp_start + comp_in_base; |
| 810 |
const unsigned int index_in_comp = |
| 811 |
fe.base_element(base) |
| 812 |
.system_to_component_index(index_in_base) |
| 813 |
.second; |
| 814 |
system_to_component_table[total_index] = |
| 815 |
std::make_pair(comp, index_in_comp); |
| 816 |
} |
| 817 |
else |
| 818 |
system_to_component_table[total_index] = |
| 819 |
non_primitive_index; |
| 820 |
} |
| 821 |
} |
| 822 |
|
| 823 |
// 4. Hexes |
| 824 |
if (dim == 3) |
| 825 |
{ |
| 826 |
unsigned int comp_start = 0; |
| 827 |
for (unsigned int base = 0; base < fe.n_base_elements(); ++base) |
| 828 |
for (unsigned int m = 0; m < fe.element_multiplicity(base); |
| 829 |
++m, |
| 830 |
comp_start += |
| 831 |
fe.base_element(base).n_components() * |
| 832 |
do_tensor_product) |
| 833 |
for (unsigned int local_index = 0; |
| 834 |
local_index < fe.base_element(base).n_dofs_per_hex(); |
| 835 |
++local_index, ++total_index) |
| 836 |
{ |
| 837 |
const unsigned int index_in_base = |
| 838 |
local_index + fe.base_element(base).get_first_hex_index(); |
| 839 |
|
| 840 |
system_to_base_table[total_index] = |
| 841 |
std::make_pair(std::make_pair(base, m), index_in_base); |
| 842 |
|
| 843 |
if (fe.base_element(base).is_primitive(index_in_base)) |
| 844 |
{ |
| 845 |
const unsigned int comp_in_base = |
| 846 |
fe.base_element(base) |
| 847 |
.system_to_component_index(index_in_base) |
| 848 |
.first; |
| 849 |
const unsigned int comp = comp_start + comp_in_base; |
| 850 |
const unsigned int index_in_comp = |
| 851 |
fe.base_element(base) |
| 852 |
.system_to_component_index(index_in_base) |
| 853 |
.second; |
| 854 |
system_to_component_table[total_index] = |
| 855 |
std::make_pair(comp, index_in_comp); |
| 856 |
} |
| 857 |
else |
| 858 |
system_to_component_table[total_index] = |
| 859 |
non_primitive_index; |
| 860 |
} |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
template <int dim, int spacedim> |
| 867 |
void |
| 868 |
build_face_tables( |
| 869 |
std::vector<std::pair<std::pair<unsigned int, unsigned int>, |
| 870 |
unsigned int>> &face_system_to_base_table, |
| 871 |
std::vector<std::pair<unsigned int, unsigned int>> |
| 872 |
&face_system_to_component_table, |
| 873 |
const FiniteElement<dim, spacedim> &fe, |
| 874 |
const bool do_tensor_product, |
| 875 |
const unsigned int face_no) |
| 876 |
{ |
| 877 |
// Initialize index tables. do this in the same way as done for the cell |
| 878 |
// tables, except that we now loop over the objects of faces |
| 879 |
|
| 880 |
// For non-primitive shape functions, have a special invalid index |
| 881 |
const std::pair<unsigned int, unsigned int> non_primitive_index( |
| 882 |
numbers::invalid_unsigned_int, numbers::invalid_unsigned_int); |
| 883 |
|
| 884 |
// 1. Vertices |
| 885 |
unsigned int total_index = 0; |
| 886 |
for (unsigned int vertex_number = 0; |
| 887 |
vertex_number < |
| 888 |
fe.reference_cell().face_reference_cell(face_no).n_vertices(); |
| 889 |
++vertex_number) |
| 890 |
{ |
| 891 |
unsigned int comp_start = 0; |
| 892 |
for (unsigned int base = 0; base < fe.n_base_elements(); ++base) |
| 893 |
for (unsigned int m = 0; m < fe.element_multiplicity(base); |
| 894 |
++m, |
| 895 |
comp_start += |
| 896 |
fe.base_element(base).n_components() * |
| 897 |
do_tensor_product) |
| 898 |
for (unsigned int local_index = 0; |
| 899 |
local_index < fe.base_element(base).n_dofs_per_vertex(); |
| 900 |
++local_index, ++total_index) |
| 901 |
{ |
| 902 |
// get (cell) index of this shape function inside the base |
| 903 |
// element to see whether the shape function is primitive |
| 904 |
// (assume that all shape functions on vertices share the same |
| 905 |
// primitivity property; assume likewise for all shape |
| 906 |
// functions located on lines, quads, etc. this way, we can |
| 907 |
// ask for primitivity of only _one_ shape function, which is |
| 908 |
// taken as representative for all others located on the same |
| 909 |
// type of object): |
| 910 |
const unsigned int index_in_base = |
| 911 |
(fe.base_element(base).n_dofs_per_vertex() * vertex_number + |
| 912 |
local_index); |
| 913 |
|
| 914 |
const unsigned int face_index_in_base = |
| 915 |
(fe.base_element(base).n_dofs_per_vertex() * vertex_number + |
| 916 |
local_index); |
| 917 |
|
| 918 |
face_system_to_base_table[total_index] = |
| 919 |
std::make_pair(std::make_pair(base, m), face_index_in_base); |
| 920 |
|
| 921 |
if (fe.base_element(base).is_primitive(index_in_base)) |
| 922 |
{ |
| 923 |
const unsigned int comp_in_base = |
| 924 |
fe.base_element(base) |
| 925 |
.face_system_to_component_index(face_index_in_base, |
| 926 |
face_no) |
| 927 |
.first; |
| 928 |
const unsigned int comp = comp_start + comp_in_base; |
| 929 |
const unsigned int face_index_in_comp = |
| 930 |
fe.base_element(base) |
| 931 |
.face_system_to_component_index(face_index_in_base, |
| 932 |
face_no) |
| 933 |
.second; |
| 934 |
face_system_to_component_table[total_index] = |
| 935 |
std::make_pair(comp, face_index_in_comp); |
| 936 |
} |
| 937 |
else |
| 938 |
face_system_to_component_table[total_index] = |
| 939 |
non_primitive_index; |
| 940 |
} |
| 941 |
} |
| 942 |
|
| 943 |
// 2. Lines |
| 944 |
for (unsigned int line_number = 0; |
| 945 |
line_number < |
| 946 |
fe.reference_cell().face_reference_cell(face_no).n_lines(); |
| 947 |
++line_number) |
| 948 |
{ |
| 949 |
unsigned int comp_start = 0; |
| 950 |
for (unsigned int base = 0; base < fe.n_base_elements(); ++base) |
| 951 |
for (unsigned int m = 0; m < fe.element_multiplicity(base); |
| 952 |
++m, |
| 953 |
comp_start += |
| 954 |
fe.base_element(base).n_components() * |
| 955 |
do_tensor_product) |
| 956 |
for (unsigned int local_index = 0; |
| 957 |
local_index < fe.base_element(base).n_dofs_per_line(); |
| 958 |
++local_index, ++total_index) |
| 959 |
{ |
| 960 |
// do everything alike for this type of object |
| 961 |
const unsigned int index_in_base = |
| 962 |
(fe.base_element(base).n_dofs_per_line() * line_number + |
| 963 |
local_index + |
| 964 |
fe.base_element(base).get_first_line_index()); |
| 965 |
|
| 966 |
const unsigned int face_index_in_base = |
| 967 |
(fe.base_element(base).get_first_face_line_index(face_no) + |
| 968 |
fe.base_element(base).n_dofs_per_line() * line_number + |
| 969 |
local_index); |
| 970 |
|
| 971 |
face_system_to_base_table[total_index] = |
| 972 |
std::make_pair(std::make_pair(base, m), face_index_in_base); |
| 973 |
|
| 974 |
if (fe.base_element(base).is_primitive(index_in_base)) |
| 975 |
{ |
| 976 |
const unsigned int comp_in_base = |
| 977 |
fe.base_element(base) |
| 978 |
.face_system_to_component_index(face_index_in_base, |
| 979 |
face_no) |
| 980 |
.first; |
| 981 |
const unsigned int comp = comp_start + comp_in_base; |
| 982 |
const unsigned int face_index_in_comp = |
| 983 |
fe.base_element(base) |
| 984 |
.face_system_to_component_index(face_index_in_base, |
| 985 |
face_no) |
| 986 |
.second; |
| 987 |
face_system_to_component_table[total_index] = |
| 988 |
std::make_pair(comp, face_index_in_comp); |
| 989 |
} |
| 990 |
else |
| 991 |
face_system_to_component_table[total_index] = |
| 992 |
non_primitive_index; |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
// 3. Quads |
| 997 |
if (dim == 3) |
| 998 |
{ |
| 999 |
unsigned int comp_start = 0; |
| 1000 |
for (unsigned int base = 0; base < fe.n_base_elements(); ++base) |
| 1001 |
for (unsigned int m = 0; m < fe.element_multiplicity(base); |
| 1002 |
++m, |
| 1003 |
comp_start += |
| 1004 |
fe.base_element(base).n_components() * |
| 1005 |
do_tensor_product) |
| 1006 |
for (unsigned int local_index = 0; |
| 1007 |
local_index < fe.base_element(base).n_dofs_per_quad(face_no); |
| 1008 |
++local_index, ++total_index) |
| 1009 |
{ |
| 1010 |
// do everything alike for this type of object |
| 1011 |
const unsigned int index_in_base = |
| 1012 |
(local_index + |
| 1013 |
fe.base_element(base).get_first_quad_index(face_no)); |
| 1014 |
|
| 1015 |
const unsigned int face_index_in_base = |
| 1016 |
(fe.base_element(base).get_first_face_quad_index(face_no) + |
| 1017 |
local_index); |
| 1018 |
|
| 1019 |
face_system_to_base_table[total_index] = |
| 1020 |
std::make_pair(std::make_pair(base, m), face_index_in_base); |
| 1021 |
|
| 1022 |
if (fe.base_element(base).is_primitive(index_in_base)) |
| 1023 |
{ |
| 1024 |
const unsigned int comp_in_base = |
| 1025 |
fe.base_element(base) |
| 1026 |
.face_system_to_component_index(face_index_in_base, |
| 1027 |
face_no) |
| 1028 |
.first; |
| 1029 |
const unsigned int comp = comp_start + comp_in_base; |
| 1030 |
const unsigned int face_index_in_comp = |
| 1031 |
fe.base_element(base) |
| 1032 |
.face_system_to_component_index(face_index_in_base, |
| 1033 |
face_no) |
| 1034 |
.second; |
| 1035 |
face_system_to_component_table[total_index] = |
| 1036 |
std::make_pair(comp, face_index_in_comp); |
| 1037 |
} |
| 1038 |
else |
| 1039 |
face_system_to_component_table[total_index] = |
| 1040 |
non_primitive_index; |
| 1041 |
} |
| 1042 |
} |
| 1043 |
Assert(total_index == fe.n_dofs_per_face(face_no), ExcInternalError()); |
| 1044 |
Assert(total_index == face_system_to_component_table.size(), |
| 1045 |
ExcInternalError()); |
| 1046 |
Assert(total_index == face_system_to_base_table.size(), |
| 1047 |
ExcInternalError()); |
| 1048 |
} |
| 1049 |
} // namespace Compositing |
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
template <class FE> |
| 1054 |
std::unique_ptr<FiniteElement<FE::dimension, FE::space_dimension>> |
| 1055 |
FEFactory<FE>::get(const Quadrature<1> &quad) const |
| 1056 |
{ |
| 1057 |
// Specializations for FE_Q. |
| 1058 |
if constexpr (std::is_same_v<FE, FE_Q<1, 1>>) |
| 1059 |
return std::make_unique<FE_Q<1>>(quad); |
| 1060 |
if constexpr (std::is_same_v<FE, FE_Q<2, 2>>) |
| 1061 |
return std::make_unique<FE_Q<2>>(quad); |
| 1062 |
if constexpr (std::is_same_v<FE, FE_Q<3, 3>>) |
| 1063 |
return std::make_unique<FE_Q<3>>(quad); |
| 1064 |
|
| 1065 |
// Specializations for FE_Q_DG0. |
| 1066 |
if constexpr (std::is_same_v<FE, FE_Q_DG0<1, 1>>) |
| 1067 |
return std::make_unique<FE_Q_DG0<1>>(quad); |
| 1068 |
if constexpr (std::is_same_v<FE, FE_Q_DG0<2, 2>>) |
| 1069 |
return std::make_unique<FE_Q_DG0<2>>(quad); |
| 1070 |
if constexpr (std::is_same_v<FE, FE_Q_DG0<3, 3>>) |
| 1071 |
return std::make_unique<FE_Q_DG0<3>>(quad); |
| 1072 |
|
| 1073 |
// Specializations for FE_Q_Bubbles. |
| 1074 |
if constexpr (std::is_same_v<FE, FE_Q_Bubbles<1, 1>>) |
| 1075 |
return std::make_unique<FE_Q_Bubbles<1>>(quad); |
| 1076 |
if constexpr (std::is_same_v<FE, FE_Q_Bubbles<2, 2>>) |
| 1077 |
return std::make_unique<FE_Q_Bubbles<2>>(quad); |
| 1078 |
if constexpr (std::is_same_v<FE, FE_Q_Bubbles<3, 3>>) |
| 1079 |
return std::make_unique<FE_Q_Bubbles<3>>(quad); |
| 1080 |
|
| 1081 |
// Specializations for FE_DGQArbitraryNodes. |
| 1082 |
if constexpr (std::is_same_v<FE, FE_DGQ<1>>) |
| 1083 |
return std::make_unique<FE_DGQArbitraryNodes<1>>(quad); |
| 1084 |
if constexpr (std::is_same_v<FE, FE_DGQ<1, 2>>) |
| 1085 |
return std::make_unique<FE_DGQArbitraryNodes<1, 2>>(quad); |
| 1086 |
if constexpr (std::is_same_v<FE, FE_DGQ<1, 3>>) |
| 1087 |
return std::make_unique<FE_DGQArbitraryNodes<1, 3>>(quad); |
| 1088 |
|
| 1089 |
// Specializations for FE_DG. |
| 1090 |
if constexpr (std::is_same_v<FE, FE_DGQ<2>>) |
| 1091 |
return std::make_unique<FE_DGQArbitraryNodes<2>>(quad); |
| 1092 |
if constexpr (std::is_same_v<FE, FE_DGQ<2, 3>>) |
| 1093 |
return std::make_unique<FE_DGQArbitraryNodes<2, 3>>(quad); |
| 1094 |
if constexpr (std::is_same_v<FE, FE_DGQ<3>>) |
| 1095 |
return std::make_unique<FE_DGQArbitraryNodes<3>>(quad); |
| 1096 |
|
| 1097 |
DEAL_II_NOT_IMPLEMENTED(); |
| 1098 |
return nullptr; |
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
namespace internal |
| 1104 |
{ |
| 1105 |
// The following three functions serve to fill the maps from element |
| 1106 |
// names to elements fe_name_map below. The first one exists because |
| 1107 |
// we have finite elements which are not implemented for nonzero |
| 1108 |
// codimension. These should be transferred to the second function |
| 1109 |
// eventually. |
| 1110 |
namespace FEToolsAddFENameHelper |
| 1111 |
{ |
| 1112 |
template <int dim> |
| 1113 |
void |
| 1114 |
fill_no_codim_fe_names( |
| 1115 |
std::map<std::string, std::unique_ptr<const EnableObserverPointer>> |
| 1116 |
&result) |
| 1117 |
{ |
| 1118 |
result["FE_Q_Hierarchical"] = |
| 1119 |
std::make_unique<FETools::FEFactory<FE_Q_Hierarchical<dim>>>(); |
| 1120 |
result["FE_ABF"] = std::make_unique<FETools::FEFactory<FE_ABF<dim>>>(); |
| 1121 |
result["FE_Bernstein"] = |
| 1122 |
std::make_unique<FETools::FEFactory<FE_Bernstein<dim>>>(); |
| 1123 |
result["FE_BDM"] = std::make_unique<FETools::FEFactory<FE_BDM<dim>>>(); |
| 1124 |
result["FE_DGBDM"] = |
| 1125 |
std::make_unique<FETools::FEFactory<FE_DGBDM<dim>>>(); |
| 1126 |
result["FE_DGNedelec"] = |
| 1127 |
std::make_unique<FETools::FEFactory<FE_DGNedelec<dim>>>(); |
| 1128 |
result["FE_DGRaviartThomas"] = |
| 1129 |
std::make_unique<FETools::FEFactory<FE_DGRaviartThomas<dim>>>(); |
| 1130 |
result["FE_RaviartThomas"] = |
| 1131 |
std::make_unique<FETools::FEFactory<FE_RaviartThomas<dim>>>(); |
| 1132 |
result["FE_RaviartThomasNodal"] = |
| 1133 |
std::make_unique<FETools::FEFactory<FE_RaviartThomasNodal<dim>>>(); |
| 1134 |
result["FE_RT_Bubbles"] = |
| 1135 |
std::make_unique<FETools::FEFactory<FE_RT_Bubbles<dim>>>(); |
| 1136 |
result["FE_Nedelec"] = |
| 1137 |
std::make_unique<FETools::FEFactory<FE_Nedelec<dim>>>(); |
| 1138 |
result["FE_NedelecSZ"] = |
| 1139 |
std::make_unique<FETools::FEFactory<FE_NedelecSZ<dim>>>(); |
| 1140 |
result["FE_DGPNonparametric"] = |
| 1141 |
std::make_unique<FETools::FEFactory<FE_DGPNonparametric<dim>>>(); |
| 1142 |
result["FE_DGP"] = std::make_unique<FETools::FEFactory<FE_DGP<dim>>>(); |
| 1143 |
result["FE_DGPMonomial"] = |
| 1144 |
std::make_unique<FETools::FEFactory<FE_DGPMonomial<dim>>>(); |
| 1145 |
result["FE_DGQ"] = std::make_unique<FETools::FEFactory<FE_DGQ<dim>>>(); |
| 1146 |
result["FE_DGQArbitraryNodes"] = |
| 1147 |
std::make_unique<FETools::FEFactory<FE_DGQ<dim>>>(); |
| 1148 |
result["FE_DGQLegendre"] = |
| 1149 |
std::make_unique<FETools::FEFactory<FE_DGQLegendre<dim>>>(); |
| 1150 |
result["FE_DGQHermite"] = |
| 1151 |
std::make_unique<FETools::FEFactory<FE_DGQHermite<dim>>>(); |
| 1152 |
result["FE_FaceQ"] = |
| 1153 |
std::make_unique<FETools::FEFactory<FE_FaceQ<dim>>>(); |
| 1154 |
result["FE_FaceP"] = |
| 1155 |
std::make_unique<FETools::FEFactory<FE_FaceP<dim>>>(); |
| 1156 |
result["FE_Q"] = std::make_unique<FETools::FEFactory<FE_Q<dim>>>(); |
| 1157 |
result["FE_Q_DG0"] = |
| 1158 |
std::make_unique<FETools::FEFactory<FE_Q_DG0<dim>>>(); |
| 1159 |
result["FE_Q_Bubbles"] = |
| 1160 |
std::make_unique<FETools::FEFactory<FE_Q_Bubbles<dim>>>(); |
| 1161 |
result["FE_Q_iso_Q1"] = |
| 1162 |
std::make_unique<FETools::FEFactory<FE_Q_iso_Q1<dim>>>(); |
| 1163 |
result["FE_Nothing"] = |
| 1164 |
std::make_unique<FETools::FEFactory<FE_Nothing<dim>>>(); |
| 1165 |
result["FE_RannacherTurek"] = |
| 1166 |
std::make_unique<FETools::FEFactory<FE_RannacherTurek<dim>>>(); |
| 1167 |
// Simplex finite elements |
| 1168 |
result["FE_SimplexP"] = |
| 1169 |
std::make_unique<FETools::FEFactory<FE_SimplexP<dim>>>(); |
| 1170 |
result["FE_SimplexDGP"] = |
| 1171 |
std::make_unique<FETools::FEFactory<FE_SimplexDGP<dim>>>(); |
| 1172 |
result["FE_SimplexP_Bubbles"] = |
| 1173 |
std::make_unique<FETools::FEFactory<FE_SimplexP_Bubbles<dim>>>(); |
| 1174 |
// Mixed grids finite elements -- only valid in 3d |
| 1175 |
if constexpr (dim == 3) |
| 1176 |
{ |
| 1177 |
result["FE_PyramidP"] = |
| 1178 |
std::make_unique<FETools::FEFactory<FE_PyramidP<dim>>>(); |
| 1179 |
result["FE_PyramidDGP"] = |
| 1180 |
std::make_unique<FETools::FEFactory<FE_PyramidDGP<dim>>>(); |
| 1181 |
result["FE_WedgeP"] = |
| 1182 |
std::make_unique<FETools::FEFactory<FE_WedgeP<dim>>>(); |
| 1183 |
result["FE_WedgeDGP"] = |
| 1184 |
std::make_unique<FETools::FEFactory<FE_WedgeDGP<dim>>>(); |
| 1185 |
} |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
// This function fills a map from names to finite elements for any |
| 1191 |
// dimension and codimension for those elements which support |
| 1192 |
// nonzero codimension. |
| 1193 |
template <int dim, int spacedim> |
| 1194 |
void |
| 1195 |
fill_codim_fe_names( |
| 1196 |
std::map<std::string, std::unique_ptr<const EnableObserverPointer>> |
| 1197 |
&result) |
| 1198 |
{ |
| 1199 |
result["FE_Bernstein"] = |
| 1200 |
std::make_unique<FETools::FEFactory<FE_Bernstein<dim, spacedim>>>(); |
| 1201 |
result["FE_DGP"] = |
| 1202 |
std::make_unique<FETools::FEFactory<FE_DGP<dim, spacedim>>>(); |
| 1203 |
result["FE_DGQ"] = |
| 1204 |
std::make_unique<FETools::FEFactory<FE_DGQ<dim, spacedim>>>(); |
| 1205 |
result["FE_Nothing"] = |
| 1206 |
std::make_unique<FETools::FEFactory<FE_Nothing<dim, spacedim>>>(); |
| 1207 |
result["FE_DGQArbitraryNodes"] = |
| 1208 |
std::make_unique<FETools::FEFactory<FE_DGQ<dim, spacedim>>>(); |
| 1209 |
result["FE_DGQLegendre"] = |
| 1210 |
std::make_unique<FETools::FEFactory<FE_DGQLegendre<dim, spacedim>>>(); |
| 1211 |
result["FE_DGQHermite"] = |
| 1212 |
std::make_unique<FETools::FEFactory<FE_DGQHermite<dim, spacedim>>>(); |
| 1213 |
result["FE_Q_Bubbles"] = |
| 1214 |
std::make_unique<FETools::FEFactory<FE_Q_Bubbles<dim, spacedim>>>(); |
| 1215 |
result["FE_Q_DG0"] = |
| 1216 |
std::make_unique<FETools::FEFactory<FE_Q_DG0<dim, spacedim>>>(); |
| 1217 |
result["FE_Q_iso_Q1"] = |
| 1218 |
std::make_unique<FETools::FEFactory<FE_Q_iso_Q1<dim, spacedim>>>(); |
| 1219 |
result["FE_Q"] = |
| 1220 |
std::make_unique<FETools::FEFactory<FE_Q<dim, spacedim>>>(); |
| 1221 |
result["FE_Bernstein"] = |
| 1222 |
std::make_unique<FETools::FEFactory<FE_Bernstein<dim, spacedim>>>(); |
| 1223 |
result["FE_SimplexP"] = |
| 1224 |
std::make_unique<FETools::FEFactory<FE_SimplexP<dim, spacedim>>>(); |
| 1225 |
result["FE_SimplexDGP"] = |
| 1226 |
std::make_unique<FETools::FEFactory<FE_SimplexDGP<dim, spacedim>>>(); |
| 1227 |
result["FE_SimplexP_Bubbles"] = std::make_unique< |
| 1228 |
FETools::FEFactory<FE_SimplexP_Bubbles<dim, spacedim>>>(); |
| 1229 |
} |
| 1230 |
|
| 1231 |
// The function filling the vector fe_name_map below. It iterates |
| 1232 |
// through all legal dimension/spacedimension pairs and fills |
| 1233 |
// fe_name_map[dimension][spacedimension] with the maps generated |
| 1234 |
// by the functions above. |
| 1235 |
std::array< |
| 1236 |
std::array< |
| 1237 |
std::map<std::string, std::unique_ptr<const EnableObserverPointer>>, |
| 1238 |
4>, |
| 1239 |
4> inline fill_default_map() |
| 1240 |
{ |
| 1241 |
std::array< |
| 1242 |
std::array< |
| 1243 |
std::map<std::string, std::unique_ptr<const EnableObserverPointer>>, |
| 1244 |
4>, |
| 1245 |
4> |
| 1246 |
result; |
| 1247 |
|
| 1248 |
fill_no_codim_fe_names<1>(result[1][1]); |
| 1249 |
fill_no_codim_fe_names<2>(result[2][2]); |
| 1250 |
fill_no_codim_fe_names<3>(result[3][3]); |
| 1251 |
|
| 1252 |
fill_codim_fe_names<1, 2>(result[1][2]); |
| 1253 |
fill_codim_fe_names<1, 3>(result[1][3]); |
| 1254 |
fill_codim_fe_names<2, 3>(result[2][3]); |
| 1255 |
|
| 1256 |
return result; |
| 1257 |
} |
| 1258 |
|
| 1259 |
|
| 1260 |
// Have a lock that guarantees that at most one thread is changing |
| 1261 |
// and accessing the fe_name_map variable. The variable |
| 1262 |
// is declared 'extern' here because we are in a .h file, but |
| 1263 |
// it really needs to be defined in a .cc file (and indeed we have |
| 1264 |
// the definition there). |
| 1265 |
extern std::shared_mutex fe_name_map_lock; |
| 1266 |
|
| 1267 |
// This is the map used by FETools::get_fe_by_name and |
| 1268 |
// FETools::add_fe_name. It is only accessed by functions in this |
| 1269 |
// file, so it is safe to make it a static variable here. It must be |
| 1270 |
// static so that we can link several dimensions together. |
| 1271 |
|
| 1272 |
// The organization of this storage is such that |
| 1273 |
// fe_name_map[dim][spacedim][name] points to an |
| 1274 |
// FEFactoryBase<dim,spacedim> with the name given. Since |
| 1275 |
// all entries of this vector are of different type, we store |
| 1276 |
// pointers to generic objects and cast them when needed. |
| 1277 |
|
| 1278 |
// We use a unique pointer to factory objects, to ensure that they |
| 1279 |
// get deleted at the end of the program run and don't end up as |
| 1280 |
// apparent memory leaks to programs like valgrind. |
| 1281 |
|
| 1282 |
// This vector is initialized at program start time using the |
| 1283 |
// function above. because at this time there are no threads |
| 1284 |
// running, there are no thread-safety issues here. since this is |
| 1285 |
// compiled for all dimensions at once, need to create objects for |
| 1286 |
// each dimension and then separate between them further down |
| 1287 |
inline std::array< |
| 1288 |
std::array< |
| 1289 |
std::map<std::string, std::unique_ptr<const EnableObserverPointer>>, |
| 1290 |
4>, |
| 1291 |
4> & |
| 1292 |
get_fe_name_map() |
| 1293 |
{ |
| 1294 |
static std::array< |
| 1295 |
std::array< |
| 1296 |
std::map<std::string, std::unique_ptr<const EnableObserverPointer>>, |
| 1297 |
4>, |
| 1298 |
4> |
| 1299 |
fe_name_map = fill_default_map(); |
| 1300 |
return fe_name_map; |
| 1301 |
} |
| 1302 |
} // namespace FEToolsAddFENameHelper |
| 1303 |
|
| 1304 |
namespace FEToolsGetInterpolationMatrixHelper |
| 1305 |
{ |
| 1306 |
// forwarder function for |
| 1307 |
// FE::get_interpolation_matrix. we |
| 1308 |
// will want to call that function |
| 1309 |
// for arbitrary FullMatrix<T> |
| 1310 |
// types, but it only accepts |
| 1311 |
// double arguments. since it is a |
| 1312 |
// virtual function, this can also |
| 1313 |
// not be changed. so have a |
| 1314 |
// forwarder function that calls |
| 1315 |
// that function directly if |
| 1316 |
// T==double, and otherwise uses a |
| 1317 |
// temporary |
| 1318 |
template <int dim, int spacedim> |
| 1319 |
inline void |
| 1320 |
gim_forwarder(const FiniteElement<dim, spacedim> &fe1, |
| 1321 |
const FiniteElement<dim, spacedim> &fe2, |
| 1322 |
FullMatrix<double> &interpolation_matrix) |
| 1323 |
{ |
| 1324 |
fe2.get_interpolation_matrix(fe1, interpolation_matrix); |
| 1325 |
} |
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
template <int dim, typename number, int spacedim> |
| 1330 |
inline void |
| 1331 |
gim_forwarder(const FiniteElement<dim, spacedim> &fe1, |
| 1332 |
const FiniteElement<dim, spacedim> &fe2, |
| 1333 |
FullMatrix<number> &interpolation_matrix) |
| 1334 |
{ |
| 1335 |
FullMatrix<double> tmp(interpolation_matrix.m(), |
| 1336 |
interpolation_matrix.n()); |
| 1337 |
fe2.get_interpolation_matrix(fe1, tmp); |
| 1338 |
interpolation_matrix = tmp; |
| 1339 |
} |
| 1340 |
} // namespace FEToolsGetInterpolationMatrixHelper |
| 1341 |
} // namespace internal |
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
template <int dim, int spacedim> |
| 1346 |
void |
| 1347 |
compute_component_wise(const FiniteElement<dim, spacedim> &element, |
| 1348 |
std::vector<unsigned int> &renumbering, |
| 1349 |
std::vector<std::vector<unsigned int>> &comp_start) |
| 1350 |
{ |
| 1351 |
Assert(renumbering.size() == element.n_dofs_per_cell(), |
| 1352 |
ExcDimensionMismatch(renumbering.size(), element.n_dofs_per_cell())); |
| 1353 |
|
| 1354 |
comp_start.resize(element.n_base_elements()); |
| 1355 |
|
| 1356 |
unsigned int index = 0; |
| 1357 |
for (unsigned int i = 0; i < comp_start.size(); ++i) |
| 1358 |
{ |
| 1359 |
comp_start[i].resize(element.element_multiplicity(i)); |
| 1360 |
const unsigned int increment = |
| 1361 |
element.base_element(i).n_dofs_per_cell(); |
| 1362 |
|
| 1363 |
for (unsigned int &first_index_of_component : comp_start[i]) |
| 1364 |
{ |
| 1365 |
first_index_of_component = index; |
| 1366 |
index += increment; |
| 1367 |
} |
| 1368 |
} |
| 1369 |
|
| 1370 |
// For each index i of the |
| 1371 |
// unstructured cellwise |
| 1372 |
// numbering, renumbering |
| 1373 |
// contains the index of the |
| 1374 |
// cell-block numbering |
| 1375 |
for (unsigned int i = 0; i < element.n_dofs_per_cell(); ++i) |
| 1376 |
{ |
| 1377 |
std::pair<std::pair<unsigned int, unsigned int>, unsigned int> indices = |
| 1378 |
element.system_to_base_index(i); |
| 1379 |
renumbering[i] = comp_start[indices.first.first][indices.first.second] + |
| 1380 |
indices.second; |
| 1381 |
} |
| 1382 |
} |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
template <int dim, int spacedim> |
| 1387 |
void |
| 1388 |
compute_block_renumbering(const FiniteElement<dim, spacedim> &element, |
| 1389 |
std::vector<types::global_dof_index> &renumbering, |
| 1390 |
std::vector<types::global_dof_index> &block_data, |
| 1391 |
bool return_start_indices) |
| 1392 |
{ |
| 1393 |
Assert(renumbering.size() == element.n_dofs_per_cell(), |
| 1394 |
ExcDimensionMismatch(renumbering.size(), element.n_dofs_per_cell())); |
| 1395 |
Assert(block_data.size() == element.n_blocks(), |
| 1396 |
ExcDimensionMismatch(block_data.size(), element.n_blocks())); |
| 1397 |
|
| 1398 |
types::global_dof_index k = 0; |
| 1399 |
unsigned int count = 0; |
| 1400 |
for (unsigned int b = 0; b < element.n_base_elements(); ++b) |
| 1401 |
for (unsigned int m = 0; m < element.element_multiplicity(b); ++m) |
| 1402 |
{ |
| 1403 |
block_data[count++] = (return_start_indices) ? |
| 1404 |
k : |
| 1405 |
(element.base_element(b).n_dofs_per_cell()); |
| 1406 |
k += element.base_element(b).n_dofs_per_cell(); |
| 1407 |
} |
| 1408 |
Assert(count == element.n_blocks(), ExcInternalError()); |
| 1409 |
|
| 1410 |
std::vector<types::global_dof_index> start_indices(block_data.size()); |
| 1411 |
k = 0; |
| 1412 |
for (unsigned int i = 0; i < block_data.size(); ++i) |
| 1413 |
if (return_start_indices) |
| 1414 |
start_indices[i] = block_data[i]; |
| 1415 |
else |
| 1416 |
{ |
| 1417 |
start_indices[i] = k; |
| 1418 |
k += block_data[i]; |
| 1419 |
} |
| 1420 |
|
| 1421 |
for (unsigned int i = 0; i < element.n_dofs_per_cell(); ++i) |
| 1422 |
{ |
| 1423 |
std::pair<unsigned int, types::global_dof_index> indices = |
| 1424 |
element.system_to_block_index(i); |
| 1425 |
renumbering[i] = start_indices[indices.first] + indices.second; |
| 1426 |
} |
| 1427 |
} |
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
template <int dim, typename number, int spacedim> |
| 1432 |
void |
| 1433 |
get_interpolation_matrix(const FiniteElement<dim, spacedim> &fe1, |
| 1434 |
const FiniteElement<dim, spacedim> &fe2, |
| 1435 |
FullMatrix<number> &interpolation_matrix) |
| 1436 |
{ |
| 1437 |
Assert(fe1.n_components() == fe2.n_components(), |
| 1438 |
ExcDimensionMismatch(fe1.n_components(), fe2.n_components())); |
| 1439 |
Assert(interpolation_matrix.m() == fe2.n_dofs_per_cell() && |
| 1440 |
interpolation_matrix.n() == fe1.n_dofs_per_cell(), |
| 1441 |
ExcMatrixDimensionMismatch(interpolation_matrix.m(), |
| 1442 |
interpolation_matrix.n(), |
| 1443 |
fe2.n_dofs_per_cell(), |
| 1444 |
fe1.n_dofs_per_cell())); |
| 1445 |
|
| 1446 |
// first try the easy way: maybe the FE wants to implement things itself: |
| 1447 |
try |
| 1448 |
{ |
| 1449 |
internal::FEToolsGetInterpolationMatrixHelper::gim_forwarder( |
| 1450 |
fe1, fe2, interpolation_matrix); |
| 1451 |
return; |
| 1452 |
} |
| 1453 |
catch ( |
| 1454 |
typename FiniteElement<dim, spacedim>::ExcInterpolationNotImplemented &) |
| 1455 |
{ |
| 1456 |
// too bad.... |
| 1457 |
} |
| 1458 |
|
| 1459 |
// uh, so this was not the |
| 1460 |
// case. hm. then do it the hard |
| 1461 |
// way. note that this will only |
| 1462 |
// work if the element is |
| 1463 |
// primitive, so check this first |
| 1464 |
Assert(fe1.is_primitive() == true, ExcFENotPrimitive()); |
| 1465 |
Assert(fe2.is_primitive() == true, ExcFENotPrimitive()); |
| 1466 |
|
| 1467 |
// Initialize FEValues for fe1 at |
| 1468 |
// the unit support points of the |
| 1469 |
// fe2 element. |
| 1470 |
const std::vector<Point<dim>> &fe2_support_points = |
| 1471 |
fe2.get_unit_support_points(); |
| 1472 |
|
| 1473 |
Assert(fe2_support_points.size() == fe2.n_dofs_per_cell(), |
| 1474 |
(typename FiniteElement<dim, spacedim>::ExcFEHasNoSupportPoints())); |
| 1475 |
|
| 1476 |
for (unsigned int i = 0; i < fe2.n_dofs_per_cell(); ++i) |
| 1477 |
{ |
| 1478 |
const unsigned int i1 = fe2.system_to_component_index(i).first; |
| 1479 |
for (unsigned int j = 0; j < fe1.n_dofs_per_cell(); ++j) |
| 1480 |
{ |
| 1481 |
const unsigned int j1 = fe1.system_to_component_index(j).first; |
| 1482 |
if (i1 == j1) |
| 1483 |
interpolation_matrix(i, j) = |
| 1484 |
fe1.shape_value(j, fe2_support_points[i]); |
| 1485 |
else |
| 1486 |
interpolation_matrix(i, j) = 0.; |
| 1487 |
} |
| 1488 |
} |
| 1489 |
} |
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
template <int dim, typename number, int spacedim> |
| 1494 |
void |
| 1495 |
get_back_interpolation_matrix(const FiniteElement<dim, spacedim> &fe1, |
| 1496 |
const FiniteElement<dim, spacedim> &fe2, |
| 1497 |
FullMatrix<number> &interpolation_matrix) |
| 1498 |
{ |
| 1499 |
Assert(fe1.n_components() == fe2.n_components(), |
| 1500 |
ExcDimensionMismatch(fe1.n_components(), fe2.n_components())); |
| 1501 |
Assert(interpolation_matrix.m() == fe1.n_dofs_per_cell() && |
| 1502 |
interpolation_matrix.n() == fe1.n_dofs_per_cell(), |
| 1503 |
ExcMatrixDimensionMismatch(interpolation_matrix.m(), |
| 1504 |
interpolation_matrix.n(), |
| 1505 |
fe1.n_dofs_per_cell(), |
| 1506 |
fe1.n_dofs_per_cell())); |
| 1507 |
|
| 1508 |
FullMatrix<number> first_matrix(fe2.n_dofs_per_cell(), |
| 1509 |
fe1.n_dofs_per_cell()); |
| 1510 |
FullMatrix<number> second_matrix(fe1.n_dofs_per_cell(), |
| 1511 |
fe2.n_dofs_per_cell()); |
| 1512 |
|
| 1513 |
get_interpolation_matrix(fe1, fe2, first_matrix); |
| 1514 |
get_interpolation_matrix(fe2, fe1, second_matrix); |
| 1515 |
|
| 1516 |
// int_matrix=second_matrix*first_matrix |
| 1517 |
second_matrix.mmult(interpolation_matrix, first_matrix); |
| 1518 |
} |
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
template <int dim, typename number, int spacedim> |
| 1523 |
void |
| 1524 |
get_interpolation_difference_matrix(const FiniteElement<dim, spacedim> &fe1, |
| 1525 |
const FiniteElement<dim, spacedim> &fe2, |
| 1526 |
FullMatrix<number> &difference_matrix) |
| 1527 |
{ |
| 1528 |
Assert(fe1.n_components() == fe2.n_components(), |
| 1529 |
ExcDimensionMismatch(fe1.n_components(), fe2.n_components())); |
| 1530 |
Assert(difference_matrix.m() == fe1.n_dofs_per_cell() && |
| 1531 |
difference_matrix.n() == fe1.n_dofs_per_cell(), |
| 1532 |
ExcMatrixDimensionMismatch(difference_matrix.m(), |
| 1533 |
difference_matrix.n(), |
| 1534 |
fe1.n_dofs_per_cell(), |
| 1535 |
fe1.n_dofs_per_cell())); |
| 1536 |
|
| 1537 |
FullMatrix<number> interpolation_matrix(fe1.n_dofs_per_cell()); |
| 1538 |
get_back_interpolation_matrix(fe1, fe2, interpolation_matrix); |
| 1539 |
|
| 1540 |
// compute difference |
| 1541 |
difference_matrix = IdentityMatrix(fe1.n_dofs_per_cell()); |
| 1542 |
difference_matrix.add(-1, interpolation_matrix); |
| 1543 |
} |
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
template <int dim, typename number, int spacedim> |
| 1548 |
void |
| 1549 |
get_projection_matrix(const FiniteElement<dim, spacedim> &fe1, |
| 1550 |
const FiniteElement<dim, spacedim> &fe2, |
| 1551 |
FullMatrix<number> &matrix) |
| 1552 |
{ |
| 1553 |
Assert(matrix.m() == fe2.n_dofs_per_cell() && |
| 1554 |
matrix.n() == fe1.n_dofs_per_cell(), |
| 1555 |
ExcMatrixDimensionMismatch(matrix.m(), |
| 1556 |
matrix.n(), |
| 1557 |
fe2.n_dofs_per_cell(), |
| 1558 |
fe1.n_dofs_per_cell())); |
| 1559 |
AssertDimension(fe1.n_components(), fe2.n_components()); |
| 1560 |
|
| 1561 |
matrix = 0; |
| 1562 |
|
| 1563 |
const unsigned int n1 = fe1.n_dofs_per_cell(); |
| 1564 |
const unsigned int n2 = fe2.n_dofs_per_cell(); |
| 1565 |
const unsigned int nd = fe1.n_components(); |
| 1566 |
|
| 1567 |
const ReferenceCell reference_cell = fe1.reference_cell(); |
| 1568 |
|
| 1569 |
Assert(fe1.reference_cell() == fe2.reference_cell(), ExcNotImplemented()); |
| 1570 |
|
| 1571 |
// First, create a local mass matrix for the unit cell |
| 1572 |
Triangulation<dim, spacedim> tr; |
| 1573 |
GridGenerator::reference_cell(tr, reference_cell); |
| 1574 |
|
| 1575 |
const auto &mapping = |
| 1576 |
reference_cell.template get_default_linear_mapping<dim, spacedim>(); |
| 1577 |
|
| 1578 |
// Choose a Gauss quadrature rule that is exact up to degree 2n-1 |
| 1579 |
const unsigned int degree = |
| 1580 |
std::max(fe1.tensor_degree(), fe2.tensor_degree()); |
| 1581 |
Assert(degree != numbers::invalid_unsigned_int, ExcNotImplemented()); |
| 1582 |
const auto quadrature = |
| 1583 |
reference_cell.get_gauss_type_quadrature<dim>(degree + 1); |
| 1584 |
|
| 1585 |
const unsigned int nq = quadrature.size(); |
| 1586 |
|
| 1587 |
// Set up FEValues. |
| 1588 |
const UpdateFlags flags = |
| 1589 |
update_values | update_quadrature_points | update_JxW_values; |
| 1590 |
FEValues<dim> val1(mapping, fe1, quadrature, update_values); |
| 1591 |
val1.reinit(tr.begin_active()); |
| 1592 |
|
| 1593 |
FEValues<dim> val2(mapping, fe2, quadrature, flags); |
| 1594 |
val2.reinit(tr.begin_active()); |
| 1595 |
|
| 1596 |
// Integrate and invert mass matrix. This happens in the target space |
| 1597 |
FullMatrix<double> mass(n2, n2); |
| 1598 |
|
| 1599 |
for (unsigned int i = 0; i < n2; ++i) |
| 1600 |
for (unsigned int j = 0; j < n2; ++j) |
| 1601 |
for (unsigned int d = 0; d < nd; ++d) |
| 1602 |
for (unsigned int k = 0; k < nq; ++k) |
| 1603 |
mass(i, j) += val2.JxW(k) * val2.shape_value_component(i, k, d) * |
| 1604 |
val2.shape_value_component(j, k, d); |
| 1605 |
|
| 1606 |
// Invert the matrix. Gauss-Jordan should be sufficient since we expect |
| 1607 |
// the mass matrix to be well-conditioned |
| 1608 |
mass.gauss_jordan(); |
| 1609 |
|
| 1610 |
// Now, test every function of fe1 with test functions of fe2 and |
| 1611 |
// compute the projection of each unit vector. |
| 1612 |
Vector<double> b(n2); |
| 1613 |
Vector<double> x(n2); |
| 1614 |
|
| 1615 |
for (unsigned int j = 0; j < n1; ++j) |
| 1616 |
{ |
| 1617 |
b = 0.; |
| 1618 |
for (unsigned int i = 0; i < n2; ++i) |
| 1619 |
for (unsigned int k = 0; k < quadrature.size(); ++k) |
| 1620 |
for (unsigned int d = 0; d < nd; ++d) |
| 1621 |
b(i) += val1.shape_value_component(j, k, d) * |
| 1622 |
val2.shape_value_component(i, k, d) * val2.JxW(k); |
| 1623 |
|
| 1624 |
// Multiply by the inverse |
| 1625 |
mass.vmult(x, b); |
| 1626 |
for (unsigned int i = 0; i < n2; ++i) |
| 1627 |
matrix(i, j) = x(i); |
| 1628 |
} |
| 1629 |
} |
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
template <int dim, int spacedim> |
| 1634 |
FullMatrix<double> |
| 1635 |
compute_node_matrix(const FiniteElement<dim, spacedim> &fe) |
| 1636 |
{ |
| 1637 |
const unsigned int n_dofs = fe.n_dofs_per_cell(); |
| 1638 |
|
| 1639 |
FullMatrix<double> N(n_dofs, n_dofs); |
| 1640 |
|
| 1641 |
Assert(fe.has_generalized_support_points(), ExcNotInitialized()); |
| 1642 |
Assert(fe.n_components() == dim, ExcNotImplemented()); |
| 1643 |
|
| 1644 |
const std::vector<Point<dim>> &points = fe.get_generalized_support_points(); |
| 1645 |
|
| 1646 |
// We need the values of the polynomials in all generalized support |
| 1647 |
// points. This function specifically works for the case where shape |
| 1648 |
// functions have 'dim' vector components, so allocate that much space |
| 1649 |
std::vector<Vector<double>> support_point_values(points.size(), |
| 1650 |
Vector<double>(dim)); |
| 1651 |
|
| 1652 |
// In this vector, we store the |
| 1653 |
// result of the interpolation |
| 1654 |
std::vector<double> nodal_values(n_dofs); |
| 1655 |
|
| 1656 |
// Get the values of each shape function in turn. Remember that these |
| 1657 |
// are the 'raw' shape functions (i.e., where the element has not yet |
| 1658 |
// computed the expansion coefficients with regard to the basis |
| 1659 |
// provided by the polynomial space). |
| 1660 |
for (unsigned int i = 0; i < n_dofs; ++i) |
| 1661 |
{ |
| 1662 |
// get the values of the current set of shape functions |
| 1663 |
// at the generalized support points |
| 1664 |
for (unsigned int k = 0; k < points.size(); ++k) |
| 1665 |
for (unsigned int d = 0; d < dim; ++d) |
| 1666 |
{ |
| 1667 |
support_point_values[k][d] = |
| 1668 |
fe.shape_value_component(i, points[k], d); |
| 1669 |
Assert(numbers::is_finite(support_point_values[k][d]), |
| 1670 |
ExcInternalError()); |
| 1671 |
} |
| 1672 |
|
| 1673 |
fe.convert_generalized_support_point_values_to_dof_values( |
| 1674 |
support_point_values, nodal_values); |
| 1675 |
|
| 1676 |
// Enter the interpolated dofs into the matrix |
| 1677 |
for (unsigned int j = 0; j < n_dofs; ++j) |
| 1678 |
{ |
| 1679 |
N(j, i) = nodal_values[j]; |
| 1680 |
Assert(numbers::is_finite(nodal_values[j]), ExcInternalError()); |
| 1681 |
} |
| 1682 |
} |
| 1683 |
|
| 1684 |
return N; |
| 1685 |
} |
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
template <int dim, typename number, int spacedim> |
| 1690 |
void |
| 1691 |
compute_embedding_matrices( |
| 1692 |
const FiniteElement<dim, spacedim> &fe, |
| 1693 |
std::vector<std::vector<FullMatrix<number>>> &matrices, |
| 1694 |
const bool isotropic_only, |
| 1695 |
const double threshold) |
| 1696 |
{ |
| 1697 |
// loop over all possible refinement cases |
| 1698 |
unsigned int ref_case_start, ref_case_end; |
| 1699 |
|
| 1700 |
if (fe.reference_cell() == ReferenceCells::Tetrahedron) |
| 1701 |
{ |
| 1702 |
ref_case_start = |
| 1703 |
static_cast<unsigned int>(IsotropicRefinementChoice::cut_tet_68); |
| 1704 |
ref_case_end = |
| 1705 |
static_cast<unsigned int>(IsotropicRefinementChoice::cut_tet_49); |
| 1706 |
} |
| 1707 |
else |
| 1708 |
{ |
| 1709 |
ref_case_start = isotropic_only ? |
| 1710 |
RefinementCase<dim>::isotropic_refinement : |
| 1711 |
RefinementCase<dim>::cut_x; |
| 1712 |
ref_case_end = RefinementCase<dim>::isotropic_refinement; |
| 1713 |
} |
| 1714 |
for (unsigned int ref_case = ref_case_start; ref_case <= ref_case_end; |
| 1715 |
++ref_case) |
| 1716 |
{ |
| 1717 |
const unsigned int n = fe.n_dofs_per_cell(); |
| 1718 |
const ReferenceCell reference_cell = fe.reference_cell(); |
| 1719 |
const unsigned int nc = |
| 1720 |
reference_cell.n_children(RefinementCase<dim>(ref_case)); |
| 1721 |
|
| 1722 |
AssertDimension(matrices[ref_case - 1].size(), nc); |
| 1723 |
|
| 1724 |
for (unsigned int i = 0; i < nc; ++i) |
| 1725 |
{ |
| 1726 |
AssertDimension(matrices[ref_case - 1][i].n(), n); |
| 1727 |
AssertDimension(matrices[ref_case - 1][i].m(), n); |
| 1728 |
} |
| 1729 |
|
| 1730 |
// Set up meshes, one with a single |
| 1731 |
// reference cell and refine it once |
| 1732 |
Triangulation<dim, spacedim> tria; |
| 1733 |
GridGenerator::reference_cell(tria, reference_cell); |
| 1734 |
if (reference_cell == ReferenceCells::Tetrahedron) |
| 1735 |
{ |
| 1736 |
tria.begin_active()->set_refine_flag( |
| 1737 |
RefinementCase<dim>::isotropic_refinement); |
| 1738 |
tria.begin_active()->set_refine_choice(ref_case); |
| 1739 |
} |
| 1740 |
else |
| 1741 |
tria.begin_active()->set_refine_flag(RefinementCase<dim>(ref_case)); |
| 1742 |
tria.execute_coarsening_and_refinement(); |
| 1743 |
|
| 1744 |
const unsigned int degree = fe.degree; |
| 1745 |
|
| 1746 |
const auto &mapping = |
| 1747 |
reference_cell.template get_default_linear_mapping<dim, spacedim>(); |
| 1748 |
const auto &q_fine = |
| 1749 |
reference_cell.get_gauss_type_quadrature<dim>(degree + 1); |
| 1750 |
const unsigned int nq = q_fine.size(); |
| 1751 |
|
| 1752 |
FEValues<dim, spacedim> fine(mapping, |
| 1753 |
fe, |
| 1754 |
q_fine, |
| 1755 |
update_quadrature_points | |
| 1756 |
update_JxW_values | update_values); |
| 1757 |
|
| 1758 |
// We search for the polynomial on the small cell, being equal to the |
| 1759 |
// coarse polynomial in all quadrature points. |
| 1760 |
|
| 1761 |
// First build the matrix for this least squares problem. This |
| 1762 |
// contains the values of the fine cell polynomials in the fine cell |
| 1763 |
// grid points. |
| 1764 |
|
| 1765 |
// This matrix is the same for all |
| 1766 |
// children. |
| 1767 |
fine.reinit(tria.begin_active()); |
| 1768 |
const unsigned int nd = fe.n_components(); |
| 1769 |
FullMatrix<number> A(nq * nd, n); |
| 1770 |
|
| 1771 |
for (unsigned int j = 0; j < n; ++j) |
| 1772 |
for (unsigned int d = 0; d < nd; ++d) |
| 1773 |
for (unsigned int k = 0; k < nq; ++k) |
| 1774 |
A(k * nd + d, j) = fine.shape_value_component(j, k, d); |
| 1775 |
|
| 1776 |
Householder<double> H(A); |
| 1777 |
|
| 1778 |
for (const auto &fine_cell : tria.active_cell_iterators()) |
| 1779 |
{ |
| 1780 |
fine.reinit(fine_cell); |
| 1781 |
|
| 1782 |
// evaluate on the coarse cell (which is the first -- inactive -- |
| 1783 |
// cell on the lowest level of the triangulation we have created) |
| 1784 |
|
| 1785 |
// TODO: Convert this to FEPointEvaluation |
| 1786 |
const std::vector<Point<spacedim>> &q_points_fine = |
| 1787 |
fine.get_quadrature_points(); |
| 1788 |
std::vector<Point<dim>> q_points_coarse(q_points_fine.size()); |
| 1789 |
for (unsigned int i = 0; i < q_points_fine.size(); ++i) |
| 1790 |
for (unsigned int j = 0; j < dim; ++j) |
| 1791 |
q_points_coarse[i][j] = q_points_fine[i][j]; |
| 1792 |
const Quadrature<dim> q_coarse(q_points_coarse, |
| 1793 |
fine.get_JxW_values()); |
| 1794 |
FEValues<dim, spacedim> coarse(mapping, |
| 1795 |
fe, |
| 1796 |
q_coarse, |
| 1797 |
update_values); |
| 1798 |
|
| 1799 |
coarse.reinit(tria.begin(0)); |
| 1800 |
|
| 1801 |
FullMatrix<double> &this_matrix = |
| 1802 |
matrices[ref_case - 1][fine_cell->active_cell_index()]; |
| 1803 |
|
| 1804 |
// Compute this once for each coarse grid basis function. |
| 1805 |
|
| 1806 |
Vector<double> v_coarse(nq * nd); |
| 1807 |
Vector<double> v_fine(n); |
| 1808 |
|
| 1809 |
for (unsigned int i = 0; i < n; ++i) |
| 1810 |
{ |
| 1811 |
// The right hand side of the least squares problem consists |
| 1812 |
// of the function values of the coarse grid function in each |
| 1813 |
// quadrature point. |
| 1814 |
if (fe.is_primitive()) |
| 1815 |
{ |
| 1816 |
const unsigned int d = |
| 1817 |
fe.system_to_component_index(i).first; |
| 1818 |
const double *phi_i = &coarse.shape_value(i, 0); |
| 1819 |
|
| 1820 |
for (unsigned int k = 0; k < nq; ++k) |
| 1821 |
v_coarse(k * nd + d) = phi_i[k]; |
| 1822 |
} |
| 1823 |
|
| 1824 |
else |
| 1825 |
for (unsigned int d = 0; d < nd; ++d) |
| 1826 |
for (unsigned int k = 0; k < nq; ++k) |
| 1827 |
v_coarse(k * nd + d) = |
| 1828 |
coarse.shape_value_component(i, k, d); |
| 1829 |
|
| 1830 |
// solve the least squares problem. |
| 1831 |
const double result = H.least_squares(v_fine, v_coarse); |
| 1832 |
Assert(result <= threshold, |
| 1833 |
FETools::ExcLeastSquaresError(result)); |
| 1834 |
(void)result; |
| 1835 |
(void)threshold; |
| 1836 |
|
| 1837 |
for (unsigned int j = 0; j < n; ++j) |
| 1838 |
this_matrix(j, i) = v_fine(j); |
| 1839 |
} |
| 1840 |
|
| 1841 |
// Remove small entries from the matrix |
| 1842 |
for (unsigned int i = 0; i < this_matrix.m(); ++i) |
| 1843 |
for (unsigned int j = 0; j < this_matrix.n(); ++j) |
| 1844 |
if (std::fabs(this_matrix(i, j)) < 1e-12) |
| 1845 |
this_matrix(i, j) = 0.; |
| 1846 |
} |
| 1847 |
} |
| 1848 |
} |
| 1849 |
|
| 1850 |
|
| 1851 |
template <int dim, typename number, int spacedim> |
| 1852 |
void |
| 1853 |
compute_face_embedding_matrices(const FiniteElement<dim, spacedim> &fe, |
| 1854 |
const ArrayView<FullMatrix<number>> &matrices, |
| 1855 |
const unsigned int face_coarse, |
| 1856 |
const unsigned int face_fine, |
| 1857 |
const double threshold) |
| 1858 |
{ |
| 1859 |
AssertDimension(matrices.size(), GeometryInfo<dim>::max_children_per_face); |
| 1860 |
const unsigned int face_no = face_coarse; |
| 1861 |
|
| 1862 |
Assert(face_coarse == 0, ExcNotImplemented()); |
| 1863 |
Assert(face_fine == 0, ExcNotImplemented()); |
| 1864 |
|
| 1865 |
const unsigned int nc = GeometryInfo<dim>::max_children_per_face; |
| 1866 |
const unsigned int n = fe.n_dofs_per_face(face_no); |
| 1867 |
const unsigned int nd = fe.n_components(); |
| 1868 |
const unsigned int degree = fe.degree; |
| 1869 |
|
| 1870 |
const bool normal = fe.conforms(FiniteElementData<dim>::Hdiv); |
| 1871 |
const bool tangential = fe.conforms(FiniteElementData<dim>::Hcurl); |
| 1872 |
|
| 1873 |
for (unsigned int i = 0; i < nc; ++i) |
| 1874 |
{ |
| 1875 |
Assert(matrices[i].n() == n, ExcDimensionMismatch(matrices[i].n(), n)); |
| 1876 |
Assert(matrices[i].m() == n, ExcDimensionMismatch(matrices[i].m(), n)); |
| 1877 |
} |
| 1878 |
|
| 1879 |
// In order to make the loops below |
| 1880 |
// simpler, we introduce vectors |
| 1881 |
// containing for indices 0-n the |
| 1882 |
// number of the corresponding |
| 1883 |
// shape value on the cell. |
| 1884 |
std::vector<unsigned int> face_c_dofs(n); |
| 1885 |
std::vector<unsigned int> face_f_dofs(n); |
| 1886 |
{ |
| 1887 |
unsigned int face_dof = 0; |
| 1888 |
for (unsigned int i = 0; |
| 1889 |
i < fe.reference_cell().face_reference_cell(face_no).n_vertices(); |
| 1890 |
++i) |
| 1891 |
{ |
| 1892 |
const unsigned int offset_c = |
| 1893 |
GeometryInfo<dim>::face_to_cell_vertices(face_coarse, i) * |
| 1894 |
fe.n_dofs_per_vertex(); |
| 1895 |
const unsigned int offset_f = |
| 1896 |
GeometryInfo<dim>::face_to_cell_vertices(face_fine, i) * |
| 1897 |
fe.n_dofs_per_vertex(); |
| 1898 |
for (unsigned int j = 0; j < fe.n_dofs_per_vertex(); ++j) |
| 1899 |
{ |
| 1900 |
face_c_dofs[face_dof] = offset_c + j; |
| 1901 |
face_f_dofs[face_dof] = offset_f + j; |
| 1902 |
++face_dof; |
| 1903 |
} |
| 1904 |
} |
| 1905 |
|
| 1906 |
for (unsigned int i = 1; |
| 1907 |
i <= fe.reference_cell().face_reference_cell(face_no).n_lines(); |
| 1908 |
++i) |
| 1909 |
{ |
| 1910 |
const unsigned int offset_c = |
| 1911 |
fe.get_first_line_index() + |
| 1912 |
GeometryInfo<dim>::face_to_cell_lines(face_coarse, i - 1) * |
| 1913 |
fe.n_dofs_per_line(); |
| 1914 |
const unsigned int offset_f = |
| 1915 |
fe.get_first_line_index() + |
| 1916 |
GeometryInfo<dim>::face_to_cell_lines(face_fine, i - 1) * |
| 1917 |
fe.n_dofs_per_line(); |
| 1918 |
for (unsigned int j = 0; j < fe.n_dofs_per_line(); ++j) |
| 1919 |
{ |
| 1920 |
face_c_dofs[face_dof] = offset_c + j; |
| 1921 |
face_f_dofs[face_dof] = offset_f + j; |
| 1922 |
++face_dof; |
| 1923 |
} |
| 1924 |
} |
| 1925 |
|
| 1926 |
if (dim == 3) |
| 1927 |
{ |
| 1928 |
const unsigned int offset_c = fe.get_first_quad_index(face_coarse); |
| 1929 |
const unsigned int offset_f = fe.get_first_quad_index(face_fine); |
| 1930 |
for (unsigned int j = 0; j < fe.n_dofs_per_quad(face_no); ++j) |
| 1931 |
{ |
| 1932 |
face_c_dofs[face_dof] = offset_c + j; |
| 1933 |
face_f_dofs[face_dof] = offset_f + j; |
| 1934 |
++face_dof; |
| 1935 |
} |
| 1936 |
} |
| 1937 |
Assert(face_dof == fe.n_dofs_per_face(face_no), ExcInternalError()); |
| 1938 |
} |
| 1939 |
|
| 1940 |
// Set up meshes, one with a single |
| 1941 |
// reference cell and refine it once |
| 1942 |
Triangulation<dim, spacedim> tria; |
| 1943 |
GridGenerator::hyper_cube(tria, 0, 1); |
| 1944 |
tria.refine_global(1); |
| 1945 |
MappingCartesian<dim> mapping; |
| 1946 |
|
| 1947 |
// Setup quadrature and FEValues |
| 1948 |
// for a face. We cannot use |
| 1949 |
// FEFaceValues and |
| 1950 |
// FESubfaceValues because of |
| 1951 |
// some nifty handling of |
| 1952 |
// refinement cases. Guido stops |
| 1953 |
// disliking and instead starts |
| 1954 |
// hating the anisotropic implementation |
| 1955 |
QGauss<dim - 1> q_gauss(degree + 1); |
| 1956 |
const Quadrature<dim> q_fine = |
| 1957 |
QProjector<dim>::project_to_face(fe.reference_cell(), |
| 1958 |
q_gauss, |
| 1959 |
face_fine, |
| 1960 |
numbers::default_geometric_orientation); |
| 1961 |
const unsigned int nq = q_fine.size(); |
| 1962 |
|
| 1963 |
FEValues<dim> fine(mapping, |
| 1964 |
fe, |
| 1965 |
q_fine, |
| 1966 |
update_quadrature_points | update_JxW_values | |
| 1967 |
update_values); |
| 1968 |
|
| 1969 |
// We search for the polynomial on |
| 1970 |
// the small cell, being equal to |
| 1971 |
// the coarse polynomial in all |
| 1972 |
// quadrature points. |
| 1973 |
|
| 1974 |
// First build the matrix for this |
| 1975 |
// least squares problem. This |
| 1976 |
// contains the values of the fine |
| 1977 |
// cell polynomials in the fine |
| 1978 |
// cell grid points. |
| 1979 |
|
| 1980 |
// This matrix is the same for all |
| 1981 |
// children. |
| 1982 |
fine.reinit(tria.begin_active()); |
| 1983 |
FullMatrix<number> A(nq * nd, n); |
| 1984 |
for (unsigned int j = 0; j < n; ++j) |
| 1985 |
for (unsigned int k = 0; k < nq; ++k) |
| 1986 |
if (nd != dim) |
| 1987 |
for (unsigned int d = 0; d < nd; ++d) |
| 1988 |
A(k * nd + d, j) = fine.shape_value_component(face_f_dofs[j], k, d); |
| 1989 |
else |
| 1990 |
{ |
| 1991 |
if (normal) |
| 1992 |
A(k * nd, j) = fine.shape_value_component(face_f_dofs[j], k, 0); |
| 1993 |
if (tangential) |
| 1994 |
for (unsigned int d = 1; d < dim; ++d) |
| 1995 |
A(k * nd + d, j) = |
| 1996 |
fine.shape_value_component(face_f_dofs[j], k, d); |
| 1997 |
} |
| 1998 |
|
| 1999 |
Householder<double> H(A); |
| 2000 |
|
| 2001 |
Vector<number> v_coarse(nq * nd); |
| 2002 |
Vector<number> v_fine(n); |
| 2003 |
|
| 2004 |
|
| 2005 |
for (unsigned int cell_number = 0; |
| 2006 |
cell_number < GeometryInfo<dim>::max_children_per_face; |
| 2007 |
++cell_number) |
| 2008 |
{ |
| 2009 |
const Quadrature<dim> q_coarse = QProjector<dim>::project_to_subface( |
| 2010 |
fe.reference_cell(), |
| 2011 |
q_gauss, |
| 2012 |
face_coarse, |
| 2013 |
cell_number, |
| 2014 |
numbers::default_geometric_orientation, |
| 2015 |
RefinementCase<dim - 1>::isotropic_refinement); |
| 2016 |
FEValues<dim> coarse(mapping, fe, q_coarse, update_values); |
| 2017 |
|
| 2018 |
typename Triangulation<dim, spacedim>::active_cell_iterator fine_cell = |
| 2019 |
tria.begin(0)->child(GeometryInfo<dim>::child_cell_on_face( |
| 2020 |
tria.begin(0)->refinement_case(), face_coarse, cell_number)); |
| 2021 |
fine.reinit(fine_cell); |
| 2022 |
coarse.reinit(tria.begin(0)); |
| 2023 |
|
| 2024 |
FullMatrix<double> &this_matrix = matrices[cell_number]; |
| 2025 |
|
| 2026 |
// Compute this once for each |
| 2027 |
// coarse grid basis function |
| 2028 |
for (unsigned int i = 0; i < n; ++i) |
| 2029 |
{ |
| 2030 |
// The right hand side of |
| 2031 |
// the least squares |
| 2032 |
// problem consists of the |
| 2033 |
// function values of the |
| 2034 |
// coarse grid function in |
| 2035 |
// each quadrature point. |
| 2036 |
for (unsigned int k = 0; k < nq; ++k) |
| 2037 |
if (nd != dim) |
| 2038 |
for (unsigned int d = 0; d < nd; ++d) |
| 2039 |
v_coarse(k * nd + d) = |
| 2040 |
coarse.shape_value_component(face_c_dofs[i], k, d); |
| 2041 |
else |
| 2042 |
{ |
| 2043 |
if (normal) |
| 2044 |
v_coarse(k * nd) = |
| 2045 |
coarse.shape_value_component(face_c_dofs[i], k, 0); |
| 2046 |
if (tangential) |
| 2047 |
for (unsigned int d = 1; d < dim; ++d) |
| 2048 |
v_coarse(k * nd + d) = |
| 2049 |
coarse.shape_value_component(face_c_dofs[i], k, d); |
| 2050 |
} |
| 2051 |
// solve the least squares |
| 2052 |
// problem. |
| 2053 |
const double result = H.least_squares(v_fine, v_coarse); |
| 2054 |
Assert(result <= threshold, FETools::ExcLeastSquaresError(result)); |
| 2055 |
// Avoid compiler warnings in Release mode |
| 2056 |
(void)result; |
| 2057 |
(void)threshold; |
| 2058 |
|
| 2059 |
// Copy into the result |
| 2060 |
// matrix. Since the matrix |
| 2061 |
// maps a coarse grid |
| 2062 |
// function to a fine grid |
| 2063 |
// function, the columns |
| 2064 |
// are fine grid. |
| 2065 |
for (unsigned int j = 0; j < n; ++j) |
| 2066 |
this_matrix(j, i) = v_fine(j); |
| 2067 |
} |
| 2068 |
// Remove small entries from |
| 2069 |
// the matrix |
| 2070 |
for (unsigned int i = 0; i < this_matrix.m(); ++i) |
| 2071 |
for (unsigned int j = 0; j < this_matrix.n(); ++j) |
| 2072 |
if (std::fabs(this_matrix(i, j)) < 1e-12) |
| 2073 |
this_matrix(i, j) = 0.; |
| 2074 |
} |
| 2075 |
} |
| 2076 |
|
| 2077 |
|
| 2078 |
template <int dim, typename number, int spacedim> |
| 2079 |
void |
| 2080 |
compute_projection_matrices( |
| 2081 |
const FiniteElement<dim, spacedim> &fe, |
| 2082 |
std::vector<std::vector<FullMatrix<number>>> &matrices, |
| 2083 |
const bool isotropic_only) |
| 2084 |
{ |
| 2085 |
const unsigned int n = fe.n_dofs_per_cell(); |
| 2086 |
const unsigned int nd = fe.n_components(); |
| 2087 |
const unsigned int degree = fe.degree; |
| 2088 |
|
| 2089 |
const ReferenceCell reference_cell = fe.reference_cell(); |
| 2090 |
|
| 2091 |
const auto &mapping = |
| 2092 |
reference_cell.template get_default_linear_mapping<dim, spacedim>(); |
| 2093 |
const auto &q_fine = |
| 2094 |
reference_cell.get_gauss_type_quadrature<dim>(degree + 1); |
| 2095 |
|
| 2096 |
// prepare FEValues, quadrature etc on |
| 2097 |
// coarse cell |
| 2098 |
const unsigned int nq = q_fine.size(); |
| 2099 |
|
| 2100 |
// create mass matrix on coarse cell. |
| 2101 |
FullMatrix<number> mass(n, n); |
| 2102 |
{ |
| 2103 |
// set up a triangulation for coarse cell |
| 2104 |
Triangulation<dim, spacedim> tr; |
| 2105 |
GridGenerator::reference_cell(tr, reference_cell); |
| 2106 |
|
| 2107 |
FEValues<dim, spacedim> coarse(mapping, |
| 2108 |
fe, |
| 2109 |
q_fine, |
| 2110 |
update_JxW_values | update_values); |
| 2111 |
|
| 2112 |
typename Triangulation<dim, spacedim>::cell_iterator coarse_cell = |
| 2113 |
tr.begin(0); |
| 2114 |
coarse.reinit(coarse_cell); |
| 2115 |
|
| 2116 |
const std::vector<double> &JxW = coarse.get_JxW_values(); |
| 2117 |
for (unsigned int i = 0; i < n; ++i) |
| 2118 |
for (unsigned int j = 0; j < n; ++j) |
| 2119 |
if (fe.is_primitive()) |
| 2120 |
{ |
| 2121 |
const double *coarse_i = &coarse.shape_value(i, 0); |
| 2122 |
const double *coarse_j = &coarse.shape_value(j, 0); |
| 2123 |
double mass_ij = 0; |
| 2124 |
for (unsigned int k = 0; k < nq; ++k) |
| 2125 |
mass_ij += JxW[k] * coarse_i[k] * coarse_j[k]; |
| 2126 |
mass(i, j) = mass_ij; |
| 2127 |
} |
| 2128 |
else |
| 2129 |
{ |
| 2130 |
double mass_ij = 0; |
| 2131 |
for (unsigned int d = 0; d < nd; ++d) |
| 2132 |
for (unsigned int k = 0; k < nq; ++k) |
| 2133 |
mass_ij += JxW[k] * coarse.shape_value_component(i, k, d) * |
| 2134 |
coarse.shape_value_component(j, k, d); |
| 2135 |
mass(i, j) = mass_ij; |
| 2136 |
} |
| 2137 |
|
| 2138 |
// invert mass matrix |
| 2139 |
mass.gauss_jordan(); |
| 2140 |
} |
| 2141 |
|
| 2142 |
// finally loop over all possible refinement cases |
| 2143 |
unsigned int ref_case_start, ref_case_end; |
| 2144 |
if (reference_cell == ReferenceCells::Tetrahedron) |
| 2145 |
{ |
| 2146 |
ref_case_start = |
| 2147 |
static_cast<unsigned int>(IsotropicRefinementChoice::cut_tet_68); |
| 2148 |
ref_case_end = |
| 2149 |
static_cast<unsigned int>(IsotropicRefinementChoice::cut_tet_49); |
| 2150 |
} |
| 2151 |
else |
| 2152 |
{ |
| 2153 |
ref_case_start = |
| 2154 |
(isotropic_only ? RefinementCase<dim>::isotropic_refinement : |
| 2155 |
RefinementCase<dim>::cut_x); |
| 2156 |
ref_case_end = RefinementCase<dim>::isotropic_refinement; |
| 2157 |
} |
| 2158 |
|
| 2159 |
for (unsigned int ref_case = ref_case_start; ref_case <= ref_case_end; |
| 2160 |
++ref_case) |
| 2161 |
{ |
| 2162 |
const unsigned int nc = |
| 2163 |
reference_cell.n_children(RefinementCase<dim>(ref_case)); |
| 2164 |
|
| 2165 |
for (unsigned int i = 0; i < nc; ++i) |
| 2166 |
{ |
| 2167 |
AssertDimension(matrices[ref_case - 1][i].n(), n); |
| 2168 |
AssertDimension(matrices[ref_case - 1][i].m(), n); |
| 2169 |
} |
| 2170 |
|
| 2171 |
// create a respective refinement on the triangulation |
| 2172 |
Triangulation<dim, spacedim> tr; |
| 2173 |
GridGenerator::reference_cell(tr, reference_cell); |
| 2174 |
|
| 2175 |
if (reference_cell == ReferenceCells::Tetrahedron) |
| 2176 |
{ |
| 2177 |
tr.begin_active()->set_refine_flag( |
| 2178 |
RefinementCase<dim>::isotropic_refinement); |
| 2179 |
tr.begin_active()->set_refine_choice(ref_case); |
| 2180 |
} |
| 2181 |
else |
| 2182 |
tr.begin_active()->set_refine_flag(RefinementCase<dim>(ref_case)); |
| 2183 |
tr.execute_coarsening_and_refinement(); |
| 2184 |
|
| 2185 |
FEValues<dim, spacedim> fine(mapping, |
| 2186 |
fe, |
| 2187 |
q_fine, |
| 2188 |
update_quadrature_points | |
| 2189 |
update_JxW_values | update_values); |
| 2190 |
|
| 2191 |
typename Triangulation<dim, spacedim>::cell_iterator coarse_cell = |
| 2192 |
tr.begin(0); |
| 2193 |
|
| 2194 |
Vector<number> v_coarse(n); |
| 2195 |
Vector<number> v_fine(n); |
| 2196 |
|
| 2197 |
for (unsigned int cell_number = 0; cell_number < nc; ++cell_number) |
| 2198 |
{ |
| 2199 |
FullMatrix<double> &this_matrix = |
| 2200 |
matrices[ref_case - 1][cell_number]; |
| 2201 |
|
| 2202 |
// Compute right hand side, which is a fine level basis |
| 2203 |
// function tested with the coarse level functions. |
| 2204 |
fine.reinit(coarse_cell->child(cell_number)); |
| 2205 |
const std::vector<Point<spacedim>> &q_points_fine = |
| 2206 |
fine.get_quadrature_points(); |
| 2207 |
std::vector<Point<dim>> q_points_coarse(q_points_fine.size()); |
| 2208 |
for (unsigned int q = 0; q < q_points_fine.size(); ++q) |
| 2209 |
for (unsigned int j = 0; j < dim; ++j) |
| 2210 |
q_points_coarse[q][j] = q_points_fine[q][j]; |
| 2211 |
Quadrature<dim> q_coarse(q_points_coarse, fine.get_JxW_values()); |
| 2212 |
FEValues<dim, spacedim> coarse( |
| 2213 |
coarse_cell->reference_cell() |
| 2214 |
.template get_default_linear_mapping<dim, spacedim>(), |
| 2215 |
fe, |
| 2216 |
q_coarse, |
| 2217 |
update_values); |
| 2218 |
coarse.reinit(coarse_cell); |
| 2219 |
|
| 2220 |
// Build RHS |
| 2221 |
|
| 2222 |
const std::vector<double> &JxW = fine.get_JxW_values(); |
| 2223 |
|
| 2224 |
// Outer loop over all fine grid shape functions phi_j |
| 2225 |
for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j) |
| 2226 |
{ |
| 2227 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2228 |
{ |
| 2229 |
if (fe.is_primitive()) |
| 2230 |
{ |
| 2231 |
const double *coarse_i = &coarse.shape_value(i, 0); |
| 2232 |
const double *fine_j = &fine.shape_value(j, 0); |
| 2233 |
|
| 2234 |
double update = 0; |
| 2235 |
for (unsigned int k = 0; k < nq; ++k) |
| 2236 |
update += JxW[k] * coarse_i[k] * fine_j[k]; |
| 2237 |
v_fine(i) = update; |
| 2238 |
} |
| 2239 |
else |
| 2240 |
{ |
| 2241 |
double update = 0; |
| 2242 |
for (unsigned int d = 0; d < nd; ++d) |
| 2243 |
for (unsigned int k = 0; k < nq; ++k) |
| 2244 |
update += JxW[k] * |
| 2245 |
coarse.shape_value_component(i, k, d) * |
| 2246 |
fine.shape_value_component(j, k, d); |
| 2247 |
v_fine(i) = update; |
| 2248 |
} |
| 2249 |
} |
| 2250 |
|
| 2251 |
// RHS ready. Solve system and enter row into matrix |
| 2252 |
mass.vmult(v_coarse, v_fine); |
| 2253 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2254 |
this_matrix(i, j) = v_coarse(i); |
| 2255 |
} |
| 2256 |
|
| 2257 |
// Remove small entries from the matrix |
| 2258 |
for (unsigned int i = 0; i < this_matrix.m(); ++i) |
| 2259 |
for (unsigned int j = 0; j < this_matrix.n(); ++j) |
| 2260 |
if (std::fabs(this_matrix(i, j)) < 1e-12) |
| 2261 |
this_matrix(i, j) = 0.; |
| 2262 |
} |
| 2263 |
} |
| 2264 |
} |
| 2265 |
|
| 2266 |
|
| 2267 |
template <int dim, int spacedim> |
| 2268 |
void |
| 2269 |
add_fe_name(const std::string ¶meter_name, |
| 2270 |
const FEFactoryBase<dim, spacedim> *factory) |
| 2271 |
{ |
| 2272 |
// Erase everything after the |
| 2273 |
// actual class name |
| 2274 |
std::string name = parameter_name; |
| 2275 |
unsigned int name_end = name.find_first_not_of(std::string( |
| 2276 |
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")); |
| 2277 |
if (name_end < name.size()) |
| 2278 |
name.erase(name_end); |
| 2279 |
|
| 2280 |
// Ensure that the element we are looking for isn't in the map |
| 2281 |
// yet. This only requires us to read the map, so it can happen |
| 2282 |
// in a shared locked state |
| 2283 |
if constexpr (running_in_debug_mode()) |
| 2284 |
{ |
| 2285 |
{ |
| 2286 |
std::shared_lock<std::shared_mutex> lock( |
| 2287 |
internal::FEToolsAddFENameHelper::fe_name_map_lock); |
| 2288 |
|
| 2289 |
Assert( |
| 2290 |
internal::FEToolsAddFENameHelper::get_fe_name_map()[dim][spacedim] |
| 2291 |
.find(name) == |
| 2292 |
internal::FEToolsAddFENameHelper::get_fe_name_map()[dim][spacedim] |
| 2293 |
.end(), |
| 2294 |
ExcMessage( |
| 2295 |
"Cannot change existing element in finite element name list")); |
| 2296 |
} |
| 2297 |
} |
| 2298 |
|
| 2299 |
|
| 2300 |
// Insert the normalized name into the map. This changes the map, so it |
| 2301 |
// has to happen under a non-shared (writer) lock: |
| 2302 |
std::unique_lock<std::shared_mutex> lock( |
| 2303 |
internal::FEToolsAddFENameHelper::fe_name_map_lock); |
| 2304 |
internal::FEToolsAddFENameHelper::get_fe_name_map()[dim][spacedim].emplace( |
| 2305 |
name, std::unique_ptr<const EnableObserverPointer>(factory)); |
| 2306 |
} |
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
namespace internal |
| 2311 |
{ |
| 2312 |
namespace FEToolsGetFEHelper |
| 2313 |
{ |
| 2314 |
// TODO: this encapsulates the call to the |
| 2315 |
// dimension-dependent fe_name_map so that we |
| 2316 |
// have a unique interface. could be done |
| 2317 |
// smarter? |
| 2318 |
template <int dim, int spacedim> |
| 2319 |
std::unique_ptr<FiniteElement<dim, spacedim>> |
| 2320 |
get_fe_by_name_ext( |
| 2321 |
std::string &name, |
| 2322 |
const std::map<std::string, |
| 2323 |
std::unique_ptr<const EnableObserverPointer>> |
| 2324 |
&fe_name_map) |
| 2325 |
{ |
| 2326 |
// Extract the name of the |
| 2327 |
// finite element class, which only |
| 2328 |
// contains characters, numbers and |
| 2329 |
// underscores. |
| 2330 |
unsigned int name_end = name.find_first_not_of(std::string( |
| 2331 |
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")); |
| 2332 |
const std::string name_part(name, 0, name_end); |
| 2333 |
name.erase(0, name_part.size()); |
| 2334 |
|
| 2335 |
// now things get a little more |
| 2336 |
// complicated: FESystem. it's |
| 2337 |
// more complicated, since we |
| 2338 |
// have to figure out what the |
| 2339 |
// base elements are. this can |
| 2340 |
// only be done recursively |
| 2341 |
if (name_part == "FESystem") |
| 2342 |
{ |
| 2343 |
// next we have to get at the |
| 2344 |
// base elements. start with |
| 2345 |
// the first. wrap the whole |
| 2346 |
// block into try-catch to |
| 2347 |
// make sure we destroy the |
| 2348 |
// pointers we got from |
| 2349 |
// recursive calls if one of |
| 2350 |
// these calls should throw |
| 2351 |
// an exception |
| 2352 |
std::vector<std::unique_ptr<const FiniteElement<dim, spacedim>>> |
| 2353 |
base_fes; |
| 2354 |
std::vector<unsigned int> base_multiplicities; |
| 2355 |
|
| 2356 |
// Now, just the [...] |
| 2357 |
// part should be left. |
| 2358 |
if (name.empty() || name[0] != '[') |
| 2359 |
throw "Invalid first character in " + name; |
| 2360 |
do |
| 2361 |
{ |
| 2362 |
// Erase the |
| 2363 |
// leading '[' or '-' |
| 2364 |
name.erase(0, 1); |
| 2365 |
// Now, the name of the |
| 2366 |
// first base element is |
| 2367 |
// first... Let's get it |
| 2368 |
base_fes.push_back( |
| 2369 |
get_fe_by_name_ext<dim, spacedim>(name, fe_name_map)); |
| 2370 |
// next check whether |
| 2371 |
// FESystem placed a |
| 2372 |
// multiplicity after |
| 2373 |
// the element name |
| 2374 |
if (name[0] == '^') |
| 2375 |
{ |
| 2376 |
// yes. Delete the '^' |
| 2377 |
// and read this |
| 2378 |
// multiplicity |
| 2379 |
name.erase(0, 1); |
| 2380 |
|
| 2381 |
const std::pair<int, unsigned int> tmp = |
| 2382 |
Utilities::get_integer_at_position(name, 0); |
| 2383 |
name.erase(0, tmp.second); |
| 2384 |
// add to length, |
| 2385 |
// including the '^' |
| 2386 |
base_multiplicities.push_back(tmp.first); |
| 2387 |
} |
| 2388 |
else |
| 2389 |
// no, so |
| 2390 |
// multiplicity is |
| 2391 |
// 1 |
| 2392 |
base_multiplicities.push_back(1); |
| 2393 |
|
| 2394 |
// so that's it for |
| 2395 |
// this base |
| 2396 |
// element. base |
| 2397 |
// elements are |
| 2398 |
// separated by '-', |
| 2399 |
// and the list is |
| 2400 |
// terminated by ']', |
| 2401 |
// so loop while the |
| 2402 |
// next character is |
| 2403 |
// '-' |
| 2404 |
} |
| 2405 |
while (name[0] == '-'); |
| 2406 |
|
| 2407 |
// so we got to the end |
| 2408 |
// of the '-' separated |
| 2409 |
// list. make sure that |
| 2410 |
// we actually had a ']' |
| 2411 |
// there |
| 2412 |
if (name.empty() || name[0] != ']') |
| 2413 |
throw "Invalid first character in " + name; |
| 2414 |
name.erase(0, 1); |
| 2415 |
// just one more sanity check |
| 2416 |
Assert((base_fes.size() == base_multiplicities.size()) && |
| 2417 |
(base_fes.size() > 0), |
| 2418 |
ExcInternalError()); |
| 2419 |
|
| 2420 |
// this is a workaround since the constructor for FESystem |
| 2421 |
// only accepts raw pointers. |
| 2422 |
std::vector<const FiniteElement<dim, spacedim> *> raw_base_fes; |
| 2423 |
raw_base_fes.reserve(base_fes.size()); |
| 2424 |
for (const auto &base_fe : base_fes) |
| 2425 |
raw_base_fes.push_back(base_fe.get()); |
| 2426 |
|
| 2427 |
// ok, apparently everything went ok. so generate the composed |
| 2428 |
// element. and return it. |
| 2429 |
return std::make_unique<FESystem<dim, spacedim>>( |
| 2430 |
raw_base_fes, base_multiplicities); |
| 2431 |
} |
| 2432 |
else if (name_part == "FE_Nothing") |
| 2433 |
{ |
| 2434 |
// remove the () from FE_Nothing() |
| 2435 |
name.erase(0, 2); |
| 2436 |
|
| 2437 |
// this is a bit of a hack, as |
| 2438 |
// FE_Nothing does not take a |
| 2439 |
// degree, but it does take an |
| 2440 |
// argument, which defaults to 1, |
| 2441 |
// so this properly returns |
| 2442 |
// FE_Nothing() |
| 2443 |
const EnableObserverPointer *ptr = |
| 2444 |
fe_name_map.find(name_part)->second.get(); |
| 2445 |
const FETools::FEFactoryBase<dim, spacedim> *fef = |
| 2446 |
dynamic_cast<const FETools::FEFactoryBase<dim, spacedim> *>(ptr); |
| 2447 |
return fef->get(1); |
| 2448 |
} |
| 2449 |
else |
| 2450 |
{ |
| 2451 |
// Lock access to the name map, but do so in a way that allows other |
| 2452 |
// readers to access it concurrently: |
| 2453 |
std::shared_lock<std::shared_mutex> lock( |
| 2454 |
internal::FEToolsAddFENameHelper::fe_name_map_lock); |
| 2455 |
|
| 2456 |
AssertThrow(fe_name_map.find(name_part) != fe_name_map.end(), |
| 2457 |
FETools::ExcInvalidFEName(name)); |
| 2458 |
|
| 2459 |
// Now, just the (degree) or (Quadrature<1>(degree+1)) part should |
| 2460 |
// be left. |
| 2461 |
if (name.empty() || name[0] != '(') |
| 2462 |
throw "Invalid first character in " + name; |
| 2463 |
name.erase(0, 1); |
| 2464 |
if (name[0] != 'Q') |
| 2465 |
{ |
| 2466 |
const std::pair<int, unsigned int> tmp = |
| 2467 |
Utilities::get_integer_at_position(name, 0); |
| 2468 |
name.erase(0, tmp.second + 1); |
| 2469 |
const EnableObserverPointer *ptr = |
| 2470 |
fe_name_map.find(name_part)->second.get(); |
| 2471 |
const FETools::FEFactoryBase<dim, spacedim> *fef = |
| 2472 |
dynamic_cast<const FETools::FEFactoryBase<dim, spacedim> *>( |
| 2473 |
ptr); |
| 2474 |
return fef->get(tmp.first); |
| 2475 |
} |
| 2476 |
else |
| 2477 |
{ |
| 2478 |
unsigned int position = name.find('('); |
| 2479 |
const std::string quadrature_name(name, 0, position); |
| 2480 |
name.erase(0, position + 1); |
| 2481 |
if (quadrature_name.compare("QGaussLobatto") == 0) |
| 2482 |
{ |
| 2483 |
const std::pair<int, unsigned int> tmp = |
| 2484 |
Utilities::get_integer_at_position(name, 0); |
| 2485 |
// delete "))" |
| 2486 |
name.erase(0, tmp.second + 2); |
| 2487 |
const EnableObserverPointer *ptr = |
| 2488 |
fe_name_map.find(name_part)->second.get(); |
| 2489 |
const FETools::FEFactoryBase<dim, spacedim> *fef = |
| 2490 |
dynamic_cast< |
| 2491 |
const FETools::FEFactoryBase<dim, spacedim> *>(ptr); |
| 2492 |
return fef->get(QGaussLobatto<1>(tmp.first)); |
| 2493 |
} |
| 2494 |
else if (quadrature_name.compare("QGauss") == 0) |
| 2495 |
{ |
| 2496 |
const std::pair<int, unsigned int> tmp = |
| 2497 |
Utilities::get_integer_at_position(name, 0); |
| 2498 |
// delete "))" |
| 2499 |
name.erase(0, tmp.second + 2); |
| 2500 |
const EnableObserverPointer *ptr = |
| 2501 |
fe_name_map.find(name_part)->second.get(); |
| 2502 |
const FETools::FEFactoryBase<dim, spacedim> *fef = |
| 2503 |
dynamic_cast< |
| 2504 |
const FETools::FEFactoryBase<dim, spacedim> *>(ptr); |
| 2505 |
return fef->get(QGauss<1>(tmp.first)); |
| 2506 |
} |
| 2507 |
else if (quadrature_name.compare("QIterated") == 0) |
| 2508 |
{ |
| 2509 |
// find sub-quadrature |
| 2510 |
position = name.find('('); |
| 2511 |
const std::string subquadrature_name(name, 0, position); |
| 2512 |
AssertThrow(subquadrature_name == "QTrapezoid", |
| 2513 |
ExcNotImplemented( |
| 2514 |
"Could not detect quadrature of name " + |
| 2515 |
subquadrature_name)); |
| 2516 |
// delete "QTrapezoid()," |
| 2517 |
name.erase(0, position + 3); |
| 2518 |
const std::pair<int, unsigned int> tmp = |
| 2519 |
Utilities::get_integer_at_position(name, 0); |
| 2520 |
// delete "))" |
| 2521 |
name.erase(0, tmp.second + 2); |
| 2522 |
const EnableObserverPointer *ptr = |
| 2523 |
fe_name_map.find(name_part)->second.get(); |
| 2524 |
const FETools::FEFactoryBase<dim, spacedim> *fef = |
| 2525 |
dynamic_cast< |
| 2526 |
const FETools::FEFactoryBase<dim, spacedim> *>(ptr); |
| 2527 |
return fef->get(QIterated<1>(QTrapezoid<1>(), tmp.first)); |
| 2528 |
} |
| 2529 |
else |
| 2530 |
{ |
| 2531 |
AssertThrow(false, ExcNotImplemented()); |
| 2532 |
} |
| 2533 |
} |
| 2534 |
} |
| 2535 |
|
| 2536 |
|
| 2537 |
// hm, if we have come thus far, we |
| 2538 |
// didn't know what to do with the |
| 2539 |
// string we got. so do as the docs |
| 2540 |
// say: raise an exception |
| 2541 |
AssertThrow(false, FETools::ExcInvalidFEName(name_part)); |
| 2542 |
|
| 2543 |
// make some compilers happy that |
| 2544 |
// do not realize that we can't get |
| 2545 |
// here after throwing |
| 2546 |
return nullptr; |
| 2547 |
} |
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
template <int dim, int spacedim> |
| 2552 |
std::unique_ptr<FiniteElement<dim, spacedim>> |
| 2553 |
get_fe_by_name(std::string &name) |
| 2554 |
{ |
| 2555 |
return get_fe_by_name_ext<dim, spacedim>( |
| 2556 |
name, FEToolsAddFENameHelper::get_fe_name_map()[dim][spacedim]); |
| 2557 |
} |
| 2558 |
} // namespace FEToolsGetFEHelper |
| 2559 |
} // namespace internal |
| 2560 |
|
| 2561 |
|
| 2562 |
|
| 2563 |
template <int dim, int spacedim> |
| 2564 |
std::unique_ptr<FiniteElement<dim, spacedim>> |
| 2565 |
get_fe_by_name(const std::string ¶meter_name) |
| 2566 |
{ |
| 2567 |
std::string name = Utilities::trim(parameter_name); |
| 2568 |
std::size_t index = 1; |
| 2569 |
// remove spaces that are not between two word (things that match the |
| 2570 |
// regular expression [A-Za-z0-9_]) characters. |
| 2571 |
while (2 < name.size() && index < name.size() - 1) |
| 2572 |
{ |
| 2573 |
if (name[index] == ' ' && |
| 2574 |
(!(std::isalnum(name[index - 1]) || name[index - 1] == '_') || |
| 2575 |
!(std::isalnum(name[index + 1]) || name[index + 1] == '_'))) |
| 2576 |
{ |
| 2577 |
name.erase(index, 1); |
| 2578 |
} |
| 2579 |
else |
| 2580 |
{ |
| 2581 |
++index; |
| 2582 |
} |
| 2583 |
} |
| 2584 |
|
| 2585 |
// Create a version of the name |
| 2586 |
// string where all template |
| 2587 |
// parameters are eliminated. |
| 2588 |
for (unsigned int pos1 = name.find('<'); pos1 < name.size(); |
| 2589 |
pos1 = name.find('<')) |
| 2590 |
{ |
| 2591 |
const unsigned int pos2 = name.find('>'); |
| 2592 |
// If there is only a single |
| 2593 |
// character between those two, |
| 2594 |
// it should be 'd' or the number |
| 2595 |
// representing the dimension. |
| 2596 |
if (pos2 - pos1 == 2) |
| 2597 |
{ |
| 2598 |
const char dimchar = '0' + dim; |
| 2599 |
(void)dimchar; |
| 2600 |
if (name.at(pos1 + 1) != 'd') |
| 2601 |
Assert(name.at(pos1 + 1) == dimchar, |
| 2602 |
ExcInvalidFEDimension(name.at(pos1 + 1), dim)); |
| 2603 |
} |
| 2604 |
else |
| 2605 |
Assert(pos2 - pos1 == 4, ExcInvalidFEName(name)); |
| 2606 |
|
| 2607 |
// If pos1==pos2, then we are |
| 2608 |
// probably at the end of the |
| 2609 |
// string |
| 2610 |
if (pos2 != pos1) |
| 2611 |
name.erase(pos1, pos2 - pos1 + 1); |
| 2612 |
} |
| 2613 |
// Replace all occurrences of "^dim" |
| 2614 |
// by "^d" to be handled by the |
| 2615 |
// next loop |
| 2616 |
for (unsigned int pos = name.find("^dim"); pos < name.size(); |
| 2617 |
pos = name.find("^dim")) |
| 2618 |
name.erase(pos + 2, 2); |
| 2619 |
|
| 2620 |
// Replace all occurrences of "^d" |
| 2621 |
// by using the actual dimension |
| 2622 |
for (unsigned int pos = name.find("^d"); pos < name.size(); |
| 2623 |
pos = name.find("^d")) |
| 2624 |
name.at(pos + 1) = '0' + dim; |
| 2625 |
|
| 2626 |
try |
| 2627 |
{ |
| 2628 |
auto fe = |
| 2629 |
internal::FEToolsGetFEHelper::get_fe_by_name<dim, spacedim>(name); |
| 2630 |
|
| 2631 |
// Make sure the auxiliary function |
| 2632 |
// ate up all characters of the name. |
| 2633 |
AssertThrow(name.empty(), |
| 2634 |
ExcInvalidFEName(parameter_name + |
| 2635 |
std::string(" extra characters after " |
| 2636 |
"end of name"))); |
| 2637 |
return fe; |
| 2638 |
} |
| 2639 |
catch (const std::string &errline) |
| 2640 |
{ |
| 2641 |
AssertThrow(false, ExcInvalidFEName(parameter_name + " at " + errline)); |
| 2642 |
return nullptr; |
| 2643 |
} |
| 2644 |
} |
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
template <int dim, int spacedim> |
| 2649 |
void |
| 2650 |
compute_projection_from_quadrature_points_matrix( |
| 2651 |
const FiniteElement<dim, spacedim> &fe, |
| 2652 |
const Quadrature<dim> &lhs_quadrature, |
| 2653 |
const Quadrature<dim> &rhs_quadrature, |
| 2654 |
FullMatrix<double> &X) |
| 2655 |
{ |
| 2656 |
Assert(fe.n_components() == 1, ExcNotImplemented()); |
| 2657 |
|
| 2658 |
// first build the matrices M and Q |
| 2659 |
// described in the documentation |
| 2660 |
FullMatrix<double> M(fe.n_dofs_per_cell(), fe.n_dofs_per_cell()); |
| 2661 |
FullMatrix<double> Q(fe.n_dofs_per_cell(), rhs_quadrature.size()); |
| 2662 |
|
| 2663 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2664 |
for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j) |
| 2665 |
for (unsigned int q = 0; q < lhs_quadrature.size(); ++q) |
| 2666 |
M(i, j) += fe.shape_value(i, lhs_quadrature.point(q)) * |
| 2667 |
fe.shape_value(j, lhs_quadrature.point(q)) * |
| 2668 |
lhs_quadrature.weight(q); |
| 2669 |
|
| 2670 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2671 |
for (unsigned int q = 0; q < rhs_quadrature.size(); ++q) |
| 2672 |
Q(i, q) += |
| 2673 |
fe.shape_value(i, rhs_quadrature.point(q)) * rhs_quadrature.weight(q); |
| 2674 |
|
| 2675 |
// then invert M |
| 2676 |
FullMatrix<double> M_inverse(fe.n_dofs_per_cell(), fe.n_dofs_per_cell()); |
| 2677 |
M_inverse.invert(M); |
| 2678 |
|
| 2679 |
// finally compute the result |
| 2680 |
X.reinit(fe.n_dofs_per_cell(), rhs_quadrature.size()); |
| 2681 |
M_inverse.mmult(X, Q); |
| 2682 |
|
| 2683 |
Assert(X.m() == fe.n_dofs_per_cell(), ExcInternalError()); |
| 2684 |
Assert(X.n() == rhs_quadrature.size(), ExcInternalError()); |
| 2685 |
} |
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
template <int dim, int spacedim> |
| 2690 |
void |
| 2691 |
compute_interpolation_to_quadrature_points_matrix( |
| 2692 |
const FiniteElement<dim, spacedim> &fe, |
| 2693 |
const Quadrature<dim> &quadrature, |
| 2694 |
FullMatrix<double> &I_q) |
| 2695 |
{ |
| 2696 |
Assert(fe.n_components() == 1, ExcNotImplemented()); |
| 2697 |
Assert(I_q.m() == quadrature.size(), ExcMessage("Wrong matrix size")); |
| 2698 |
Assert(I_q.n() == fe.n_dofs_per_cell(), ExcMessage("Wrong matrix size")); |
| 2699 |
|
| 2700 |
for (unsigned int q = 0; q < quadrature.size(); ++q) |
| 2701 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2702 |
I_q(q, i) = fe.shape_value(i, quadrature.point(q)); |
| 2703 |
} |
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
template <int dim> |
| 2708 |
void |
| 2709 |
compute_projection_from_quadrature_points( |
| 2710 |
const FullMatrix<double> &projection_matrix, |
| 2711 |
const std::vector<Tensor<1, dim>> &vector_of_tensors_at_qp, |
| 2712 |
std::vector<Tensor<1, dim>> &vector_of_tensors_at_nodes) |
| 2713 |
{ |
| 2714 |
// check that the number columns of the projection_matrix |
| 2715 |
// matches the size of the vector_of_tensors_at_qp |
| 2716 |
Assert(projection_matrix.n_cols() == vector_of_tensors_at_qp.size(), |
| 2717 |
ExcDimensionMismatch(projection_matrix.n_cols(), |
| 2718 |
vector_of_tensors_at_qp.size())); |
| 2719 |
|
| 2720 |
// check that the number rows of the projection_matrix |
| 2721 |
// matches the size of the vector_of_tensors_at_nodes |
| 2722 |
Assert(projection_matrix.n_rows() == vector_of_tensors_at_nodes.size(), |
| 2723 |
ExcDimensionMismatch(projection_matrix.n_rows(), |
| 2724 |
vector_of_tensors_at_nodes.size())); |
| 2725 |
|
| 2726 |
// number of support points (nodes) to project to |
| 2727 |
const unsigned int n_support_points = projection_matrix.n_rows(); |
| 2728 |
// number of quadrature points to project from |
| 2729 |
const unsigned int n_quad_points = projection_matrix.n_cols(); |
| 2730 |
|
| 2731 |
// component projected to the nodes |
| 2732 |
Vector<double> component_at_node(n_support_points); |
| 2733 |
// component at the quadrature point |
| 2734 |
Vector<double> component_at_qp(n_quad_points); |
| 2735 |
|
| 2736 |
for (unsigned int ii = 0; ii < dim; ++ii) |
| 2737 |
{ |
| 2738 |
component_at_qp = 0; |
| 2739 |
|
| 2740 |
// populate the vector of components at the qps |
| 2741 |
// from vector_of_tensors_at_qp |
| 2742 |
// vector_of_tensors_at_qp data is in form: |
| 2743 |
// columns: 0, 1, ..., dim |
| 2744 |
// rows: 0,1,...., n_quad_points |
| 2745 |
// so extract the ii'th column of vector_of_tensors_at_qp |
| 2746 |
for (unsigned int q = 0; q < n_quad_points; ++q) |
| 2747 |
{ |
| 2748 |
component_at_qp(q) = vector_of_tensors_at_qp[q][ii]; |
| 2749 |
} |
| 2750 |
|
| 2751 |
// project from the qps -> nodes |
| 2752 |
// component_at_node = projection_matrix_u * component_at_qp |
| 2753 |
projection_matrix.vmult(component_at_node, component_at_qp); |
| 2754 |
|
| 2755 |
// rewrite the projection of the components |
| 2756 |
// back into the vector of tensors |
| 2757 |
for (unsigned int nn = 0; nn < n_support_points; ++nn) |
| 2758 |
{ |
| 2759 |
vector_of_tensors_at_nodes[nn][ii] = component_at_node(nn); |
| 2760 |
} |
| 2761 |
} |
| 2762 |
} |
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
template <int dim> |
| 2767 |
void |
| 2768 |
compute_projection_from_quadrature_points( |
| 2769 |
const FullMatrix<double> &projection_matrix, |
| 2770 |
const std::vector<SymmetricTensor<2, dim>> &vector_of_tensors_at_qp, |
| 2771 |
std::vector<SymmetricTensor<2, dim>> &vector_of_tensors_at_nodes) |
| 2772 |
{ |
| 2773 |
// check that the number columns of the projection_matrix |
| 2774 |
// matches the size of the vector_of_tensors_at_qp |
| 2775 |
Assert(projection_matrix.n_cols() == vector_of_tensors_at_qp.size(), |
| 2776 |
ExcDimensionMismatch(projection_matrix.n_cols(), |
| 2777 |
vector_of_tensors_at_qp.size())); |
| 2778 |
|
| 2779 |
// check that the number rows of the projection_matrix |
| 2780 |
// matches the size of the vector_of_tensors_at_nodes |
| 2781 |
Assert(projection_matrix.n_rows() == vector_of_tensors_at_nodes.size(), |
| 2782 |
ExcDimensionMismatch(projection_matrix.n_rows(), |
| 2783 |
vector_of_tensors_at_nodes.size())); |
| 2784 |
|
| 2785 |
// number of support points (nodes) |
| 2786 |
const unsigned int n_support_points = projection_matrix.n_rows(); |
| 2787 |
// number of quadrature points to project from |
| 2788 |
const unsigned int n_quad_points = projection_matrix.n_cols(); |
| 2789 |
|
| 2790 |
// number of unique entries in a symmetric second-order tensor |
| 2791 |
const unsigned int n_independent_components = |
| 2792 |
SymmetricTensor<2, dim>::n_independent_components; |
| 2793 |
|
| 2794 |
// component projected to the nodes |
| 2795 |
Vector<double> component_at_node(n_support_points); |
| 2796 |
// component at the quadrature point |
| 2797 |
Vector<double> component_at_qp(n_quad_points); |
| 2798 |
|
| 2799 |
// loop over the number of unique dimensions of the tensor |
| 2800 |
for (unsigned int ii = 0; ii < n_independent_components; ++ii) |
| 2801 |
{ |
| 2802 |
component_at_qp = 0; |
| 2803 |
|
| 2804 |
// row-column entry of tensor corresponding the unrolled index |
| 2805 |
TableIndices<2> row_column_index = |
| 2806 |
SymmetricTensor<2, dim>::unrolled_to_component_indices(ii); |
| 2807 |
const unsigned int row = row_column_index[0]; |
| 2808 |
const unsigned int column = row_column_index[1]; |
| 2809 |
|
| 2810 |
// populate the vector of components at the qps |
| 2811 |
// from vector_of_tensors_at_qp |
| 2812 |
// vector_of_tensors_at_qp is in form: |
| 2813 |
// columns: 0, 1, ..., n_independent_components |
| 2814 |
// rows: 0,1,...., n_quad_points |
| 2815 |
// so extract the ii'th column of vector_of_tensors_at_qp |
| 2816 |
for (unsigned int q = 0; q < n_quad_points; ++q) |
| 2817 |
{ |
| 2818 |
component_at_qp(q) = (vector_of_tensors_at_qp[q])[row][column]; |
| 2819 |
} |
| 2820 |
|
| 2821 |
// project from the qps -> nodes |
| 2822 |
// component_at_node = projection_matrix_u * component_at_qp |
| 2823 |
projection_matrix.vmult(component_at_node, component_at_qp); |
| 2824 |
|
| 2825 |
// rewrite the projection of the components back into the vector of |
| 2826 |
// tensors |
| 2827 |
for (unsigned int nn = 0; nn < n_support_points; ++nn) |
| 2828 |
{ |
| 2829 |
(vector_of_tensors_at_nodes[nn])[row][column] = |
| 2830 |
component_at_node(nn); |
| 2831 |
} |
| 2832 |
} |
| 2833 |
} |
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
template <int dim, int spacedim> |
| 2838 |
void |
| 2839 |
compute_projection_from_face_quadrature_points_matrix( |
| 2840 |
const FiniteElement<dim, spacedim> &fe, |
| 2841 |
const Quadrature<dim - 1> &lhs_quadrature, |
| 2842 |
const Quadrature<dim - 1> &rhs_quadrature, |
| 2843 |
const typename DoFHandler<dim, spacedim>::active_cell_iterator &cell, |
| 2844 |
const unsigned int face, |
| 2845 |
FullMatrix<double> &X) |
| 2846 |
{ |
| 2847 |
Assert(fe.n_components() == 1, ExcNotImplemented()); |
| 2848 |
Assert(lhs_quadrature.size() > fe.degree, |
| 2849 |
ExcNotGreaterThan(lhs_quadrature.size(), fe.degree)); |
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
// build the matrices M and Q |
| 2854 |
// described in the documentation |
| 2855 |
FullMatrix<double> M(fe.n_dofs_per_cell(), fe.n_dofs_per_cell()); |
| 2856 |
FullMatrix<double> Q(fe.n_dofs_per_cell(), rhs_quadrature.size()); |
| 2857 |
|
| 2858 |
{ |
| 2859 |
// need an FEFaceValues object to evaluate shape function |
| 2860 |
// values on the specified face. |
| 2861 |
FEFaceValues<dim> fe_face_values(fe, lhs_quadrature, update_values); |
| 2862 |
fe_face_values.reinit(cell, face); // setup shape_value on this face. |
| 2863 |
|
| 2864 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2865 |
for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j) |
| 2866 |
for (unsigned int q = 0; q < lhs_quadrature.size(); ++q) |
| 2867 |
M(i, j) += fe_face_values.shape_value(i, q) * |
| 2868 |
fe_face_values.shape_value(j, q) * |
| 2869 |
lhs_quadrature.weight(q); |
| 2870 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2871 |
{ |
| 2872 |
M(i, i) = (M(i, i) == 0 ? 1 : M(i, i)); |
| 2873 |
} |
| 2874 |
} |
| 2875 |
|
| 2876 |
{ |
| 2877 |
FEFaceValues<dim> fe_face_values(fe, rhs_quadrature, update_values); |
| 2878 |
fe_face_values.reinit(cell, face); // setup shape_value on this face. |
| 2879 |
|
| 2880 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2881 |
for (unsigned int q = 0; q < rhs_quadrature.size(); ++q) |
| 2882 |
Q(i, q) += |
| 2883 |
fe_face_values.shape_value(i, q) * rhs_quadrature.weight(q); |
| 2884 |
} |
| 2885 |
// then invert M |
| 2886 |
FullMatrix<double> M_inverse(fe.n_dofs_per_cell(), fe.n_dofs_per_cell()); |
| 2887 |
M_inverse.invert(M); |
| 2888 |
|
| 2889 |
// finally compute the result |
| 2890 |
X.reinit(fe.n_dofs_per_cell(), rhs_quadrature.size()); |
| 2891 |
M_inverse.mmult(X, Q); |
| 2892 |
|
| 2893 |
Assert(X.m() == fe.n_dofs_per_cell(), ExcInternalError()); |
| 2894 |
Assert(X.n() == rhs_quadrature.size(), ExcInternalError()); |
| 2895 |
} |
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
template <int dim, int spacedim> |
| 2900 |
Quadrature<dim> |
| 2901 |
compute_nodal_quadrature(const FiniteElement<dim, spacedim> &fe) |
| 2902 |
{ |
| 2903 |
Assert(fe.has_support_points(), ExcNotImplemented()); |
| 2904 |
Assert(fe.n_blocks() == 1, ExcNotImplemented()); |
| 2905 |
Assert(fe.n_components() == 1, ExcNotImplemented()); |
| 2906 |
|
| 2907 |
const ReferenceCell type = fe.reference_cell(); |
| 2908 |
|
| 2909 |
const Quadrature<dim> q_gauss = |
| 2910 |
type.get_gauss_type_quadrature<dim>(fe.tensor_degree() + 1); |
| 2911 |
Triangulation<dim, spacedim> tria; |
| 2912 |
GridGenerator::reference_cell(tria, type); |
| 2913 |
const Mapping<dim, spacedim> &mapping = |
| 2914 |
type.template get_default_linear_mapping<dim, spacedim>(); |
| 2915 |
|
| 2916 |
auto cell = tria.begin_active(); |
| 2917 |
FEValues<dim, spacedim> fe_values(mapping, |
| 2918 |
fe, |
| 2919 |
q_gauss, |
| 2920 |
update_values | update_JxW_values); |
| 2921 |
fe_values.reinit(cell); |
| 2922 |
|
| 2923 |
const std::vector<Point<dim>> &nodal_quad_points = |
| 2924 |
fe.get_unit_support_points(); |
| 2925 |
std::vector<double> nodal_quad_weights(nodal_quad_points.size()); |
| 2926 |
Assert(nodal_quad_points.size() > 0, ExcNotImplemented()); |
| 2927 |
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) |
| 2928 |
{ |
| 2929 |
double integral = 0.0; |
| 2930 |
for (unsigned int q = 0; q < q_gauss.size(); ++q) |
| 2931 |
integral += fe_values.shape_value(i, q) * fe_values.JxW(q); |
| 2932 |
nodal_quad_weights[i] = integral; |
| 2933 |
} |
| 2934 |
return {nodal_quad_points, nodal_quad_weights}; |
| 2935 |
} |
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
namespace internal |
| 2940 |
{ |
| 2941 |
namespace FEToolsConvertHelper |
| 2942 |
{ |
| 2943 |
// Helper functions for |
| 2944 |
// FETools::convert_generalized_support_point_values_to_dof_values |
| 2945 |
|
| 2946 |
template <int dim, int spacedim, typename number> |
| 2947 |
void |
| 2948 |
convert_helper(const FiniteElement<dim, spacedim> &finite_element, |
| 2949 |
const std::vector<Vector<number>> &support_point_values, |
| 2950 |
std::vector<number> &dof_values) |
| 2951 |
{ |
| 2952 |
static Threads::ThreadLocalStorage<std::vector<Vector<double>>> |
| 2953 |
double_support_point_values; |
| 2954 |
static Threads::ThreadLocalStorage<std::vector<double>> |
| 2955 |
double_dof_values; |
| 2956 |
|
| 2957 |
double_support_point_values.get().resize(support_point_values.size()); |
| 2958 |
double_dof_values.get().resize(dof_values.size()); |
| 2959 |
|
| 2960 |
for (unsigned int i = 0; i < support_point_values.size(); ++i) |
| 2961 |
{ |
| 2962 |
double_support_point_values.get()[i].reinit( |
| 2963 |
finite_element.n_components(), false); |
| 2964 |
std::copy(std::begin(support_point_values[i]), |
| 2965 |
std::end(support_point_values[i]), |
| 2966 |
std::begin(double_support_point_values.get()[i])); |
| 2967 |
} |
| 2968 |
|
| 2969 |
finite_element.convert_generalized_support_point_values_to_dof_values( |
| 2970 |
double_support_point_values.get(), double_dof_values.get()); |
| 2971 |
|
| 2972 |
std::copy(std::begin(double_dof_values.get()), |
| 2973 |
std::end(double_dof_values.get()), |
| 2974 |
std::begin(dof_values)); |
| 2975 |
} |
| 2976 |
|
| 2977 |
|
| 2978 |
template <int dim, int spacedim, typename number> |
| 2979 |
void |
| 2980 |
convert_helper( |
| 2981 |
const FiniteElement<dim, spacedim> &finite_element, |
| 2982 |
const std::vector<Vector<std::complex<number>>> &support_point_values, |
| 2983 |
std::vector<std::complex<number>> &dof_values) |
| 2984 |
{ |
| 2985 |
static Threads::ThreadLocalStorage<std::vector<Vector<double>>> |
| 2986 |
double_support_point_values_real; |
| 2987 |
static Threads::ThreadLocalStorage<std::vector<double>> |
| 2988 |
double_dof_values_real; |
| 2989 |
static Threads::ThreadLocalStorage<std::vector<Vector<double>>> |
| 2990 |
double_support_point_values_imag; |
| 2991 |
static Threads::ThreadLocalStorage<std::vector<double>> |
| 2992 |
double_dof_values_imag; |
| 2993 |
|
| 2994 |
double_support_point_values_real.get().resize( |
| 2995 |
support_point_values.size()); |
| 2996 |
double_dof_values_real.get().resize(dof_values.size()); |
| 2997 |
double_support_point_values_imag.get().resize( |
| 2998 |
support_point_values.size()); |
| 2999 |
double_dof_values_imag.get().resize(dof_values.size()); |
| 3000 |
|
| 3001 |
for (unsigned int i = 0; i < support_point_values.size(); ++i) |
| 3002 |
{ |
| 3003 |
double_support_point_values_real.get()[i].reinit( |
| 3004 |
finite_element.n_components(), false); |
| 3005 |
double_support_point_values_imag.get()[i].reinit( |
| 3006 |
finite_element.n_components(), false); |
| 3007 |
|
| 3008 |
std::transform( |
| 3009 |
std::begin(support_point_values[i]), |
| 3010 |
std::end(support_point_values[i]), |
| 3011 |
std::begin(double_support_point_values_real.get()[i]), |
| 3012 |
[](std::complex<number> c) -> double { return c.real(); }); |
| 3013 |
|
| 3014 |
std::transform( |
| 3015 |
std::begin(support_point_values[i]), |
| 3016 |
std::end(support_point_values[i]), |
| 3017 |
std::begin(double_support_point_values_imag.get()[i]), |
| 3018 |
[](std::complex<number> c) -> double { return c.imag(); }); |
| 3019 |
} |
| 3020 |
|
| 3021 |
finite_element.convert_generalized_support_point_values_to_dof_values( |
| 3022 |
double_support_point_values_real.get(), double_dof_values_real.get()); |
| 3023 |
finite_element.convert_generalized_support_point_values_to_dof_values( |
| 3024 |
double_support_point_values_imag.get(), double_dof_values_imag.get()); |
| 3025 |
|
| 3026 |
std::transform(std::begin(double_dof_values_real.get()), |
| 3027 |
std::end(double_dof_values_real.get()), |
| 3028 |
std::begin(double_dof_values_imag.get()), |
| 3029 |
std::begin(dof_values), |
| 3030 |
[](number real, number imag) -> std::complex<number> { |
| 3031 |
return {real, imag}; |
| 3032 |
}); |
| 3033 |
} |
| 3034 |
|
| 3035 |
|
| 3036 |
template <int dim, int spacedim> |
| 3037 |
void |
| 3038 |
convert_helper(const FiniteElement<dim, spacedim> &finite_element, |
| 3039 |
const std::vector<Vector<double>> &support_point_values, |
| 3040 |
std::vector<double> &dof_values) |
| 3041 |
{ |
| 3042 |
finite_element.convert_generalized_support_point_values_to_dof_values( |
| 3043 |
support_point_values, dof_values); |
| 3044 |
} |
| 3045 |
|
| 3046 |
} // namespace FEToolsConvertHelper |
| 3047 |
} // namespace internal |
| 3048 |
|
| 3049 |
|
| 3050 |
|
| 3051 |
template <int dim, int spacedim, typename number> |
| 3052 |
void |
| 3053 |
convert_generalized_support_point_values_to_dof_values( |
| 3054 |
const FiniteElement<dim, spacedim> &finite_element, |
| 3055 |
const std::vector<Vector<number>> &support_point_values, |
| 3056 |
std::vector<number> &dof_values) |
| 3057 |
{ |
| 3058 |
AssertDimension(support_point_values.size(), |
| 3059 |
finite_element.get_generalized_support_points().size()); |
| 3060 |
AssertDimension(dof_values.size(), finite_element.n_dofs_per_cell()); |
| 3061 |
|
| 3062 |
internal::FEToolsConvertHelper::convert_helper<dim, spacedim>( |
| 3063 |
finite_element, support_point_values, dof_values); |
| 3064 |
} |
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
template <int dim> |
| 3069 |
std::vector<unsigned int> |
| 3070 |
hierarchic_to_lexicographic_numbering(const unsigned int degree) |
| 3071 |
{ |
| 3072 |
// number of support points in each direction |
| 3073 |
const unsigned int n = degree + 1; |
| 3074 |
|
| 3075 |
const unsigned int dofs_per_cell = Utilities::fixed_power<dim>(n); |
| 3076 |
|
| 3077 |
std::vector<unsigned int> h2l(dofs_per_cell); |
| 3078 |
|
| 3079 |
// polynomial degree |
| 3080 |
const unsigned int dofs_per_line = degree - 1; |
| 3081 |
|
| 3082 |
// the following lines of code are somewhat odd, due to the way the |
| 3083 |
// hierarchic numbering is organized. if someone would really want to |
| 3084 |
// understand these lines, you better draw some pictures where you |
| 3085 |
// indicate the indices and orders of vertices, lines, etc, along with the |
| 3086 |
// numbers of the degrees of freedom in hierarchical and lexicographical |
| 3087 |
// order |
| 3088 |
switch (dim) |
| 3089 |
{ |
| 3090 |
case 0: |
| 3091 |
{ |
| 3092 |
h2l[0] = 0; |
| 3093 |
break; |
| 3094 |
} |
| 3095 |
case 1: |
| 3096 |
{ |
| 3097 |
h2l[0] = 0; |
| 3098 |
h2l[1] = dofs_per_cell - 1; |
| 3099 |
for (unsigned int i = 2; i < dofs_per_cell; ++i) |
| 3100 |
h2l[i] = i - 1; |
| 3101 |
|
| 3102 |
break; |
| 3103 |
} |
| 3104 |
|
| 3105 |
case 2: |
| 3106 |
{ |
| 3107 |
unsigned int next_index = 0; |
| 3108 |
// first the four vertices |
| 3109 |
h2l[next_index++] = 0; |
| 3110 |
h2l[next_index++] = n - 1; |
| 3111 |
h2l[next_index++] = n * (n - 1); |
| 3112 |
h2l[next_index++] = n * n - 1; |
| 3113 |
|
| 3114 |
// left line |
| 3115 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3116 |
h2l[next_index++] = (1 + i) * n; |
| 3117 |
|
| 3118 |
// right line |
| 3119 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3120 |
h2l[next_index++] = (2 + i) * n - 1; |
| 3121 |
|
| 3122 |
// bottom line |
| 3123 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3124 |
h2l[next_index++] = 1 + i; |
| 3125 |
|
| 3126 |
// top line |
| 3127 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3128 |
h2l[next_index++] = n * (n - 1) + i + 1; |
| 3129 |
|
| 3130 |
// inside quad |
| 3131 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3132 |
for (unsigned int j = 0; j < dofs_per_line; ++j) |
| 3133 |
h2l[next_index++] = n * (i + 1) + j + 1; |
| 3134 |
|
| 3135 |
Assert(next_index == dofs_per_cell, ExcInternalError()); |
| 3136 |
|
| 3137 |
break; |
| 3138 |
} |
| 3139 |
|
| 3140 |
case 3: |
| 3141 |
{ |
| 3142 |
unsigned int next_index = 0; |
| 3143 |
// first the eight vertices |
| 3144 |
h2l[next_index++] = 0; // 0 |
| 3145 |
h2l[next_index++] = (1) * degree; // 1 |
| 3146 |
h2l[next_index++] = (n)*degree; // 2 |
| 3147 |
h2l[next_index++] = (n + 1) * degree; // 3 |
| 3148 |
h2l[next_index++] = (n * n) * degree; // 4 |
| 3149 |
h2l[next_index++] = (n * n + 1) * degree; // 5 |
| 3150 |
h2l[next_index++] = (n * n + n) * degree; // 6 |
| 3151 |
h2l[next_index++] = (n * n + n + 1) * degree; // 7 |
| 3152 |
|
| 3153 |
// line 0 |
| 3154 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3155 |
h2l[next_index++] = (i + 1) * n; |
| 3156 |
// line 1 |
| 3157 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3158 |
h2l[next_index++] = n - 1 + (i + 1) * n; |
| 3159 |
// line 2 |
| 3160 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3161 |
h2l[next_index++] = 1 + i; |
| 3162 |
// line 3 |
| 3163 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3164 |
h2l[next_index++] = 1 + i + n * (n - 1); |
| 3165 |
|
| 3166 |
// line 4 |
| 3167 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3168 |
h2l[next_index++] = (n - 1) * n * n + (i + 1) * n; |
| 3169 |
// line 5 |
| 3170 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3171 |
h2l[next_index++] = (n - 1) * (n * n + 1) + (i + 1) * n; |
| 3172 |
// line 6 |
| 3173 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3174 |
h2l[next_index++] = n * n * (n - 1) + i + 1; |
| 3175 |
// line 7 |
| 3176 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3177 |
h2l[next_index++] = n * n * (n - 1) + i + 1 + n * (n - 1); |
| 3178 |
|
| 3179 |
// line 8 |
| 3180 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3181 |
h2l[next_index++] = (i + 1) * n * n; |
| 3182 |
// line 9 |
| 3183 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3184 |
h2l[next_index++] = n - 1 + (i + 1) * n * n; |
| 3185 |
// line 10 |
| 3186 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3187 |
h2l[next_index++] = (i + 1) * n * n + n * (n - 1); |
| 3188 |
// line 11 |
| 3189 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3190 |
h2l[next_index++] = n - 1 + (i + 1) * n * n + n * (n - 1); |
| 3191 |
|
| 3192 |
|
| 3193 |
// inside quads |
| 3194 |
// face 0 |
| 3195 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3196 |
for (unsigned int j = 0; j < dofs_per_line; ++j) |
| 3197 |
h2l[next_index++] = (i + 1) * n * n + n * (j + 1); |
| 3198 |
// face 1 |
| 3199 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3200 |
for (unsigned int j = 0; j < dofs_per_line; ++j) |
| 3201 |
h2l[next_index++] = (i + 1) * n * n + n - 1 + n * (j + 1); |
| 3202 |
// face 2, note the orientation! |
| 3203 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3204 |
for (unsigned int j = 0; j < dofs_per_line; ++j) |
| 3205 |
h2l[next_index++] = (j + 1) * n * n + i + 1; |
| 3206 |
// face 3, note the orientation! |
| 3207 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3208 |
for (unsigned int j = 0; j < dofs_per_line; ++j) |
| 3209 |
h2l[next_index++] = (j + 1) * n * n + n * (n - 1) + i + 1; |
| 3210 |
// face 4 |
| 3211 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3212 |
for (unsigned int j = 0; j < dofs_per_line; ++j) |
| 3213 |
h2l[next_index++] = n * (i + 1) + j + 1; |
| 3214 |
// face 5 |
| 3215 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3216 |
for (unsigned int j = 0; j < dofs_per_line; ++j) |
| 3217 |
h2l[next_index++] = (n - 1) * n * n + n * (i + 1) + j + 1; |
| 3218 |
|
| 3219 |
// inside hex |
| 3220 |
for (unsigned int i = 0; i < dofs_per_line; ++i) |
| 3221 |
for (unsigned int j = 0; j < dofs_per_line; ++j) |
| 3222 |
for (unsigned int k = 0; k < dofs_per_line; ++k) |
| 3223 |
h2l[next_index++] = n * n * (i + 1) + n * (j + 1) + k + 1; |
| 3224 |
|
| 3225 |
Assert(next_index == dofs_per_cell, ExcInternalError()); |
| 3226 |
|
| 3227 |
break; |
| 3228 |
} |
| 3229 |
|
| 3230 |
default: |
| 3231 |
DEAL_II_NOT_IMPLEMENTED(); |
| 3232 |
} |
| 3233 |
|
| 3234 |
return h2l; |
| 3235 |
} |
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
template <int dim> |
| 3240 |
std::vector<unsigned int> |
| 3241 |
lexicographic_to_hierarchic_numbering(const unsigned int degree) |
| 3242 |
{ |
| 3243 |
return Utilities::invert_permutation( |
| 3244 |
hierarchic_to_lexicographic_numbering<dim>(degree)); |
| 3245 |
} |
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
template <int dim> |
| 3250 |
std::pair<std::vector<unsigned int>, std::vector<unsigned int>> |
| 3251 |
cell_to_face_patch(const unsigned int °ree, |
| 3252 |
const unsigned int &direction, |
| 3253 |
const bool &cell_hierarchical_numbering, |
| 3254 |
const bool &is_continuous) |
| 3255 |
{ |
| 3256 |
AssertThrow(dim > 1, ExcInvalidFEDimension(1, dim)); |
| 3257 |
AssertThrow(direction < dim, ExcInvalidFEDimension(direction, dim)); |
| 3258 |
|
| 3259 |
// n_1d: DoFs per 1D edge (parallel to face) |
| 3260 |
const unsigned int n_1d = degree + 1; |
| 3261 |
// n_ort: DoFs in the direction orthogonal to the face in the combined face |
| 3262 |
// space For discontinuous: 2*n (n for cell0 face, n for cell1 face) For |
| 3263 |
// continuous: 2*n - 1 (shared DoFs) |
| 3264 |
const unsigned int n_ort_1d = 2 * n_1d - (is_continuous ? 1 : 0); |
| 3265 |
|
| 3266 |
const unsigned int dofs_per_cell = Utilities::fixed_power<dim>(n_1d); |
| 3267 |
const unsigned int dofs_per_face_patch = |
| 3268 |
Utilities::fixed_power<dim - 1>(n_1d) * n_ort_1d; |
| 3269 |
|
| 3270 |
std::array<unsigned int, dim> face_patch_dofs_in_direction; |
| 3271 |
for (unsigned int d = 0; d < dim; ++d) |
| 3272 |
face_patch_dofs_in_direction[d] = n_1d; |
| 3273 |
face_patch_dofs_in_direction[direction] = n_ort_1d; |
| 3274 |
|
| 3275 |
// Initialize maps for cell0 and cell1 DoFs to face DoFs |
| 3276 |
std::array<std::vector<unsigned int>, 2> results; |
| 3277 |
results[0].resize(dofs_per_cell, numbers::invalid_unsigned_int); |
| 3278 |
results[1].resize(dofs_per_cell, numbers::invalid_unsigned_int); |
| 3279 |
|
| 3280 |
// Compute with lexicographic first |
| 3281 |
for (unsigned int i = 0; i < dofs_per_face_patch; ++i) |
| 3282 |
{ |
| 3283 |
// Decompose i into multiindex |
| 3284 |
std::array<unsigned int, dim> face_multiindex; |
| 3285 |
unsigned int temp = i; |
| 3286 |
for (unsigned int d = 0; d < dim; ++d) |
| 3287 |
{ |
| 3288 |
face_multiindex[d] = temp % face_patch_dofs_in_direction[d]; |
| 3289 |
temp /= face_patch_dofs_in_direction[d]; |
| 3290 |
} |
| 3291 |
|
| 3292 |
std::array<unsigned int, dim> cell_multiindex = face_multiindex; |
| 3293 |
|
| 3294 |
// compute corresponding cell |
| 3295 |
unsigned int cell = face_multiindex[direction] / n_1d; |
| 3296 |
cell_multiindex[direction] = face_multiindex[direction] % n_1d; |
| 3297 |
if (is_continuous) |
| 3298 |
cell_multiindex[direction] += cell; |
| 3299 |
|
| 3300 |
{ |
| 3301 |
unsigned int cell_index = 0; |
| 3302 |
unsigned int stride = 1; |
| 3303 |
for (unsigned int d = 0; d < dim; ++d) |
| 3304 |
{ |
| 3305 |
cell_index += cell_multiindex[d] * stride; |
| 3306 |
stride *= n_1d; |
| 3307 |
} |
| 3308 |
results[cell][cell_index] = i; |
| 3309 |
} |
| 3310 |
|
| 3311 |
if (face_multiindex[direction] == n_1d - 1 && is_continuous) |
| 3312 |
{ |
| 3313 |
// fill the other cell |
| 3314 |
unsigned other_cell = 1; |
| 3315 |
cell_multiindex[direction] = 0; |
| 3316 |
unsigned int cell_index = 0; |
| 3317 |
unsigned int stride = 1; |
| 3318 |
for (unsigned int d = 0; d < dim; ++d) |
| 3319 |
{ |
| 3320 |
cell_index += cell_multiindex[d] * stride; |
| 3321 |
stride *= n_1d; |
| 3322 |
} |
| 3323 |
results[other_cell][cell_index] = i; |
| 3324 |
} |
| 3325 |
} |
| 3326 |
// Now we have the DoFs in lexicographic order |
| 3327 |
if (!cell_hierarchical_numbering) |
| 3328 |
return std::make_pair(results[0], results[1]); |
| 3329 |
|
| 3330 |
// Renumbering required for hierarchical numbering |
| 3331 |
std::vector<unsigned int> lex_to_hie = |
| 3332 |
lexicographic_to_hierarchic_numbering<dim>(degree); |
| 3333 |
|
| 3334 |
for (auto &result : results) |
| 3335 |
{ |
| 3336 |
std::vector<unsigned int> renumbered_result = result; |
| 3337 |
for (unsigned int i = 0; i < dofs_per_cell; ++i) |
| 3338 |
renumbered_result[lex_to_hie[i]] = result[i]; |
| 3339 |
result = renumbered_result; |
| 3340 |
} |
| 3341 |
return std::make_pair(results[0], results[1]); |
| 3342 |
} |
| 3343 |
|
| 3344 |
} // namespace FETools |
| 3345 |
|
| 3346 |
|
| 3347 |
DEAL_II_NAMESPACE_CLOSE |
| 3348 |
|
| 3349 |
#endif /* dealii_fe_tools_templates_H */ |