// File: jamesliu516[P]amrdg2d/background_grid.cpp
// Function: background_grid()
void background_grid()
{
    int j,k, m;
    unsigned NO;

    double xMin, yMin;

    OctCell *pc;
    pc=bodygrid+1;
    NO=1u;
#ifndef EQUAL_SPACE_STEP
    bgrid = new GRIDCELL [Ny][Nx];
    gpoint = new PXYZ [NPOINT+1];
    gcell = new GRIDCELL [NCELL+1];	
    load_grid();
#endif        
    xMin=xLeft-2.0*hx;  //�Ⱦ�����
    yMin=yLow- 2.0*hy;

    for(j=1;j<=Ny;j++) {
        for(k=1;k<=Nx;k++) {	
            //	�Ⱦ�����
#ifdef  EQUAL_SPACE_STEP            				       		       
            bodygrid[(j-1)*Nx +k].xc1=hx/2.0+(k-1)*hx+xMin;
            bodygrid[(j-1)*Nx +k].yc1=hy/2.0+(j-1)*hy+yMin;	
            bodygrid[(j-1)*Nx +k].dx=hx;
            bodygrid[(j-1)*Nx +k].dy=hy;

            //------------------------------------------------------------------				
            //bodygrid[(j-1)*Nx +k]
#else 
            bodygrid[(j-1)*Nx +k].xc1 = 0.5*(gpoint[bgrid[j-1][k-1].pn[0]].x
                +gpoint[bgrid[j-1][k-1].pn[2]].x);
            bodygrid[(j-1)*Nx +k].yc1 = 0.5*(gpoint[bgrid[j-1][k-1].pn[0]].y
                +gpoint[bgrid[j-1][k-1].pn[2]].y);

            bodygrid[(j-1)*Nx +k].dx=gpoint[bgrid[j-1][k-1].pn[2]].x-gpoint[bgrid[j-1][k-1].pn[1]].x;
            bodygrid[(j-1)*Nx +k].dy=gpoint[bgrid[j-1][k-1].pn[0]].y-gpoint[bgrid[j-1][k-1].pn[1]].y; 
#endif				 
            //=================================================================				
            pc->set_invM();

            pc->flag=0;
            pc->level=0;
            pc->reflag=0;
            pc->coflag=0;
            pc->NOparent=NO;
            pc->parent=NULL;

            for(m=0;m<4;m++)  pc->children[m]=NULL;
            pc++;
            NO++;									  

            //	bodygrid[j][k].d = sqrt(bodygrid[j][k].xc1*bodygrid[j][k].xc1
            //		+bodygrid[j][k].yc1*bodygrid[j][k].yc1) - RADII;
        }			
    }
    cout<<"total background grid: "<< NO-1<<endl;	
#ifndef EQUAL_SPACE_STEP		
    delete [] gpoint;
    delete [] gcell;
    delete [] bgrid;
#endif
}

// Assembly:
subq $0x28, %rsp
leaq 0x46815(%rip), %rax     # 0x4b370
movq (%rax), %rax
addq $0x360, %rax            # imm = 0x360
movq %rax, (%rsp)
movl $0x1, 0x18(%rsp)
movsd 0x3a4a0(%rip), %xmm0    # 0x3f018
movsd %xmm0, 0x10(%rsp)
movsd 0x3a48a(%rip), %xmm0    # 0x3f010
movsd %xmm0, 0x8(%rsp)
movl $0x1, 0x24(%rsp)
cmpl $0x41, 0x24(%rsp)
jg 0x4d8c
movl $0x1, 0x20(%rsp)
cmpl $0x7b, 0x20(%rsp)
jg 0x4d7a
movl 0x20(%rsp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
movsd 0x3a463(%rip), %xmm1    # 0x3f028
mulsd %xmm1, %xmm0
movsd 0x3a467(%rip), %xmm1    # 0x3f038
addsd %xmm1, %xmm0
addsd 0x10(%rsp), %xmm0
leaq 0x4678e(%rip), %rax     # 0x4b370
movq (%rax), %rax
movl 0x24(%rsp), %ecx
subl $0x1, %ecx
imull $0x7b, %ecx, %ecx
addl 0x20(%rsp), %ecx
movslq %ecx, %rcx
imulq $0x360, %rcx, %rcx      # imm = 0x360
addq %rcx, %rax
movsd %xmm0, 0x278(%rax)
movl 0x24(%rsp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
movsd 0x3a405(%rip), %xmm1    # 0x3f020
mulsd %xmm1, %xmm0
movsd 0x3a409(%rip), %xmm1    # 0x3f030
addsd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm0
leaq 0x46738(%rip), %rax     # 0x4b370
movq (%rax), %rax
movl 0x24(%rsp), %ecx
subl $0x1, %ecx
imull $0x7b, %ecx, %ecx
addl 0x20(%rsp), %ecx
movslq %ecx, %rcx
imulq $0x360, %rcx, %rcx      # imm = 0x360
addq %rcx, %rax
movsd %xmm0, 0x280(%rax)
leaq 0x4670b(%rip), %rax     # 0x4b370
movq (%rax), %rax
movl 0x24(%rsp), %ecx
subl $0x1, %ecx
imull $0x7b, %ecx, %ecx
addl 0x20(%rsp), %ecx
movslq %ecx, %rcx
imulq $0x360, %rcx, %rcx      # imm = 0x360
addq %rcx, %rax
movsd 0x3a39d(%rip), %xmm0    # 0x3f028
movsd %xmm0, 0x288(%rax)
leaq 0x466d6(%rip), %rax     # 0x4b370
movq (%rax), %rax
movl 0x24(%rsp), %ecx
subl $0x1, %ecx
imull $0x7b, %ecx, %ecx
addl 0x20(%rsp), %ecx
movslq %ecx, %rcx
imulq $0x360, %rcx, %rcx      # imm = 0x360
addq %rcx, %rax
movsd 0x3a360(%rip), %xmm0    # 0x3f020
movsd %xmm0, 0x290(%rax)
movq (%rsp), %rdi
callq 0x5010
movq (%rsp), %rax
movw $0x0, 0x1b0(%rax)
movq (%rsp), %rax
movw $0x0, 0x1f8(%rax)
movq (%rsp), %rax
movw $0x0, 0x1fc(%rax)
movq (%rsp), %rax
movb $0x0, 0x1fe(%rax)
movl 0x18(%rsp), %ecx
movq (%rsp), %rax
movl %ecx, 0x200(%rax)
movq (%rsp), %rax
movq $0x0, 0x250(%rax)
movl $0x0, 0x1c(%rsp)
cmpl $0x4, 0x1c(%rsp)
jge 0x4d51
movq (%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq $0x0, 0x258(%rax,%rcx,8)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x4d28
movq (%rsp), %rax
addq $0x360, %rax            # imm = 0x360
movq %rax, (%rsp)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x4ba7
jmp 0x4d7c
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x4b94
movq 0x4623d(%rip), %rdi     # 0x4afd0
leaq 0x3a2c6(%rip), %rsi     # 0x3f060
callq 0x3240
movq %rax, %rdi
movl 0x18(%rsp), %esi
subl $0x1, %esi
callq 0x3350
movq %rax, %rdi
movq 0x46200(%rip), %rsi     # 0x4afb8
callq 0x3290
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)