// File: /workspace/github_cpp_makefile_star2_O2/tlestang[P]IW_gene/main.cpp
// Function: main
int main(int argc, char *argv[])
{

  string folderName = "test_temp/";
  string instru = "mkdir " + folderName;
  system(instru.c_str());
  instru = "mkdir " + folderName + "vtk_fluid/";
  system(instru.c_str());
  
  
  double **rho = NULL;;
  double ***velocity = NULL;
  double **temp = NULL;

  // declaration of parameters in PHYSICAL units to
  // be init. from input_file.
  double U0, nuPhi, kappaPhi, D, asp, hb, Pr, N2Phi;

  // declaration of parameters in LATTICE units.

  int Nx;
  double beta = 1;
  double nu, kappa, tau_prim, N2;
  int h;
  int Dx, Dy; double gr;

  ifstream input_file(argv[1]);
  if(input_file.is_open())
    {
      input_file >> U0;
      input_file >> Pr;
      input_file >> D;
      input_file >> asp;
      input_file >> hb;
      input_file >> Dx;
      input_file >> N2Phi;
      input_file.close();
    }

  else
    {
      cout << "ERROR - Could not open input file " << endl; return(0);
    }

  // Now compute simulation parameters from physical values.
  //Lattice velocity set to 0.1 (Low Ma limit).
  double u0 = 0.01;
  double delta_x = D/(Dx-1);
  double delta_t = (delta_x*u0)/U0;

  //Lattice viscosity is set so that tau = 0.51 which is expected to be stable enough.
  double tau = 0.6;
  //double tau = 3./2.;
  nu = (2*tau -1)/6.; nuPhi = nu*(delta_x*delta_x/delta_t);
  kappa = nu/Pr; kappaPhi = kappa*(delta_x*delta_x/delta_t);
  tau_prim = 2.*kappa + 0.5;

  h = floor(hb/delta_x);
  cout << asp << " " << Dx << " " << endl;
  Dy = asp*(Dx-1) + 1; N2 = delta_t*delta_t*N2Phi;
  gr = N2*(Dy-1); // So that T = 1 on top of the domain
  ofstream paramFile("parameters.datout");
  paramFile << "PHYSICAL SETUP IN LATTICE UNITS" << endl;
  paramFile << "--------------------" << endl;
  paramFile << "  Grid is " << Dx << "x" << Dy << endl;
  paramFile << "  tau = " << tau << " | tau_prim = " << tau_prim << endl;
  paramFile << "  Dy = " << Dy << endl;
  paramFile << "  h = " << h << endl;
  paramFile << "  g = " << gr << endl;
  paramFile << "  N2 = " << N2 << endl;

  paramFile << "PHYSICAL SETUP IN PHYSICAL UNITS" << endl;
  paramFile << "  nu = " << nuPhi << endl;
  paramFile << "  kappa = " << kappaPhi << endl;
  paramFile << "  dx = " << delta_x << " m" << endl;
  paramFile << "  dt = " << delta_t << " s" << endl;
  paramFile.close();

  int dims[2] = {Dx, Dy};
  double omega[2];
  omega[0] = 1./tau;
  omega[1]  = 1./tau_prim;


  LatticeBoltzmann *lb;

  lb = new LatticeBoltzmann(dims, omega, gr*beta, u0, h, N2);
  lb->setSpgeLayer(floor((Dy-1)/4));

  lb->getDensityAndVelocityField(temp, rho, velocity);

  int N = 1600000;
  int k = 0; int tt = 0;
  double d;
  for (int i=0;i<N;i++)
    {

      lb->update();
      if(i%(N/100)==0)
      	{
      	  cout << k << "%" << endl;
      	  k++;
      	}
      if(i%1000 == 0)
      	{
      	  write_fluid_vtk(tt, dims[0], dims[1], temp, velocity, folderName.c_str());
      	  tt++;
      	}
    }    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4e8, %rsp            # imm = 0x4E8
movq %rsi, %rbx
leaq 0xc59(%rip), %rsi       # 0x5340
leaq 0xc0(%rsp), %r14
leaq 0x2e0(%rsp), %rdx
movq %r14, %rdi
callq 0x45f2
leaq 0xc45(%rip), %rsi       # 0x534b
leaq 0xa0(%rsp), %rdi
movq %r14, %rdx
callq 0x4e1c
movq 0xa0(%rsp), %rdi
callq 0x2130
leaq 0xc21(%rip), %rsi       # 0x534b
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x4e1c
leaq 0xac0(%rip), %rdx       # 0x5206
leaq 0x2e0(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x45c9
leaq 0xa0(%rsp), %r14
leaq 0x2e0(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2190
movq %r15, %rdi
callq 0x20b0
leaq 0xe0(%rsp), %rdi
callq 0x20b0
movq (%r14), %rdi
callq 0x2130
andq $0x0, 0x88(%rsp)
andq $0x0, 0x50(%rsp)
andq $0x0, 0x48(%rsp)
movq 0x8(%rbx), %rsi
leaq 0x2e0(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2280
leaq 0x358(%rsp), %rdi
callq 0x2080
testb %al, %al
je 0x4d39
leaq 0x2e0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x20d0
leaq 0x2e0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
callq 0x2060
movl 0x4(%rsp), %eax
decl %eax
cvtsi2sd %eax, %xmm0
movsd 0x78(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0xaad(%rip), %xmm0      # 0x5328
mulsd %xmm1, %xmm0
divsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xa9a(%rip), %xmm0      # 0x5330
divsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm1, 0x30(%rsp)
divsd %xmm1, %xmm0
callq 0x2220
movsd %xmm0, 0x18(%rsp)
movsd 0x40(%rsp), %xmm0
movq 0x370e(%rip), %rdi      # 0x7fd8
callq 0x2210
leaq 0xb27(%rip), %rsi       # 0x53fd
movq %rax, %rdi
callq 0x2150
movl 0x4(%rsp), %esi
movq %rax, %rdi
callq 0x2240
leaq 0xb0c(%rip), %rsi       # 0x53fd
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
movl 0x4(%rsp), %eax
decl %eax
cvtsi2sd %eax, %xmm0
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0xa41(%rip), %rsi       # 0x5375
leaq 0xe0(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x2180
leaq 0xa3c(%rip), %rsi       # 0x5387
leaq 0xe0(%rsp), %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0xa40(%rip), %rsi       # 0x53a7
leaq 0xe0(%rsp), %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0xa39(%rip), %rsi       # 0x53bc
leaq 0xe0(%rsp), %rdi
callq 0x2150
movl 0x4(%rsp), %esi
movq %rax, %rdi
callq 0x2240
leaq 0xa24(%rip), %rsi       # 0x53c7
movq %rax, %rdi
callq 0x2150
movsd 0x20(%rsp), %xmm0
addsd 0x657(%rip), %xmm0      # 0x5010
cvttsd2si %xmm0, %ebx
movq %rax, %rdi
movl %ebx, %esi
callq 0x2240
movq %rax, %rdi
callq 0x20c0
leaq 0x9f3(%rip), %rsi       # 0x53c9
leaq 0xe0(%rsp), %rdi
callq 0x2150
movsd 0x94d(%rip), %xmm0      # 0x5338
movq %rax, %rdi
callq 0x2210
leaq 0x9d8(%rip), %rsi       # 0x53d2
movq %rax, %rdi
callq 0x2150
movsd 0x38(%rsp), %xmm0
addsd %xmm0, %xmm0
addsd 0x774(%rip), %xmm0      # 0x5188
movq %rax, %rdi
movsd %xmm0, 0x20(%rsp)
callq 0x2210
movq %rax, %rdi
callq 0x20c0
leaq 0x9b0(%rip), %rsi       # 0x53e1
leaq 0xe0(%rsp), %rdi
callq 0x2150
movq %rax, %rdi
movl %ebx, %esi
callq 0x2240
movq %rax, %rdi
callq 0x20c0
leaq 0x992(%rip), %rsi       # 0x53e9
leaq 0xe0(%rsp), %rdi
callq 0x2150
cvttsd2si 0x18(%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x2240
movq %rax, %rdi
callq 0x20c0
leaq 0x96d(%rip), %rsi       # 0x53f0
leaq 0xe0(%rsp), %rdi
callq 0x2150
leal -0x1(%rbx), %r14d
cvtsi2sd %r14d, %xmm0
mulsd 0x28(%rsp), %xmm0
movq %rax, %rdi
movsd %xmm0, 0x58(%rsp)
callq 0x2210
movq %rax, %rdi
callq 0x20c0
leaq 0x93b(%rip), %rsi       # 0x53f7
leaq 0xe0(%rsp), %rdi
callq 0x2150
movq %rax, %rdi
movsd 0x28(%rsp), %xmm0
callq 0x2210
movq %rax, %rdi
callq 0x20c0
leaq 0x919(%rip), %rsi       # 0x53ff
leaq 0xe0(%rsp), %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0x91e(%rip), %rsi       # 0x5420
leaq 0xe0(%rsp), %rdi
callq 0x2150
movsd 0x30(%rsp), %xmm1
mulsd %xmm1, %xmm1
divsd 0x8(%rsp), %xmm1
movsd 0x809(%rip), %xmm0      # 0x5330
movsd %xmm1, 0x18(%rsp)
mulsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x20c0
leaq 0x8e0(%rip), %rsi       # 0x5428
leaq 0xe0(%rsp), %rdi
callq 0x2150
movsd 0x38(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x20c0
leaq 0x8bb(%rip), %rsi       # 0x5433
leaq 0xe0(%rsp), %rdi
callq 0x2150
movq %rax, %rdi
movsd 0x30(%rsp), %xmm0
callq 0x2210
leaq 0x8a1(%rip), %rsi       # 0x543b
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0x88d(%rip), %rsi       # 0x543e
leaq 0xe0(%rsp), %rdi
callq 0x2150
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x2210
leaq 0x873(%rip), %rsi       # 0x5446
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0xe0(%rsp), %rdi
callq 0x21b0
movl 0x4(%rsp), %eax
movl %eax, 0x10(%rsp)
movl %ebx, 0x14(%rsp)
movabsq $0x3ffaaaaaaaaaaaab, %rax # imm = 0x3FFAAAAAAAAAAAAB
movq %rax, 0x90(%rsp)
movsd 0x3fa(%rip), %xmm0      # 0x5010
divsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
movl $0x90, %edi
callq 0x2160
movq %rax, %rbx
leaq 0x10(%rsp), %rsi
leaq 0x90(%rsp), %rdx
movsd 0x6e1(%rip), %xmm1      # 0x5328
movq %rax, %rdi
movsd 0x58(%rsp), %xmm0
movl %ebp, %ecx
movsd 0x28(%rsp), %xmm2
callq 0x3644
pushq $0x4
popq %rcx
movl %r14d, %eax
cltd
idivl %ecx
movq %rbx, %rdi
movl %eax, %esi
callq 0x3fea
leaq 0x48(%rsp), %rsi
leaq 0x88(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %rbx, %rdi
callq 0x3e2c
movq %rbx, 0x8(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r13d, %r13d
movl %r13d, %eax
xorl %edx, %edx
movl $0x3e8, %ecx            # imm = 0x3E8
divl %ecx
movl %eax, %r14d
movl %r13d, %eax
xorl %edx, %edx
movl $0x3e80, %ecx           # imm = 0x3E80
divl %ecx
cmpl $0xffe79600, %ebx       # imm = 0xFFE79600
je 0x4d56
movl %eax, %r15d
movq 0x8(%rsp), %rdi
callq 0x3c0c
imull $0xffffc180, %r15d, %eax # imm = 0xFFFFC180
cmpl %ebx, %eax
jne 0x4cff
movq 0x32f9(%rip), %rdi      # 0x7fd8
movl %ebp, %esi
callq 0x2240
movq %rax, %rdi
leaq 0x759(%rip), %rsi       # 0x5449
callq 0x2150
movq %rax, %rdi
callq 0x20c0
incl %ebp
imull $0xfffffc18, %r14d, %eax # imm = 0xFFFFFC18
cmpl %ebx, %eax
jne 0x4d2f
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0xc0(%rsp), %r9
movl %r12d, %edi
callq 0x4090
incl %r12d
incl %r13d
decl %ebx
jmp 0x4c99
movq 0x3298(%rip), %rdi      # 0x7fd8
leaq 0x60b(%rip), %rsi       # 0x5352
callq 0x2150
movq %rax, %rdi
callq 0x20c0
jmp 0x4d63
leaq 0xe0(%rsp), %rdi
callq 0x21c0
leaq 0x2e0(%rsp), %rdi
callq 0x2090
leaq 0xa0(%rsp), %rdi
callq 0x20b0
leaq 0xc0(%rsp), %rdi
callq 0x20b0
xorl %eax, %eax
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x90, %esi
movq %rbx, %rdi
callq 0x2170
jmp 0x4de0
jmp 0x4dd6
jmp 0x4dcf
movq %rax, %r14
leaq 0xe0(%rsp), %rdi
callq 0x20b0
jmp 0x4dfa
jmp 0x4dcf
movq %rax, %r14
jmp 0x4e07
jmp 0x4ddd
movq %rax, %r14
jmp 0x4dfa
jmp 0x4dd6
movq %rax, %r14
jmp 0x4ded
jmp 0x4ddd
movq %rax, %r14
leaq 0xe0(%rsp), %rdi
callq 0x21c0
leaq 0x2e0(%rsp), %rdi
callq 0x2090
leaq 0xa0(%rsp), %rdi
callq 0x20b0
leaq 0xc0(%rsp), %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x2250