% ============================================================================
% GetAcceleration.m
% Author: Brent Dingle, Ph.D.
% Creation Date: 2020
%
% rock.thrust MUST be set correctly before calling this function
% rock.fuelMass also assumed to be updated as needed (and non-negative)
%
% ============================================================================
function a = GetAcceleration (sim, rock)
  % gravity may vary with height
  g     = GetGravity(sim, rock.height);
  
  % Most of our force is thrust
  % As we have takeoff and landing, thrust is calculated before
  % calling this function, and stored in rocket structure
  force = rock.thrust;

  % We estimate the mass as what it was at beginning of time step (dt)
  % Because dt should be small, this small error is acceptable
  % Use smaller time steps to get a better integration / less error
  % Or use another method of integration (not Euler)
  % Fuel mass expected to be updated in UpdateRocket() each time step
  m = rock.baseMass + rock.fuelMass;  % kg

  % Drag is our other contributor to total force
  d     = GetDrag(sim, rock);

  % Adjust sign depending on rocket's vertical direction of motion
  if (rock.vel < 0)
    d = -1 * d;
  endif

  % 'blips' in acceleration may be caused by discountinuities in 
  % gravity or drag --- see GetGravity and GetDrag functions   
  
  % Perform actual acceleration calculation, and return result
  a     = (force - m*g - d)/m;    % totalF = ma --> a = totalF/m
endfunction