Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added element type class + implementation of linear line element

  • Loading branch information...
commit db55a8b353f537945769a6c42b8c45b2314e1187 1 parent 0d3c73a
Adrien Haxaire authored

Showing 1 changed file with 67 additions and 0 deletions. Show diff stats Hide diff stats

  1. +67 0 Numeric/Funfem/Elements.hs
67 Numeric/Funfem/Elements.hs
... ... @@ -0,0 +1,67 @@
  1 +----------------------------------------------------------------------------------
  2 +-- |
  3 +-- Module : Elements
  4 +-- Copyright : (c) Adrien Haxaire 2012
  5 +-- Licence : BSD3
  6 +--
  7 +-- Maintainer : Adrien Haxaire <adrien@funfem.org>
  8 +-- Stability : experimental
  9 +-- Portabilty : not tested
  10 +--
  11 +----------------------------------------------------------------------------------
  12 +--
  13 +
  14 +module Numeric.Funfem.Elements where
  15 +
  16 +import qualified Data.Vector as V
  17 +import qualified Data.Map as M
  18 +
  19 +import Numeric.Funfem.Algebra.Vector
  20 +import Numeric.Funfem.Algebra.Matrix
  21 +
  22 +type Point = [Double]
  23 +
  24 +data Node = Node {coordinates :: Point, nodeNumber :: Int}
  25 + deriving (Eq, Ord, Show)
  26 +
  27 +type Material = M.Map String Double
  28 +
  29 +-- | Type class for an element.
  30 +class Element a where
  31 + nodes :: a -> [Node]
  32 + material :: a -> Material
  33 + shape :: a -> [([Double] -> Double)]
  34 +
  35 +-- | Linear line element.
  36 +data Lin2 = Lin2 {nodesLin2 :: [Node], matLin2 :: Material}
  37 + deriving (Eq, Ord, Show)
  38 +
  39 +coorsLin2 :: Lin2 -> [Double]
  40 +coorsLin2 el = map (head . coordinates) $ nodesLin2 el
  41 +
  42 +lengthLin2 :: Lin2 -> Double
  43 +lengthLin2 el = let [x1,x2] = coorsLin2 el in abs (x1 - x2)
  44 +
  45 +shapeLin2 :: Lin2 -> [([Double] -> Double)]
  46 +shapeLin2 el = [f1, f2]
  47 + where
  48 + l = lengthLin2 el
  49 + f1 [x] = 1-x/l
  50 + f2 [x] = x/l
  51 +
  52 +instance Element Lin2 where
  53 + nodes = nodesLin2
  54 + material = matLin2
  55 + shape = shapeLin2
  56 +
  57 +
  58 +
  59 +
  60 +
  61 +{-
  62 +n1 = Node [0.0] 1
  63 +n2 = Node [1.0] 2
  64 +mat = M.fromList [("conductivity", 1.0)]
  65 +
  66 +el1 = Lin2 [n1,n2] mat
  67 +-}

0 comments on commit db55a8b

Please sign in to comment.
Something went wrong with that request. Please try again.