// File: jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: reflectionForMoving6(double, privariables const*, pointxy const*, pointxy const*, pointxy const*, double, privariables*)
void reflectionForMoving6(double hc, const JBBL *jbu,				
    const PXYZ *wall, const PXYZ *gstc, const PXYZ *nxyz, 
    double vnsolid, JBBL *jbugst)
{
    double tx,ty;
    double jl, un1,ut1, un2,ut2, nx, ny;
    double sign, rd;
    double dil,dir,ui,prei;
#ifdef NORMAL_DIR_MOD
    PXYZ ndir;
    jl = sqrt((wall->x - gstc->x) * (wall->x - gstc->x)
        +(wall->y - gstc->y) * (wall->y - gstc->y));
    rd=getWallCurvatureRadius(wall, ndir);
    if(rd>1.0e10){
        ndir.x=nxyz->x;
        ndir.y=nxyz->y;
    }
    tx=ndir.y;
    ty=-ndir.x;
    un1=jbu->u * ndir.x + jbu->v * ndir.y;
    ut1=jbu->u * tx + jbu->v * ty;			
    if(ut1>=0.0) sign = 1.0;
    else sign = -1.0;
    jbugst->p = jbu->p - jbu->q * ut1 * ut1 * 2 *jl/rd; //���ʰ뾶��������,����ֻ���������������ڹ���������

    jbugst->q = jbu->q * pow(jbugst->p/jbu->p, 1.0/GAMMA);	
   // ut2=sign * sqrt(ut1*ut1 + (2*GAMMA/(GAMMA-1)) * (jbu->p/jbu->q - jbugst->p/jbugst->q));
    ut2=ut1;

    un2= - un1;
/*    if(b_ARS){
        solveARS(jbugst->q,jbu->q,1.4,1.4,0.0,0.0,un2,un1,jbugst->p,jbu->p,
            &dil,&dir,&ui,&prei);
        //cout<<fabs(dil-dir)<<" "<<fabs(prei-jbugst->p)<<endl;
        jbugst->p=prei;
     //   jbugst->q=0.5*(dil+dir);
        jbugst->q = jbu->q * pow(jbugst->p/jbu->p, 1.0/GAMMA);
    }*/
    nx=ndir.x;
    ny=ndir.y;
    jbugst->u = (ny * ut2 - ty * un2)/(tx * ny - nx * ty);
    jbugst->v = (tx * un2 - nx * ut2)/(tx * ny - nx * ty);			
#else	

    //	jbugst->q = jbu->q;
    //	jbugst->p = jbu->p;
    //	hc=h/pow(2.0, Nr);
    jl = sqrt((wall->x - gstc->x) * (wall->x - gstc->x)
        +(wall->y - gstc->y) * (wall->y - gstc->y));
    nx=nxyz->x;
    ny=nxyz->y;

    rd=getWallCurvatureRadius(wall);

    //   cout<<"cur R=" << rd << endl;

    tx=ny;
    ty=-nx;
    un1=jbu->u * nx + jbu->v * ny;
    ut1=jbu->u * tx + jbu->v * ty;
    if(ut1>=0.0) sign = 1.0;
    else sign = -1.0;

    //	jbugst->p = 0.5*(jbu->p + pw + jl * (pw - pwh)/hc);
    jbugst->p = jbu->p - jbu->q * ut1 * ut1 * 2 *jl/rd; //���ʰ뾶��������,����ֻ���������������ڹ���������
 if(jbu->p<1e-10)jbugst->p = jbu->p ;
    jbugst->q = jbu->q * pow(jbugst->p/jbu->p, 1.0/GAMMA);
    //	jbugst->q = qw1 + jl *(qw1-qwh1)/hc;
    //-------------------------------------------------------------
    /*	jbugst->u = (- nxyz->x * nxyz->x + nxyz->y * nxyz->y) * jbu->u
        - 2 * nxyz->x * nxyz->y * jbu->v + 2 * nxyz->x * vnsolid; 

        jbugst->v = - 2 * nxyz->x * nxyz->y * jbu->u + (nxyz->x * nxyz->x - nxyz->y * nxyz->y)* jbu->v 
        + 2 * nxyz->y * vnsolid; */

//    ut2=sign * sqrt(ut1*ut1 + (2*GAMMA/(GAMMA-1)) * (jbu->p/jbu->q - jbugst->p/jbugst->q));
    ut2=ut1;
    un2= - un1;
    /*if(b_ARS){
        solveARS(jbugst->q,jbu->q,1.4,1.4,0.0,0.0,un2,un1,jbugst->p,jbu->p,
            &dil,&dir,&ui,&prei);
        //cout<<fabs(dil-dir)<<" "<<fabs(prei-jbugst->p)<<endl;
        jbugst->p=prei;
    //    jbugst->q=0.5*(dil+dir);
    jbugst->q = jbu->q * pow(jbugst->p/jbu->p, 1.0/GAMMA);
    }*/
    //void  solveARS(double dl,double dr,double gl,double gr,double bl,
    //			   double br,double ul,double ur,double pl,double pr,
    //			   double *dil,double *dir,double *ui,double *pi);

    jbugst->u = (ny * ut2 - ty * un2)/(tx * ny - nx * ty);
    jbugst->v = (tx * un2 - nx * ut2)/(tx * ny - nx * ty);

    //	jbugst->u = (- nxyz->x * nxyz->x + nxyz->y * nxyz->y) * jbu->u - 2 * nxyz->x * nxyz->y * jbu->v; 
    //	jbugst->v = - 2 * nxyz->x * nxyz->y * jbu->u + (nxyz->x * nxyz->x - nxyz->y * nxyz->y)* jbu->v; 

#endif
}

// Assembly:
subq $0xb8, %rsp
movsd %xmm0, 0xb0(%rsp)
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdx, 0x98(%rsp)
movq %rcx, 0x90(%rsp)
movsd %xmm1, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq 0xa0(%rsp), %rax
movsd (%rax), %xmm0
movq 0x98(%rsp), %rax
subsd (%rax), %xmm0
movq 0xa0(%rsp), %rax
movsd (%rax), %xmm2
movq 0x98(%rsp), %rax
subsd (%rax), %xmm2
movq 0xa0(%rsp), %rax
movsd 0x8(%rax), %xmm1
movq 0x98(%rsp), %rax
subsd 0x8(%rax), %xmm1
movq 0xa0(%rsp), %rax
movsd 0x8(%rax), %xmm3
movq 0x98(%rsp), %rax
subsd 0x8(%rax), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x31c0
movsd %xmm0, 0x68(%rsp)
movq 0x90(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x90(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x270f0
movsd %xmm0, 0x28(%rsp)
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x40(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x70(%rsp)
movq 0xa8(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd 0x40(%rsp), %xmm2
movq 0xa8(%rsp), %rax
movsd 0x10(%rax), %xmm1
mulsd 0x38(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0xa8(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd 0x78(%rsp), %xmm2
movq 0xa8(%rsp), %rax
movsd 0x10(%rax), %xmm1
mulsd 0x70(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x58(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x26eda
movsd 0x18186(%rip), %xmm0    # 0x3f058
movsd %xmm0, 0x30(%rsp)
jmp 0x26ee8
movsd 0x184ae(%rip), %xmm0    # 0x3f390
movsd %xmm0, 0x30(%rsp)
movq 0xa8(%rsp), %rax
movsd 0x18(%rax), %xmm0
movq 0xa8(%rsp), %rax
movsd (%rax), %xmm1
mulsd 0x58(%rsp), %xmm1
mulsd 0x58(%rsp), %xmm1
movsd 0x1818b(%rip), %xmm2    # 0x3f0a0
mulsd %xmm2, %xmm1
mulsd 0x68(%rsp), %xmm1
divsd 0x28(%rsp), %xmm1
subsd %xmm1, %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, 0x18(%rax)
movq 0xa8(%rsp), %rax
movsd 0x184ca(%rip), %xmm0    # 0x3f410
ucomisd 0x18(%rax), %xmm0
jbe 0x26f67
movq 0xa8(%rsp), %rax
movsd 0x18(%rax), %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, 0x18(%rax)
movq 0xa8(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x80(%rsp), %rax
movsd 0x18(%rax), %xmm0
movq 0xa8(%rsp), %rax
divsd 0x18(%rax), %xmm0
movsd 0x1884e(%rip), %xmm1    # 0x3f7e8
callq 0x3430
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x60(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x48(%rsp), %xmm2
movsd 0x70(%rsp), %xmm1
mulsd 0x50(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x78(%rsp), %xmm1
movsd 0x38(%rsp), %xmm3
movsd 0x40(%rsp), %xmm2
mulsd 0x70(%rsp), %xmm2
movq %xmm2, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movsd 0x78(%rsp), %xmm0
movsd 0x50(%rsp), %xmm2
movsd 0x40(%rsp), %xmm1
mulsd 0x48(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x78(%rsp), %xmm1
movsd 0x38(%rsp), %xmm3
movsd 0x40(%rsp), %xmm2
mulsd 0x70(%rsp), %xmm2
movq %xmm2, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq 0x80(%rsp), %rax
movsd %xmm0, 0x10(%rax)
addq $0xb8, %rsp
retq
nopl (%rax)