Implemented some form of LM optimization, but it's proper fucked somehow.
This commit is contained in:
@@ -28,6 +28,8 @@ class Material mat where
|
||||
iorAtWavelength :: Double -> mat -> Double
|
||||
-- | A material with a constant IOR of 1
|
||||
air :: mat
|
||||
air = constMat 1
|
||||
constMat :: Double -> mat
|
||||
|
||||
-- | Calculates IOR based on the Sellemeier equation
|
||||
data SellemeierMat = SellemeierMat [(Double, Double)]
|
||||
@@ -37,6 +39,7 @@ instance Material SellemeierMat where
|
||||
where contrib (b,c) = b * w2 / (w2 - c)
|
||||
w2 = λ ^ 2
|
||||
air = SellemeierMat []
|
||||
constMat ior = SellemeierMat [(ior * ior - 1, 0)]
|
||||
|
||||
-- | A material with a constant IOR
|
||||
newtype ConstMat = ConstMat Double
|
||||
@@ -45,6 +48,7 @@ newtype ConstMat = ConstMat Double
|
||||
instance Material ConstMat where
|
||||
iorAtWavelength _ (ConstMat ior) = ior
|
||||
air = ConstMat 1
|
||||
constMat = ConstMat
|
||||
|
||||
-- | A representation of IOR as (previous,new) IOR at a surface
|
||||
data BakedIOR = BakedIOR Double Double
|
||||
@@ -74,30 +78,7 @@ isStop _ = False
|
||||
isSurface :: Element mat a -> Bool
|
||||
isSurface Surface{} = True
|
||||
isSurface _ = False
|
||||
{-
|
||||
-- | The space after the current element
|
||||
thickness :: Lens (Element mat a) (Element mat a) a a
|
||||
thickness inj (s@Surface{_thickness}) = (\nt -> s{_thickness=nt}) <$> inj _thickness
|
||||
thickness inj (s@Stop{_thickness}) = (\nt -> s{_thickness=nt}) <$> inj _thickness
|
||||
-- | The outside radius of the element. Rays that intersect the element beyond this radius are considered to have missed.
|
||||
outsideRadius :: Lens (Element mat a) (Element mat a) a a
|
||||
outsideRadius inj (s@Surface{_outsideRadius}) = (\nt -> s{_outsideRadius=nt}) <$> inj _outsideRadius
|
||||
outsideRadius inj (s@Stop{_outsideRadius}) = (\nt -> s{_outsideRadius=nt}) <$> inj _outsideRadius
|
||||
|
||||
infinity :: (RealFloat a) => a
|
||||
infinity = encodeFloat (floatRadix 0 - 1) (snd $ floatRange 0)
|
||||
-- | The radius of curvature of an element. This is 1 for stops
|
||||
roc :: RealFloat a => Lens (Element mat a) (Element mat a) a a
|
||||
roc inj (s@Surface{_roc}) = (\nt -> s{_roc=nt}) <$> inj _roc
|
||||
roc inj (s@Stop{}) = (const s) <$> inj infinity
|
||||
|
||||
-- | The material that a surface transitions into
|
||||
--
|
||||
-- For stops, this returns None and ignores being set.
|
||||
material :: (Material mat, Material mat') => Lens (Element mat a) (Element mat' a) (Maybe mat) (Maybe mat')
|
||||
material inj (s@Surface{_thickness, _outsideRadius, _roc, _material}) = (\nt -> Surface{_material=fromMaybe air nt, _thickness, _outsideRadius, _roc}) <$> inj (Just _material)
|
||||
material inj (s@Stop{_thickness, _outsideRadius}) = (const Stop{_thickness, _outsideRadius}) <$> inj Nothing
|
||||
-}
|
||||
-- | Translate a lens element from one FP type to another. E.g., can be used to convert from scalars to the types in an automatic differentiation tool.
|
||||
liftFp :: (Applicative f) => (fp -> f fp') -> Element m fp -> f (Element m fp')
|
||||
liftFp inj (s@Stop{_thickness, _outsideRadius}) = Stop <$> inj _thickness <*> inj _outsideRadius
|
||||
|
||||
Reference in New Issue
Block a user