sandbox/Maknine/stabilityRT.h
The solution of linear stability problem of the classical Rayleigh-Taylor instability using the one-fluid approach can be obtained from the solution of \begin{aligned} &\tilde \rho_0 \partial_t u' = - \partial_x p' + \partial_x (\tilde \mu_0 2 \partial_x u') + \partial_y (\tilde \mu_0 (\partial_y u' + \partial_x v') ) \\ & \tilde \rho_0 \partial_t v' = - \partial_y p' + \partial_y (\tilde \mu_0 2 \partial_y v') + \partial_x (\tilde \mu_0 (\partial_y u' + \partial_x v') ) + \tilde \rho' g + \sigma \kappa' \partial_y f_0 \\ & \partial_t h' = v' \end{aligned}
This system can be expressed as a system of equations for the (complex) streamfunction-vorticity variables u' = \partial_y \psi, ~~~~ v' = -\partial_x \psi Linearizing h(x,t)=h'e^{i(kx - \omega t)}, ~~~~ \psi = \phi e^{i(kx - \omega t)}, and introducing the rescaled variable \tilde{\Phi} \equiv \tilde{\phi} \frac{\frac{\tilde{\omega}}{k}}{h^{'} \left(\left(\rho_1 - \rho_2\right)g - \sigma k^2\right) } we obtain \begin{aligned} & D^2 \Phi -k^2 \Phi = -\eta \\ & D^2 (\tilde \mu_0 \eta ) - (k^2 \tilde \mu_0 - \tilde \rho_0 i \omega) \eta - i \omega D\tilde \rho_0 D\Phi - 2 k^2 \Phi D^2 \tilde \mu_0 = i \omega Df_0 \\ & \tilde{\Phi}(0) \equiv \frac{\frac{\tilde{\omega}^2}{k^2}}{h^{'}\left(\left(\rho_1 - \rho_2\right)g - \sigma k^2\right)} \end{aligned} where D() denotes the derivative in y, g is the magnitude of gravity in direction y. The fraction is defined as f=0.5 - \frac{y}{\Delta_I}
double fraction_profile(double y, double DeltaI) {
if (y>DeltaI/2) return 0.;
if (y<-DeltaI/2) return 1.;
return 0.5 - y/DeltaI;
}The rescaled variables are chosen such that the Kinematic condition at the interface (placed at x=0) contains all the information required to capture the two branches of the instability.
We solve this system using a coupled Poisson solver adapted to work with complex variables. Note that the problem is 1D in y
#include "poisson.h"
#include <complex.h>
double complex om;//Complex growth rate (Guess)
double rho1, rho2;
double mu1, mu2;
double g, sigma;
# define rho(f) (clamp(f,0.,1.)*(rho1 - rho2) + rho2)
# define mu(f) (clamp(f,0.,1.)*(mu1 - mu2) + mu2)Computation of the most unstable growth rate using the Kinematic condition
double complex get_omega (double RePsi0, double IMPsi0, double k) {
double complex omega_sq=( RePsi0 + I*IMPsi0)*((rho1 - rho2)*g - sigma*sq(k))*sq(k);
double omega_R = sqrt( ( sqrt( sq(creal(omega_sq)) + sq(cimag(omega_sq)) ) + creal(omega_sq) )/2 );
double omega_I = sqrt( ( sqrt( sq(creal(omega_sq)) + sq(cimag(omega_sq)) ) - creal(omega_sq) )/2 );
return omega_R + I*omega_I;
}Coupled Poisson solver: we define the relax and residual functions based on the original equations
struct PoissonSystem {
scalar REPhi, RErhsPhi;
scalar IMPhi, IMrhsPhi;
scalar rho0;
scalar mu0;
double k;
double tolerance;
int nrelax, minlevel;
scalar * res;
};
static void relax_system (scalar * al, scalar * bl, int l, void * data)
{
scalar REPhi = al[0], RErhsPhi = bl[0];
scalar IMPhi = al[1], IMrhsPhi = bl[1];
scalar REEta = al[2], RErhsEta = bl[2];
scalar IMEta = al[3], IMrhsEta = bl[3];
struct PoissonSystem * p = (struct PoissonSystem *) data;
scalar rho0 = p->rho0;
scalar mu0 = p->mu0;
double k = p->k;
double complex numPhi, denPhi, PhiR, PhiL, Phi, Phirhs;
double complex numEta, denEta, EtaR, EtaL, Eta, Etarhs;
#if JACOBI
scalar cREPhi[], cIMPhi[], cREEta[], cIMEta[];
#else
scalar cREPhi = REPhi, cIMPhi = IMPhi, cREEta = REEta, cIMEta = IMEta;
#endif
foreach_level_or_leaf (l) {
Phi = REPhi[] + I*IMPhi[];
Phirhs = RErhsPhi[] + I*IMrhsPhi[];
Eta = REEta[] + I*IMEta[];
Etarhs = RErhsEta[] + I*IMrhsEta[];
PhiR = REPhi[1] + I*IMPhi[1] ;
PhiL = REPhi[-1] + I*IMPhi[-1] ;
EtaR = REEta[1] + I*IMEta[1] ;
EtaL = REEta[-1] + I*IMEta[-1] ;
denPhi = -2. - sq(k*Delta);
numPhi = Phirhs*sq(Delta) - Eta*sq(Delta) - (PhiR + PhiL);
denEta = - 2*mu0[] + (I*rho0[]*om - mu0[]*sq(k))*sq(Delta);
numEta = -mu0[1]*EtaR - mu0[-1]*EtaL;
numEta += Etarhs*sq(Delta) + I*om*(PhiR - PhiL)/2.*(rho0[1] - rho0[-1])/2.;
numEta += 2*sq(k)*Phi*(mu0[1] - 2*mu0[] + mu0[-1]);
//end of terms
Phi = numPhi/denPhi;
Eta = numEta/denEta;
cREPhi[] = creal(Phi);
cIMPhi[] = cimag(Phi);
cREEta[] = creal(Eta);
cIMEta[] = cimag(Eta);
}
#if JACOBI
foreach_level_or_leaf (l) {
REPhi[] = (REPhi[] + 2.*cREPhi[])/3.;
IMPhi[] = (IMPhi[] + 2.*cIMPhi[])/3.;
REEta[] = (REEta[] + 2.*cREEta[])/3.;
IMEta[] = (IMEta[] + 2.*cIMEta[])/3.;
}
#endif
}
static double residual_system (scalar * al, scalar * bl, scalar * resl, void * data)
{
scalar REPhi = al[0], RErhsPhi = bl[0], REres = resl[0];
scalar IMPhi = al[1], IMrhsPhi = bl[1], IMres = resl[1];
scalar REEta = al[2], RErhsEta = bl[2], REresEta = resl[2];
scalar IMEta = al[3], IMrhsEta = bl[3], IMresEta = resl[3];
scalar REmuEta[], IMmuEta[];
struct PoissonSystem * p = (struct PoissonSystem *) data;
scalar rho0 = p->rho0;
scalar mu0 = p->mu0;
double k = p->k;
double maxres = 0.;
double maxresPhi = 0.;
double maxresEta = 0.;
double complex resPhi, Phi , PhiR ,PhiL , Phirhs;
double complex resEta, Eta, Etarhs;
foreach () {
REmuEta[] = REEta[]*mu0[];
IMmuEta[] = IMEta[]*mu0[];
}
#if TREE
/* conservative coarse/fine discretisation (2nd order) */
face vector REgradPhi[] ,IMgradPhi[];
face vector REgradEtamu[] ,IMgradEtamu[];
foreach_face() {
REgradPhi.x[] = face_gradient_x (REPhi, 0);
IMgradPhi.x[] = face_gradient_x (IMPhi, 0);
REgradEtamu.x[] = face_gradient_x (REmuEta, 0);
IMgradEtamu.x[] = face_gradient_x (IMmuEta, 0);
}
foreach (reduction(max:maxres), nowarning) {
Phi = REPhi[] + I*IMPhi[];
Phirhs = RErhsPhi[] + I*IMrhsPhi[];
Eta = REEta[] + I*IMEta[];
Etarhs = RErhsEta[] + I*IMrhsEta[];
PhiR = REPhi[1] + I*IMPhi[1] ;
PhiL = REPhi[-1] + I*IMPhi[-1] ;
resPhi = Phirhs - Eta + sq(k)*Phi;
resEta = Etarhs + I*om*(PhiR - PhiL)/(2*Delta)*(rho0[1] - rho0[-1])/(2*Delta) - (I*rho0[]*om - sq(k)*mu0[])*Eta;
resEta += 2*sq(k)*Phi*(mu0[1] - 2*mu0[] + mu0[-1])/sq(Delta);
resPhi -= (REgradPhi.x[1] - REgradPhi.x[] + I*(IMgradPhi.x[1] - IMgradPhi.x[]))/Delta;
double complex DDmuEta = (REgradEtamu.x[1] - REgradEtamu.x[] + I*(IMgradEtamu.x[1] - IMgradEtamu.x[]))/Delta;
resEta -= DDmuEta;
REres[] = creal(resPhi);
IMres[] = cimag(resPhi);
REresEta[] = creal(resEta);
IMresEta[] = cimag(resEta);
}
if (cabs (resPhi) > maxresPhi)
maxresPhi = cabs (resPhi);
if (cabs (resEta) > maxresEta)
maxresEta = cabs (resEta);
maxres = max(maxresPhi, maxresEta);
#else // !TREE
/* "naive" discretisation (only 1st order on trees) */
foreach (reduction(max:maxres), nowarning) {
Phi = REPhi[] + I*IMPhi[];
Phirhs = RErhsPhi[] + I*IMrhsPhi[];
Eta = REEta[] + I*IMEta[];
Etarhs = RErhsEta[] + I*IMrhsEta[];
PhiR = REPhi[1] + I*IMPhi[1] ;
PhiL = REPhi[-1] + I*IMPhi[-1] ;
resPhi = Phirhs - Eta + sq(k)*Phi;
resEta = Etarhs + I*om*(PhiR - PhiL)/(2*Delta)*(rho0[1] - rho0[-1])/(2*Delta) - (I*rho0[]*om - sq(k)*mu0[])*Eta;
resEta += 2*sq(k)*Phi*(mu0[1] - 2*mu0[] + mu0[-1])/sq(Delta);
resPhi -= (face_gradient_x (REPhi, 1) - face_gradient_x (REPhi, 0))/Delta
+ I*(face_gradient_x (IMPhi, 1) - face_gradient_x (IMPhi, 0))/Delta;
double complex DDmuEta = (face_gradient_x (REmuEta, 1) - face_gradient_x (REmuEta, 0))/Delta
+ I*(face_gradient_x (IMmuEta, 1) - face_gradient_x (IMmuEta, 0))/Delta;
resEta -= DDmuEta;
REres[] = creal(resPhi);
IMres[] = cimag(resPhi);
REresEta[] = creal(resEta);
IMresEta[] = cimag(resEta);
if (cabs(resPhi) > maxresPhi)
maxresPhi = cabs (resPhi);
if (cabs (resEta) > maxres)
maxresEta = cabs (resEta);
maxres = max(maxresPhi, maxresEta);
}
#endif // !TREE
return maxres;
}The final solver becomes
double complex solve_stability_RT (
scalar REPhi, scalar IMPhi,
scalar REEta, scalar IMEta,
double DeltaI,
double k,
double tolerance = 0.,
int nrelax = 4,
int minlevel = 0,
scalar * res = NULL,
double (* flux) (Point, scalar, vector, double *) = NULL)
{
scalar rho0[], mu0[], f[];
scalar RErhsEta[] ;
scalar IMrhsEta[] ;
scalar RErhsPhi[];
scalar IMrhsPhi[];
/* Definition of the parametres of the PDE */
foreach(){
f[] = fraction_profile(x, DeltaI);
rho0[] = rho(f[]);
mu0[] = mu(f[]);
RErhsPhi[] = 0.;
IMrhsPhi[] = 0.;
}
restriction ((scalar *){rho0, mu0});
double defaultol = TOLERANCE;
if (tolerance)
TOLERANCE = tolerance;
struct PoissonSystem p = {REPhi, RErhsPhi, IMPhi, IMrhsPhi, rho0, mu0, k, tolerance, nrelax, minlevel, res };
#if EMBED
if (!flux && a.boundary[embed] != symmetry)
p.embed_flux = embed_flux;
else
p.embed_flux = flux;
#endif // EMBED
/Internal Loop over omega
double complex omold, omerr = 1 + I;
do {
/* We initialize the forcing using the currently available value of $\omega$*/
foreach () {
double Df0 = (f[1] - f[-1])/Delta/2.;
RErhsEta[] = -cimag(om) * Df0;
IMrhsEta[] = creal(om) * Df0;
}
omold = om;We solve for the system of equations
mg_solve ({REPhi,IMPhi,REEta, IMEta}, {RErhsPhi,IMrhsPhi,RErhsEta, IMrhsEta}, residual_system, relax_system, &p,
nrelax, res, max(1, minlevel));
/* We update $\omega$ */
om= get_omega (interpolate (REPhi, 0, 0), interpolate (IMPhi, 0, 0), k);
omerr = om - omold;
} while (cabs(omerr) > TOLERANCE);
return om;
}