| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2017 - 2023 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_function_spherical_h |
| 16 |
#define dealii_function_spherical_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#include <deal.II/base/function.h> |
| 21 |
#include <deal.II/base/point.h> |
| 22 |
|
| 23 |
#include <array> |
| 24 |
|
| 25 |
DEAL_II_NAMESPACE_OPEN |
| 26 |
|
| 27 |
namespace Functions |
| 28 |
{ |
| 29 |
/** |
| 30 |
* An abstract base class for a scalar-valued function $f=f(r,\theta,\phi)$ |
| 31 |
* defined in spherical coordinates. This class wraps transformation of |
| 32 |
* values, gradients and hessians from spherical coordinates to the Cartesian |
| 33 |
* coordinate system used by the Function base class. Therefore derived |
| 34 |
* classes only need to implement those functions in spherical coordinates |
| 35 |
* (specifically svalue(), sgradient() and shessian() ). The convention for |
| 36 |
* angles is the same as in GeometricUtilities::Coordinates. |
| 37 |
* |
| 38 |
* @note This function is currently only implemented for dim==3 . |
| 39 |
* |
| 40 |
* @ingroup functions |
| 41 |
*/ |
| 42 |
template <int dim> |
| 43 |
class Spherical : public Function<dim> |
| 44 |
{ |
| 45 |
public: |
| 46 |
/** |
| 47 |
* Constructor which should be provided with @p center defining the origin |
| 48 |
* of the coordinate system. |
| 49 |
* |
| 50 |
* Note that components of this function are treated as entirely separate |
| 51 |
* quantities -- not as the components of a vector that will be |
| 52 |
* re-interpreted in a different coordinate system. |
| 53 |
*/ |
| 54 |
Spherical(const Point<dim> ¢er = Point<dim>(), |
| 55 |
const unsigned int n_components = 1); |
| 56 |
|
| 57 |
/** |
| 58 |
* Return the value of the function at the given point. |
| 59 |
* |
| 60 |
* This function converts the given point to spherical coordinates, |
| 61 |
* calls svalue() with it, and returns the result. |
| 62 |
*/ |
| 63 |
virtual double |
| 64 |
value(const Point<dim> &point, |
| 65 |
const unsigned int component = 0) const override; |
| 66 |
|
| 67 |
/** |
| 68 |
* Return the gradient with respect to the Cartesian coordinates at point @p p. |
| 69 |
* |
| 70 |
* This function converts the given point to spherical coordinates, |
| 71 |
* calls sgradient() with it, and converts the result into Cartesian |
| 72 |
* coordinates. |
| 73 |
*/ |
| 74 |
virtual Tensor<1, dim> |
| 75 |
gradient(const Point<dim> &p, |
| 76 |
const unsigned int component = 0) const override; |
| 77 |
|
| 78 |
/** |
| 79 |
* Return the Hessian with respect to the Cartesian coordinates at point @p p. |
| 80 |
* |
| 81 |
* This function converts the given point to spherical coordinates, |
| 82 |
* calls sgradient and shessian() with it, and converts the result into |
| 83 |
* Cartesian coordinates. |
| 84 |
*/ |
| 85 |
virtual SymmetricTensor<2, dim> |
| 86 |
hessian(const Point<dim> &p, |
| 87 |
const unsigned int component = 0) const override; |
| 88 |
|
| 89 |
/** |
| 90 |
* Return an estimate for the memory consumption, in bytes, of this object. |
| 91 |
*/ |
| 92 |
virtual std::size_t |
| 93 |
memory_consumption() const override; |
| 94 |
|
| 95 |
private: |
| 96 |
/** |
| 97 |
* Return the value at point @p sp. Here, @p sp is provided in spherical |
| 98 |
* coordinates. |
| 99 |
*/ |
| 100 |
virtual double |
| 101 |
svalue(const std::array<double, dim> &sp, |
| 102 |
const unsigned int component) const; |
| 103 |
|
| 104 |
/** |
| 105 |
* Return the gradient in spherical coordinates. |
| 106 |
* |
| 107 |
* The returned object should contain derivatives in the following order: |
| 108 |
* $\{ f_{,r},\, f_{,\theta},\, f_{,\phi}\}$. |
| 109 |
*/ |
| 110 |
virtual std::array<double, dim> |
| 111 |
sgradient(const std::array<double, dim> &sp, |
| 112 |
const unsigned int component) const; |
| 113 |
|
| 114 |
/** |
| 115 |
* Return the Hessian in spherical coordinates. |
| 116 |
* |
| 117 |
* The returned object should contain derivatives in the following order: |
| 118 |
* $\{ f_{,rr},\, f_{,\theta\theta},\, f_{,\phi\phi},\, f_{,r\theta},\, |
| 119 |
* f_{,r\phi},\, f_{,\theta\phi}\}$. |
| 120 |
*/ |
| 121 |
virtual std::array<double, 6> |
| 122 |
shessian(const std::array<double, dim> &sp, |
| 123 |
const unsigned int component) const; |
| 124 |
|
| 125 |
/** |
| 126 |
* A vector from the origin to the center of spherical coordinate system. |
| 127 |
*/ |
| 128 |
const Tensor<1, dim> coordinate_system_offset; |
| 129 |
}; |
| 130 |
} // namespace Functions |
| 131 |
|
| 132 |
DEAL_II_NAMESPACE_CLOSE |
| 133 |
|
| 134 |
#endif |