kill(all);

load("myhelpers.mac");

/* redefine this to change dimensionality: */
n:[nx,ny]; 

dims:length(n);

assume(c>0);

if dims = 1 then n:[1];

esymmatrix(n, v, i,j):=ematrix(n,n,v,i,j)+ematrix(n,n,v,j,i);
wave_A:sum(n[i]*esymmatrix(dims+1, -c, 1+i,1),i,1,dims);

[wave_V, wave_D, wave_invV]:hypdiagonalize(wave_A);

wave_wm:append([um],makelist(concat(vm,i),i,1,dims));
wave_wp:append([up],makelist(concat(vp,i),i,1,dims));

wave_sm:makelist(concat(sm,i),i,1,length(wave_D));
wave_sp:makelist(concat(sp,i),i,1,length(wave_D));

wave_sminw:wave_invV.wave_wm;
wave_spinw:wave_invV.wave_wp;

wave_radbdryspinw:makelist( 
  if wave_D[i,i] >= 0 then wave_sminw[i,1] else 0,
  i, 1, length(wave_D));
wave_radbdrywp:fullhypsimp(wave_V.wave_radbdryspinw);

print("Radiation boundary condition for the wave equation:");
print(wave_radbdrywp);

/* ------------------------------------------------------------------------- */

wave_eigenvalues:makelist(wave_D[i,i], i, 1, length(wave_D));

if member(0, wave_eigenvalues) then
  wave_sflux:hyp_upwind_flux([-c,0,c], wave_D)
else
  wave_sflux:hyp_upwind_flux([-c,c], wave_D);
wave_wflux:ratsimp(wave_V.ev(wave_sflux, [sm=wave_sminw,sp=wave_spinw]));
wave_strongwflux:fullhypsimp(subst([c=cm], wave_A).wave_wm - wave_wflux);

print("Wave equation flux in terms of characteristic variables:");
print(wave_sflux);


print("Wave equation flux in terms of physical variables:");
print(wave_wflux);
print("Weak flux divided by (-c), as implemented in StrongWaveOperator:");
print(hypsimp(ev(wave_wflux, cp=c, cm=c)/(-c)));
/*
print("Strong-form wave equation flux in terms of physical variables:");
print(wave_strongwflux);
print(fullhypsimp(ev(wave_strongwflux, cp=c, cm=c)));
*/
