/usr/include/deal.II/base/tensor_product_polynomials.h is in libdeal.ii-dev 6.3.1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | //---------------------------------------------------------------------------
// $Id: tensor_product_polynomials.h 20161 2009-11-24 22:54:51Z kanschat $
// Version: $Name$
//
// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__tensor_product_polynomials_h
#define __deal2__tensor_product_polynomials_h
#include <base/config.h>
#include <base/exceptions.h>
#include <base/tensor.h>
#include <base/point.h>
#include <base/polynomial.h>
#include <vector>
DEAL_II_NAMESPACE_OPEN
/**
* @addtogroup Polynomials
* @{
*/
/**
* Tensor product of given polynomials.
*
* Given a vector of <i>n</i> one-dimensional polynomials
* <i>P<sub>1</sub></i> to <i>P<sub>n</sub></i>, this class generates
* <i>n<sup>dim</sup></i> polynomials of the form
* <i>Q<sub>ijk</sub>(x,y,z) =
* P<sub>i</sub>(x)P<sub>j</sub>(y)P<sub>k</sub>(z)</i>. If the base
* polynomials are mutually orthogonal on the interval [-1,1] or
* [0,1], then the tensor product polynomials are orthogonal on
* [-1,1]<sup>dim</sup> or [0,1]<sup>dim</sup>, respectively.
*
* Indexing is as follows: the order of dim-dimensional polynomials is
* x-coordinates running fastest, then y-coordinate, etc. The first
* few polynomials are thus <i>P<sub>1</sub>(x)P<sub>1</sub>(y),
* P<sub>2</sub>(x)P<sub>1</sub>(y), P<sub>3</sub>(x)P<sub>1</sub>(y),
* ..., P<sub>1</sub>(x)P<sub>2</sub>(y),
* P<sub>2</sub>(x)P<sub>2</sub>(y), P<sub>3</sub>(x)P<sub>2</sub>(y),
* ...</i> and likewise in 3d.
*
* The output_indices() function prints the ordering of the
* dim-dimensional polynomials, i.e. for each polynomial in the
* polynomial space it gives the indices i,j,k of the one-dimensional
* polynomials in x,y and z direction. The ordering of the
* dim-dimensional polynomials can be changed by using the
* set_numbering() function.
*
* @author Ralf Hartmann, 2000, 2004, Guido Kanschat, 2000, Wolfgang Bangerth 2003
*/
template <int dim>
class TensorProductPolynomials
{
public:
/**
* Access to the dimension of
* this object, for checking and
* automatic setting of dimension
* in other classes.
*/
static const unsigned int dimension = dim;
/**
* Constructor. <tt>pols</tt> is
* a vector of objects that
* should be derived or otherwise
* convertible to one-dimensional
* polynomial objects. It will be
* copied element by element into
* a private variable.
*/
template <class Pol>
TensorProductPolynomials (const std::vector<Pol> &pols);
/**
* Prints the list of the indices
* to <tt>out</tt>.
*/
void output_indices(std::ostream &out) const;
/**
* Sets the ordering of the
* polynomials. Requires
* <tt>renumber.size()==n()</tt>.
* Stores a copy of
* <tt>renumber</tt>.
*/
void set_numbering(const std::vector<unsigned int> &renumber);
/**
* Gives read access to the
* renumber vector.
*/
const std::vector<unsigned int> &get_numbering() const;
/**
* Gives read access to the
* inverse renumber vector.
*/
const std::vector<unsigned int> &get_numbering_inverse() const;
/**
* Computes the value and the
* first and second derivatives
* of each tensor product
* polynomial at <tt>unit_point</tt>.
*
* The size of the vectors must
* either be equal 0 or equal
* n(). In the first case, the
* function will not compute
* these values.
*
* If you need values or
* derivatives of all tensor
* product polynomials then use
* this function, rather than
* using any of the
* compute_value(),
* compute_grad() or
* compute_grad_grad()
* functions, see below, in a
* loop over all tensor product
* polynomials.
*/
void compute (const Point<dim> &unit_point,
std::vector<double> &values,
std::vector<Tensor<1,dim> > &grads,
std::vector<Tensor<2,dim> > &grad_grads) const;
/**
* Computes the value of the
* <tt>i</tt>th tensor product
* polynomial at
* <tt>unit_point</tt>. Here <tt>i</tt> is
* given in tensor product
* numbering.
*
* Note, that using this function
* within a loop over all tensor
* product polynomials is not
* efficient, because then each
* point value of the underlying
* (one-dimensional) polynomials
* is (unnecessarily) computed
* several times. Instead use
* the compute() function with
* <tt>values.size()==</tt>n()
* to get the point values of all
* tensor polynomials all at once
* and in a much more efficient
* way.
*/
double compute_value (const unsigned int i,
const Point<dim> &p) const;
/**
* Computes the grad of the
* <tt>i</tt>th tensor product
* polynomial at
* <tt>unit_point</tt>. Here <tt>i</tt> is
* given in tensor product
* numbering.
*
* Note, that using this function
* within a loop over all tensor
* product polynomials is not
* efficient, because then each
* derivative value of the
* underlying (one-dimensional)
* polynomials is (unnecessarily)
* computed several times.
* Instead use the compute()
* function, see above, with
* <tt>grads.size()==</tt>n()
* to get the point value of all
* tensor polynomials all at once
* and in a much more efficient
* way.
*/
Tensor<1,dim> compute_grad (const unsigned int i,
const Point<dim> &p) const;
/**
* Computes the second
* derivative (grad_grad) of the
* <tt>i</tt>th tensor product
* polynomial at
* <tt>unit_point</tt>. Here <tt>i</tt> is
* given in tensor product
* numbering.
*
* Note, that using this function
* within a loop over all tensor
* product polynomials is not
* efficient, because then each
* derivative value of the
* underlying (one-dimensional)
* polynomials is (unnecessarily)
* computed several times.
* Instead use the compute()
* function, see above, with
* <tt>grad_grads.size()==</tt>n()
* to get the point value of all
* tensor polynomials all at once
* and in a much more efficient
* way.
*/
Tensor<2,dim> compute_grad_grad (const unsigned int i,
const Point<dim> &p) const;
/**
* Returns the number of tensor
* product polynomials. For <i>n</i>
* 1d polynomials this is <i>n<sup>dim</sup></i>.
*/
unsigned int n () const;
private:
/**
* Copy of the vector <tt>pols</tt> of
* polynomials given to the
* constructor.
*/
std::vector<Polynomials::Polynomial<double> > polynomials;
/**
* Number of tensor product
* polynomials. See n().
*/
unsigned int n_tensor_pols;
/**
* Index map for reordering the
* polynomials.
*/
std::vector<unsigned int> index_map;
/**
* Index map for reordering the
* polynomials.
*/
std::vector<unsigned int> index_map_inverse;
/**
* Each tensor product polynomial
* <i>i</i> is a product of
* one-dimensional polynomials in
* each space direction. Compute
* the indices of these
* one-dimensional polynomials
* for each space direction,
* given the index <i>i</i>.
*/
void compute_index (const unsigned int i,
unsigned int (&indices)[dim]) const;
/**
* Computes
* <i>x<sup>dim</sup></i> for
* unsigned int <i>x</i>. Used in
* the constructor.
*/
static
unsigned int x_to_the_dim (const unsigned int x);
};
#ifndef DOXYGEN
template <int dim>
inline
const std::vector<unsigned int> &
TensorProductPolynomials<dim>::get_numbering() const
{
return index_map;
}
template <int dim>
inline
const std::vector<unsigned int> &
TensorProductPolynomials<dim>::get_numbering_inverse() const
{
return index_map_inverse;
}
#endif // DOXYGEN
/**
* Anisotropic tensor product of given polynomials.
*
* Given one-dimensional polynomials <tt>Px1</tt>, <tt>Px2</tt>, ... in
* x-direction, <tt>Py1</tt>, <tt>Py2</tt>, ... in y-direction, and so on, this
* class generates polynomials of the form <i>Q<sub>ijk</sub>(x,y,z) =
* Pxi(x)Pyj(y)Pzk(z)</i>. If the base polynomials are mutually
* orthogonal on the interval $[-1,1]$ or $[0,d]$, then the tensor
* product polynomials are orthogonal on $[-1,1]^d$ or $[0,1]^d$,
* respectively.
*
* Indexing is as follows: the order of dim-dimensional polynomials
* is x-coordinates running fastest, then y-coordinate, etc. The first
* few polynomials are thus <tt>Px1(x)Py1(y)</tt>, <tt>Px2(x)Py1(y)</tt>,
* <tt>Px3(x)Py1(y)</tt>, ..., <tt>Px1(x)Py2(y)</tt>, <tt>Px2(x)Py2(y)</tt>,
* <tt>Px3(x)Py2(y)</tt>, ..., and likewise in 3d.
*
* @author Wolfgang Bangerth 2003
*/
template <int dim>
class AnisotropicPolynomials
{
public:
/**
* Constructor. <tt>pols</tt> is a
* table of one-dimensional
* polynomials. The number of
* rows in this table should be
* equal to the space dimension,
* with the elements of each row
* giving the polynomials that
* shall be used in this
* particular coordinate
* direction. These polynomials
* may vary between coordinates,
* as well as their number.
*/
AnisotropicPolynomials (const std::vector<std::vector<Polynomials::Polynomial<double> > > &pols);
/**
* Computes the value and the
* first and second derivatives
* of each tensor product
* polynomial at <tt>unit_point</tt>.
*
* The size of the vectors must
* either be equal <tt>0</tt> or equal
* <tt>n_tensor_pols</tt>. In the
* first case, the function will
* not compute these values.
*
* If you need values or
* derivatives of all tensor
* product polynomials then use
* this function, rather than
* using any of the
* <tt>compute_value</tt>,
* <tt>compute_grad</tt> or
* <tt>compute_grad_grad</tt>
* functions, see below, in a
* loop over all tensor product
* polynomials.
*/
void compute (const Point<dim> &unit_point,
std::vector<double> &values,
std::vector<Tensor<1,dim> > &grads,
std::vector<Tensor<2,dim> > &grad_grads) const;
/**
* Computes the value of the
* <tt>i</tt>th tensor product
* polynomial at
* <tt>unit_point</tt>. Here <tt>i</tt> is
* given in tensor product
* numbering.
*
* Note, that using this function
* within a loop over all tensor
* product polynomials is not
* efficient, because then each
* point value of the underlying
* (one-dimensional) polynomials
* is (unnecessarily) computed
* several times. Instead use
* the <tt>compute</tt> function, see
* above, with
* <tt>values.size()==n_tensor_pols</tt>
* to get the point values of all
* tensor polynomials all at once
* and in a much more efficient
* way.
*/
double compute_value (const unsigned int i,
const Point<dim> &p) const;
/**
* Computes the grad of the
* <tt>i</tt>th tensor product
* polynomial at
* <tt>unit_point</tt>. Here <tt>i</tt> is
* given in tensor product
* numbering.
*
* Note, that using this function
* within a loop over all tensor
* product polynomials is not
* efficient, because then each
* derivative value of the
* underlying (one-dimensional)
* polynomials is (unnecessarily)
* computed several times.
* Instead use the <tt>compute</tt>
* function, see above, with
* <tt>grads.size()==n_tensor_pols</tt>
* to get the point value of all
* tensor polynomials all at once
* and in a much more efficient
* way.
*/
Tensor<1,dim> compute_grad (const unsigned int i,
const Point<dim> &p) const;
/**
* Computes the second
* derivative (grad_grad) of the
* <tt>i</tt>th tensor product
* polynomial at
* <tt>unit_point</tt>. Here <tt>i</tt> is
* given in tensor product
* numbering.
*
* Note, that using this function
* within a loop over all tensor
* product polynomials is not
* efficient, because then each
* derivative value of the
* underlying (one-dimensional)
* polynomials is (unnecessarily)
* computed several times.
* Instead use the <tt>compute</tt>
* function, see above, with
* <tt>grad_grads.size()==n_tensor_pols</tt>
* to get the point value of all
* tensor polynomials all at once
* and in a much more efficient
* way.
*/
Tensor<2,dim> compute_grad_grad (const unsigned int i,
const Point<dim> &p) const;
/**
* Returns the number of tensor
* product polynomials. It is the
* product of the number of
* polynomials in each coordinate
* direction.
*/
unsigned int n () const;
private:
/**
* Copy of the vector <tt>pols</tt> of
* polynomials given to the
* constructor.
*/
std::vector<std::vector<Polynomials::Polynomial<double> > > polynomials;
/**
* Number of tensor product
* polynomials. This is
* <tt>Nx*Ny*Nz</tt>, or with terms
* dropped if the number of space
* dimensions is less than 3.
*/
unsigned int n_tensor_pols;
/**
* Each tensor product polynomial
* @รพ{i} is a product of
* one-dimensional polynomials in
* each space direction. Compute
* the indices of these
* one-dimensional polynomials
* for each space direction,
* given the index <tt>i</tt>.
*/
void compute_index (const unsigned int i,
unsigned int (&indices)[dim]) const;
/**
* Given the input to the
* constructor, compute
* <tt>n_tensor_pols</tt>.
*/
static
unsigned int
get_n_tensor_pols (const std::vector<std::vector<Polynomials::Polynomial<double> > > &pols);
};
/** @} */
#ifndef DOXYGEN
/* -------------- declaration of explicit specializations --- */
template <>
void
TensorProductPolynomials<1>::compute_index(const unsigned int n,
unsigned int (&index)[1]) const;
template <>
void
TensorProductPolynomials<2>::compute_index(const unsigned int n,
unsigned int (&index)[2]) const;
template <>
void
TensorProductPolynomials<3>::compute_index(const unsigned int n,
unsigned int (&index)[3]) const;
/* ---------------- template and inline functions ---------- */
template <int dim>
inline
unsigned int
TensorProductPolynomials<dim>::
x_to_the_dim (const unsigned int x)
{
unsigned int y = 1;
for (unsigned int d=0; d<dim; ++d)
y *= x;
return y;
}
template <int dim>
template <class Pol>
TensorProductPolynomials<dim>::
TensorProductPolynomials(const std::vector<Pol> &pols)
:
polynomials (pols.begin(), pols.end()),
n_tensor_pols(x_to_the_dim(pols.size())),
index_map(n_tensor_pols),
index_map_inverse(n_tensor_pols)
{
// per default set this index map
// to identity. This map can be
// changed by the user through the
// set_numbering() function
for (unsigned int i=0; i<n_tensor_pols; ++i)
{
index_map[i]=i;
index_map_inverse[i]=i;
}
}
template <>
void
AnisotropicPolynomials<1>::compute_index(const unsigned int n,
unsigned int (&index)[1]) const;
template <>
void
AnisotropicPolynomials<2>::compute_index(const unsigned int n,
unsigned int (&index)[2]) const;
template <>
void
AnisotropicPolynomials<3>::compute_index(const unsigned int n,
unsigned int (&index)[3]) const;
#endif // DOXYGEN
DEAL_II_NAMESPACE_CLOSE
#endif
|