module Numerics.VectorAnalysis (
grad
, divergence
, curl
, curlZ
, laplace
, gradH
, divH
, curlH
, curlZH
, laplaceH
) where
import Geometry.Core
standardH :: Double
standardH :: Double
standardH = Double
1e-3
grad :: (Vec2 -> Double) -> Vec2 -> Vec2
grad :: (Vec2 -> Double) -> Vec2 -> Vec2
grad = Double -> (Vec2 -> Double) -> Vec2 -> Vec2
gradH Double
standardH
divergence :: (Vec2 -> Vec2) -> Vec2 -> Double
divergence :: (Vec2 -> Vec2) -> Vec2 -> Double
divergence = Double -> (Vec2 -> Vec2) -> Vec2 -> Double
divH Double
standardH
curl :: (Vec2 -> Vec2) -> Vec2 -> Double
curl :: (Vec2 -> Vec2) -> Vec2 -> Double
curl = Double -> (Vec2 -> Vec2) -> Vec2 -> Double
curlH Double
standardH
laplace :: (Vec2 -> Double) -> Vec2 -> Double
laplace :: (Vec2 -> Double) -> Vec2 -> Double
laplace = Double -> (Vec2 -> Double) -> Vec2 -> Double
laplaceH Double
standardH
gradH
:: Double
-> (Vec2 -> Double)
-> (Vec2 -> Vec2)
gradH :: Double -> (Vec2 -> Double) -> Vec2 -> Vec2
gradH Double
h Vec2 -> Double
f = \Vec2
x ->
let f_x :: Double
f_x = Vec2 -> Double
f Vec2
x
in Double -> Double -> Vec2
Vec2 (Vec2 -> Double
f (Vec2
x Vec2 -> Vec2 -> Vec2
forall v. VectorSpace v => v -> v -> v
+. Double -> Double -> Vec2
Vec2 Double
h Double
0) Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
f_x) (Vec2 -> Double
f (Vec2
x Vec2 -> Vec2 -> Vec2
forall v. VectorSpace v => v -> v -> v
+. Double -> Double -> Vec2
Vec2 Double
0 Double
h) Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
f_x) Vec2 -> Double -> Vec2
forall v. VectorSpace v => v -> Double -> v
/. Double
h
divH
:: Double
-> (Vec2 -> Vec2)
-> (Vec2 -> Double)
divH :: Double -> (Vec2 -> Vec2) -> Vec2 -> Double
divH Double
h Vec2 -> Vec2
f = \v :: Vec2
v@(Vec2 Double
x Double
y) ->
let f_v :: Vec2
f_v = Vec2 -> Vec2
f Vec2
v
Vec2 Double
dx Double
_ = Vec2 -> Vec2
f (Double -> Double -> Vec2
Vec2 (Double
xDouble -> Double -> Double
forall a. Num a => a -> a -> a
+Double
h) Double
y) Vec2 -> Vec2 -> Vec2
forall v. VectorSpace v => v -> v -> v
-. Vec2
f_v
Vec2 Double
_ Double
dy = Vec2 -> Vec2
f (Double -> Double -> Vec2
Vec2 Double
x (Double
yDouble -> Double -> Double
forall a. Num a => a -> a -> a
+Double
h)) Vec2 -> Vec2 -> Vec2
forall v. VectorSpace v => v -> v -> v
-. Vec2
f_v
in (Double
dxDouble -> Double -> Double
forall a. Num a => a -> a -> a
+Double
dy)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
h
curlH
:: Double
-> (Vec2 -> Vec2)
-> (Vec2 -> Double)
curlH :: Double -> (Vec2 -> Vec2) -> Vec2 -> Double
curlH Double
h Vec2 -> Vec2
f = \v :: Vec2
v@(Vec2 Double
x Double
y) ->
let f_v :: Vec2
f_v = Vec2 -> Vec2
f Vec2
v
Vec2 Double
dy_fx Double
_ = Vec2 -> Vec2
f (Double -> Double -> Vec2
Vec2 Double
x (Double
yDouble -> Double -> Double
forall a. Num a => a -> a -> a
+Double
h)) Vec2 -> Vec2 -> Vec2
forall v. VectorSpace v => v -> v -> v
-. Vec2
f_v
Vec2 Double
_ Double
dx_fy = Vec2 -> Vec2
f (Double -> Double -> Vec2
Vec2 (Double
xDouble -> Double -> Double
forall a. Num a => a -> a -> a
+Double
h) Double
y) Vec2 -> Vec2 -> Vec2
forall v. VectorSpace v => v -> v -> v
-. Vec2
f_v
in (Double
dx_fyDouble -> Double -> Double
forall a. Num a => a -> a -> a
-Double
dy_fx) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
h
laplaceH
:: Double
-> (Vec2 -> Double)
-> (Vec2 -> Double)
laplaceH :: Double -> (Vec2 -> Double) -> Vec2 -> Double
laplaceH Double
h = Double -> (Vec2 -> Vec2) -> Vec2 -> Double
divH Double
h ((Vec2 -> Vec2) -> Vec2 -> Double)
-> ((Vec2 -> Double) -> Vec2 -> Vec2)
-> (Vec2 -> Double)
-> Vec2
-> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> (Vec2 -> Double) -> Vec2 -> Vec2
gradH Double
h
curlZ :: (Vec2 -> Double) -> Vec2 -> Vec2
curlZ :: (Vec2 -> Double) -> Vec2 -> Vec2
curlZ Vec2 -> Double
f = Double -> (Vec2 -> Double) -> Vec2 -> Vec2
curlZH Double
standardH Vec2 -> Double
f
curlZH
:: Double
-> (Vec2 -> Double)
-> Vec2
-> Vec2
curlZH :: Double -> (Vec2 -> Double) -> Vec2 -> Vec2
curlZH Double
h Vec2 -> Double
f = \Vec2
x ->
let f_x :: Double
f_x = Vec2 -> Double
f Vec2
x
in Double -> Double -> Vec2
Vec2 (Vec2 -> Double
f (Vec2
x Vec2 -> Vec2 -> Vec2
forall v. VectorSpace v => v -> v -> v
+. Double -> Double -> Vec2
Vec2 Double
0 Double
h) Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
f_x) (- Vec2 -> Double
f (Vec2
x Vec2 -> Vec2 -> Vec2
forall v. VectorSpace v => v -> v -> v
+. Double -> Double -> Vec2
Vec2 Double
h Double
0) Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
f_x) Vec2 -> Double -> Vec2
forall v. VectorSpace v => v -> Double -> v
/. Double
h