Last active
December 20, 2015 14:59
-
-
Save fbmnds/6151402 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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