// File: /workspace/github_cpp_makefile_star2_O3/jamesliu516[P]amrdg2d/main.cpp
// Function: main
int main()
{
    clock_t start, finish; 
    double duration; 

    bool is_stop=false; 
    bool b_in_set=false;

    int nstp=0;
    int lscc=0; 
    int c_amr=1;
    string str123("_");
    double tpr0,tpr1;
    bool btpr0=true, btpr1=true;
    bool bl00=false,bl11=false;
    tpr0=0.08;
    tpr1=0.125;

    if(!(nDOF==3||nDOF==6)) {
        cout<<"We only consider p1 or p2 polynomial.\nSo nDOF=3 or nDOF=6.\nOthers are wrong.\n";
        cout<<"You input nDOF="<<nDOF<<".\n";
        cout<<"The code stop here."<<endl;
        return 0;
    }
    // cout<<"please input a string to add the file name: ";
    // cin>>str123;

    out_para(str123);
    bodygrid=new OctCell[Nx*Ny+1];

    background_grid();

    pointsAtSolid(); 
    shapeTransfer();
    creatgrid(); 

    refineCicleDemain(localRefine); // 1,2,3,4,5�μ���  

    formListForAllGrid();  

    setFlagForAll();
    formListFaceCellAll();   
#if IS_TUBE==1
    set_exFlag4All(NPT_EXT_WALL, ext_wall);
    formExtWallInOutBndry();
#endif
    //  start = clock(); 
    face_vec();
    //   finish = clock();   
    //   duration = static_cast<double>(finish - start) / CLOCKS_PER_SEC;   
    //   cout<<duration<<" seconds-faces."<<endl; 

    initialDataGrid();
//    read4restart();
    initiallevel();
    //  start = clock();     
    point_vec();     
    outputcell_new(0);//output mesh
//    int j8;
  //  cin >>j8;
    //    finish = clock();  
    //   duration = static_cast<double>(finish - start) / CLOCKS_PER_SEC;   
    //   cout<<duration<<" seconds-output mesh modify.\n"<<endl;     

    //   start = clock();         
    //    outputcell(10);
    //    finish = clock();  
    //   duration = static_cast<double>(finish - start) / CLOCKS_PER_SEC;   
    //   cout<<duration<<" seconds-output mesh."<<endl;   
    
#if HAVE_MV!=0
    for(int wy=0; wy<N_BODY;++wy){
        for(int i_t=0;i_t<MVptNum[wy];++i_t){  
            MBsharp_point[wy][i_t]
                =MultiCircle[wy][n_sharp_point[wy][i_t]];

            find_multivalue_cell(MBsharp_point[wy][i_t]);
        }
    }
#endif
          
    computeNormalArea();
    form_inter_cell_set();
    wherePointAll();
    outputcell_sol(0,str123);
    // outputcell_new(0);
    for(int n=0; ; n++) {
#ifndef FIXED_DT
        timestep();
#else
        dt=fixed_dt;
#endif

#ifndef LOCAL_TIME         
        if(timesum+dt > t_print){
            dt=t_print-timesum;
            is_stop=true;
        }

        if(btpr0 && timesum+dt>tpr0){
            dt=tpr0-timesum;
            btpr0=false;
            bl00=true;
            CFL=0.034;
        }

        if(btpr1 && timesum+dt>tpr1){
            dt=tpr1-timesum;
            btpr1=false;
            bl11=true;
        }
#endif    
        //--------------------------------------------------------------
        runge_kutta(n);  
        if(n%20==0){
            cout<<"n: "<<n<<", dt="<<dt<<", time="<<timesum<<
                "  ";
            cal_te_res();
        }
        //---------------------------------------------------------------
#ifndef LOCAL_TIME       
        timesum+=dt;
        if( bl00 ) {			
            if(b_in_set){
                form_inter_cell_set();
                wherePointAll();
                b_in_set=false;
            }
            outputcell_sol(-time(NULL),"_t0p11");
            bl00=false;
        }

        if( bl11 ) {			
            if(b_in_set){
                form_inter_cell_set();
                wherePointAll();
                b_in_set=false;
            }
            outputcell_sol(-time(NULL),"_t0p2");
            bl11=false;
        }

        if(timesum>0.15)value_kxrcf_amr=1.0;
#endif
        if( (n%201 == 0&&n>=4000 )||(n<4000 && n%201==0&&n>0) ) {
//        if( (n%301 == 0 && n>0 ) ) {			
            lscc++;
            if(b_in_set){
                form_inter_cell_set();
                wherePointAll();
                b_in_set=false;
            }
            outputcell_sol(lscc,str123);
        }


     //   if(n==12000) output4restart();
        if(n%200==0 && n>=100 && SwAMR==true){
         //   if(n%1000==0 && n>=800 && SwAMR==true&& c_amr<=6){
    //    if(((n%200==0 && n>300 && n<2000)||(n%300==0&&n>2100) )
      //  if(((n%300==0&&n>200) )
        //    && SwAMR==true){
            SolutionAMR(c_amr);
            b_in_set=true;
            ++c_amr;
        }

        if(n>=max_time_steps&&n%500==0){
            cout<<"input an integer: 0 stop, !=0 continue to compute"<<endl;
            cin>>nstp;
            if(nstp==0) 
                is_stop=true;
        }

        if(is_stop) {
#ifndef LOCAL_TIME          
            cout<<"End time: "<<t_print<<endl;
#endif          
            if(b_in_set){
                form_inter_cell_set();
                wherePointAll();
                b_in_set=false;
            }
            outputcell_sol(-time(NULL));
            break;
        }
    }


    releaseList(); 
    releaseFaceCellList();
    delete [] bodygrid;     
    return 0;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl $0x0, 0x3c(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xfffc(%rip), %rsi      # 0x1d256
leaq 0xfff6(%rip), %rdx      # 0x1d257
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x8b9a
movq %rbx, %rdi
callq 0x19af8
movl $0x696a80, %edi         # imm = 0x696A80
callq 0x3030
movq %rax, %r14
xorl %ebx, %ebx
leaq (%r14,%rbx), %rdi
callq 0x463a
addq $0x360, %rbx            # imm = 0x360
cmpq $0x696a80, %rbx         # imm = 0x696A80
jne 0xd285
leaq 0x1703b(%rip), %rax     # 0x242e0
movq %r14, (%rax)
callq 0x42fc
callq 0xa3e0
callq 0xa681
callq 0xc7e9
xorl %edi, %edi
callq 0xc9e0
callq 0xbae8
callq 0x4e90
callq 0xbf33
leaq 0x1afa7(%rip), %rsi     # 0x28280
movl $0x138, %edi            # imm = 0x138
callq 0x5014
callq 0xbc9f
callq 0x8e6a
callq 0x17c88
callq 0xbf7a
callq 0x56ac
xorl %edi, %edi
callq 0x78b2
leaq 0x1c446(%rip), %rbx     # 0x29750
xorl %r14d, %r14d
leaq 0x103cc(%rip), %r15     # 0x1d6e0
leaq 0x17065(%rip), %r12     # 0x24380
movslq (%r14,%r15), %rax
shlq $0x4, %rax
movupd (%r12,%rax), %xmm0
movupd %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x1c54d
addq $0x10, %rbx
addq $0x4, %r14
cmpq $0xc, %r14
jne 0xd31b
callq 0x14664
callq 0x14434
callq 0x145db
xorl %ebx, %ebx
leaq 0x48(%rsp), %rsi
xorl %edi, %edi
callq 0x7c9d
movb $0x1, %al
movl %eax, 0x14(%rsp)
movl $0x1, 0x38(%rsp)
movl $0x0, 0xc(%rsp)
movb $0x1, %al
movl %eax, 0x10(%rsp)
xorl %r13d, %r13d
callq 0x17627
leaq 0x1c38d(%rip), %rax     # 0x29718
movsd (%rax), %xmm0
leaq 0x1c37a(%rip), %rax     # 0x29710
movsd (%rax), %xmm1
movapd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x40(%rsp)
ucomisd 0x102a8(%rip), %xmm2    # 0x1d658
jbe 0xd3c9
movsd 0x1029e(%rip), %xmm1    # 0x1d658
subsd %xmm0, %xmm1
leaq 0x1c34b(%rip), %rax     # 0x29710
movsd %xmm1, (%rax)
testb $0x1, 0x14(%rsp)
je 0xd41a
movapd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd 0x10280(%rip), %xmm3    # 0x1d660
ucomisd %xmm3, %xmm2
jbe 0xd424
movapd %xmm3, %xmm1
subsd %xmm0, %xmm1
leaq 0x1c31b(%rip), %rax     # 0x29710
movsd %xmm1, (%rax)
leaq 0x16e20(%rip), %rax     # 0x24220
movabsq $0x3fa16872b020c49c, %rcx # imm = 0x3FA16872B020C49C
movq %rcx, (%rax)
movb $0x1, %bpl
movl $0x0, 0x14(%rsp)
jmp 0xd42c
movl $0x0, 0x14(%rsp)
jmp 0xd42a
movb $0x1, %al
movl %eax, 0x14(%rsp)
xorl %ebp, %ebp
testb $0x1, 0x10(%rsp)
je 0xd465
addsd %xmm0, %xmm1
movsd 0x10229(%rip), %xmm2    # 0x1d668
ucomisd %xmm2, %xmm1
jbe 0xd46f
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
leaq 0x1c2bc(%rip), %rax     # 0x29710
movsd %xmm1, (%rax)
movb $0x1, %r15b
movl $0x0, 0x10(%rsp)
jmp 0xd478
movl $0x0, 0x10(%rsp)
jmp 0xd475
movb $0x1, %al
movl %eax, 0x10(%rsp)
xorl %r15d, %r15d
movl %r13d, %edi
callq 0x14fb3
movl %r13d, %r14d
movq %r14, %rax
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
imulq %rcx, %rax
shrq $0x24, %rax
shll $0x2, %eax
leal (%rax,%rax,4), %eax
cmpl %r13d, %eax
jne 0xd536
movl $0x3, %edx
movq 0x16b1a(%rip), %rdi     # 0x23fc8
leaq 0x101c3(%rip), %rsi     # 0x1d678
callq 0x3250
movq 0x16b07(%rip), %rdi     # 0x23fc8
movl %r13d, %esi
callq 0x3350
movq %rax, %r12
movl $0x5, %edx
movq %rax, %rdi
leaq 0x101a1(%rip), %rsi     # 0x1d67c
callq 0x3250
leaq 0x1c229(%rip), %rax     # 0x29710
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x3300
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x1017d(%rip), %rsi     # 0x1d682
callq 0x3250
leaq 0x1c207(%rip), %rax     # 0x29718
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x3300
movl $0x2, %edx
movq %rax, %rdi
leaq 0x108d1(%rip), %rsi     # 0x1ddfd
callq 0x3250
callq 0x1c6a8
leaq 0x1c1d3(%rip), %rax     # 0x29710
movsd (%rax), %xmm0
leaq 0x1c1d0(%rip), %rax     # 0x29718
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
testb %bpl, %bpl
je 0xd5c7
testb $0x1, 0xc(%rsp)
je 0xd56e
callq 0x14434
callq 0x145db
movl $0x0, 0xc(%rsp)
xorl %edi, %edi
callq 0x31f0
movq %rax, %r12
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x18(%rsp), %rbp
movq %rbp, %rdi
leaq 0x100f9(%rip), %rsi     # 0x1d68a
leaq 0x100f8(%rip), %rdx     # 0x1d690
callq 0x8b9a
negl %r12d
movl %r12d, %edi
movq %rbp, %rsi
callq 0x7c9d
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xd5c7
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3220
testb %r15b, %r15b
je 0xd63e
testb $0x1, 0xc(%rsp)
je 0xd5e5
callq 0x14434
callq 0x145db
movl $0x0, 0xc(%rsp)
xorl %edi, %edi
callq 0x31f0
movq %rax, %r12
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x18(%rsp), %r15
movq %r15, %rdi
leaq 0x10089(%rip), %rsi     # 0x1d691
leaq 0x10087(%rip), %rdx     # 0x1d696
callq 0x8b9a
negl %r12d
movl %r12d, %edi
movq %r15, %rsi
callq 0x7c9d
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xd63e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3220
leaq 0x1c0d3(%rip), %rax     # 0x29718
movsd (%rax), %xmm0
ucomisd 0x1001f(%rip), %xmm0    # 0x1d670
jbe 0xd667
leaq 0x16bb6(%rip), %rax     # 0x24210
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax)
imulq $0x28c1979, %r14, %rax  # imm = 0x28C1979
shrq $0x21, %rax
imull $0xc9, %eax, %eax
cmpl %r13d, %eax
sete %cl
cmpl $0xfa0, %r13d           # imm = 0xFA0
setae %dl
testb %cl, %dl
jne 0xd6a3
cmpl %r13d, %eax
setne %al
leal -0x1(%r13), %ecx
cmpl $0xf9f, %ecx            # imm = 0xF9F
setae %cl
orb %al, %cl
jne 0xd6ca
testb $0x1, 0xc(%rsp)
je 0xd6bc
callq 0x14434
callq 0x145db
movl $0x0, 0xc(%rsp)
incl %ebx
movl %ebx, %edi
leaq 0x48(%rsp), %rsi
callq 0x7c9d
cmpl $0x64, %r13d
jb 0xd6f9
imulq $0x51eb851f, %r14, %rax # imm = 0x51EB851F
shrq $0x26, %rax
imull $0xc8, %eax, %eax
cmpl %r13d, %eax
jne 0xd6f9
movl 0x38(%rsp), %edi
callq 0x1c412
incl 0x38(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
cmpl $0x13880, %r13d         # imm = 0x13880
jb 0xd77a
imulq $0x10624dd3, %r14, %rax # imm = 0x10624DD3
shrq $0x25, %rax
imull $0x1f4, %eax, %eax      # imm = 0x1F4
cmpl %r13d, %eax
jne 0xd77a
movl $0x31, %edx
movq 0x168a4(%rip), %rdi     # 0x23fc8
leaq 0xff6c(%rip), %rsi      # 0x1d697
callq 0x3250
movq 0x16891(%rip), %rcx     # 0x23fc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq 0x16873(%rip), %rdi     # 0x23fc8
callq 0x3040
movq %rax, %rdi
callq 0x3170
movq 0x16877(%rip), %rdi     # 0x23fe0
leaq 0x3c(%rsp), %rsi
callq 0x3130
cmpl $0x0, 0x3c(%rsp)
je 0xd792
movsd 0x40(%rsp), %xmm0
ucomisd 0xfed0(%rip), %xmm0     # 0x1d658
ja 0xd792
incl %r13d
jmp 0xd37f
movq 0x1682f(%rip), %rdi     # 0x23fc8
leaq 0xff29(%rip), %rsi      # 0x1d6c9
movl $0xa, %edx
callq 0x3250
movq 0x16817(%rip), %rdi     # 0x23fc8
movsd 0xfe9f(%rip), %xmm0     # 0x1d658
callq 0x3300
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
testb $0x1, 0xc(%rsp)
je 0xd7f9
callq 0x14434
callq 0x145db
xorl %edi, %edi
callq 0x31f0
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
movq %rax, (%rdi)
leaq 0xfebd(%rip), %rsi      # 0x1d6d4
leaq 0xfeb9(%rip), %rdx      # 0x1d6d7
callq 0x8b9a
leaq 0x16ab6(%rip), %r14     # 0x242e0
negl %ebx
leaq 0x18(%rsp), %rsi
movl %ebx, %edi
callq 0x7c9d
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xd854
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3220
callq 0xbfa2
callq 0xbff7
movq (%r14), %rdi
testq %rdi, %rdi
je 0xd86b
callq 0x3280
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xd887
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3220
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd8a0
jmp 0xd8db
jmp 0xd8db
jmp 0xd8a0
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xd8de
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3220
jmp 0xd8de
jmp 0xd8db
jmp 0xd8db
jmp 0xd8db
jmp 0xd8db
movq %rax, %rbx
movl $0x696a80, %esi         # imm = 0x696A80
movq %r14, %rdi
callq 0x33a0
jmp 0xd8de
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xd8fa
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3220
movq %rbx, %rdi
callq 0x3370
nop