Reference documentation for deal.II version 9.1.0-pre
tensor_product_polynomials_const.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2012 - 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/exceptions.h>
18 #include <deal.II/base/table.h>
19 #include <deal.II/base/tensor_product_polynomials_const.h>
20 
21 DEAL_II_NAMESPACE_OPEN
22 
23 
24 
25 /* ------------------- TensorProductPolynomialsConst -------------- */
26 
27 
28 template <int dim>
29 double
31  const Point<dim> & p) const
32 {
33  const unsigned int max_indices = this->n_tensor_pols;
34  Assert(i <= max_indices, ExcInternalError());
35 
36  // treat the regular basis functions
37  if (i < max_indices)
39  else
40  // this is for the constant function
41  return 1.;
42 }
43 
44 
45 
46 template <>
47 double
49  const Point<0> &) const
50 {
51  Assert(false, ExcNotImplemented());
52  return 0.;
53 }
54 
55 
56 template <int dim>
59  const Point<dim> & p) const
60 {
61  const unsigned int max_indices = this->n_tensor_pols;
62  Assert(i <= max_indices, ExcInternalError());
63 
64  // treat the regular basis functions
65  if (i < max_indices)
67  else
68  // this is for the constant function
69  return Tensor<1, dim>();
70 }
71 
72 template <int dim>
75  const Point<dim> &p) const
76 {
77  const unsigned int max_indices = this->n_tensor_pols;
78  Assert(i <= max_indices, ExcInternalError());
79 
80  // treat the regular basis functions
81  if (i < max_indices)
83  else
84  // this is for the constant function
85  return Tensor<2, dim>();
86 }
87 
88 template <int dim>
89 void
91  const Point<dim> & p,
92  std::vector<double> & values,
93  std::vector<Tensor<1, dim>> &grads,
94  std::vector<Tensor<2, dim>> &grad_grads,
95  std::vector<Tensor<3, dim>> &third_derivatives,
96  std::vector<Tensor<4, dim>> &fourth_derivatives) const
97 {
98  Assert(values.size() == this->n_tensor_pols + 1 || values.size() == 0,
99  ExcDimensionMismatch2(values.size(), this->n_tensor_pols + 1, 0));
100  Assert(grads.size() == this->n_tensor_pols + 1 || grads.size() == 0,
101  ExcDimensionMismatch2(grads.size(), this->n_tensor_pols + 1, 0));
102  Assert(grad_grads.size() == this->n_tensor_pols + 1 || grad_grads.size() == 0,
103  ExcDimensionMismatch2(grad_grads.size(), this->n_tensor_pols + 1, 0));
104  Assert(third_derivatives.size() == this->n_tensor_pols + 1 ||
105  third_derivatives.size() == 0,
106  ExcDimensionMismatch2(third_derivatives.size(),
107  this->n_tensor_pols + 1,
108  0));
109  Assert(fourth_derivatives.size() == this->n_tensor_pols + 1 ||
110  fourth_derivatives.size() == 0,
111  ExcDimensionMismatch2(fourth_derivatives.size(),
112  this->n_tensor_pols + 1,
113  0));
114 
115  // remove slot for const value, go into the base class compute method and
116  // finally append the const value again
117  bool do_values = false, do_grads = false, do_grad_grads = false;
118  bool do_3rd_derivatives = false, do_4th_derivatives = false;
119  if (values.empty() == false)
120  {
121  values.pop_back();
122  do_values = true;
123  }
124  if (grads.empty() == false)
125  {
126  grads.pop_back();
127  do_grads = true;
128  }
129  if (grad_grads.empty() == false)
130  {
131  grad_grads.pop_back();
132  do_grad_grads = true;
133  }
134  if (third_derivatives.empty() == false)
135  {
136  third_derivatives.resize(this->n_tensor_pols);
137  do_3rd_derivatives = true;
138  }
139  if (fourth_derivatives.empty() == false)
140  {
141  fourth_derivatives.resize(this->n_tensor_pols);
142  do_4th_derivatives = true;
143  }
144 
146  p, values, grads, grad_grads, third_derivatives, fourth_derivatives);
147 
148  // for dgq node: values =1, grads=0, grads_grads=0, third_derivatives=0,
149  // fourth_derivatives=0
150  if (do_values)
151  values.push_back(1.);
152  if (do_grads)
153  grads.emplace_back();
154  if (do_grad_grads)
155  grad_grads.emplace_back();
156  if (do_3rd_derivatives)
157  third_derivatives.emplace_back();
158  if (do_4th_derivatives)
159  fourth_derivatives.emplace_back();
160 }
161 
162 
163 /* ------------------- explicit instantiations -------------- */
164 template class TensorProductPolynomialsConst<1>;
165 template class TensorProductPolynomialsConst<2>;
166 template class TensorProductPolynomialsConst<3>;
167 
168 DEAL_II_NAMESPACE_CLOSE
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const
double compute_value(const unsigned int i, const Point< dim > &p) const
static::ExceptionBase & ExcDimensionMismatch2(int arg1, int arg2, int arg3)
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const
double compute_value(const unsigned int i, const Point< dim > &p) const
void compute(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
void compute(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
#define Assert(cond, exc)
Definition: exceptions.h:1227
static::ExceptionBase & ExcNotImplemented()
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const
static::ExceptionBase & ExcInternalError()