21#include <boost/container/small_vector.hpp>
37 template <std::
size_t dim>
39 compute_tensor_index(
const unsigned int,
42 std::array<unsigned int, dim> &)
48 compute_tensor_index(
const unsigned int n,
51 std::array<unsigned int, 1> &indices)
57 compute_tensor_index(
const unsigned int n,
58 const unsigned int n_pols_0,
60 std::array<unsigned int, 2> &indices)
62 indices[0] = n % n_pols_0;
63 indices[1] = n / n_pols_0;
67 compute_tensor_index(
const unsigned int n,
68 const unsigned int n_pols_0,
69 const unsigned int n_pols_1,
70 std::array<unsigned int, 3> &indices)
72 indices[0] = n % n_pols_0;
73 indices[1] = (n / n_pols_0) % n_pols_1;
74 indices[2] = n / (n_pols_0 * n_pols_1);
81template <
int dim,
typename PolynomialType>
85 std::array<unsigned int, dim> &indices)
const
87 Assert(i < Utilities::fixed_power<dim>(polynomials.size()),
89 internal::compute_tensor_index(index_map[i],
101 std::array<unsigned int, 0> &)
const
108template <
int dim,
typename PolynomialType>
111 std::ostream &out)
const
113 std::array<unsigned int, dim> ix;
114 for (
unsigned int i = 0; i < this->n(); ++i)
116 compute_index(i, ix);
118 for (
unsigned int d = 0; d < dim; ++d)
129 std::ostream &)
const
137inline const std::vector<unsigned int> &
146inline const std::vector<unsigned int> &
149 return index_map_inverse;
157 const std::vector<unsigned int> &renumber)
159 Assert(renumber.size() == index_map.size(),
162 index_map = renumber;
163 for (
unsigned int i = 0; i < index_map.size(); ++i)
164 index_map_inverse[index_map[i]] = i;
178template <
int dim,
typename PolynomialType>
181 const std::vector<unsigned int> &renumber)
183 Assert(renumber.size() == index_map.size(),
186 index_map = renumber;
187 for (
unsigned int i = 0; i < index_map.size(); ++i)
188 index_map_inverse[index_map[i]] = i;
196 const std::vector<unsigned int> &)
203template <
int dim,
typename PolynomialType>
206 const unsigned int i,
211 std::array<unsigned int, dim> indices;
212 compute_index(i, indices);
215 for (
unsigned int d = 0; d < dim; ++d)
216 value *= polynomials[indices[d]].value(p[d]);
236template <
int dim,
typename PolynomialType>
239 const unsigned int i,
242 std::array<unsigned int, dim> indices;
243 compute_index(i, indices);
251 std::vector<double> tmp(2);
252 for (
unsigned int d = 0; d < dim; ++d)
254 polynomials[indices[d]].value(p[d], tmp);
261 for (
unsigned int d = 0;
d < dim; ++
d)
264 for (
unsigned int x = 0; x < dim; ++x)
265 grad[d] *= v[x][d == x];
286template <
int dim,
typename PolynomialType>
289 const unsigned int i,
292 std::array<unsigned int, dim> indices;
293 compute_index(i, indices);
297 std::vector<double> tmp(3);
298 for (
unsigned int d = 0; d < dim; ++d)
300 polynomials[indices[d]].value(p[d], tmp);
308 for (
unsigned int d1 = 0; d1 < dim; ++d1)
309 for (
unsigned int d2 = 0; d2 < dim; ++d2)
311 grad_grad[d1][d2] = 1.;
312 for (
unsigned int x = 0; x < dim; ++x)
314 unsigned int derivative = 0;
315 if (d1 == x || d2 == x)
322 grad_grad[d1][d2] *= v[x][derivative];
352 template <
int dim, std::
size_t dim1>
355 const unsigned int n_derivatives,
358 const unsigned int size_x,
359 const boost::container::small_vector<std::array<unsigned int, dim1>, 64>
361 const std::vector<unsigned int> &index_map,
362 std::vector<double> &values,
368 const bool update_values = (values.size() == indices.size() * size_x);
369 const bool update_grads = (grads.size() == indices.size() * size_x);
370 const bool update_grad_grads =
371 (grad_grads.size() == indices.size() * size_x);
373 (third_derivatives.size() == indices.size() * size_x);
374 const bool update_4th_derivatives =
375 (fourth_derivatives.size() == indices.size() * size_x);
379 if (n_derivatives == 0)
380 for (
unsigned int i = 0, i1 = 0; i1 < indices.size(); ++i1)
382 double value_outer = 1.;
383 if constexpr (dim > 1)
384 for (
unsigned int d = 1; d < dim; ++d)
385 value_outer *= values_1d[indices[i1][d - 1]][0][d];
386 if (index_map.empty())
387 for (
unsigned int ix = 0; ix < size_x; ++ix, ++i)
388 values[i] = value_outer * values_1d[ix][0][0];
390 for (
unsigned int ix = 0; ix < size_x; ++ix, ++i)
391 values[index_map[i]] = value_outer * values_1d[ix][0][0];
394 for (
unsigned int iy = 0, i1 = 0; i1 < indices.size(); ++i1)
397 std::array<double, dim + (dim * (dim - 1)) / 2> value_outer;
399 if constexpr (dim > 1)
401 for (
unsigned int x = 1; x < dim; ++x)
402 value_outer[0] *= values_1d[indices[i1][x - 1]][0][x];
403 for (
unsigned int d = 1; d < dim; ++d)
405 value_outer[d] = values_1d[indices[i1][d - 1]][1][d];
406 for (
unsigned int x = 1; x < dim; ++x)
408 value_outer[d] *= values_1d[indices[i1][x - 1]][0][x];
410 for (
unsigned int d1 = 1, count = dim; d1 < dim; ++d1)
411 for (
unsigned int d2 = d1; d2 < dim; ++d2, ++count)
413 value_outer[count] = 1.;
414 for (
unsigned int x = 1; x < dim; ++x)
416 unsigned int derivative = 0;
422 value_outer[count] *=
423 values_1d[indices[i1][x - 1]][derivative][x];
430 for (
unsigned int ix = 0, i = iy; ix < size_x; ++ix, ++i)
432 std::array<double, 3> val_x{{values_1d[ix][0][0],
434 values_1d[ix][2][0]}};
435 const unsigned int index =
436 (index_map.empty() ? i : index_map[i]);
439 values[
index] = value_outer[0] * val_x[0];
443 grads[
index][0] = value_outer[0] * val_x[1];
444 if constexpr (dim > 1)
445 for (
unsigned int d = 1; d < dim; ++d)
446 grads[
index][d] = value_outer[d] * val_x[0];
449 if (update_grad_grads)
451 grad_grads[
index][0][0] = value_outer[0] * val_x[2];
452 if constexpr (dim > 1)
454 for (
unsigned int d = 1; d < dim; ++d)
455 grad_grads[
index][0][d] = grad_grads[
index][d][0] =
456 value_outer[d] * val_x[1];
457 for (
unsigned int d1 = 1, count = dim; d1 < dim; ++d1)
458 for (
unsigned int d2 = d1; d2 < dim; ++d2, ++count)
459 grad_grads[
index][d1][d2] =
460 grad_grads[
index][d2][d1] =
461 value_outer[count] * val_x[0];
468 for (
unsigned int ix = 0, i = iy; ix < size_x; ++ix, ++i)
470 const unsigned int index =
471 (index_map.empty() ? i : index_map[i]);
472 std::array<unsigned int, dim> my_indices;
474 if constexpr (dim > 1)
475 for (
unsigned int d = 1; d < dim; ++d)
476 my_indices[d] = indices[i1][d - 1];
477 for (
unsigned int d1 = 0; d1 < dim; ++d1)
478 for (
unsigned int d2 = 0; d2 < dim; ++d2)
479 for (
unsigned int d3 = 0; d3 < dim; ++d3)
482 for (
unsigned int x = 0; x < dim; ++x)
484 unsigned int derivative = 0;
492 der3 *= values_1d[my_indices[x]][derivative][x];
494 third_derivatives[
index][d1][d2][d3] = der3;
498 if (update_4th_derivatives)
499 for (
unsigned int ix = 0, i = iy; ix < size_x; ++ix, ++i)
501 const unsigned int index =
502 (index_map.empty() ? i : index_map[i]);
503 std::array<unsigned int, dim> my_indices;
505 if constexpr (dim > 1)
506 for (
unsigned int d = 1; d < dim; ++d)
507 my_indices[d] = indices[i1][d - 1];
508 for (
unsigned int d1 = 0; d1 < dim; ++d1)
509 for (
unsigned int d2 = 0; d2 < dim; ++d2)
510 for (
unsigned int d3 = 0; d3 < dim; ++d3)
511 for (
unsigned int d4 = 0; d4 < dim; ++d4)
514 for (
unsigned int x = 0; x < dim; ++x)
516 unsigned int derivative = 0;
526 der4 *= values_1d[my_indices[x]][derivative][x];
528 fourth_derivatives[
index][d1][d2][d3][d4] = der4;
540template <
int dim,
typename PolynomialType>
544 std::vector<double> &values,
551 Assert(values.size() == this->n() || values.empty(),
553 Assert(grads.size() == this->n() || grads.empty(),
555 Assert(grad_grads.size() == this->n() || grad_grads.empty(),
557 Assert(third_derivatives.size() == this->n() || third_derivatives.empty(),
559 Assert(fourth_derivatives.size() == this->n() || fourth_derivatives.empty(),
563 unsigned int n_derivatives = 0;
564 if (values.size() == this->n())
566 if (grads.size() == this->n())
568 if (grad_grads.size() == this->n())
570 if (third_derivatives.size() == this->n())
572 if (fourth_derivatives.size() == this->n())
578 const unsigned int n_polynomials = polynomials.size();
579 boost::container::small_vector<ndarray<double, 5, dim>, 10> values_1d(
581 if constexpr (std::is_same<PolynomialType,
584 std::array<double, dim> point_array;
585 for (
unsigned int d = 0; d < dim; ++d)
586 point_array[d] = p[d];
587 for (
unsigned int i = 0; i < n_polynomials; ++i)
588 polynomials[i].values_of_array(point_array,
590 values_1d[i].
data());
593 for (
unsigned int i = 0; i < n_polynomials; ++i)
594 for (
unsigned int d = 0; d < dim; ++d)
596 std::array<double, 5> derivatives;
597 polynomials[i].value(p[d], n_derivatives, derivatives.data());
598 for (
unsigned int j = 0; j <= n_derivatives; ++j)
599 values_1d[i][j][d] = derivatives[j];
604 constexpr unsigned int dim1 = dim > 1 ? dim - 1 : 1;
605 boost::container::small_vector<std::array<unsigned int, dim1>, 64> indices(1);
606 if constexpr (dim > 1)
607 for (
unsigned int d = 1; d < dim; ++d)
609 const unsigned int size = indices.size();
610 for (
unsigned int i = 1; i < n_polynomials; ++i)
611 for (
unsigned int j = 0; j <
size; ++j)
613 std::array<unsigned int, dim1> next_index = indices[j];
614 next_index[d - 1] = i;
615 indices.push_back(next_index);
620 internal::TensorProductPolynomials::evaluate_tensor_product<dim>(
639 std::vector<double> &,
650template <
int dim,
typename PolynomialType>
651std::unique_ptr<ScalarPolynomialsBase<dim>>
654 return std::make_unique<TensorProductPolynomials<dim, PolynomialType>>(*this);
659template <
int dim,
typename PolynomialType>
670template <
int dim,
typename PolynomialType>
671std::vector<PolynomialType>
688 , index_map(this->n())
689 , index_map_inverse(this->n())
692 for (
const auto &pols_d : pols)
696 ExcMessage(
"The number of polynomials must be larger than zero "
697 "for all coordinate directions."));
702 for (
unsigned int i = 0; i < this->
n(); ++i)
714 const unsigned int i,
715 std::array<unsigned int, dim> &indices)
const
718 unsigned int n_poly = 1;
719 for (
unsigned int d = 0; d < dim; ++d)
720 n_poly *= polynomials[d].
size();
728 internal::compute_tensor_index(index_map[i],
729 polynomials[0].
size(),
733 internal::compute_tensor_index(index_map[i],
734 polynomials[0].
size(),
735 polynomials[1].
size(),
744 std::array<unsigned int, 0> &)
const
756 std::array<unsigned int, dim> indices;
757 compute_index(i, indices);
760 for (
unsigned int d = 0; d < dim; ++d)
761 value *= polynomials[d][indices[d]].value(p[d]);
785 std::array<unsigned int, dim> indices;
786 compute_index(i, indices);
793 for (
unsigned int d = 0; d < dim; ++d)
794 polynomials[d][indices[d]].value(p[d], 1, v[d].
data());
797 for (
unsigned int d = 0; d < dim; ++d)
800 for (
unsigned int x = 0; x < dim; ++x)
801 grad[d] *= v[x][d == x];
826 std::array<unsigned int, dim> indices;
827 compute_index(i, indices);
830 for (
unsigned int d = 0; d < dim; ++d)
831 polynomials[d][indices[d]].value(p[d], 2, v[d].
data());
834 for (
unsigned int d1 = 0; d1 < dim; ++d1)
835 for (
unsigned int d2 = 0; d2 < dim; ++d2)
837 grad_grad[d1][d2] = 1.;
838 for (
unsigned int x = 0; x < dim; ++x)
840 unsigned int derivative = 0;
841 if (d1 == x || d2 == x)
848 grad_grad[d1][d2] *= v[x][derivative];
873 std::vector<double> &values,
879 Assert(values.size() == this->n() || values.empty(),
881 Assert(grads.size() == this->n() || grads.empty(),
883 Assert(grad_grads.size() == this->n() || grad_grads.empty(),
885 Assert(third_derivatives.size() == this->n() || third_derivatives.empty(),
887 Assert(fourth_derivatives.size() == this->n() || fourth_derivatives.empty(),
891 unsigned int n_derivatives = 0;
892 if (values.size() == this->n())
894 if (grads.size() == this->n())
896 if (grad_grads.size() == this->n())
898 if (third_derivatives.size() == this->n())
900 if (fourth_derivatives.size() == this->n())
905 std::size_t max_n_polynomials = 0;
906 for (
unsigned int d = 0; d < dim; ++d)
907 max_n_polynomials =
std::max(max_n_polynomials, polynomials[d].
size());
910 boost::container::small_vector<ndarray<double, 5, dim>, 10> values_1d(
912 if (n_derivatives == 0)
913 for (
unsigned int d = 0; d < dim; ++d)
914 for (
unsigned int i = 0; i < polynomials[d].size(); ++i)
915 values_1d[i][0][d] = polynomials[d][i].value(p[d]);
917 for (
unsigned int d = 0; d < dim; ++d)
918 for (
unsigned int i = 0; i < polynomials[d].size(); ++i)
923 std::array<double, 5> derivatives;
924 polynomials[d][i].value(p[d], n_derivatives, derivatives.data());
925 for (
unsigned int j = 0; j <= n_derivatives; ++j)
926 values_1d[i][j][d] = derivatives[j];
930 constexpr unsigned int dim1 = dim > 1 ? dim - 1 : 1;
931 boost::container::small_vector<std::array<unsigned int, dim1>, 64> indices(1);
932 for (
unsigned int d = 1; d < dim; ++d)
934 const unsigned int size = indices.size();
935 for (
unsigned int i = 1; i < polynomials[d].size(); ++i)
936 for (
unsigned int j = 0; j <
size; ++j)
938 std::array<unsigned int, dim1> next_index = indices[j];
939 next_index[d - 1] = i;
940 indices.push_back(next_index);
944 internal::TensorProductPolynomials::evaluate_tensor_product<dim>(
947 polynomials[0].
size(),
962 std::vector<double> &,
979 for (
unsigned int d = 0; d < dim; ++d)
999std::unique_ptr<ScalarPolynomialsBase<dim>>
1002 return std::make_unique<AnisotropicPolynomials<dim>>(*this);
void evaluate(const Point< dim > &unit_point, 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 override
double compute_value(const unsigned int i, const Point< dim > &p) const override
void set_numbering(const std::vector< unsigned int > &renumber)
AnisotropicPolynomials(const std::vector< std::vector< Polynomials::Polynomial< double > > > &base_polynomials)
static unsigned int get_n_tensor_pols(const std::vector< std::vector< Polynomials::Polynomial< double > > > &pols)
std::vector< unsigned int > index_map
void compute_index(const unsigned int i, std::array< unsigned int, dim > &indices) const
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const override
const std::vector< unsigned int > & get_numbering() const
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const override
std::vector< unsigned int > index_map_inverse
const std::vector< unsigned int > & get_numbering_inverse() const
virtual std::unique_ptr< ScalarPolynomialsBase< dim > > clone() const override
void evaluate(const Point< dim > &unit_point, 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 override
void output_indices(std::ostream &out) const
void compute_index(const unsigned int i, std::array< unsigned int, dim > &indices) const
double compute_value(const unsigned int i, const Point< dim > &p) const override
virtual std::size_t memory_consumption() const override
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const override
virtual std::unique_ptr< ScalarPolynomialsBase< dim > > clone() const override
std::vector< PolynomialType > get_underlying_polynomials() const
void set_numbering(const std::vector< unsigned int > &renumber)
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch2(std::size_t arg1, std::size_t arg2, std::size_t arg3)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
@ update_values
Shape function values.
@ update_3rd_derivatives
Third derivatives of shape functions.
#define DEAL_II_NOT_IMPLEMENTED()
std::vector< index_type > data
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
constexpr T pow(const T base, const int iexp)
void evaluate_tensor_product(const unsigned int n_derivatives, const boost::container::small_vector<::ndarray< double, 5, dim >, 10 > &values_1d, const unsigned int size_x, const boost::container::small_vector< std::array< unsigned int, dim1 >, 64 > &indices, const std::vector< unsigned int > &index_map, 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)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
typename internal::ndarray::HelperArray< T, Ns... >::type ndarray