// File: jamesliu516[P]amrdg2d/farfield_boundary.cpp
// Function: getInletOutletBndry_1(bodygridclass*, int)
void getInletOutletBndry_1(OctCell *ghostcell, int in2out)
{
    double nx,ny;
    double speed, a, vbn=0.0;
    PXYZ symtrcpt; 
    PXYZ ghostpt, plsA, plsB;
    int i1,j1;

    //Rieman problem������
    //    double dil,dir,ui,prei;
    JBBL jb1,jb2; 

    SHBL sh;

    //	OctCell *leafp;
    OctCell *pincell=NULL;
    vector< OctCell * > grid;


    ghostpt.x = ghostcell->xc1;
    ghostpt.y = ghostcell->yc1;	
    if(in2out==0){
        symtrcpt.x=2.0*xInlet-ghostpt.x;
        symtrcpt.y=ghostpt.y;
        nx=1.0;
        ny=0.0;
    }
    else {
        symtrcpt.x=2.0*xOutlet-ghostpt.x;
        symtrcpt.y=ghostpt.y;
        nx=-1.0;
        ny=0.0;
    }
    getGridIndex2(ghostcell, &symtrcpt, pincell);
    findIntpltCell(pincell, ghostpt, symtrcpt, grid);
    chazhi4smtrictPshbl(grid, symtrcpt, jb1); 

    a = sqrt(GAMMA * jb1.p / jb1.q);

    speed = jb1.u * nx + jb1.v * ny;

    if(speed > 0.0 && fabs(speed) >= a)  //inflow
    {
        jb2.q=initQ;
        jb2.p=initP;
        jb2.u=uFree;
        jb2.v=vFree;

        jbblToShbl(&jb2, &sh);

        ghostcell->dof[0][0] = sh.q;
        ghostcell->dof[1][0]= sh.qu;
        ghostcell->dof[2][0]= sh.qv;
        ghostcell->dof[3][0]= sh.te;
        for( i1=0; i1<4; ++i1) 
            for(j1=1; j1<nDOF; ++j1)
                ghostcell->dof[i1][j1]=0.0;

    }
    else if(speed > 0.0 && fabs(speed) < a) //inflow
    {

        jb2.p = 0.5 * (initP + jb1.p) + 0.5 * jb1.q * a * (nx * (uFree - jb1.u) + ny * (vFree - jb1.v));
        vbn = 0.5 / (jb1.q * a) *  (initP - jb1.p) + 0.5 * (nx * (uFree + jb1.u) + ny * (vFree + jb1.v));

        jb2.q = initQ * pow(jb2.p/initP, 1./GAMMA);

        jb2.u = uFree + (vbn - (uFree * nx + vFree * ny )) * nx;
        jb2.v = vFree + (vbn - (uFree * nx + vFree * ny )) * ny;

        jbblToShbl(&jb2, &sh);

        ghostcell->dof[0][0] = sh.q;
        ghostcell->dof[1][0]= sh.qu;
        ghostcell->dof[2][0]= sh.qv;
        ghostcell->dof[3][0]= sh.te;
        for(i1=0; i1<4; ++i1) 
            for(j1=1; j1<nDOF; ++j1)
                ghostcell->dof[i1][j1]=0.0;

    }
    else if(speed <= 0.0 && fabs(speed) >= a) //outflow
    {
        jb2.q=jb1.q;
        jb2.p=jb1.p;
        jb2.u=jb1.u;
        jb2.v=jb1.v;

        jbblToShbl(&jb2, &sh);

        ghostcell->dof[0][0] = sh.q;
        ghostcell->dof[1][0]= sh.qu;
        ghostcell->dof[2][0]= sh.qv;
        ghostcell->dof[3][0]= sh.te;
        for(i1=0; i1<4; ++i1) 
            for(j1=1; j1<nDOF; ++j1)
                ghostcell->dof[i1][j1]=0.0;

    }
    else if(speed <= 0.0 && fabs(speed) < a) //outflow
    {

        jb2.p = 0.5 * (initP + jb1.p) + 0.5 * jb1.q * a * (nx * (uFree - jb1.u) + ny * (vFree - jb1.v));
        vbn = 0.5 / (jb1.q * a) *  (initP - jb1.p) + 0.5 * (nx * (uFree + jb1.u) + ny * (vFree + jb1.v));
        jb2.q = jb1.q * pow(jb2.p/jb1.p, 1./GAMMA);

        jb2.u = jb1.u + (vbn - (jb1.u * nx + jb1.v * ny)) * nx;

        jb2.v = jb1.v + (vbn - (jb1.u * nx + jb1.v * ny)) * ny;


        jbblToShbl(&jb2, &sh);

        ghostcell->dof[0][0] = sh.q;
        ghostcell->dof[1][0]= sh.qu;
        ghostcell->dof[2][0]= sh.qv;
        ghostcell->dof[3][0]= sh.te;
        for(i1=0; i1<4; ++i1) 
            for( j1=1; j1<nDOF; ++j1)
                ghostcell->dof[i1][j1]=0.0;

    }
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movl %esi, 0x11c(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xf0(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x6310
leaq 0xd0(%rsp), %rdi
callq 0x6310
leaq 0xc0(%rsp), %rdi
callq 0x6310
leaq 0xb0(%rsp), %rdi
callq 0x6310
leaq 0x88(%rsp), %rdi
callq 0x6530
leaq 0x68(%rsp), %rdi
callq 0x6530
leaq 0x48(%rsp), %rdi
callq 0x21aa0
movq $0x0, 0x40(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x62a0
movq 0x120(%rsp), %rax
movsd 0x278(%rax), %xmm0
movsd %xmm0, 0xd0(%rsp)
movq 0x120(%rsp), %rax
movsd 0x280(%rax), %xmm0
movsd %xmm0, 0xd8(%rsp)
cmpl $0x0, 0x11c(%rsp)
jne 0x2fd61
movsd 0xfbca(%rip), %xmm0     # 0x3f8e8
subsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0xf30e(%rip), %xmm0     # 0x3f058
movsd %xmm0, 0x110(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x108(%rsp)
jmp 0x2fdaa
movsd 0xfb77(%rip), %xmm0     # 0x3f8e0
subsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0xf5fb(%rip), %xmm0     # 0x3f390
movsd %xmm0, 0x110(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x108(%rsp)
movq 0x120(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x2a4c0
jmp 0x2fdc6
movq 0x40(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x2a8b0
jmp 0x2fde7
leaq 0x28(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x2b9f0
jmp 0x2fe03
movsd 0xf3cd(%rip), %xmm0     # 0x3f1d8
mulsd 0xa0(%rsp), %xmm0
divsd 0x88(%rsp), %xmm0
callq 0x31c0
movsd %xmm0, 0xf8(%rsp)
movsd 0x90(%rsp), %xmm0
movsd 0x110(%rsp), %xmm2
movsd 0x98(%rsp), %xmm1
mulsd 0x108(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x100(%rsp)
movsd 0x100(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2ffda
movsd 0x100(%rsp), %xmm0
movaps 0xf37a(%rip), %xmm1     # 0x3f200
pand %xmm1, %xmm0
ucomisd 0xf8(%rsp), %xmm0
jb 0x2ffda
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x68(%rsp)
movsd 0x2e788(%rip), %xmm0    # 0x5e638
movsd %xmm0, 0x80(%rsp)
movabsq $0x4024000000000000, %rax # imm = 0x4024000000000000
movq %rax, 0x70(%rsp)
movq $0x0, 0x78(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x23570
jmp 0x2fee2
movsd 0x48(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x30(%rax)
movsd 0x50(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x60(%rax)
movsd 0x58(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x90(%rax)
movsd 0x60(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0xc0(%rax)
movl $0x0, 0xac(%rsp)
cmpl $0x4, 0xac(%rsp)
jge 0x2ffd5
movl $0x1, 0xa8(%rsp)
cmpl $0x6, 0xa8(%rsp)
jge 0x2ffbd
movq 0x120(%rsp), %rax
addq $0x30, %rax
movslq 0xac(%rsp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movslq 0xa8(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x2ff58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x62b0
jmp 0x3074f
jmp 0x2ffbf
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x2ff3f
jmp 0x3073d
movsd 0x100(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x302cc
movsd 0x100(%rsp), %xmm1
movaps 0xf200(%rip), %xmm0     # 0x3f200
pand %xmm0, %xmm1
movsd 0xf8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x302cc
movsd 0x2e619(%rip), %xmm0    # 0x5e638
movsd 0xa0(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd 0x88(%rsp), %xmm1
movsd 0x90(%rsp), %xmm5
movsd 0xf0fa(%rip), %xmm3     # 0x3f140
mulsd %xmm3, %xmm1
movsd 0xf8(%rsp), %xmm2
mulsd %xmm2, %xmm1
movsd 0x110(%rsp), %xmm2
movsd 0xf878(%rip), %xmm4     # 0x3f8e0
movsd %xmm4, 0x8(%rsp)
movaps %xmm4, %xmm6
subsd %xmm5, %xmm6
movsd 0x108(%rsp), %xmm5
movsd 0x98(%rsp), %xmm9
xorps %xmm7, %xmm7
movsd %xmm7, 0x10(%rsp)
movaps %xmm7, %xmm8
subsd %xmm9, %xmm8
mulsd %xmm8, %xmm5
mulsd %xmm6, %xmm2
addsd %xmm5, %xmm2
mulsd %xmm2, %xmm1
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0xf8(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movsd 0x90(%rsp), %xmm5
mulsd %xmm0, %xmm1
movaps %xmm3, %xmm0
divsd %xmm1, %xmm0
movsd 0x2e54e(%rip), %xmm2    # 0x5e638
movsd 0xa0(%rsp), %xmm1
subsd %xmm1, %xmm2
movsd 0x110(%rsp), %xmm1
addsd %xmm4, %xmm5
movsd 0x108(%rsp), %xmm4
movsd 0x98(%rsp), %xmm6
addsd %xmm7, %xmm6
mulsd %xmm6, %xmm4
mulsd %xmm5, %xmm1
addsd %xmm4, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x80(%rsp), %xmm0
movsd 0x2e4ec(%rip), %xmm1    # 0x5e638
divsd %xmm1, %xmm0
movsd 0xf690(%rip), %xmm1     # 0x3f7e8
callq 0x3430
movsd 0x8(%rsp), %xmm5
movsd 0x10(%rsp), %xmm1
movsd %xmm0, 0x68(%rsp)
movsd 0xf0(%rsp), %xmm0
movsd 0x110(%rsp), %xmm2
movsd 0x108(%rsp), %xmm4
mulsd %xmm1, %xmm4
movaps %xmm2, %xmm3
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
subsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm5, %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0xf0(%rsp), %xmm0
movsd 0x110(%rsp), %xmm3
movsd 0x108(%rsp), %xmm2
movaps %xmm2, %xmm4
mulsd %xmm1, %xmm4
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
subsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x23570
jmp 0x301f8
movsd 0x48(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x30(%rax)
movsd 0x50(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x60(%rax)
movsd 0x58(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x90(%rax)
movsd 0x60(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0xc0(%rax)
movl $0x0, 0xac(%rsp)
cmpl $0x4, 0xac(%rsp)
jge 0x302c7
movl $0x1, 0xa8(%rsp)
cmpl $0x6, 0xa8(%rsp)
jge 0x302b2
movq 0x120(%rsp), %rax
addq $0x30, %rax
movslq 0xac(%rsp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movslq 0xa8(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x3026a
jmp 0x302b4
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x30255
jmp 0x3073b
xorps %xmm0, %xmm0
ucomisd 0x100(%rsp), %xmm0
jb 0x30425
movsd 0x100(%rsp), %xmm0
movaps 0xef12(%rip), %xmm1     # 0x3f200
pand %xmm1, %xmm0
ucomisd 0xf8(%rsp), %xmm0
jb 0x30425
movsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x23570
jmp 0x30351
movsd 0x48(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x30(%rax)
movsd 0x50(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x60(%rax)
movsd 0x58(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x90(%rax)
movsd 0x60(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0xc0(%rax)
movl $0x0, 0xac(%rsp)
cmpl $0x4, 0xac(%rsp)
jge 0x30420
movl $0x1, 0xa8(%rsp)
cmpl $0x6, 0xa8(%rsp)
jge 0x3040b
movq 0x120(%rsp), %rax
addq $0x30, %rax
movslq 0xac(%rsp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movslq 0xa8(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x303c3
jmp 0x3040d
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x303ae
jmp 0x30739
xorps %xmm0, %xmm0
ucomisd 0x100(%rsp), %xmm0
jb 0x30737
movsd 0x100(%rsp), %xmm1
movaps 0xedb9(%rip), %xmm0     # 0x3f200
pand %xmm0, %xmm1
movsd 0xf8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x30737
movsd 0x2e1d2(%rip), %xmm0    # 0x5e638
movsd 0xa0(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd 0x88(%rsp), %xmm1
movsd 0x90(%rsp), %xmm5
movsd 0xecb3(%rip), %xmm3     # 0x3f140
mulsd %xmm3, %xmm1
movsd 0xf8(%rsp), %xmm2
mulsd %xmm2, %xmm1
movsd 0x110(%rsp), %xmm2
movsd 0xf431(%rip), %xmm4     # 0x3f8e0
movaps %xmm4, %xmm6
subsd %xmm5, %xmm6
movsd 0x108(%rsp), %xmm5
movsd 0x98(%rsp), %xmm9
xorps %xmm7, %xmm7
movaps %xmm7, %xmm8
subsd %xmm9, %xmm8
mulsd %xmm8, %xmm5
mulsd %xmm6, %xmm2
addsd %xmm5, %xmm2
mulsd %xmm2, %xmm1
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0xf8(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movsd 0x90(%rsp), %xmm5
mulsd %xmm0, %xmm1
movaps %xmm3, %xmm0
divsd %xmm1, %xmm0
movsd 0x2e113(%rip), %xmm2    # 0x5e638
movsd 0xa0(%rsp), %xmm1
subsd %xmm1, %xmm2
movsd 0x110(%rsp), %xmm1
addsd %xmm4, %xmm5
movsd 0x108(%rsp), %xmm4
movsd 0x98(%rsp), %xmm6
addsd %xmm7, %xmm6
mulsd %xmm6, %xmm4
mulsd %xmm5, %xmm1
addsd %xmm4, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x80(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movsd %xmm1, (%rsp)
movsd 0xa0(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0xf246(%rip), %xmm1     # 0x3f7e8
callq 0x3430
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0xf0(%rsp), %xmm0
movsd 0x110(%rsp), %xmm2
movsd 0x90(%rsp), %xmm1
movsd 0x98(%rsp), %xmm4
movsd 0x108(%rsp), %xmm3
mulsd %xmm3, %xmm4
movaps %xmm1, %xmm3
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
subsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x90(%rsp), %xmm3
movsd 0x98(%rsp), %xmm1
movsd 0xf0(%rsp), %xmm0
movsd 0x110(%rsp), %xmm5
movsd 0x108(%rsp), %xmm2
movaps %xmm1, %xmm4
mulsd %xmm2, %xmm4
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
subsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x23570
jmp 0x30666
movsd 0x48(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x30(%rax)
movsd 0x50(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x60(%rax)
movsd 0x58(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0x90(%rax)
movsd 0x60(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd %xmm0, 0xc0(%rax)
movl $0x0, 0xac(%rsp)
cmpl $0x4, 0xac(%rsp)
jge 0x30735
movl $0x1, 0xa8(%rsp)
cmpl $0x6, 0xa8(%rsp)
jge 0x30720
movq 0x120(%rsp), %rax
addq $0x30, %rax
movslq 0xac(%rsp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movslq 0xa8(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x306d8
jmp 0x30722
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x306c3
jmp 0x30737
jmp 0x30739
jmp 0x3073b
jmp 0x3073d
leaq 0x28(%rsp), %rdi
callq 0x62b0
addq $0x128, %rsp            # imm = 0x128
retq
movq 0x20(%rsp), %rdi
callq 0x3440
nopl (%rax)