diff +rv/+time/BDFDerivative.m @ 1013:eb441fbdf379 feature/advectionRV

Draft implementation of RungeKutta with exterior RV updates - Draft class RungeKuttaExteriorRV which updates the residual using a BDF approximation of the derivtive outside of the RK stages. - Draft class for BDF derivative
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Wed, 05 Dec 2018 15:04:44 +0100
parents
children e547794a9407
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+rv/+time/BDFDerivative.m	Wed Dec 05 15:04:44 2018 +0100
@@ -0,0 +1,33 @@
+class BDFDerivative < handle
+    properties
+        dt
+        coefficents
+    end
+    methods
+        function obj = BDFDerivative(order, dt)
+            obj.coefficents = obj.getBDFCoefficients(order);
+            obj.dt = dt;
+        end
+
+        function DvDt = evaluate(v, v_prev)
+            DvDt = (obj.coefficients(1)*v - sum(obj.coefficients(2:end).*v_prev),2)/obj.dt;
+        end
+
+        function c = getBDFCoefficients(obj, order)
+            switch order
+                case 1
+                    c(1,1) = 1; c(1,2) = 1;
+                case 2 
+                    c(1,1) = 3/2; c(1,2) = 4/2; c(1,3) = -1/2;
+                case 3
+                    c(1,1) = 11/6; c(1,2) = 18/6; c(1,3) = -9/6; c(1,4) = 2/6;
+                case 4
+                    c(1,1) = 25/12; c(1,2) = 48/12; c(1,3) = -36/12; c(1,4) = 16/12; c(1,5) = -3/12;
+                case 5
+                    c(1,1) = 137/60; c(1,2) = 300/60; c(1,3) = -300/60; c(1,4) = 200/60; c(1,5) = -75/60; c(1,6) = 12/60;
+                case 6
+                    c(1,1) = 147/60; c(1,2) = 360/60; c(1,3) = -450/60; c(1,4) = 400/60; c(1,5) = -225/60; c(1,6) = 72/60; c(1,7) = -10/60;
+            assert(length(c) == (order+1));
+        end
+    end
+end