// File: jamesliu516[P]amrdg2d/solveAMR.cpp
// Function: creat_amr_grid()
void creat_amr_grid()
{   
    int kr,Nk;
    int i,j,k,ir;
    OctCell *parent;

    // Nk=Namr-1;//需要加密的网格
    Nk=solrefcell.size()-1;
    //printf("refine solution grid number: Nk=%d\n",Nk);		   

    OctCell *pp[9]={NULL},*pc[9]={NULL},*p=NULL;
    //物面相交的网格邻近的需要加密的网格单元地址 
#if NAR_MAXAMR==1
    for(ir=0;ir<=Nr+Nar;ir++)
#elif NAR_MAXAMR==0
    for(ir=0;ir<MaxAMR;ir++)
#endif
    { 
        for(kr=0;kr<=Nk;kr++)//Nk与解自适应网格数	 		   
        {			   
            parent = solrefcell[kr];			  	 
          //  if(parent==NULL){cout<<"parent NULL\n";}
            if(parent->level==ir)
            {		   		   
                //找到需加密的网格邻近的需要加密的网格单元		  
                find_sol_refp(pp,parent);
               // find_sol_4nbr(pp,parent);
                pp[8]=parent;	 
                k=0;	   
                for(i=0;i<9;i++)		
                {
                    if(pp[i]!=NULL)//here do not need if TODO 
                    {pc[k]=pp[i];k++;}	  
                }
                //根据网格单元的层次对这些网格进行排序  	 
                for(j=1;j<=k-1;j++)	 
                {		  
                    for(i=1;i<=k-j;i++)				 
                        if(pc[i-1]->level>pc[i]->level)			   
                        {p=pc[i-1];pc[i-1]=pc[i];pc[i]=p;}
                }
                for(i=0;i<k;i++)
                {
                    if(pc[i]!=NULL&&pc[i]->reflag == 0)
                    {		 			  				 
                        //creat_sol_children(pc[i],pc[i]->cflag); 
                        creat_sol_children(pc[i]); 
                        //					   pc[i]->reflag=1;			  			  			   			
                    }	  		 		   	 
                }	
            }
        }
    }
    cout<<"refine solution grid number: Nk= "<<Nk<<endl;		   
}

// Assembly:
subq $0xc8, %rsp
leaq 0xf382(%rip), %rdi      # 0x4b3e0
callq 0x1bd50
subq $0x1, %rax
movl %eax, 0xc0(%rsp)
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x3150
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x3150
movq $0x0, 0x8(%rsp)
movl $0x0, 0xb0(%rsp)
cmpl $0x4, 0xb0(%rsp)
jge 0x3c32d
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
cmpl 0xc0(%rsp), %eax
jg 0x3c315
movslq 0xc4(%rsp), %rsi
leaq 0xf300(%rip), %rdi      # 0x4b3e0
callq 0x1e180
movq (%rax), %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
movswl 0x1f8(%rax), %eax
cmpl 0xb0(%rsp), %eax
jne 0x3c2fd
leaq 0x60(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0x3b130
movq 0xa8(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl $0x0, 0xb4(%rsp)
movl $0x0, 0xbc(%rsp)
cmpl $0x9, 0xbc(%rsp)
jge 0x3c19e
movslq 0xbc(%rsp), %rax
cmpq $0x0, 0x60(%rsp,%rax,8)
je 0x3c189
movslq 0xbc(%rsp), %rax
movq 0x60(%rsp,%rax,8), %rcx
movslq 0xb4(%rsp), %rax
movq %rcx, 0x10(%rsp,%rax,8)
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x3c18b
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x3c144
movl $0x1, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
movl 0xb4(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x3c290
movl $0x1, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
movl 0xb4(%rsp), %ecx
subl 0xb8(%rsp), %ecx
cmpl %ecx, %eax
jg 0x3c278
movl 0xbc(%rsp), %eax
subl $0x1, %eax
cltq
movq 0x10(%rsp,%rax,8), %rax
movswl 0x1f8(%rax), %eax
movslq 0xbc(%rsp), %rcx
movq 0x10(%rsp,%rcx,8), %rcx
movswl 0x1f8(%rcx), %ecx
cmpl %ecx, %eax
jle 0x3c260
movl 0xbc(%rsp), %eax
subl $0x1, %eax
cltq
movq 0x10(%rsp,%rax,8), %rax
movq %rax, 0x8(%rsp)
movslq 0xbc(%rsp), %rax
movq 0x10(%rsp,%rax,8), %rcx
movl 0xbc(%rsp), %eax
subl $0x1, %eax
cltq
movq %rcx, 0x10(%rsp,%rax,8)
movq 0x8(%rsp), %rcx
movslq 0xbc(%rsp), %rax
movq %rcx, 0x10(%rsp,%rax,8)
jmp 0x3c262
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x3c1cd
jmp 0x3c27a
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x3c1a9
movl $0x0, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jge 0x3c2fb
movslq 0xbc(%rsp), %rax
cmpq $0x0, 0x10(%rsp,%rax,8)
je 0x3c2e6
movslq 0xbc(%rsp), %rax
movq 0x10(%rsp,%rax,8), %rax
movswl 0x1fc(%rax), %eax
cmpl $0x0, %eax
jne 0x3c2e6
movslq 0xbc(%rsp), %rax
movq 0x10(%rsp,%rax,8), %rdi
callq 0x3b340
jmp 0x3c2e8
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x3c29b
jmp 0x3c2fd
jmp 0x3c2ff
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x3c0bd
jmp 0x3c317
movl 0xb0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb0(%rsp)
jmp 0x3c0a4
movq 0xec9c(%rip), %rdi      # 0x4afd0
leaq 0x38a5(%rip), %rsi      # 0x3fbe0
callq 0x3240
movq %rax, %rdi
movl 0xc0(%rsp), %esi
callq 0x3420
movq %rax, %rdi
movq 0xec5f(%rip), %rsi      # 0x4afb8
callq 0x3290
addq $0xc8, %rsp
retq
nopw %cs:(%rax,%rax)