Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/tensor_product_polynomials_const.h>
18 #include <deal.II/base/exceptions.h>
19 #include <deal.II/base/table.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 compute (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 || third_derivatives.size()==0,
105  ExcDimensionMismatch2(third_derivatives.size(), this->n_tensor_pols+1, 0));
106  Assert (fourth_derivatives.size()==this->n_tensor_pols+1 || fourth_derivatives.size()==0,
107  ExcDimensionMismatch2(fourth_derivatives.size(), this->n_tensor_pols+1, 0));
108 
109  // remove slot for const value, go into the base class compute method and
110  // finally append the const value again
111  bool do_values = false, do_grads = false, do_grad_grads = false;
112  bool do_3rd_derivatives = false, do_4th_derivatives = false;
113  if (values.empty() == false)
114  {
115  values.pop_back();
116  do_values = true;
117  }
118  if (grads.empty() == false)
119  {
120  grads.pop_back();
121  do_grads = true;
122  }
123  if (grad_grads.empty() == false)
124  {
125  grad_grads.pop_back();
126  do_grad_grads = true;
127  }
128  if (third_derivatives.empty() == false)
129  {
130  third_derivatives.resize(this->n_tensor_pols);
131  do_3rd_derivatives = true;
132  }
133  if (fourth_derivatives.empty() == false)
134  {
135  fourth_derivatives.resize(this->n_tensor_pols);
136  do_4th_derivatives = true;
137  }
138 
139  this->TensorProductPolynomials<dim>::compute(p, values, grads, grad_grads, third_derivatives, fourth_derivatives);
140 
141  //for dgq node: values =1, grads=0, grads_grads=0, third_derivatives=0, fourth_derivatives=0
142  if (do_values)
143  values.push_back(1.);
144  if (do_grads)
145  grads.emplace_back();
146  if (do_grad_grads)
147  grad_grads.emplace_back();
148  if (do_3rd_derivatives)
149  third_derivatives.emplace_back();
150  if (do_4th_derivatives)
151  fourth_derivatives.emplace_back();
152 }
153 
154 
155 /* ------------------- explicit instantiations -------------- */
156 template class TensorProductPolynomialsConst<1>;
157 template class TensorProductPolynomialsConst<2>;
158 template class TensorProductPolynomialsConst<3>;
159 
160 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
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const
static ::ExceptionBase & ExcDimensionMismatch2(int arg1, int arg2, int arg3)
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
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const
#define Assert(cond, exc)
Definition: exceptions.h:1142
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
static ::ExceptionBase & ExcNotImplemented()
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const
double compute_value(const unsigned int i, const Point< dim > &p) const
static ::ExceptionBase & ExcInternalError()