// File: /workspace/github_cpp_makefile_star2_O3/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 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1950(%rip), %rsi      # 0x6340
leaq 0x1953(%rip), %rdx      # 0x634a
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x492c
leaq 0x1940(%rip), %rsi      # 0x634b
leaq 0xb0(%rsp), %rdi
movq %r14, %rdx
callq 0x550b
movq 0xb0(%rsp), %rdi
callq 0x2160
leaq 0x191c(%rip), %rsi      # 0x634b
leaq 0xe0(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x550b
leaq 0x17be(%rip), %rsi      # 0x6206
leaq 0xe0(%rsp), %rdi
callq 0x22d0
leaq 0x2f0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4a85
movq %rdx, 0x2e0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x2f0(%rsp)
jmp 0x4a8e
movupd (%rcx), %xmm0
movupd %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x2e0(%rsp), %r14
movq %rdx, 0x8(%r14)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xb0(%rsp), %rdi
movq %r14, %rsi
callq 0x21e0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x4ad5
movq 0x2f0(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0xf0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4af6
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0xb0(%rsp), %rdi
callq 0x2160
xorl %eax, %eax
movq %rax, 0xa8(%rsp)
movq %rax, 0x50(%rsp)
movq %rax, 0x48(%rsp)
movq 0x8(%rbx), %rsi
leaq 0x2e0(%rsp), %rdi
movl $0x8, %edx
callq 0x22b0
leaq 0x358(%rsp), %rdi
callq 0x2090
testb %al, %al
je 0x53b2
leaq 0x2e0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x20f0
leaq 0x2e0(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x20f0
leaq 0x2e0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x20f0
leaq 0x2e0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x20f0
leaq 0x2e0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x20f0
leaq 0x2e0(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x20f0
leaq 0x2e0(%rsp), %rdi
callq 0x2070
movl 0x4(%rsp), %eax
decl %eax
cvtsi2sd %eax, %xmm0
movsd 0x98(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x172d(%rip), %xmm0     # 0x6328
mulsd %xmm1, %xmm0
divsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x171a(%rip), %xmm0     # 0x6330
divsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x90(%rsp), %xmm0
movsd %xmm1, 0x30(%rsp)
divsd %xmm1, %xmm0
callq 0x2250
movsd %xmm0, 0x18(%rsp)
movsd 0x40(%rsp), %xmm0
movq 0x4388(%rip), %rdi      # 0x8fd8
callq 0x2240
movq %rax, %rbx
leaq 0x179e(%rip), %rsi      # 0x63fd
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0x2270
movq %rax, %rbx
leaq 0x177b(%rip), %rsi      # 0x63fd
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movl 0x4(%rsp), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x1686(%rip), %rsi      # 0x6375
leaq 0xe0(%rsp), %rdi
movl $0x10, %edx
callq 0x21b0
leaq 0x167f(%rip), %rsi      # 0x6387
leaq 0xe0(%rsp), %rbx
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x21d0
movq 0xe0(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
leaq 0xe0(%rsp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x1652(%rip), %rsi      # 0x63a7
leaq 0xe0(%rsp), %rbx
movl $0x14, %edx
movq %rbx, %rdi
callq 0x21d0
movq 0xe0(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
leaq 0xe0(%rsp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x161a(%rip), %rsi      # 0x63bc
leaq 0xe0(%rsp), %rdi
movl $0xa, %edx
callq 0x21d0
movl 0x4(%rsp), %esi
leaq 0xe0(%rsp), %rdi
callq 0x2270
movq %rax, %r14
leaq 0x15f8(%rip), %rsi      # 0x63c7
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movsd 0x20(%rsp), %xmm0
addsd 0x1226(%rip), %xmm0     # 0x6010
cvttsd2si %xmm0, %ebx
movq %r14, %rdi
movl %ebx, %esi
callq 0x2270
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x15a0(%rip), %rsi      # 0x63c9
leaq 0xe0(%rsp), %rdi
movl $0x8, %edx
callq 0x21d0
leaq 0xe0(%rsp), %rdi
movsd 0x14ed(%rip), %xmm0     # 0x6338
callq 0x2240
movq %rax, %r14
leaq 0x1578(%rip), %rsi      # 0x63d2
movl $0xe, %edx
movq %rax, %rdi
callq 0x21d0
movsd 0x38(%rsp), %xmm0
addsd %xmm0, %xmm0
addsd 0x130f(%rip), %xmm0     # 0x6188
movq %r14, %rdi
movsd %xmm0, 0x20(%rsp)
callq 0x2240
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x1529(%rip), %rsi      # 0x63e1
leaq 0xe0(%rsp), %rdi
movl $0x7, %edx
callq 0x21d0
leaq 0xe0(%rsp), %rdi
movl %ebx, %esi
callq 0x2270
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x14df(%rip), %rsi      # 0x63e9
leaq 0xe0(%rsp), %rdi
movl $0x6, %edx
callq 0x21d0
cvttsd2si 0x18(%rsp), %ebp
leaq 0xe0(%rsp), %rdi
movl %ebp, %esi
callq 0x2270
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x148e(%rip), %rsi      # 0x63f0
leaq 0xe0(%rsp), %rdi
movl $0x6, %edx
callq 0x21d0
leal -0x1(%rbx), %r15d
cvtsi2sd %r15d, %xmm0
mulsd 0x28(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
movsd %xmm0, 0x78(%rsp)
callq 0x2240
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x1430(%rip), %rsi      # 0x63f7
leaq 0xe0(%rsp), %rdi
movl $0x7, %edx
callq 0x21d0
leaq 0xe0(%rsp), %rdi
movsd 0x28(%rsp), %xmm0
callq 0x2240
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x13e2(%rip), %rsi      # 0x63ff
leaq 0xe0(%rsp), %r14
movl $0x20, %edx
movq %r14, %rdi
callq 0x21d0
movq 0xe0(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
leaq 0xe0(%rsp), %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x13b6(%rip), %rsi      # 0x6420
leaq 0xe0(%rsp), %rdi
movl $0x7, %edx
callq 0x21d0
movsd 0x30(%rsp), %xmm1
mulsd %xmm1, %xmm1
divsd 0x8(%rsp), %xmm1
movsd 0x129c(%rip), %xmm0     # 0x6330
movsd %xmm1, 0x18(%rsp)
mulsd %xmm1, %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x2240
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x134c(%rip), %rsi      # 0x6428
leaq 0xe0(%rsp), %rdi
movl $0xa, %edx
callq 0x21d0
movsd 0x38(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
callq 0x2240
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x12fb(%rip), %rsi      # 0x6433
leaq 0xe0(%rsp), %rdi
movl $0x7, %edx
callq 0x21d0
leaq 0xe0(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
callq 0x2240
movq %rax, %r14
leaq 0x12d4(%rip), %rsi      # 0x643b
movl $0x2, %edx
movq %rax, %rdi
callq 0x21d0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x129c(%rip), %rsi      # 0x643e
leaq 0xe0(%rsp), %rdi
movl $0x7, %edx
callq 0x21d0
leaq 0xe0(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
callq 0x2240
movq %rax, %r14
leaq 0x1275(%rip), %rsi      # 0x6446
movl $0x2, %edx
movq %rax, %rdi
callq 0x21d0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0xe0(%rsp), %rdi
callq 0x21f0
movl 0x4(%rsp), %eax
movl %eax, 0x10(%rsp)
movl %ebx, 0x14(%rsp)
movabsq $0x3ffaaaaaaaaaaaab, %rax # imm = 0x3FFAAAAAAAAAAAAB
movq %rax, 0xd0(%rsp)
movsd 0xdd8(%rip), %xmm0      # 0x6010
divsd 0x20(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movl $0x90, %edi
callq 0x2190
movq %rax, %rbx
leaq 0x10(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
movsd 0x10bf(%rip), %xmm1     # 0x6328
movq %rax, %rdi
movsd 0x78(%rsp), %xmm0
movl %ebp, %ecx
movsd 0x28(%rsp), %xmm2
callq 0x36e0
leal 0x3(%r15), %esi
testl %r15d, %r15d
cmovnsl %r15d, %esi
sarl $0x2, %esi
movq %rbx, %rdi
callq 0x4110
leaq 0x48(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %rbx, %rdi
callq 0x3f48
movq %rbx, 0x8(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x8(%rsp), %rdi
callq 0x3d1a
movl %r15d, %eax
imulq $0x10624dd3, %rax, %rbx # imm = 0x10624DD3
movq %rbx, %rax
shrq $0x2a, %rax
imull $0xffffc180, %eax, %eax # imm = 0xFFFFC180
cmpl %r14d, %eax
jne 0x5336
movq 0x3cec(%rip), %rdi      # 0x8fd8
movl %r12d, %esi
callq 0x2270
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1143(%rip), %rsi      # 0x6449
callq 0x21d0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
incl %r12d
shrq $0x26, %rbx
imull $0xfffffc18, %ebx, %eax # imm = 0xFFFFFC18
cmpl %r14d, %eax
jne 0x5365
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x58(%rsp), %r9
movl %ebp, %edi
callq 0x41bc
incl %ebp
incl %r15d
decl %r14d
cmpl $0xffe79600, %r14d      # imm = 0xFFE79600
jne 0x52bf
movq 0x3c51(%rip), %rax      # 0x8fd0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0xe8(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0xe0(%rsp,%rcx)
callq 0x2150
leaq 0x1d8(%rsp), %rdi
callq 0x20c0
jmp 0x53f8
movq 0x3c1f(%rip), %rbx      # 0x8fd8
leaq 0xf92(%rip), %rsi       # 0x6352
movl $0x22, %edx
movq %rbx, %rdi
callq 0x21d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq 0x3bed(%rip), %rdi      # 0x8fd8
callq 0x2040
movq %rax, %rdi
callq 0x2100
leaq 0x2e0(%rsp), %rdi
callq 0x20a0
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5426
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x5442
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21a0
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 0x21a0
jmp 0x54ac
jmp 0x54a2
jmp 0x549b
movq %rax, %r14
leaq 0xf0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x54c6
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x54c6
jmp 0x549b
movq %rax, %r14
jmp 0x54e7
jmp 0x54a9
movq %rax, %r14
jmp 0x54c6
jmp 0x54a2
movq %rax, %r14
jmp 0x54b9
jmp 0x54a9
movq %rax, %r14
leaq 0xe0(%rsp), %rdi
callq 0x2200
leaq 0x2e0(%rsp), %rdi
callq 0x20a0
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x54e7
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x5503
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %r14, %rdi
callq 0x2280