# FSim An attempt at a simplest possible functional programming syntax for simulation model specification using the [Fay](http://fay-lang.org/) embedded domain specific language ([EDSL](http://en.wikipedia.org/wiki/Embedded_domain_specific_language#Usage_patterns)) and Javascript compiler. The following code snippets are under test and might provide a basis for a first FSim.hs. They have mostly been lifted directly from other people's code in Haskell or ported from other languages. ## Tools * Matrix operations * Fourier transform (inverse missing) * Euler's method * RK4 * Crank-Nicholson method * Kalman filter * Circuits * Onsager * misc. ## Models * Ring oscillator * Zero-dimension energy balance model (EBM) * One-dimensional EBM * Kamp advective ocean model * Game of Life * misc. ### Ring oscillator Ian Ross's ["Fun with Fay"](http://www.skybluetrades.net/blog/posts/2012/11/13/fay-ring-oscillator/index.html) is a literate blog post using Fay and html5 canvas and a timer to display an animated 5 ring oscillator with dynamic graphs. This seemed like a good example to start with but is too complicated for describing simple simulations. The stripped-out [user interface](http://stuttard.org/oscillator uses html5 Options for parameter values. This avoids the FF non-working html5 slider problem. Work is in progress on the simulation function (loop step? iterate step?) and graph rendering etc. He also has another blog post on creating a good-looking jquery slider. Unfortunately this is for the [Yesod](http://www.yesodweb.com/) web framework and needs to be ported to [Snap](http://snapframework.com) TBD. ### Zero-Dimension EBM I have no idea where these parameters came from, it's merely for illustrative purposes. #### In the Fay proper subset of Haskell `testCO2 = temp 4.3` `temp f = (-f)/totalF where` ` lambda0 = 3.2 :: Double -- Plank` ` totalF = avLambda - lambda0` ` avLambda = (maxSumF - minSumF)/2` ` minSumF = foldl (+) 0 (fmap fst lambda)` ` maxSumF = foldl (+) 0 (fmap snd lambda)` ` lambda = [waterVapour,lapseRate,clouds,albedo]` ` waterVapour = (1.48,2.14)` ` lapseRate = (-0.41,-1.27)` ` clouds = (0.18,1.18)` ` albedo = (0.07,0.34)` #### The resulting [Javascript](http://stuttard.org:8000/ebm). This is supposed to be literate code so you should be able to cut and paste it into a text editor, save it as <filename>.js and run it with node.js, ie. ` node <filename>.js and get an answer of ~1.6 deg. C. #### Dependency [node.js](http://nodejs.org)