{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE Safe #-}
module Physics.Learn.Current
(
Current
, CurrentDistribution(..)
, bField
, bFieldFromLineCurrent
, bFieldFromSurfaceCurrent
, bFieldFromVolumeCurrent
, magneticFlux
)
where
import Physics.Learn.CarrotVec
( magnitude
, (*^)
, (^/)
, (><)
)
import Physics.Learn.Position
( VectorField
, displacement
, addFields
)
import Physics.Learn.Curve
( Curve(..)
, crossedLineIntegral
)
import Physics.Learn.Surface
( Surface(..)
, surfaceIntegral
, dottedSurfaceIntegral
)
import Physics.Learn.Volume
( Volume(..)
, volumeIntegral
)
type Current = Double
data CurrentDistribution = LineCurrent Current Curve
| SurfaceCurrent VectorField Surface
| VolumeCurrent VectorField Volume
| MultipleCurrents [CurrentDistribution]
bFieldFromLineCurrent
:: Current
-> Curve
-> VectorField
bFieldFromLineCurrent :: Double -> Curve -> VectorField
bFieldFromLineCurrent Double
i Curve
c Position
r
= Double
k forall v. VectorSpace v => Scalar v -> v -> v
*^ Int -> VectorField -> Curve -> Vec
crossedLineIntegral Int
1000 VectorField
integrand Curve
c
where
k :: Double
k = Double
1e-7
integrand :: VectorField
integrand Position
r' = (-Double
i) forall v. VectorSpace v => Scalar v -> v -> v
*^ Vec
d forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/ forall v s. (InnerSpace v, s ~ Scalar v, Floating s) => v -> s
magnitude Vec
d forall a. Floating a => a -> a -> a
** Double
3
where
d :: Vec
d = Position -> VectorField
displacement Position
r' Position
r
bFieldFromSurfaceCurrent
:: VectorField
-> Surface
-> VectorField
bFieldFromSurfaceCurrent :: VectorField -> Surface -> VectorField
bFieldFromSurfaceCurrent VectorField
kCurrent Surface
c Position
r
= Double
k forall v. VectorSpace v => Scalar v -> v -> v
*^ forall v.
(VectorSpace v, Scalar v ~ Double) =>
Int -> Int -> Field v -> Surface -> v
surfaceIntegral Int
100 Int
100 VectorField
integrand Surface
c
where
k :: Double
k = Double
1e-7
integrand :: VectorField
integrand Position
r' = (VectorField
kCurrent Position
r' Vec -> Vec -> Vec
>< Vec
d) forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/ forall v s. (InnerSpace v, s ~ Scalar v, Floating s) => v -> s
magnitude Vec
d forall a. Floating a => a -> a -> a
** Double
3
where
d :: Vec
d = Position -> VectorField
displacement Position
r' Position
r
bFieldFromVolumeCurrent
:: VectorField
-> Volume
-> VectorField
bFieldFromVolumeCurrent :: VectorField -> Volume -> VectorField
bFieldFromVolumeCurrent VectorField
j Volume
c Position
r
= Double
k forall v. VectorSpace v => Scalar v -> v -> v
*^ forall v.
(VectorSpace v, Scalar v ~ Double) =>
Int -> Int -> Int -> Field v -> Volume -> v
volumeIntegral Int
50 Int
50 Int
50 VectorField
integrand Volume
c
where
k :: Double
k = Double
1e-7
integrand :: VectorField
integrand Position
r' = (VectorField
j Position
r' Vec -> Vec -> Vec
>< Vec
d) forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/ forall v s. (InnerSpace v, s ~ Scalar v, Floating s) => v -> s
magnitude Vec
d forall a. Floating a => a -> a -> a
** Double
3
where
d :: Vec
d = Position -> VectorField
displacement Position
r' Position
r
bField :: CurrentDistribution -> VectorField
bField :: CurrentDistribution -> VectorField
bField (LineCurrent Double
i Curve
c) = Double -> Curve -> VectorField
bFieldFromLineCurrent Double
i Curve
c
bField (SurfaceCurrent VectorField
kC Surface
s) = VectorField -> Surface -> VectorField
bFieldFromSurfaceCurrent VectorField
kC Surface
s
bField (VolumeCurrent VectorField
j Volume
v) = VectorField -> Volume -> VectorField
bFieldFromVolumeCurrent VectorField
j Volume
v
bField (MultipleCurrents [CurrentDistribution]
cds) = forall v. AdditiveGroup v => [Field v] -> Field v
addFields forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map CurrentDistribution -> VectorField
bField [CurrentDistribution]
cds
magneticFlux :: Surface -> CurrentDistribution -> Double
magneticFlux :: Surface -> CurrentDistribution -> Double
magneticFlux Surface
surf CurrentDistribution
dist = Int -> Int -> VectorField -> Surface -> Double
dottedSurfaceIntegral Int
100 Int
100 (CurrentDistribution -> VectorField
bField CurrentDistribution
dist) Surface
surf