// File: /workspace/github_cpp_makefile_star2_O1/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 0x10cd4(%rip), %rsi     # 0x1e276
leaq 0x10cce(%rip), %rdx     # 0x1e277
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x8ce8
movq %rbx, %rdi
callq 0x19ff8
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 0xd5cd
leaq 0x17cf3(%rip), %rax     # 0x252e0
movq %r14, (%rax)
callq 0x42fc
callq 0xa51c
callq 0xa7be
callq 0xc97a
xorl %edi, %edi
callq 0xcb71
callq 0xbc5c
callq 0x4f50
callq 0xc0ae
leaq 0x1bc5f(%rip), %rsi     # 0x29280
movl $0x138, %edi            # imm = 0x138
callq 0x50cd
callq 0xbe13
callq 0x8fad
callq 0x181a4
callq 0xc0f5
callq 0x57fc
xorl %edi, %edi
callq 0x79e8
leaq 0x1d0fe(%rip), %rbx     # 0x2a750
xorl %r14d, %r14d
leaq 0x110a4(%rip), %r15     # 0x1e700
leaq 0x17d1d(%rip), %r12     # 0x25380
movslq (%r14,%r15), %rax
shlq $0x4, %rax
movupd (%r12,%rax), %xmm0
movupd %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x1ca4f
addq $0x10, %rbx
addq $0x4, %r14
cmpq $0xc, %r14
jne 0xd663
callq 0x14d07
callq 0x14ad7
callq 0x14c7e
movq $0x0, 0x40(%rsp)
leaq 0x48(%rsp), %rsi
xorl %edi, %edi
callq 0x7dd3
movb $0x1, %al
movl %eax, 0x38(%rsp)
xorl %r15d, %r15d
movl $0x1, 0x30(%rsp)
xorl %ebx, %ebx
movb $0x1, %al
movl %eax, 0x34(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
xorl %ebp, %ebp
callq 0x17b53
leaq 0x1d032(%rip), %rax     # 0x2a718
movsd (%rax), %xmm0
leaq 0x1d01f(%rip), %rax     # 0x2a710
movsd (%rax), %xmm1
addsd %xmm0, %xmm1
ucomisd 0x10f77(%rip), %xmm1    # 0x1e678
jbe 0xd71c
movsd 0x10f6d(%rip), %xmm1    # 0x1e678
subsd %xmm0, %xmm1
leaq 0x1cffa(%rip), %rax     # 0x2a710
movsd %xmm1, (%rax)
movb $0x1, %bl
testb $0x1, 0x38(%rsp)
je 0xd775
leaq 0x1cfe6(%rip), %rax     # 0x2a710
movsd (%rax), %xmm1
addsd %xmm0, %xmm1
ucomisd 0x10f46(%rip), %xmm1    # 0x1e680
jbe 0xd775
movsd 0x10f3c(%rip), %xmm1    # 0x1e680
subsd %xmm0, %xmm1
leaq 0x1cfc1(%rip), %rax     # 0x2a710
movsd %xmm1, (%rax)
leaq 0x17ac6(%rip), %rax     # 0x25220
movabsq $0x3fa16872b020c49c, %rcx # imm = 0x3FA16872B020C49C
movq %rcx, (%rax)
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl $0x0, 0x38(%rsp)
testb $0x1, 0x34(%rsp)
je 0xd7ba
leaq 0x1cf8d(%rip), %rax     # 0x2a710
movsd (%rax), %xmm1
addsd %xmm0, %xmm1
ucomisd 0x10ef5(%rip), %xmm1    # 0x1e688
jbe 0xd7ba
movsd 0x10eeb(%rip), %xmm1    # 0x1e688
subsd %xmm0, %xmm1
leaq 0x1cf68(%rip), %rax     # 0x2a710
movsd %xmm1, (%rax)
movb $0x1, %al
movl %eax, 0x8(%rsp)
movl $0x0, 0x34(%rsp)
movl %ebp, %edi
callq 0x15657
movl %ebp, %r14d
movq %r14, %rax
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
imulq %rcx, %rax
shrq $0x24, %rax
shll $0x2, %eax
leal (%rax,%rax,4), %eax
cmpl %ebp, %eax
jne 0xd875
movl $0x3, %edx
movq 0x177da(%rip), %rdi     # 0x24fc8
leaq 0x10ea3(%rip), %rsi     # 0x1e698
callq 0x3250
movq 0x177c7(%rip), %rdi     # 0x24fc8
movl %ebp, %esi
callq 0x3350
movq %rax, %r12
movl $0x5, %edx
movq %rax, %rdi
leaq 0x10e82(%rip), %rsi     # 0x1e69c
callq 0x3250
leaq 0x1ceea(%rip), %rax     # 0x2a710
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x3300
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x10e5e(%rip), %rsi     # 0x1e6a2
callq 0x3250
leaq 0x1cec8(%rip), %rax     # 0x2a718
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x3300
movl $0x2, %edx
movq %rax, %rdi
leaq 0x1158a(%rip), %rsi     # 0x1edf5
callq 0x3250
callq 0x1cba8
leaq 0x1ce94(%rip), %rax     # 0x2a710
movsd (%rax), %xmm0
leaq 0x1ce91(%rip), %rax     # 0x2a718
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
testb $0x1, 0xc(%rsp)
je 0xd910
testb $0x1, %r15b
je 0xd8a9
callq 0x14ad7
callq 0x14c7e
xorl %r15d, %r15d
movl %r15d, %r13d
xorl %edi, %edi
callq 0x31f0
movq %rax, %r12
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x10ddb(%rip), %rsi     # 0x1e6aa
leaq 0x10dda(%rip), %rdx     # 0x1e6b0
callq 0x8ce8
negl %r12d
movl %r12d, %edi
movq %r15, %rsi
callq 0x7dd3
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
movl %r13d, %r15d
je 0xd908
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3220
movl $0x0, 0xc(%rsp)
testb $0x1, 0x8(%rsp)
je 0xd991
testb $0x1, %r15b
je 0xd92a
callq 0x14ad7
callq 0x14c7e
xorl %r15d, %r15d
movl %r15d, %r13d
xorl %edi, %edi
callq 0x31f0
movq %rax, %r12
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x10d61(%rip), %rsi     # 0x1e6b1
leaq 0x10d5f(%rip), %rdx     # 0x1e6b6
callq 0x8ce8
negl %r12d
movl %r12d, %edi
movq %r15, %rsi
callq 0x7dd3
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
movl %r13d, %r15d
je 0xd989
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3220
movl $0x0, 0x8(%rsp)
leaq 0x1cd80(%rip), %rax     # 0x2a718
movsd (%rax), %xmm0
ucomisd 0x10cec(%rip), %xmm0    # 0x1e690
jbe 0xd9ba
leaq 0x17863(%rip), %rax     # 0x25210
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax)
imulq $0x28c1979, %r14, %rax  # imm = 0x28C1979
shrq $0x21, %rax
imull $0xc9, %eax, %eax
cmpl %ebp, %eax
sete %cl
cmpl $0xfa0, %ebp            # imm = 0xFA0
setae %dl
testb %cl, %dl
jne 0xd9f2
cmpl %ebp, %eax
setne %al
leal -0x1(%rbp), %ecx
cmpl $0xf9f, %ecx            # imm = 0xF9F
setae %cl
orb %al, %cl
jne 0xda1b
testb $0x1, %r15b
je 0xda05
callq 0x14ad7
callq 0x14c7e
xorl %r15d, %r15d
movq 0x40(%rsp), %rdi
incl %edi
movq %rdi, 0x40(%rsp)
leaq 0x48(%rsp), %rsi
callq 0x7dd3
cmpl $0x64, %ebp
jb 0xda45
imulq $0x51eb851f, %r14, %rax # imm = 0x51EB851F
shrq $0x26, %rax
imull $0xc8, %eax, %eax
cmpl %ebp, %eax
jne 0xda45
movl 0x30(%rsp), %edi
callq 0x1c91e
incl 0x30(%rsp)
movb $0x1, %r15b
cmpl $0x13880, %ebp          # imm = 0x13880
jb 0xdad1
imulq $0x10624dd3, %r14, %rax # imm = 0x10624DD3
shrq $0x25, %rax
imull $0x1f4, %eax, %eax      # imm = 0x1F4
cmpl %ebp, %eax
jne 0xdad1
movl $0x31, %edx
movq 0x17556(%rip), %rdi     # 0x24fc8
leaq 0x10c3e(%rip), %rsi     # 0x1e6b7
callq 0x3250
movq 0x17543(%rip), %rcx     # 0x24fc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq 0x17525(%rip), %rdi     # 0x24fc8
callq 0x3040
movq %rax, %rdi
callq 0x3170
movq 0x17529(%rip), %rdi     # 0x24fe0
leaq 0x3c(%rsp), %rsi
callq 0x3130
cmpl $0x0, 0x3c(%rsp)
movzbl %bl, %ebx
movl $0x1, %eax
cmovel %eax, %ebx
incl %ebp
testb $0x1, %bl
je 0xd6da
movq 0x174e5(%rip), %rdi     # 0x24fc8
leaq 0x10bff(%rip), %rsi     # 0x1e6e9
movl $0xa, %edx
callq 0x3250
movq 0x174cd(%rip), %rdi     # 0x24fc8
movsd 0x10b75(%rip), %xmm0    # 0x1e678
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, %r15b
je 0xdb42
callq 0x14ad7
callq 0x14c7e
xorl %edi, %edi
callq 0x31f0
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
movq %rax, (%rdi)
leaq 0x10b94(%rip), %rsi     # 0x1e6f4
leaq 0x10b90(%rip), %rdx     # 0x1e6f7
callq 0x8ce8
leaq 0x1776d(%rip), %r14     # 0x252e0
negl %ebx
leaq 0x10(%rsp), %rsi
movl %ebx, %edi
callq 0x7dd3
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xdb9d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3220
callq 0xc11d
callq 0xc172
movq (%r14), %rdi
testq %rdi, %rdi
je 0xdbb4
callq 0x3280
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xdbd0
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 0xdbe9
jmp 0xdc24
jmp 0xdc24
jmp 0xdbe9
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xdc27
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3220
jmp 0xdc27
jmp 0xdc24
jmp 0xdc24
jmp 0xdc24
jmp 0xdc24
movq %rax, %rbx
movl $0x696a80, %esi         # imm = 0x696A80
movq %r14, %rdi
callq 0x33a0
jmp 0xdc27
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xdc43
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3220
movq %rbx, %rdi
callq 0x3370
nop