Skip to content

Instantly share code, notes, and snippets.

@fbmnds
Last active December 20, 2015 14:59
Show Gist options
  • Select an option

  • Save fbmnds/6151402 to your computer and use it in GitHub Desktop.

Select an option

Save fbmnds/6151402 to your computer and use it in GitHub Desktop.
(ns cfd-clojure
(:use (incanter core charts)))
;; provide discretisation linear in t and up to second order in x
(defn discretize [f m u]
(let [l (last u)
g (fn [u] (conj (map #(f m %) (partition (:x-steps m) 1 u)) (first u)))
h (fn [u] (g (concat u [l])))]
(if (= 2 (:x-steps m))
(iterate g u)
(iterate h u))))
;; Step 1
(defn linear-convection [m [u_ni-1 u_ni]]
(- u_ni (/ (* (:c m) (:dt m) (- u_ni u_ni-1)) (:dx m))))
;; Step 2
(defn non-linear-convection [m [u_ni-1 u_ni]]
(- u_ni (/ (* u_ni (:dt m) (- u_ni u_ni-1)) (:dx m))))
;; Step 3
(defn diffusion-1D [m [u_ni-1 u_ni u_ni+1]]
(+ u_ni (/ (* (:nu m) (:dt m) (+ u_ni+1 u_ni-1 (* -2. u_ni))) (Math/pow (:dx m) 2.))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment