// File: /workspace/github_cpp_makefile_star2_O2/tlestang[P]IW_gene/topo.cpp
// Function: Topography::Topography(int const*, int, double***, VelSite**, VelSite**)
Topography::Topography(const int d[2], int h, double ***u,
		       VelSite **sites, VelSite **_sites)
{
  nbNodes = d[0];
  double u0[2] = {0.0, 0.0};
  int x,y;
  lbl = new int[nbNodes];
  nodes = new int*[nbNodes];
  for (int i=0;i<nbNodes;i++)
    {nodes[i] = new int[2];}

  double a;
  int cc = 0;
  for (int xx=0;xx<d[0];xx++)
    {
      nodes[cc][0] = xx;
      a = 2.*M_PI / d[0];
      nodes[cc][1] = floor(h*sin(a*xx)) + h;
      for(int yy=0;yy<nodes[cc][1];yy++)
	{
	  sites[xx][yy].init(LatticeSite::Solid, 1.0, u0, 0);
	  _sites[xx][yy].init(LatticeSite::Solid, 1.0, u0, 0);
	}
            
      cc += 1;
    }

  for(int i=1;i<nbNodes-1;i++)
    {
      x = nodes[i][0]; y = nodes[i][1];
      if(nodes[i-1][1] == (y-1) && nodes[i+1][1] == (y+1)){lbl[i]=2; } //3 pts aligned along y
      else if(nodes[i-1][1] == nodes[i+1][1]){lbl[i]=1;}
      else if((nodes[i-1][1] == (y-1) && nodes[i+1][1] == y) || (nodes[i-1][1] == y && nodes[i+1][1] == y-1) ){lbl[i] = 2;}
      else{lbl[i] = 0;}
    }

  
  x = nodes[0][0]; y = nodes[0][1];
  if(nodes[nbNodes-1][0] == nodes[1][0]){lbl[0]=2;}
  else if(nodes[nbNodes-1][1] == nodes[1][1]){lbl[0]=1;}
  else if((nodes[nbNodes-1][1] == (y-1) && nodes[1][1] == y) || (nodes[nbNodes-1][1] == y && nodes[1][1] == y-1) ){lbl[0] = 2;}
  else{lbl[0] = 0;}
  
  x = nodes[nbNodes-1][0]; y = nodes[nbNodes-1][1];
  if(nodes[nbNodes-2][0] == nodes[0][0]){lbl[nbNodes-1]=2;}
  else if(nodes[nbNodes-2][1] == nodes[0][1]){lbl[nbNodes-1]=1;}
  else if((nodes[nbNodes-2][1] == (y-1) && nodes[0][1] == y) || (nodes[nbNodes-2][1] == y && nodes[0][1] == y-1) ){lbl[nbNodes-1] = 2;}
  else{lbl[nbNodes-1] = 0;}


  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x28(%rsp)
movq %r8, %r15
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x2888
leaq 0x4ef6(%rip), %rax      # 0x7d98
movq %rax, (%rbx)
movq %r14, 0x18(%rsp)
movslq (%r14), %r12
movl %r12d, 0x8(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
leaq (,%r12,4), %rdi
testq %r12, %r12
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
leaq (,%r12,8), %r13
cmovsq %rax, %r13
callq 0x2030
movq %rax, 0x18(%rbx)
movq %r13, %rdi
callq 0x2030
movq %rbx, %r10
movq %rax, 0x10(%rbx)
xorl %ebx, %ebx
testl %r12d, %r12d
movl $0x0, %r14d
movq %r12, 0x20(%rsp)
cmovgl %r12d, %r14d
pushq $0x8
popq %r13
movq %r10, 0x8(%rsp)
cmpq %rbx, %r14
je 0x2f2b
movq %r13, %rdi
callq 0x2030
movq 0x8(%rsp), %r10
movq 0x10(%r10), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x2f0c
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %r12d, %r12d
pushq $0x62
popq %rbp
leaq 0x30(%rsp), %r13
movq 0x20(%rsp), %rax
cltq
movq 0x10(%r10), %rcx
cmpq %rax, %r12
jge 0x301c
movq (%rcx,%r12,8), %rax
movl %r12d, (%rax)
movq 0x18(%rsp), %rax
cvtsi2sdl (%rax), %xmm0
movsd 0x2214(%rip), %xmm1     # 0x5180
divsd %xmm0, %xmm1
cvtsi2sd %r12d, %xmm0
mulsd %xmm1, %xmm0
callq 0x2070
mulsd 0x10(%rsp), %xmm0
callq 0x2220
movq 0x8(%rsp), %r10
addsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movq 0x10(%r10), %rcx
movq (%rcx,%r12,8), %rcx
movl %eax, 0x4(%rcx)
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x10(%r10), %rax
movq (%rax,%r12,8), %rax
movslq 0x4(%rax), %rax
cmpq %rax, %r14
jge 0x300d
movq (%r15,%r12,8), %rdi
movq (%rdi,%rbx), %rax
addq %rbx, %rdi
xorpd %xmm1, %xmm1
movl %ebp, %esi
movsd 0x203e(%rip), %xmm0     # 0x5010
movq %r13, %rdx
callq *0x18(%rax)
movq 0x28(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq (%rdi,%rbx), %rax
addq %rbx, %rdi
xorpd %xmm1, %xmm1
movl %ebp, %esi
movsd 0x201a(%rip), %xmm0     # 0x5010
movq %r13, %rdx
callq *0x18(%rax)
movq 0x8(%rsp), %r10
incq %r14
addq $0x88, %rbx
jmp 0x2fa8
incq %r12
movq 0x18(%rsp), %rax
movl (%rax), %eax
jmp 0x2f45
movq 0x18(%r10), %rax
pushq $0x1
popq %rdx
pushq $0x2
popq %rsi
pushq $0x1
popq %rdi
movslq 0x8(%r10), %r8
leaq -0x1(%r8), %r9
cmpq %r9, %rdx
jge 0x309f
movq -0x8(%rcx,%rdx,8), %r8
movq (%rcx,%rdx,8), %r9
movl 0x4(%r9), %r9d
movl 0x4(%r8), %r8d
leal -0x1(%r9), %r10d
cmpl %r10d, %r8d
jne 0x3066
movq 0x8(%rcx,%rdx,8), %r11
movl 0x4(%r11), %r11d
leal 0x1(%r9), %ebp
movl %esi, %ebx
cmpl %ebp, %r11d
jne 0x306f
jmp 0x3092
movq 0x8(%rcx,%rdx,8), %r11
movl 0x4(%r11), %r11d
movl %edi, %ebx
cmpl %r11d, %r8d
je 0x3092
cmpl %r10d, %r8d
jne 0x3082
movl %esi, %ebx
cmpl %r9d, %r11d
je 0x3092
xorl %r9d, %r8d
xorl %r10d, %r11d
xorl %ebx, %ebx
orl %r8d, %r11d
sete %bl
addl %ebx, %ebx
movl %ebx, (%rax,%rdx,4)
incq %rdx
movq 0x8(%rsp), %r10
jmp 0x3029
movq 0x10(%r10), %rcx
movq (%rcx), %rdx
movq 0x8(%rcx), %rdi
movq -0x8(%rcx,%r8,8), %rsi
movl (%rsi), %r8d
cmpl (%rdi), %r8d
jne 0x30bf
movl $0x2, (%rax)
jmp 0x30cf
movl 0x4(%rsi), %esi
movl 0x4(%rdi), %edi
cmpl %edi, %esi
jne 0x310b
movl $0x1, (%rax)
movslq 0x8(%r10), %rsi
movq -0x10(%rcx,%rsi,8), %rdi
movl (%rdi), %r8d
cmpl (%rdx), %r8d
jne 0x30ea
movl $0x2, -0x4(%rax,%rsi,4)
jmp 0x30fc
movl 0x4(%rdi), %edi
movl 0x4(%rdx), %edx
cmpl %edx, %edi
jne 0x3123
movl $0x1, -0x4(%rax,%rsi,4)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%rdx), %r8d
leal -0x1(%r8), %r9d
cmpl %r9d, %esi
jne 0x3149
cmpl %r8d, %edi
jne 0x3149
movq 0x18(%r10), %rax
jmp 0x30b7
movq -0x8(%rcx,%rsi,8), %rcx
movl 0x4(%rcx), %r8d
leal -0x1(%r8), %ecx
cmpl %ecx, %edi
jne 0x3139
cmpl %r8d, %edx
je 0x30e0
cmpl %r8d, %edi
jne 0x3142
cmpl %ecx, %edx
je 0x30e0
andl $0x0, -0x4(%rax,%rsi,4)
jmp 0x30fc
movq 0x18(%r10), %rax
cmpl %r9d, %edi
jne 0x315b
cmpl %r8d, %esi
je 0x30b7
andl $0x0, (%rax)
jmp 0x30cf
nop