// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %r9, %r14
movq %r8, %r15
movl %edx, (%rsp)
movq %rsi, %rbx
movq %rdi, %r12
callq 0x28c4
leaq 0x5e9b(%rip), %rax      # 0x8d88
movq %rax, (%r12)
movslq (%rbx), %rbp
movl %ebp, 0x8(%r12)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
leaq (,%rbp,4), %rdi
testq %rbp, %rbp
movq $-0x1, %rax
cmovsq %rax, %rdi
leaq (,%rbp,8), %r13
cmovsq %rax, %r13
callq 0x2030
movq %rax, 0x18(%r12)
movq %r13, %rdi
callq 0x2030
movq %rax, 0x10(%r12)
testq %rbp, %rbp
jle 0x3109
movq %rbx, 0x8(%rsp)
xorl %ebx, %ebx
movl $0x8, %edi
callq 0x2030
movq 0x10(%r12), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq %rbx, %rbp
jne 0x2f4c
movq 0x10(%r12), %rax
testl %ebp, %ebp
jle 0x3109
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%rsp), %xmm0
movsd %xmm0, (%rsp)
xorl %ebp, %ebp
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %r13
movq (%rax,%rbp,8), %rax
movl %ebp, (%rax)
xorps %xmm0, %xmm0
cvtsi2sdl (%rdx), %xmm0
movsd 0x31d4(%rip), %xmm1     # 0x6180
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd %xmm1, %xmm0
callq 0x2080
mulsd (%rsp), %xmm0
callq 0x2250
addsd (%rsp), %xmm0
cvttsd2si %xmm0, %ecx
movq 0x10(%r12), %rax
movq (%rax,%rbp,8), %rdx
movl %ecx, 0x4(%rdx)
testl %ecx, %ecx
movq %r12, %rsi
leaq 0x20(%rsp), %r15
jle 0x305b
xorl %r12d, %r12d
xorl %ebx, %ebx
movq (%r13,%rbp,8), %rdi
movq (%rdi,%r12), %rax
addq %r12, %rdi
xorpd %xmm1, %xmm1
movq %rsi, %r14
movl $0x62, %esi
movsd 0x3000(%rip), %xmm0     # 0x6010
movq %r15, %rdx
callq *0x18(%rax)
movq 0x18(%rsp), %rax
movq (%rax,%rbp,8), %rdi
movq (%rdi,%r12), %rax
addq %r12, %rdi
xorpd %xmm1, %xmm1
movl $0x62, %esi
movsd 0x2fd9(%rip), %xmm0     # 0x6010
movq %r15, %rdx
callq *0x18(%rax)
movq %r14, %rsi
incq %rbx
movq 0x10(%r14), %rax
movq (%rax,%rbp,8), %rcx
movslq 0x4(%rcx), %rcx
addq $0x88, %r12
cmpq %rcx, %rbx
jl 0x2ff0
incq %rbp
movq 0x8(%rsp), %rdx
movslq (%rdx), %rcx
cmpq %rcx, %rbp
movq %rsi, %r12
jl 0x2f97
movl 0x8(%r12), %ebp
cmpl $0x2, %ebp
jle 0x3109
movq 0x18(%r12), %rcx
movl $0x1, %edx
movq -0x8(%rax,%rdx,8), %rsi
movq (%rax,%rdx,8), %rdi
movl 0x4(%rdi), %edi
movl 0x4(%rsi), %esi
leal -0x1(%rdi), %r8d
cmpl %r8d, %esi
jne 0x30bc
movq 0x8(%rax,%rdx,8), %r9
movl 0x4(%r9), %r9d
leal 0x1(%rdi), %r11d
movl $0x2, %r10d
cmpl %r11d, %r9d
jne 0x30c5
jmp 0x30f2
movq 0x8(%rax,%rdx,8), %r9
movl 0x4(%r9), %r9d
movl $0x1, %r10d
cmpl %r9d, %esi
je 0x30f2
cmpl %r8d, %esi
jne 0x30e0
movl $0x2, %r10d
cmpl %edi, %r9d
je 0x30f2
xorl %edi, %esi
xorl %r8d, %r9d
xorl %r10d, %r10d
orl %esi, %r9d
sete %r10b
addl %r10d, %r10d
movl %r10d, (%rcx,%rdx,4)
incq %rdx
movslq 0x8(%r12), %rbp
leaq -0x1(%rbp), %rsi
cmpq %rsi, %rdx
jl 0x308a
jmp 0x310f
leal -0x1(%rbp), %ecx
movslq %ecx, %rsi
movq (%rax), %rcx
movq 0x8(%rax), %rdi
movq (%rax,%rsi,8), %rdx
movl (%rdx), %esi
cmpl (%rdi), %esi
jne 0x312d
movq 0x18(%r12), %rdx
movl $0x2, (%rdx)
jmp 0x3142
movl 0x4(%rdx), %edx
movl 0x4(%rdi), %edi
cmpl %edi, %edx
jne 0x317f
movq 0x18(%r12), %rdx
movl $0x1, (%rdx)
movslq 0x8(%r12), %rsi
movq -0x10(%rax,%rsi,8), %rdi
movl (%rdi), %r8d
cmpl (%rcx), %r8d
jne 0x315e
movl $0x2, -0x4(%rdx,%rsi,4)
jmp 0x3170
movl 0x4(%rdi), %edi
movl 0x4(%rcx), %ecx
cmpl %ecx, %edi
jne 0x31b2
movl $0x1, -0x4(%rdx,%rsi,4)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%rcx), %esi
leal -0x1(%rsi), %r8d
cmpl %r8d, %edx
jne 0x318f
cmpl %esi, %edi
je 0x3120
movq 0x18(%r12), %rdx
cmpl %r8d, %edi
jne 0x31aa
movslq %ebp, %rdi
movq -0x8(%rax,%rdi,8), %rdi
cmpl %esi, 0x4(%rdi)
je 0x3125
movl $0x0, (%rdx)
jmp 0x3142
movq -0x8(%rax,%rsi,8), %rax
movl 0x4(%rax), %r8d
leal -0x1(%r8), %eax
cmpl %eax, %edi
jne 0x31c8
cmpl %r8d, %ecx
je 0x3154
cmpl %r8d, %edi
jne 0x31d1
cmpl %eax, %ecx
je 0x3154
movl $0x0, -0x4(%rdx,%rsi,4)
jmp 0x3170
nop