Mercurial > repos > public > sbplib
changeset 976:ea8fefc326b2
Add getEnergy methods to CdiffImplicit
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 07 Jan 2019 15:01:26 +0100 |
parents | 2412f407749a |
children | c9009d5a3101 |
files | +time/CdiffImplicit.m |
diffstat | 1 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/+time/CdiffImplicit.m Wed Dec 12 23:16:44 2018 +0100 +++ b/+time/CdiffImplicit.m Mon Jan 07 15:01:26 2019 +0100 @@ -13,7 +13,7 @@ methods % Solves - % A*u_tt + B*u + C*v_t = G(t) + % A*u_tt + B*u + C*u_t = G(t) % u(t0) = f1 % u_t(t0) = f2 % starting at time t0 with timestep k @@ -107,6 +107,15 @@ t = obj.t; end + % Calculate the conserved energy (Dm*v_n)^2_A + Im*v_n^2_B + function E = getEnergy(obj) + v = obj.v; + vp = obj.v_prev; + vt = (obj.v - obj.v_prev)/obj.k; + + E = vt'*obj.A*vt + 1/2*(v'*obj.B*v + vp'*obj.B*vp); + end + function obj = step(obj) b = obj.G(obj.t) - obj.BB*obj.v - obj.CC*obj.v_prev; obj.v_prev = obj.v;