49 const std::vector<unsigned int> &renumber)
51 Assert(renumber.size() == index_map.size(),
55 for (
unsigned int i = 0; i < index_map.size(); ++i)
56 index_map_inverse[index_map[i]] = i;
58 std::vector<unsigned int> renumber_base;
59 for (
unsigned int i = 0; i < tensor_polys.n(); ++i)
60 renumber_base.push_back(renumber[i]);
62 tensor_polys.set_numbering(renumber_base);
71 const unsigned int q_degree = tensor_polys.polynomials.size() - 1;
72 const unsigned int max_q_indices = tensor_polys.n();
73 Assert(i < max_q_indices + ((q_degree <= 1) ? 1 : dim),
77 if (i < max_q_indices)
78 return tensor_polys.compute_value(i, p);
80 const unsigned int comp = i - tensor_polys.n();
84 for (
unsigned int j = 0; j < dim; ++j)
85 value *= 4 * p[j] * (1 - p[j]);
89 for (
unsigned int i = 0; i < q_degree - 1; ++i)
90 value *= (2 * p[comp] - 1);
112 const unsigned int q_degree = tensor_polys.polynomials.size() - 1;
113 const unsigned int max_q_indices = tensor_polys.n();
114 Assert(i < max_q_indices + ((q_degree <= 1) ? 1 : dim),
118 if (i < max_q_indices)
119 return tensor_polys.compute_grad(i, p);
121 const unsigned int comp = i - tensor_polys.n();
124 for (
unsigned int d = 0; d < dim; ++d)
128 for (
unsigned j = 0; j < dim; ++j)
129 grad[d] *= (d == j ? 4 * (1 - 2 * p[j]) : 4 * p[j] * (1 - p[j]));
131 for (
unsigned int i = 0; i < q_degree - 1; ++i)
132 grad[d] *= 2 * p[comp] - 1;
139 for (
unsigned int j = 0; j < dim; ++j)
140 value *= 4 * p[j] * (1 - p[j]);
142 double tmp = value * 2 * (q_degree - 1);
143 for (
unsigned int i = 0; i < q_degree - 2; ++i)
144 tmp *= 2 * p[comp] - 1;
156 const unsigned int i,
159 const unsigned int q_degree = tensor_polys.polynomials.size() - 1;
160 const unsigned int max_q_indices = tensor_polys.n();
161 Assert(i < max_q_indices + ((q_degree <= 1) ? 1 : dim),
165 if (i < max_q_indices)
166 return tensor_polys.compute_grad_grad(i, p);
168 const unsigned int comp = i - tensor_polys.n();
170 double v[dim + 1][3];
172 for (
unsigned int c = 0; c < dim; ++c)
174 v[c][0] = 4 * p[c] * (1 - p[c]);
175 v[c][1] = 4 * (1 - 2 * p[c]);
180 for (
unsigned int i = 0; i < q_degree - 1; ++i)
181 tmp *= 2 * p[comp] - 1;
186 double tmp = 2 * (q_degree - 1);
187 for (
unsigned int i = 0; i < q_degree - 2; ++i)
188 tmp *= 2 * p[comp] - 1;
196 double tmp = 4 * (q_degree - 2) * (q_degree - 1);
197 for (
unsigned int i = 0; i < q_degree - 3; ++i)
198 tmp *= 2 * p[comp] - 1;
207 for (
unsigned int d1 = 0; d1 < dim; ++d1)
208 for (
unsigned int d2 = 0; d2 < dim; ++d2)
210 grad_grad_1[d1][d2] = v[dim][0];
211 for (
unsigned int x = 0; x < dim; ++x)
213 unsigned int derivative = 0;
214 if (d1 == x || d2 == x)
221 grad_grad_1[d1][d2] *= v[x][derivative];
229 for (
unsigned int d = 0; d < dim; ++d)
231 grad_grad_2[d][comp] = v[dim][1];
232 grad_grad_3[comp][d] = v[dim][1];
233 for (
unsigned int x = 0; x < dim; ++x)
235 grad_grad_2[d][comp] *= v[x][d == x];
236 grad_grad_3[comp][d] *= v[x][d == x];
242 double psi_value = 1.;
243 for (
unsigned int x = 0; x < dim; ++x)
244 psi_value *= v[x][0];
246 for (
unsigned int d1 = 0; d1 < dim; ++d1)
247 for (
unsigned int d2 = 0; d2 < dim; ++d2)
249 grad_grad_1[d1][d2] + grad_grad_2[d1][d2] + grad_grad_3[d1][d2];
250 grad_grad[comp][comp] += psi_value * v[dim][2];
261 std::vector<double> &values,
267 const unsigned int q_degree = tensor_polys.polynomials.size() - 1;
268 const unsigned int max_q_indices = tensor_polys.n();
270 const unsigned int n_bubbles = ((q_degree <= 1) ? 1 : dim);
271 Assert(values.size() == max_q_indices + n_bubbles || values.empty(),
273 Assert(grads.size() == max_q_indices + n_bubbles || grads.empty(),
275 Assert(grad_grads.size() == max_q_indices + n_bubbles || grad_grads.empty(),
277 max_q_indices + n_bubbles,
279 Assert(third_derivatives.size() == max_q_indices + n_bubbles ||
280 third_derivatives.empty(),
282 max_q_indices + n_bubbles,
284 Assert(fourth_derivatives.size() == max_q_indices + n_bubbles ||
285 fourth_derivatives.empty(),
287 max_q_indices + n_bubbles,
290 bool do_values =
false, do_grads =
false, do_grad_grads =
false;
291 bool do_3rd_derivatives =
false, do_4th_derivatives =
false;
292 if (values.empty() ==
false)
294 values.resize(tensor_polys.n());
297 if (grads.empty() ==
false)
299 grads.resize(tensor_polys.n());
302 if (grad_grads.empty() ==
false)
304 grad_grads.resize(tensor_polys.n());
305 do_grad_grads =
true;
307 if (third_derivatives.empty() ==
false)
309 third_derivatives.resize(tensor_polys.n());
310 do_3rd_derivatives =
true;
312 if (fourth_derivatives.empty() ==
false)
314 fourth_derivatives.resize(tensor_polys.n());
315 do_4th_derivatives =
true;
318 tensor_polys.evaluate(
319 p, values, grads, grad_grads, third_derivatives, fourth_derivatives);
321 for (
unsigned int i = tensor_polys.n(); i < tensor_polys.n() + n_bubbles; ++i)
324 values.push_back(compute_value(i, p));
326 grads.push_back(compute_grad(i, p));
328 grad_grads.push_back(compute_grad_grad(i, p));
329 if (do_3rd_derivatives)
330 third_derivatives.push_back(compute_derivative<3>(i, p));
331 if (do_4th_derivatives)
332 fourth_derivatives.push_back(compute_derivative<4>(i, p));
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