// File: jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: getGhostValueMagazine(bodygridclass*)
void getGhostValueMagazine(OctCell * ghostcell)
{
    PXYZ nml1;
    PXYZ symtrcpt,jiaodian,wnph; 
    PXYZ ghostpt, plsA, plsB;

    int jj,kk,m,numbergrid,lsflag,lsint, ils;
    int nb;
//Rieman problem������
//    double dil,dir,ui,prei;
    JBBL ingrid1,jbu1; 

    JBBL jbgst1;

    SHBL shgst1;

    //	OctCell *leafp;
    OctCell *pincell=NULL;
    vector< OctCell * > grid;

    double pwh1, vnsolid,pw1;	
    double  hc;

    ghostpt.x = ghostcell->xc1;
    ghostpt.y = ghostcell->yc1;	

    //hc=max2(ghostcell->dx, ghostcell->dy);
    hc=sqrt(ghostcell->dx*ghostcell->dx+ghostcell->dy*ghostcell->dy);

    if(qvlvModify == 0)
    {
        ils = getIndexAtWallPoint(&ghostpt,nb); //TODO

        if(ils == NWallPts[nb]-1) 
        {
            plsA.x = MultiCircle[nb][ils].x; 
            plsA.y = MultiCircle[nb][ils].y;
            plsB.x = MultiCircle[nb][0].x; 
            plsB.y = MultiCircle[nb][0].y;
        }
        else
        {
            plsA.x = MultiCircle[nb][ils].x; 
            plsA.y = MultiCircle[nb][ils].y;
            plsB.x = MultiCircle[nb][ils+1].x; 
            plsB.y = MultiCircle[nb][ils+1].y;
        }

        getsmtrctAB(&ghostpt, &plsA, &plsB,
            &symtrcpt, &jiaodian, &nml1);

#ifdef DEBUG
        //cout<<"("<<ghostpt.x<<", "<<ghostpt.y<<")  ("<<jiaodian.x<<", "<<jiaodian.y<<")   ("
        // << symtrcpt.x<<", "<<symtrcpt.y<<")\n";
#endif

        //void getGridIndex(OctCell *gstc, const PXYZ *p_sm, int &iy, int &ix)
        //    getGridIndex(ghostcell, &symtrcpt, jj, kk);
        //void getGridIndex(OctCell *parent, const PXYZ *p_sm, ptrOctCell &pcell)

        getGridIndex(ghostcell, &symtrcpt, pincell);

        //----------------------------------------------------------begin
        //void findIntpltCell(int iy, int ix, const PXYZ &gstp, const PXYZ &smtricp, vector< OctCell * > &grid) 

        //   findIntpltCell(jj, kk, ghostpt, symtrcpt, grid);
        //incellΪ���������ڵĿ�����
        //void findIntpltCell(const OctCell * incell, const PXYZ &gstp, const PXYZ &smtricp, vector< OctCell * > &grid)     
        findIntpltCell(pincell, ghostpt, symtrcpt, grid);

        // 	numbergrid = grid.size();

        //cout<<"numbergrid"<<numbergrid<<endl;

        // 	void chazhi4smtrictPshbl(vector< OctCell * > &grid, const PXYZ &smtrict, JBBL &jbu )

        chazhi4smtrictPshbl(grid, symtrcpt, ingrid1); 

        //2011-9.9	  									
        //    	InterpolateForMoving(grid, &symtrcpt, numbergrid, &ingrid1); 
        //------------------------------------------------------end-----------

        //	linearInterpolate(grid, &symtrcpt, &ingrid1);  

        reflection(&ingrid1, &nml1, &jbgst1);
    }//------------------------------------------------------------------------
    else if(qvlvModify == 1)
    {
        ils = getIndexAtWallPoint(&ghostpt,nb); //TODO

        if(ils == NWallPts[nb]-1) 
        {
            plsA.x = MultiCircle[nb][ils].x; 
            plsA.y = MultiCircle[nb][ils].y;
            plsB.x = MultiCircle[nb][0].x; 
            plsB.y = MultiCircle[nb][0].y;
        }
        else
        {
            plsA.x = MultiCircle[nb][ils].x; 
            plsA.y = MultiCircle[nb][ils].y;
            plsB.x = MultiCircle[nb][ils+1].x; 
            plsB.y = MultiCircle[nb][ils+1].y;
        }
        /////////////////////////////////////2008-12-6//////////////////////////////////////////////

        getsmtrctAB(&ghostpt, &plsA, &plsB,
            &symtrcpt, &jiaodian, &nml1);
        //ȷ�������еĵ�p_sm�����ĸ�cell

        //void getGridIndex(OctCell *gstc, const PXYZ *p_sm, int &iy, int &ix)
        //	getGridIndex(ghostcell, &symtrcpt, jj, kk);
        getGridIndex(ghostcell, &symtrcpt, pincell);       	

        //  findIntpltCell(jj, kk, ghostpt, symtrcpt, grid);
        findIntpltCell(pincell, ghostpt, symtrcpt, grid);
        //----------------------------------------------------------begin
        //	numbergrid = grid.size();
        // 	void chazhi4smtrictPshbl(vector< OctCell * > &grid, const PXYZ &smtrict, JBBL &jbu )

        chazhi4smtrictPshbl(grid, symtrcpt, ingrid1); 

        // 	InterpolateForMoving(grid, &symtrcpt, numbergrid, &ingrid1); 
        //------------------------------------------------------end--------
        vnsolid=0.0;						
        reflectionForMoving6(hc,&ingrid1, &jiaodian, &ghostpt, 
            &nml1, vnsolid, &jbgst1);
//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);
        //////////////////////////2008-12-6//////2008-12-6///////////////////////////////////////////
    }
    //////////////////				
    jbblToShbl(&jbgst1, &shgst1);

    ghostcell->dof[0][0] = shgst1.q;
    ghostcell->dof[1][0] = shgst1.qu;
    ghostcell->dof[2][0]  = shgst1.qv;
    ghostcell->dof[3][0] = shgst1.te;
    for(int itm=0; itm<4; ++itm) {
        for(int jtm=1;jtm<nDOF; ++jtm) {
            ghostcell->dof[itm][jtm]=0.0;
        }
    }
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x6310
leaq 0x160(%rsp), %rdi
callq 0x6310
leaq 0x150(%rsp), %rdi
callq 0x6310
leaq 0x140(%rsp), %rdi
callq 0x6310
leaq 0x130(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x6310
leaq 0x120(%rsp), %rdi
callq 0x6310
leaq 0x110(%rsp), %rdi
callq 0x6310
leaq 0xd0(%rsp), %rdi
callq 0x6530
leaq 0xb0(%rsp), %rdi
callq 0x6530
leaq 0x90(%rsp), %rdi
callq 0x6530
leaq 0x70(%rsp), %rdi
callq 0x21aa0
movq $0x0, 0x68(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x62a0
movq 0x180(%rsp), %rax
movsd 0x278(%rax), %xmm0
movsd %xmm0, 0x130(%rsp)
movq 0x180(%rsp), %rax
movsd 0x280(%rax), %xmm0
movsd %xmm0, 0x138(%rsp)
movq 0x180(%rsp), %rax
movsd 0x288(%rax), %xmm0
movsd 0x290(%rax), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
callq 0x31c0
movq 0x10(%rsp), %rdi
movsd %xmm0, 0x30(%rsp)
leaq 0xf0(%rsp), %rsi
callq 0x27aa0
movl %eax, 0x18(%rsp)
jmp 0x2ca5c
movl 0x18(%rsp), %eax
movl %eax, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
movslq 0xf0(%rsp), %rdx
leaq 0x1e813(%rip), %rcx     # 0x4b290
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2cb65
movslq 0xf0(%rsp), %rcx
leaq 0x1e976(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0xf4(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x120(%rsp)
movslq 0xf0(%rsp), %rcx
leaq 0x1e941(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0xf4(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x128(%rsp)
movslq 0xf0(%rsp), %rcx
leaq 0x1e90b(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x110(%rsp)
movslq 0xf0(%rsp), %rcx
leaq 0x1e8e5(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x118(%rsp)
jmp 0x2cc45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x62b0
jmp 0x2cdf6
movslq 0xf0(%rsp), %rcx
leaq 0x1e89c(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0xf4(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x120(%rsp)
movslq 0xf0(%rsp), %rcx
leaq 0x1e867(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0xf4(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x128(%rsp)
movslq 0xf0(%rsp), %rcx
leaq 0x1e831(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movl 0xf4(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x110(%rsp)
movslq 0xf0(%rsp), %rcx
leaq 0x1e7f7(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movl 0xf4(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x118(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x120(%rsp), %rsi
leaq 0x110(%rsp), %rdx
leaq 0x160(%rsp), %rcx
movq %rcx, 0x8(%rsp)
leaq 0x150(%rsp), %r8
leaq 0x170(%rsp), %r9
callq 0x25d40
movq 0x8(%rsp), %rsi
movq 0x180(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x29dd0
jmp 0x2cc98
movq 0x68(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x160(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0x2a8b0
jmp 0x2ccb9
leaq 0x50(%rsp), %rdi
leaq 0x160(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0x2b9f0
jmp 0x2ccd5
movq $0x0, 0x40(%rsp)
movsd 0x30(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
leaq 0xd0(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x130(%rsp), %rdx
leaq 0x170(%rsp), %rcx
leaq 0x90(%rsp), %r8
callq 0x26d30
jmp 0x2cd19
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x23570
jmp 0x2cd2d
movsd 0x70(%rsp), %xmm0
movq 0x180(%rsp), %rax
movsd %xmm0, 0x30(%rax)
movsd 0x78(%rsp), %xmm0
movq 0x180(%rsp), %rax
movsd %xmm0, 0x60(%rax)
movsd 0x80(%rsp), %xmm0
movq 0x180(%rsp), %rax
movsd %xmm0, 0x90(%rax)
movsd 0x88(%rsp), %xmm0
movq 0x180(%rsp), %rax
movsd %xmm0, 0xc0(%rax)
movl $0x0, 0x20(%rsp)
cmpl $0x4, 0x20(%rsp)
jge 0x2cde4
movl $0x1, 0x1c(%rsp)
cmpl $0x6, 0x1c(%rsp)
jge 0x2cdd5
movq 0x180(%rsp), %rax
addq $0x30, %rax
movslq 0x20(%rsp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movslq 0x1c(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x2cd9c
jmp 0x2cdd7
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x2cd8d
leaq 0x50(%rsp), %rdi
callq 0x62b0
addq $0x188, %rsp            # imm = 0x188
retq
movq 0x28(%rsp), %rdi
callq 0x3440