Skip to content

Instantly share code, notes, and snippets.

@philzook58
Created December 22, 2019 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philzook58/d61531a29e74dd7434b97ce2fb8220f1 to your computer and use it in GitHub Desktop.
Save philzook58/d61531a29e74dd7434b97ce2fb8220f1 to your computer and use it in GitHub Desktop.
Laplace equation using linear relations in hmatrix
type HLinRel2D u d l r = HLinRel (Either u l) (Either d r)
{-
A stencil of 2d resistors for tiling
u
/
\
/
|
l -/\/\/----/\/\/\- r
|
/
\
/
|
d
-}
stencil :: HLinRel2D IV IV IV IV
stencil = (hpar r10 r10) <<< short <<< (hpar r10 r10) where r10 = resistor 10
horicomp :: forall w w' w'' w''' a b c. (BEnum w, BEnum w', BEnum a, BEnum w''', BEnum b, BEnum w'', BEnum c ) => HLinRel2D w' w'' b c -> HLinRel2D w w''' a b -> HLinRel2D (Either w' w) (Either w'' w''') a c
horicomp f g = hcompose f' g' where
f' :: HLinRel (Either (Either w' w''') b) (Either (Either w'' w''') c)
f' = (first hswap) <<< hassoc' <<< (hpar hid f) <<< hassoc <<< (first hswap)
g' :: HLinRel (Either (Either w' w) a) (Either (Either w' w''') b)
g' = hassoc' <<< (hpar hid g) <<< hassoc
rotate :: (BEnum w, BEnum w', BEnum a, BEnum b) => HLinRel2D w w' a b -> HLinRel2D a b w w'
rotate f = hswap <<< f <<< hswap
vertcomp :: (BEnum w, BEnum w', BEnum a, BEnum d, BEnum b, BEnum w'', BEnum c ) => HLinRel2D w' w'' c d -> HLinRel2D w w' a b -> HLinRel2D w w'' (Either c a) (Either d b)
vertcomp f g = rotate (horicomp (rotate f) (rotate g) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment