// File: /workspace/github_cpp_makefile_star2_O2/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
andl $0x0, 0x14(%rsp)
leaq 0xeeb0(%rip), %rsi      # 0x1b2d6
leaq 0x48(%rsp), %rbx
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x4b4e
movq %rbx, %rdi
callq 0x17c7c
movl $0x696a80, %edi         # imm = 0x696A80
callq 0x3030
movq %rax, %r14
xorl %ebx, %ebx
leaq (%r14,%rbx), %rdi
callq 0x442e
addq $0x360, %rbx            # imm = 0x360
cmpq $0x696a80, %rbx         # imm = 0x696A80
jne 0xc44f
leaq 0x16e71(%rip), %rax     # 0x232e0
movq %r14, (%rax)
callq 0x413c
callq 0x9a40
callq 0x9bf9
callq 0xb99d
xorl %edi, %edi
callq 0xbbb6
callq 0xad30
callq 0x4e00
callq 0xb129
leaq 0x1addd(%rip), %rsi     # 0x27280
movl $0x138, %edi            # imm = 0x138
callq 0x4f80
callq 0xaed8
callq 0x86c2
callq 0x160ae
callq 0xb171
callq 0x55dc
xorl %edi, %edi
callq 0x766c
leaq 0x1c27c(%rip), %rbx     # 0x28750
xorl %r14d, %r14d
leaq 0xf222(%rip), %r15      # 0x1b700
leaq 0x16e9b(%rip), %r12     # 0x23380
cmpq $0xc, %r14
je 0xc50f
movslq (%r14,%r15), %rax
shlq $0x4, %rax
movupd (%r12,%rax), %xmm0
movupd %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x1a0f1
addq $0x4, %r14
addq $0x10, %rbx
jmp 0xc4e5
callq 0x12c77
callq 0x12a8d
callq 0x12c14
xorl %ebx, %ebx
leaq 0x48(%rsp), %rsi
xorl %edi, %edi
callq 0x792e
movb $0x1, %al
movl %eax, 0xc(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
movb $0x1, %al
movl %eax, 0x8(%rsp)
xorl %r12d, %r12d
movl %r12d, %eax
xorl %edx, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
divl %ecx
movl %eax, 0x18(%rsp)
movl %r12d, %eax
xorl %edx, %edx
movl $0xc8, %ecx
divl %ecx
movl %eax, 0x1c(%rsp)
movl %r12d, %eax
xorl %edx, %edx
movl $0xc9, %ecx
divl %ecx
movl %eax, %ebp
movl %r12d, %eax
xorl %edx, %edx
pushq $0x14
popq %rcx
divl %ecx
movl %eax, %r13d
callq 0x15aa3
leaq 0x1c187(%rip), %rax     # 0x28718
movsd (%rax), %xmm0
leaq 0x1c174(%rip), %rax     # 0x28710
movsd (%rax), %xmm1
movapd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x20(%rsp)
ucomisd 0xf0c2(%rip), %xmm2     # 0x1b678
jbe 0xc5cf
movsd 0xf0b8(%rip), %xmm1     # 0x1b678
subsd %xmm0, %xmm1
leaq 0x1c145(%rip), %rax     # 0x28710
movsd %xmm1, (%rax)
testb $0x1, 0xc(%rsp)
je 0xc620
movapd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd 0xf09a(%rip), %xmm3     # 0x1b680
ucomisd %xmm3, %xmm2
jbe 0xc62a
movapd %xmm3, %xmm1
subsd %xmm0, %xmm1
leaq 0x1c115(%rip), %rax     # 0x28710
movsd %xmm1, (%rax)
leaq 0x16c1a(%rip), %rax     # 0x23220
movabsq $0x3fa16872b020c49c, %rcx # imm = 0x3FA16872B020C49C
movq %rcx, (%rax)
movb $0x1, %r15b
movl $0x0, 0xc(%rsp)
jmp 0xc633
movl $0x0, 0xc(%rsp)
jmp 0xc630
movb $0x1, %al
movl %eax, 0xc(%rsp)
xorl %r15d, %r15d
testb $0x1, 0x8(%rsp)
je 0xc66c
addsd %xmm0, %xmm1
movsd 0xf042(%rip), %xmm2     # 0x1b688
ucomisd %xmm2, %xmm1
jbe 0xc676
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
leaq 0x1c0b5(%rip), %rax     # 0x28710
movsd %xmm1, (%rax)
movb $0x1, %r14b
movl $0x0, 0x8(%rsp)
jmp 0xc67f
movl $0x0, 0x8(%rsp)
jmp 0xc67c
movb $0x1, %al
movl %eax, 0x8(%rsp)
xorl %r14d, %r14d
movl %r12d, %edi
callq 0x13530
imull $0x14, %r13d, %eax
cmpl %r12d, %eax
jne 0xc706
movq 0x16929(%rip), %rdi     # 0x22fc0
leaq 0xeffa(%rip), %rsi      # 0x1b698
callq 0x31d0
movq %rax, %rdi
movl %r12d, %esi
callq 0x3330
movq %rax, %rdi
leaq 0xefe4(%rip), %rsi      # 0x1b69c
callq 0x31d0
leaq 0x1c04c(%rip), %rcx     # 0x28710
movsd (%rcx), %xmm0
movq %rax, %rdi
callq 0x32e0
movq %rax, %rdi
leaq 0xefc8(%rip), %rsi      # 0x1b6a2
callq 0x31d0
leaq 0x1c032(%rip), %rcx     # 0x28718
movsd (%rcx), %xmm0
movq %rax, %rdi
callq 0x32e0
movq %rax, %rdi
leaq 0xf681(%rip), %rsi      # 0x1bd7d
callq 0x31d0
callq 0x1a250
leaq 0x1c003(%rip), %rax     # 0x28710
movsd (%rax), %xmm0
leaq 0x1c000(%rip), %rax     # 0x28718
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
testb %r15b, %r15b
je 0xc777
testb $0x1, 0x4(%rsp)
je 0xc73e
callq 0x12a8d
callq 0x12c14
movl $0x0, 0x4(%rsp)
xorl %edi, %edi
callq 0x31c0
movq %rax, %r13
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0xef53(%rip), %rsi      # 0x1b6aa
leaq 0x3(%rsp), %rdx
callq 0x4b4e
negl %r13d
movl %r13d, %edi
movq %r15, %rsi
callq 0x792e
movq %r15, %rdi
callq 0x33b8
testb %r14b, %r14b
je 0xc7ce
testb $0x1, 0x4(%rsp)
je 0xc795
callq 0x12a8d
callq 0x12c14
movl $0x0, 0x4(%rsp)
xorl %edi, %edi
callq 0x31c0
movq %rax, %r13
leaq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0xef03(%rip), %rsi      # 0x1b6b1
leaq 0x3(%rsp), %rdx
callq 0x4b4e
negl %r13d
movl %r13d, %edi
movq %r14, %rsi
callq 0x792e
movq %r14, %rdi
callq 0x33b8
leaq 0x1bf43(%rip), %rax     # 0x28718
movsd (%rax), %xmm0
ucomisd 0xeeaf(%rip), %xmm0     # 0x1b690
jbe 0xc7f7
leaq 0x16a26(%rip), %rax     # 0x23210
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax)
imull $0xc9, %ebp, %eax
cmpl %r12d, %eax
sete %cl
cmpl $0xfa0, %r12d           # imm = 0xFA0
setae %dl
testb %cl, %dl
jne 0xc829
cmpl %r12d, %eax
setne %al
leal -0x1(%r12), %ecx
cmpl $0xf9f, %ecx            # imm = 0xF9F
setae %cl
orb %al, %cl
jne 0xc850
testb $0x1, 0x4(%rsp)
je 0xc842
callq 0x12a8d
callq 0x12c14
movl $0x0, 0x4(%rsp)
incl %ebx
movl %ebx, %edi
leaq 0x48(%rsp), %rsi
callq 0x792e
cmpl $0x64, %r12d
jb 0xc876
imull $0xc8, 0x1c(%rsp), %eax
cmpl %r12d, %eax
jne 0xc876
movl 0x10(%rsp), %edi
callq 0x19fc0
incl 0x10(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
cmpl $0x13880, %r12d         # imm = 0x13880
jb 0xc8bf
imull $0x1f4, 0x18(%rsp), %eax # imm = 0x1F4
cmpl %r12d, %eax
jne 0xc8bf
movq 0x1672d(%rip), %rdi     # 0x22fc0
leaq 0xee1d(%rip), %rsi      # 0x1b6b7
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
movq 0x16732(%rip), %rdi     # 0x22fe0
leaq 0x14(%rsp), %rsi
callq 0x3110
cmpl $0x0, 0x14(%rsp)
je 0xc8d7
movsd 0x20(%rsp), %xmm0
ucomisd 0xedab(%rip), %xmm0     # 0x1b678
ja 0xc8d7
incl %r12d
jmp 0xc54a
movq 0x166e2(%rip), %rdi     # 0x22fc0
leaq 0xee04(%rip), %rsi      # 0x1b6e9
callq 0x31d0
leaq 0x169ef(%rip), %r14     # 0x232e0
movsd 0xed7f(%rip), %xmm0     # 0x1b678
movq %rax, %rdi
callq 0x32e0
movq %rax, %rdi
callq 0x30d0
testb $0x1, 0x4(%rsp)
je 0xc91a
callq 0x12a8d
callq 0x12c14
xorl %edi, %edi
callq 0x31c0
movq %rax, %rbx
leaq 0xedc9(%rip), %rsi      # 0x1b6f4
leaq 0x28(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0x4b4e
negl %ebx
leaq 0x28(%rsp), %rsi
movl %ebx, %edi
callq 0x792e
leaq 0x28(%rsp), %rdi
callq 0x33b8
callq 0xb199
callq 0xb1e6
movq (%r14), %rdi
testq %rdi, %rdi
je 0xc969
callq 0x3250
leaq 0x48(%rsp), %rdi
callq 0x33b8
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc98c
jmp 0xc9b5
jmp 0xc9b5
jmp 0xc98c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x33b8
jmp 0xc9b8
jmp 0xc9b5
jmp 0xc9b5
jmp 0xc9b5
jmp 0xc9b5
movq %rax, %rbx
movl $0x696a80, %esi         # imm = 0x696A80
movq %r14, %rdi
callq 0x3390
jmp 0xc9b8
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x33b8
movq %rbx, %rdi
callq 0x3350
nop