// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x1f18f(%rip), %r15     # 0x232e0
movl $0x360, %r14d           # imm = 0x360
addq (%r15), %r14
pushq $0x1
popq %rbx
pushq $0x1
popq %rax
pushq $0x4b
popq %r13
cmpq $0x42, %rax
je 0x426a
movq %rax, 0x8(%rsp)
decq %rax
imulq $0x7b, %rax, %r12
cvtsi2sd %eax, %xmm0
mulsd 0x16e82(%rip), %xmm0    # 0x1b008
addsd 0x16e82(%rip), %xmm0    # 0x1b010
addsd 0x16e82(%rip), %xmm0    # 0x1b018
movsd %xmm0, 0x10(%rsp)
pushq $0x1
popq %rbp
cmpq $0x7c, %rbp
je 0x425d
leal -0x1(%rbp), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x16e68(%rip), %xmm0    # 0x1b020
addsd 0x16e68(%rip), %xmm0    # 0x1b028
addsd 0x16e68(%rip), %xmm0    # 0x1b030
movq (%r15), %rax
leaq (%r12,%rbp), %rcx
imulq $0x360, %rcx, %rcx      # imm = 0x360
movsd %xmm0, 0x278(%rax,%rcx)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x280(%rax,%rcx)
movapd 0x16e4a(%rip), %xmm0    # 0x1b040
movupd %xmm0, 0x288(%rax,%rcx)
movq %r14, %rdi
callq 0x43ce
andw $0x0, 0x1b0(%r14)
andw $0x0, 0x1f8(%r14)
andw $0x0, 0x1fc(%r14)
movb $0x0, 0x1fe(%r14)
movl %ebx, 0x200(%r14)
andq $0x0, 0x250(%r14)
movq %r13, %rax
cmpq $0x4f, %rax
je 0x424c
andq $0x0, (%r14,%rax,8)
incq %rax
jmp 0x423c
addq $0x360, %r14            # imm = 0x360
incl %ebx
incq %rbp
jmp 0x419f
movq 0x8(%rsp), %rax
incq %rax
jmp 0x4164
movq 0x1ed4f(%rip), %rdi     # 0x22fc0
leaq 0x16df8(%rip), %rsi     # 0x1b070
callq 0x31d0
decl %ebx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3140
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30d0