Calculus
Calculus with geometries is possible thanks to careful parametrizations and high-level interfaces such as DifferentiationInterface.jl and IntegrationInterface.jl.
Consider the following quadrangle for illustration purposes:
q = Quadrangle((0, 0, 0), (2, 0, 0), (2, 1, 0), (0, 1, 0))Quadrangle
├─ Point(x: 0.0 m, y: 0.0 m, z: 0.0 m)
├─ Point(x: 2.0 m, y: 0.0 m, z: 0.0 m)
├─ Point(x: 2.0 m, y: 1.0 m, z: 0.0 m)
└─ Point(x: 0.0 m, y: 1.0 m, z: 0.0 m)Differentiation
Meshes.derivative — Function
derivative(geom, uvw, j; dbackend)Calculate the derivative of the geometry's parametric function at parametric coordinates uvw and along j-th coordinate using a differentiation dbackend from DifferentationInterface.jl. By default, the dbackend is set to finite differences.
# derivative at center point along first axis
derivative(q, (0.5, 0.5), 1)Vec(2.000000000000007 m, 2.6542114837909546e-15 m, 0.0 m)Meshes.jacobian — Function
jacobian(geom, uvw; dbackend)Calculate the Jacobian of the geometry's parametric function at parametric coordinates uvw using a differentiation dbackend from DifferentationInterface.jl. Returns a tuple of vectors, each corresponding to the derivative along a parametric coordinate. By default, dbackend is set to finite differences.
# Jacobian at center (i.e., derivative along both axes)
jacobian(q, (0.5, 0.5))(Vec(2.000000000000007 m, 2.6542114837909546e-15 m, 0.0 m), Vec(4.621250604642514e-15 m, 0.9999999999999989 m, 0.0 m))Meshes.differential — Function
differential(geom, uvw; dbackend)Calculate the differential element (length, area, volume, etc.) of the geometry at parametric coordinates uvw using a differentiation dbackend from DifferentiationInterface.jl. By default, the dbackend is set to finite differences.
# differential element (i.e., infinitesimal area)
differential(q, (0.5, 0.5))2.000000000000005 m^2Integration
Meshes.integral — Function
integral(fun, geom; ibackend, dbackend)Calculate the integral over the geometry of the function that maps Points to values in a linear space using an integration ibackend from IntegrationInterface.jl and a differentiation dbackend from DifferentiationInterface.jl.
integral(fun, dom; ibackend, dbackend)Alternatively, calculate the integral over the domain (e.g., mesh) by summing the integrals for each constituent geometry.
By default, ibackend is set to h-adaptive integration for good accuracy across a wide range of geometries and dbackend is set to finite differences.
See also localintegral.
# integral of constant 1 over quadrangle gives area
integral(p -> 1, q)2.000000000000001 m^2# unitful integrand is also supported
integral(p -> 1u"W/m^2", q)2.000000000000001 W# less trivial integrand in terms of Cartesian coordinates
integral(q) do p
x, y, z = to(p)
x + 2y + 3z # meter units
end3.999999999999999 m^3Meshes.localintegral — Function
localintegral(fun, geom; ibackend, dbackend)Calculate the integral over the geometry of the function that maps parametric coordinates uvw to values in a linear space using an integration ibackend from IntegrationInterface.jl and a differentiation dbackend from DifferentiationInterface.jl.
By default, ibackend is set to h-adaptive integration for good accuracy across a wide range of geometries and dbackend is set to finite differences.
See also integral.
# local integral in terms of parametric coordinates in [0, 1]²
localintegral((u, v) -> u^2 + 3v, q)3.6666666666666647 m^2