/usr/include/deal.II/base/derivative_form.h is in libdeal.ii-dev 8.1.0-6ubuntu1.
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 | // ---------------------------------------------------------------------
// $Id: derivative_form.h 31808 2013-11-26 16:43:06Z heister $
//
// Copyright (C) 2013 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#ifndef __deal2__derivative_form_h
#define __deal2__derivative_form_h
#include <deal.II/base/tensor.h>
DEAL_II_NAMESPACE_OPEN
/**
This class represents the (tangential) derivatives of a function
$ f: {\mathbb R}^{\text{dim}} \rightarrow {\mathbb R}^{\text{spacedim}}$.
Such functions are always used to map the reference dim-dimensional
cell into spacedim-dimensional space.
For such objects, the first derivative of the function is a linear map from
${\mathbb R}^{\text{dim}}$ to ${\mathbb R}^{\text{spacedim}}$,
the second derivative a bilinear map
from ${\mathbb R}^{\text{dim}} \times {\mathbb R}^{\text{dim}}$
to ${\mathbb R}^{\text{spacedim}}$ and so on.
In deal.II we represent these derivaties using objects of
type DerivativeForm<1,dim,spacedim>, DerivativeForm<2,dim,spacedim> and so on.
@author Sebastian Pauletti, 2011
*/
template <int order, int dim, int spacedim>
class DerivativeForm
{
public:
/**
* Constructor. Initialize all entries
* to zero.
*/
DerivativeForm ();
/**
Constructor from a second order tensor.
*/
DerivativeForm (const Tensor<2,dim> &);
/**
* Read-Write access operator.
*/
Tensor<order,dim> &operator [] (const unsigned int i);
/**
* Read-only access operator.
*/
const Tensor<order,dim> &operator [] (const unsigned int i) const;
/**
* Assignment operator.
*/
DerivativeForm &operator = (const DerivativeForm <order, dim, spacedim> &);
/**
* Assignment operator.
*/
DerivativeForm &operator = (const Tensor<2,dim> &);
/**
* Assignment operator.
*/
DerivativeForm &operator = (const Tensor<1,dim> &);
/**
Converts a DerivativeForm <1,dim, dim>
to Tensor<2,dim>.
If the derivative is the Jacobian of F,
then Tensor[i] = grad(F^i).
*/
operator Tensor<2,dim>() const;
/**
Converts a DerivativeForm <1, dim, 1>
to Tensor<1,dim>.
*/
operator Tensor<1,dim>() const;
/**
Return the transpose of a rectangular DerivativeForm,
that is to say viewed as a two dimensional matrix.
*/
DerivativeForm<1, spacedim, dim> transpose () const;
/**
Computes the volume element associated with the
jacobian of the tranformation F.
That is to say if $DF$ is square, it computes
$\det(DF)$, in case DF is not square returns
$\sqrt(\det(DF^{t} * DF))$.
*/
double determinant () const;
/**
Assuming (*this) stores the jacobian of
the mapping F, it computes its covariant
matrix, namely $DF*G^{-1}$, where
$G = DF^{t}*DF$.
If $DF$ is square, covariant from
gives $DF^{-t}$.
*/
DerivativeForm<1, dim, spacedim> covariant_form() const;
/**
* Determine an estimate for the
* memory consumption (in bytes)
* of this object.
*/
static std::size_t memory_consumption ();
/**
* Exception.
*/
DeclException1 (ExcInvalidTensorIndex,
int,
<< "Invalid DerivativeForm index " << arg1);
private:
/** Auxiliary function that computes
(*this) * T^{t} */
DerivativeForm<1, dim, spacedim> times_T_t (Tensor<2,dim> T) const;
private:
/**
* Array of tensors holding the
* subelements.
*/
Tensor<order,dim> tensor[spacedim];
};
/*--------------------------- Inline functions -----------------------------*/
#ifndef DOXYGEN
template <int order, int dim, int spacedim>
inline
DerivativeForm<order, dim, spacedim>::DerivativeForm ()
{
// default constructor. not specifying an initializer list calls
// the default constructor of the subobjects, which initialize them
// selves. therefore, the tensor array is set to zero this way
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<order, dim, spacedim>::DerivativeForm(const Tensor<2,dim> &T)
{
Assert( (dim == spacedim) && (order==1),
ExcMessage("Only allowed for square tensors."));
if ((dim == spacedim) && (order==1))
for (unsigned int j=0; j<dim; ++j)
(*this)[j] = T[j];
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<order, dim, spacedim> &
DerivativeForm<order, dim, spacedim>::
operator = (const DerivativeForm<order, dim, spacedim> &ta)
{
for (unsigned int j=0; j<spacedim; ++j)
(*this)[j] = ta[j];
return *this;
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<order, dim, spacedim> &DerivativeForm<order, dim, spacedim>::
operator = (const Tensor<2,dim> &ta)
{
Assert( (dim == spacedim) && (order==1),
ExcMessage("Only allowed for square tensors."));
if ((dim == spacedim) && (order==1))
for (unsigned int j=0; j<dim; ++j)
(*this)[j] = ta[j];
return *this;
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<order, dim, spacedim> &DerivativeForm<order, dim, spacedim>::
operator = (const Tensor<1,dim> &T)
{
Assert( (1 == spacedim) && (order==1),
ExcMessage("Only allowed for spacedim==1 and order==1."));
(*this)[0] = T;
return *this;
}
template <int order, int dim, int spacedim>
inline
Tensor<order,dim> &DerivativeForm<order, dim, spacedim>::
operator[] (const unsigned int i)
{
Assert (i<spacedim, ExcIndexRange(i, 0, spacedim));
return tensor[i];
}
template <int order, int dim, int spacedim>
inline
const Tensor<order,dim> &DerivativeForm<order, dim, spacedim>::
operator[] (const unsigned int i) const
{
Assert (i<spacedim, ExcIndexRange(i, 0, spacedim));
return tensor[i];
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<order, dim, spacedim>::operator Tensor<1,dim>() const
{
Assert( (1 == spacedim) && (order==1),
ExcMessage("Only allowed for spacedim==1."));
return (*this)[0];
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<order, dim, spacedim>::operator Tensor<2,dim>() const
{
Assert( (dim == spacedim) && (order==1),
ExcMessage("Only allowed for square tensors."));
Tensor<2,dim> t;
if ((dim == spacedim) && (order==1))
for (unsigned int j=0; j<dim; ++j)
t[j] = (*this)[j];
return t;
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<1,spacedim,dim>
DerivativeForm<order,dim,spacedim>::
transpose () const
{
Assert(order==1, ExcMessage("Only for rectangular DerivativeForm."));
DerivativeForm<1,spacedim,dim> tt;
for (unsigned int i=0; i<spacedim; ++i)
for (unsigned int j=0; j<dim; ++j)
tt[j][i] = (*this)[i][j];
return tt;
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<1, dim, spacedim>
DerivativeForm<order,dim,spacedim>::times_T_t (Tensor<2,dim> T) const
{
Assert( order==1, ExcMessage("Only for order == 1."));
DerivativeForm<1,dim, spacedim> dest;
for (unsigned int i=0; i<spacedim; ++i)
for (unsigned int j=0; j<dim; ++j)
dest[i][j] = (*this)[i] * T[j];
return dest;
}
template <int order, int dim, int spacedim>
inline
double
DerivativeForm<order,dim,spacedim>::determinant () const
{
Assert( order==1, ExcMessage("Only for order == 1."));
if (dim == spacedim)
{
Tensor<2,dim> T = (Tensor<2,dim>)( (*this) );
return dealii::determinant(T);
}
else
{
Assert( spacedim>dim, ExcMessage("Only for spacedim>dim."));
DerivativeForm<1,spacedim,dim> DF_t = this->transpose();
Tensor<2, dim> G; //First fundamental form
for (unsigned int i=0; i<dim; ++i)
for (unsigned int j=0; j<dim; ++j)
G[i][j] = DF_t[i] * DF_t[j];
return ( sqrt(dealii::determinant(G)) );
}
}
template <int order, int dim, int spacedim>
inline
DerivativeForm<1,dim,spacedim>
DerivativeForm<order,dim,spacedim>::covariant_form() const
{
if (dim == spacedim)
{
Tensor<2,dim> DF_t (dealii::transpose(invert( (Tensor<2,dim>)(*this) )));
DerivativeForm<1,dim, spacedim> result = DF_t;
return (result);
}
else
{
DerivativeForm<1,spacedim,dim> DF_t = this->transpose();
Tensor<2, dim> G; //First fundamental form
for (unsigned int i=0; i<dim; ++i)
for (unsigned int j=0; j<dim; ++j)
G[i][j] = DF_t[i] * DF_t[j];
return (this->times_T_t(invert(G)));
}
}
template <int order, int dim, int spacedim>
inline
std::size_t
DerivativeForm<order, dim, spacedim>::memory_consumption ()
{
return sizeof(DerivativeForm<order, dim, spacedim>);
}
#endif // DOXYGEN
/**
One of the uses of DerivativeForm is to apply it as a transformation.
This is what this function does.
If @p T is DerivativeForm<1,dim,1> it computes $DF * T$,
if @p T is DerivativeForm<1,dim,rank> it computes $T*DF^{t}$.
@relates DerivativeForm
@author Sebastian Pauletti, 2011
*/
template <int spacedim, int dim>
inline
Tensor<1, spacedim>
apply_transformation (const DerivativeForm<1,dim,spacedim> &DF,
const Tensor<1,dim> &T)
{
Tensor<1, spacedim> dest;
for (unsigned int i=0; i<spacedim; ++i)
dest[i] = DF[i] * T;
return dest;
}
/**
Similar to previous apply_transformation.
It computes $T*DF^{t}$
@relates DerivativeForm
@author Sebastian Pauletti, 2011
*/
//rank=2
template <int spacedim, int dim>
inline
DerivativeForm<1, spacedim, dim>
apply_transformation (const DerivativeForm<1,dim,spacedim> &DF,
const Tensor<2,dim> &T)
{
DerivativeForm<1, spacedim, dim> dest;
for (unsigned int i=0; i<dim; ++i)
dest[i] = apply_transformation(DF, T[i]);
return dest;
}
/**
Similar to previous apply_transformation.
It computes $DF2*DF1^{t}$
@relates DerivativeForm
@author Sebastian Pauletti, 2011
*/
template <int spacedim, int dim>
inline
Tensor<2, spacedim>
apply_transformation (const DerivativeForm<1,dim,spacedim> &DF1,
const DerivativeForm<1,dim,spacedim> &DF2)
{
Tensor<2, spacedim> dest;
for (unsigned int i=0; i<spacedim; ++i)
dest[i] = apply_transformation(DF1, DF2[i]);
return dest;
}
/**
Transpose of a rectangular DerivativeForm DF,
mostly for compatibility reasons.
@relates DerivativeForm
@author Sebastian Pauletti, 2011
*/
template <int dim, int spacedim>
inline
DerivativeForm<1,spacedim,dim>
transpose (const DerivativeForm<1,dim,spacedim> &DF)
{
DerivativeForm<1,spacedim,dim> tt;
tt = DF.transpose();
return tt;
}
DEAL_II_NAMESPACE_CLOSE
#endif
|