function [ ur, br ] = mhd_resid ( x, y )

%*****************************************************************************80
%
%% mhd_resid(): residuals for underlying exact solution definitions.
%
%  Discussion:
%
%    Formulas for u(y) and b(y) are used to define an exact solution
%    of an MHD system.  This function tests whether these formulas
%    satisfy the underlying equations involving u''(y) and b''(y).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 August 2024
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Jean-Frederic Gerbeau, Claude Le Bris, Tony Lelievre,
%    Mathematical methods for the magnetohydrodynamics
%    of liquid metals,
%    Oxford University Press, 2006,
%    ISBN 978-0-19-856665-6
%
%  Input:
%
%    real X(:), Y(:): the spatial locations.
%
%  Output:
%
%    real ur(:):
%
%    real br(:):
%
  [ G, Ha, L, p0, Re, Rm, S ] = mhd_parameters ( );
%
%  The velocity function u(y):
%
  u =     G * Re / tanh ( Ha ) / Ha * ( 1.0 - cosh ( y * Ha ) / cosh ( Ha ) );
  uy =  - G * Re / sinh ( Ha )              * sinh ( y * Ha );
  uyy = - G * Re / sinh ( Ha ) * Ha         * cosh ( y * Ha );
%
%  The magnetic field function b(y):
%
  b =   G / S * (          sinh ( y * Ha ) / sinh ( Ha ) - y );
  by =  G / S * ( Ha     * cosh ( y * Ha ) / sinh ( Ha ) - 1.0 );
  byy = G / S *   Ha^2 * ( sinh ( y * Ha ) / sinh ( Ha ) );
%
%  Residuals associated with velocity and magnetic field.
%
  ur = uyy + Re * S * by + G * Re;
  br = byy + Rm * uy;

  return
end

