// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, %rbx
movq %rcx, %r12
movq %rsi, %r15
movq %rdi, %r14
movsd (%rsi), %xmm0
movsd 0x8(%rsi), %xmm1
subsd (%rdx), %xmm0
subsd 0x8(%rdx), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x11720
sqrtsd %xmm0, %xmm0
jmp 0x11725
callq 0x31b0
movsd %xmm0, (%rsp)
movsd (%r12), %xmm0
movaps %xmm0, 0x20(%rsp)
movsd 0x8(%r12), %xmm0
movapd %xmm0, 0x30(%rsp)
movq %r15, %rdi
callq 0x11886
movapd 0xc94e(%rip), %xmm1     # 0x1e0a0
movapd 0x20(%rsp), %xmm4
xorpd %xmm4, %xmm1
movapd %xmm1, 0x50(%rsp)
movsd (%r14), %xmm3
movsd 0x8(%r14), %xmm7
movsd 0x10(%r14), %xmm1
movapd %xmm1, %xmm2
movapd %xmm4, %xmm6
mulsd %xmm4, %xmm2
movapd %xmm7, %xmm5
movapd 0x30(%rsp), %xmm8
movapd %xmm8, %xmm4
mulsd %xmm8, %xmm5
subsd %xmm2, %xmm5
movsd 0x18(%r14), %xmm2
movsd %xmm3, 0x18(%rsp)
mulsd %xmm5, %xmm3
movapd %xmm5, 0x40(%rsp)
mulsd %xmm5, %xmm3
addsd %xmm3, %xmm3
mulsd (%rsp), %xmm3
divsd %xmm0, %xmm3
subsd %xmm3, %xmm2
movsd %xmm2, 0x18(%rbx)
movsd 0x18(%r14), %xmm0
movsd 0xcc0a(%rip), %xmm2     # 0x1e3e0
ucomisd %xmm0, %xmm2
jbe 0x117e1
movsd %xmm0, 0x18(%rbx)
mulsd %xmm4, %xmm1
mulsd %xmm6, %xmm7
addsd %xmm1, %xmm7
movapd %xmm7, (%rsp)
movsd 0x18(%rbx), %xmm0
divsd 0x18(%r14), %xmm0
movsd 0xd063(%rip), %xmm1     # 0x1e868
callq 0x3360
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rbx)
movapd 0xc880(%rip), %xmm0     # 0x1e0a0
movapd (%rsp), %xmm5
xorpd %xmm5, %xmm0
movapd 0x20(%rsp), %xmm2
mulsd %xmm2, %xmm2
movapd 0x30(%rsp), %xmm4
movapd %xmm4, %xmm1
mulsd %xmm4, %xmm1
addsd %xmm2, %xmm1
movapd 0x40(%rsp), %xmm3
unpcklpd %xmm3, %xmm5            # xmm5 = xmm5[0],xmm3[0]
movapd 0x50(%rsp), %xmm2
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm5, %xmm2
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
mulpd %xmm4, %xmm3
addpd %xmm2, %xmm3
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm3
movupd %xmm3, 0x8(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq