changeset 816:b5e5b195da1e feature/timesteppers

Add getState to timesteppers, returning the relevant state of the timestepper - Add getState which returns the 'state' of the specialized timestepper.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 10 Sep 2018 16:19:16 +0200
parents 2ce903f28193
children 8894e9c49e40
files +time/Cdiff.m +time/CdiffNonlin.m +time/Ode45.m +time/Rk4SecondOrderNonlin.m +time/Rungekutta4.m +time/Rungekutta4SecondOrder.m +time/Rungekutta4proper.m +time/SBPInTime.m +time/SBPInTimeSecondOrderForm.m +time/Timestepper.m
diffstat 10 files changed, 62 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/+time/Cdiff.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/Cdiff.m	Mon Sep 10 16:19:16 2018 +0200
@@ -45,6 +45,10 @@
             t = obj.t;
         end
 
+        function state = getState(obj)
+            state = struct('v', obj.v, 'v_prev', obj.v_prev, 't', obj.t, 'k', obj.k);
+        end
+
         function obj = step(obj)
             [obj.v, obj.v_prev] = time.cdiff.cdiff(obj.v, obj.v_prev, obj.k, obj.D, obj.E, obj.S);
             obj.t = obj.t + obj.k;
--- a/+time/CdiffNonlin.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/CdiffNonlin.m	Mon Sep 10 16:19:16 2018 +0200
@@ -50,6 +50,12 @@
             t = obj.t;
         end
 
+        function state = getState(obj)
+            [v, t] = obj.getV();
+            [vt] = obj.getVt();
+            state = struct('v', v, 'vt', vt, 't', t, 'k', obj.k);
+        end
+
         function obj = step(obj)
             D = obj.D(obj.v);
             E = obj.E(obj.v);
--- a/+time/Ode45.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/Ode45.m	Mon Sep 10 16:19:16 2018 +0200
@@ -48,6 +48,12 @@
             t = obj.t;
         end
 
+        function state = getState(obj)
+            [v, t] = obj.getV();
+            [vt] = obj.getVt();
+            state = struct('v', v, 'vt', vt, 't', t, 'k', obj.k);
+        end
+
         function obj = step(obj)
             [t,w] = ode45(@(t,w)(obj.F(w,t)),[obj.t obj.t+obj.k],obj.w);
 
--- a/+time/Rk4SecondOrderNonlin.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/Rk4SecondOrderNonlin.m	Mon Sep 10 16:19:16 2018 +0200
@@ -60,6 +60,12 @@
             t = obj.t;
         end
 
+        function state = getState(obj)
+            [v, t] = obj.getV();
+            [vt] = obj.getVt();
+            state = struct('v', v, 'vt', vt, 't', t, 'k', obj.k);
+        end
+
         function obj = step(obj)
             obj.w = time.rk4.rungekutta_4(obj.w, obj.t, obj.k, obj.F);
             obj.t = obj.t + obj.k;
--- a/+time/Rungekutta4.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/Rungekutta4.m	Mon Sep 10 16:19:16 2018 +0200
@@ -38,6 +38,10 @@
             t = obj.t;
         end
 
+        function state = getState(obj)
+            state = struct('v', obj.v, 't', obj.t, 'k', obj.k);
+        end
+
         function obj = step(obj)
             obj.v = time.rk4.rungekutta_4(obj.v, obj.t, obj.k, obj.F);
             obj.t = obj.t + obj.k;
--- a/+time/Rungekutta4SecondOrder.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/Rungekutta4SecondOrder.m	Mon Sep 10 16:19:16 2018 +0200
@@ -49,6 +49,12 @@
             t = obj.t;
         end
 
+        function state = getState(obj)
+            [v, t] = obj.getV();
+            [vt] = obj.getVt();
+            state = struct('v', v, 'vt', vt, 't', t, 'k', obj.k);
+        end
+
         function obj = step(obj)
             obj.w = time.rk4.rungekutta_4(obj.w, obj.t, obj.k, obj.F);
             obj.t = obj.t + obj.k;
--- a/+time/Rungekutta4proper.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/Rungekutta4proper.m	Mon Sep 10 16:19:16 2018 +0200
@@ -18,10 +18,15 @@
             obj.m = length(v0);
             obj.n = 0;
         end
+        
+        function [v, t] = getV(obj)
+            v = obj.v;
+            t = obj.t
 
-        function [v,t] = getV(obj)
-            v = obj.v;
-            t = obj.t;
+        end
+
+        function state = getState(obj)
+            state = struct('v', obj.v, 't', obj.t, 'k', obj.k);
         end
 
         function obj = step(obj)
--- a/+time/SBPInTime.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/SBPInTime.m	Mon Sep 10 16:19:16 2018 +0200
@@ -94,6 +94,11 @@
             t = obj.t;
         end
 
+        function state = getState(obj)
+            [v, t] = getV(obj);
+            state = struct('v', v, 't', t, 'k', obj.k);
+        end
+
         function obj = step(obj)
             obj.v = time.sbp.sbpintime(obj.v, obj.t, obj.nodes,...
                               obj.penalty, obj.f, obj.blockSize,...
--- a/+time/SBPInTimeSecondOrderForm.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/SBPInTimeSecondOrderForm.m	Mon Sep 10 16:19:16 2018 +0200
@@ -58,6 +58,12 @@
             t = obj.t;
         end
 
+        function state = getState(obj)
+            [v, t] = obj.getV();
+            [vt] = obj.getVt();
+            state = struct('v', v, 'vt', vt, 't', t, 'k', obj.k);
+        end
+
         function obj = step(obj)
             obj.firstOrderTimeStepper.step();
             obj.t = obj.firstOrderTimeStepper.t;
--- a/+time/Timestepper.m	Thu Sep 07 09:54:21 2017 +0200
+++ b/+time/Timestepper.m	Mon Sep 10 16:19:16 2018 +0200
@@ -3,11 +3,20 @@
         t
         k
         n
+        % TBD: Decide on accessibility of properties.
+        % Properties that are not intended to be modified from the outside
+        % should ideally be made private and the specialized classes should be extended with
+        % getter functions for their relevant members, e.g v, t, k, etc.
     end
 
     methods (Abstract)
-         [v,t] = getV(obj)
-         obj = step(obj)
+        % Returns the solution vector v at timestep t.
+        % TBD: Replace with getters for the separate members if the above suggestion is implemented?
+        [v,t] = getV(obj)
+        % Returns struct holding relevant state properties for the specialized timestepper.
+        % E.g [v, t, k].
+        state = getState(obj)
+        obj = step(obj)
     end