|
| 1 | +# How it Works (By Example) |
| 2 | + |
| 3 | +## Example Problem |
| 4 | + |
| 5 | +Let $f$ be a function of position $\bar{r}$ in some space. |
| 6 | +```julia |
| 7 | +function f(r̄::Meshes.Point) |
| 8 | + x, y, z = to(r̄) |
| 9 | + ... |
| 10 | +end |
| 11 | +``` |
| 12 | + |
| 13 | +Let the integration domain be the space (a ball) enclosed by a sphere centered on the origin with a radius of 5 meters. |
| 14 | +```julia |
| 15 | +center = Meshes.Point(0u"m", 0u"m", 0u"m") |
| 16 | +radius = 5.0u"m" |
| 17 | +ball = Meshes.Ball(center, radius) |
| 18 | +``` |
| 19 | + |
| 20 | +This integral is often expressed abstractly as simply the following, where the triple integral signs and $\text{d}V$ indicate that the integration domain is some three-dimensional volume. |
| 21 | +```math |
| 22 | +\iiint f(\bar{r}) ~ \text{d}V |
| 23 | +``` |
| 24 | + |
| 25 | +Integrals like this are often solved manually by selecting an appropriate coordinate system and limits that neatly represent the integration domain, e.g. |
| 26 | +```math |
| 27 | +\int_0^{\pi} \int_0^{2\pi} \int_0^{5} f(\bar{r}) ~ \text{d}\rho~\text{d}\theta~\text{d}\phi |
| 28 | +``` |
| 29 | + |
| 30 | +This works great for simple geometries, but requires integration code that is geometry-specific. This package leverages parametric functions defined in Meshes.jl and differential forms to define integral methods that are general solutions for all geometries. |
| 31 | + |
| 32 | +## [Parametric Functions](@id how-parametric) |
| 33 | + |
| 34 | +Every supported `Meshes.Geometry` type is defined as having a parametric function that maps from a local parametric coordinate system to every point on the geometry. Curve-like geometries will have a single parametric dimension, surfaces will have two dimensions, and volumes will have three dimensions; this can be checked for a particular geometry via `Meshes.paramdim(geometry)`. |
| 35 | + |
| 36 | +For consistency across geometry types, with [some notable exceptions](@ref specializations), these parametric functions are defined to take coordinates inside a normalized range $[0,1]$. In the example case of `ball`, Meshes.jl defines a parametric function mapped in normalized spherical coordinates $(t_\rho, ~t_\theta, ~t_\phi)$. We find, then: |
| 37 | +```julia |
| 38 | +Meshes.paramdim(ball) == 3 # a volume |
| 39 | + |
| 40 | +ball(tρ, tθ, tφ) # for args in range [0, 1], maps to a corresponding Meshes.Point |
| 41 | + |
| 42 | +ball(0, tθ, tφ) == center |
| 43 | +``` |
| 44 | + |
| 45 | +In effect, we can now use the geometry itself as a function that maps from three normalized ($0 \le t \le 1$) arguments to every point on the geometry. For the sake of generalization, let this parametric function be called $g$. |
| 46 | +```math |
| 47 | +\text{g}: (t_1,~t_2,~t_3) ~\mapsto~ \text{Point}\big[ x, ~y, ~z \big] |
| 48 | +``` |
| 49 | + |
| 50 | +## Differential Forms |
| 51 | + |
| 52 | +Using differential forms, the general solution for integrating a geometry with three parametric dimensions ($t_1$, $t_2$, and $t_3$) is |
| 53 | +```math |
| 54 | +\iiint f(r̄) ~ \text{d}V = \iiint f(\bar{r}) ~ \bar{\text{d}t_1} \wedge \bar{\text{d}t_2} \wedge \bar{\text{d}t_3} |
| 55 | +``` |
| 56 | + |
| 57 | +This resultant differential (volume) element is formed at each point in the integration domain by taking [the Jacobian](https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant) of the parametric function. |
| 58 | +```math |
| 59 | +\mathbf{J}_f = \begin{bmatrix} \bar{\text{d}t_1} & \bar{\text{d}t_2} & \bar{\text{d}t_3} \end{bmatrix} |
| 60 | +``` |
| 61 | +where |
| 62 | +```math |
| 63 | +\bar{\text{d}t_n} = \frac{\partial}{\partial t_n} ~ \text{g}(t_1,~t_2,~t_3) |
| 64 | +``` |
| 65 | + |
| 66 | +Each of these partial derivatives is a vector representing the direction that changing each parametric function argument will move the resultant point. The differential element ($E$) size is then calculated using geometric algebra as the magnitude of the exterior product ($\wedge$) of these three vectors. |
| 67 | +```math |
| 68 | +E(t_1,~t_2,~t_3) = \left\| \bar{\text{d}t_1} \wedge \bar{\text{d}t_2} \wedge \bar{\text{d}t_3} \right\| |
| 69 | +``` |
| 70 | + |
| 71 | +Finally, we use the parametric function itself, $g$, as a map to all points $\bar{r}$ in the integration domain. Since `Meshes.Geometry` parametric functions all operate on normalized domains, we can now solve any volume integral as simply |
| 72 | +```math |
| 73 | +\int_0^1 \int_0^1 \int_0^1 f\Big(\text{g}\big(t_1,~t_2,~t_3\big)\Big) ~ E(t_1,~t_2,~t_3) ~ \text{d}t_1 ~ \text{d}t_2 ~ \text{d}t_3 |
| 74 | +``` |
| 75 | + |
| 76 | +This form of integral can be trivially generalized to support $n$-dimensional geometries in a form that enables the use of a wide range of numerical integration libraries. |
0 commit comments