1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
// ------------------------------------------------------------------------
//
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (C) 2013 - 2025 by the deal.II authors
//
// This file is part of the deal.II library.
//
// Part of the source code is dual licensed under Apache-2.0 WITH
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
// governing the source code and code contributions can be found in
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
//
// ------------------------------------------------------------------------
#include <deal.II/base/exceptions.h>
#include <deal.II/base/tensor_product_polynomials_const.h>
#include <memory>
DEAL_II_NAMESPACE_OPEN
/* ------------------- TensorProductPolynomialsConst -------------- */
template <int dim>
void
TensorProductPolynomialsConst<dim>::output_indices(std::ostream &out) const
{
std::array<unsigned int, dim> ix;
for (unsigned int i = 0; i < tensor_polys.n(); ++i)
{
tensor_polys.compute_index(i, ix);
out << i << "\t";
for (unsigned int d = 0; d < dim; ++d)
out << ix[d] << " ";
out << std::endl;
}
}
template <int dim>
void
TensorProductPolynomialsConst<dim>::set_numbering(
const std::vector<unsigned int> &renumber)
{
Assert(renumber.size() == index_map.size(),
ExcDimensionMismatch(renumber.size(), index_map.size()));
index_map = renumber;
for (unsigned int i = 0; i < index_map.size(); ++i)
index_map_inverse[index_map[i]] = i;
std::vector<unsigned int> renumber_base;
renumber_base.reserve(tensor_polys.n());
for (unsigned int i = 0; i < tensor_polys.n(); ++i)
renumber_base.push_back(renumber[i]);
tensor_polys.set_numbering(renumber_base);
}
template <int dim>
double
TensorProductPolynomialsConst<dim>::compute_value(const unsigned int i,
const Point<dim> &p) const
{
const unsigned int max_indices = tensor_polys.n();
Assert(i <= max_indices, ExcInternalError());
// treat the regular basis functions
if (i < max_indices)
return tensor_polys.compute_value(i, p);
else
// this is for the constant function
return 1.;
}
template <int dim>
Tensor<1, dim>
TensorProductPolynomialsConst<dim>::compute_grad(const unsigned int i,
const Point<dim> &p) const
{
if constexpr (dim == 0)
{
(void)i;
(void)p;
DEAL_II_NOT_IMPLEMENTED();
return {};
}
else
{
const unsigned int max_indices = tensor_polys.n();
Assert(i <= max_indices, ExcInternalError());
// treat the regular basis functions
if (i < max_indices)
return tensor_polys.compute_grad(i, p);
else
// this is for the constant function
return Tensor<1, dim>();
}
}
template <int dim>
Tensor<2, dim>
TensorProductPolynomialsConst<dim>::compute_grad_grad(const unsigned int i,
const Point<dim> &p) const
{
const unsigned int max_indices = tensor_polys.n();
Assert(i <= max_indices, ExcInternalError());
// treat the regular basis functions
if (i < max_indices)
return tensor_polys.compute_grad_grad(i, p);
else
// this is for the constant function
return Tensor<2, dim>();
}
template <int dim>
void
TensorProductPolynomialsConst<dim>::evaluate(
const Point<dim> &p,
std::vector<double> &values,
std::vector<Tensor<1, dim>> &grads,
std::vector<Tensor<2, dim>> &grad_grads,
std::vector<Tensor<3, dim>> &third_derivatives,
std::vector<Tensor<4, dim>> &fourth_derivatives) const
{
Assert(values.size() == tensor_polys.n() + 1 || values.empty(),
ExcDimensionMismatch2(values.size(), tensor_polys.n() + 1, 0));
Assert(grads.size() == tensor_polys.n() + 1 || grads.empty(),
ExcDimensionMismatch2(grads.size(), tensor_polys.n() + 1, 0));
Assert(grad_grads.size() == tensor_polys.n() + 1 || grad_grads.empty(),
ExcDimensionMismatch2(grad_grads.size(), tensor_polys.n() + 1, 0));
Assert(third_derivatives.size() == tensor_polys.n() + 1 ||
third_derivatives.empty(),
ExcDimensionMismatch2(third_derivatives.size(),
tensor_polys.n() + 1,
0));
Assert(fourth_derivatives.size() == tensor_polys.n() + 1 ||
fourth_derivatives.empty(),
ExcDimensionMismatch2(fourth_derivatives.size(),
tensor_polys.n() + 1,
0));
// remove slot for const value, go into the base class compute method and
// finally append the const value again
bool do_values = false, do_grads = false, do_grad_grads = false;
bool do_3rd_derivatives = false, do_4th_derivatives = false;
if (values.empty() == false)
{
values.pop_back();
do_values = true;
}
if (grads.empty() == false)
{
grads.pop_back();
do_grads = true;
}
if (grad_grads.empty() == false)
{
grad_grads.pop_back();
do_grad_grads = true;
}
if (third_derivatives.empty() == false)
{
third_derivatives.resize(tensor_polys.n());
do_3rd_derivatives = true;
}
if (fourth_derivatives.empty() == false)
{
fourth_derivatives.resize(tensor_polys.n());
do_4th_derivatives = true;
}
tensor_polys.evaluate(
p, values, grads, grad_grads, third_derivatives, fourth_derivatives);
// for dgq node: values =1, grads=0, grads_grads=0, third_derivatives=0,
// fourth_derivatives=0
if (do_values)
values.push_back(1.);
if (do_grads)
grads.emplace_back();
if (do_grad_grads)
grad_grads.emplace_back();
if (do_3rd_derivatives)
third_derivatives.emplace_back();
if (do_4th_derivatives)
fourth_derivatives.emplace_back();
}
template <int dim>
std::unique_ptr<ScalarPolynomialsBase<dim>>
TensorProductPolynomialsConst<dim>::clone() const
{
return std::make_unique<TensorProductPolynomialsConst<dim>>(*this);
}
/* ------------------- explicit instantiations -------------- */
template class TensorProductPolynomialsConst<1>;
template class TensorProductPolynomialsConst<2>;
template class TensorProductPolynomialsConst<3>;
DEAL_II_NAMESPACE_CLOSE
|