// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %r12
callq 0x28d0
leaq 0x5e73(%rip), %rax      # 0x8d88
movq %rax, (%r12)
movslq (%r15), %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 0x2f86
xorl %ebx, %ebx
movl $0x8, %edi
callq 0x2030
movq 0x10(%r12), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq %rbx, %rbp
jne 0x2f6b
cmpl $0x0, (%r15)
jle 0x308a
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, (%rsp)
xorl %ebp, %ebp
movq %r15, 0x8(%rsp)
movq 0x10(%rsp), %r13
movq 0x10(%r12), %rax
movq (%rax,%rbp,8), %rax
movl %ebp, (%rax)
xorps %xmm0, %xmm0
cvtsi2sdl (%r15), %xmm0
movsd 0x31bc(%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, %eax
movq 0x10(%r12), %rcx
movq (%rcx,%rbp,8), %rcx
movl %eax, 0x4(%rcx)
testl %eax, %eax
movq %r12, %rcx
leaq 0x20(%rsp), %r15
jle 0x3073
xorl %r12d, %r12d
xorl %ebx, %ebx
movq (%r13,%rbp,8), %rdi
movq (%rdi,%r12), %rax
addq %r12, %rdi
xorpd %xmm1, %xmm1
movl $0x62, %esi
movsd 0x2feb(%rip), %xmm0     # 0x6010
movq %r15, %rdx
movq %rcx, %r14
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 0x2fc1(%rip), %xmm0     # 0x6010
movq %r15, %rdx
callq *0x18(%rax)
movq %r14, %rcx
incq %rbx
movq 0x10(%r14), %rax
movq (%rax,%rbp,8), %rax
movslq 0x4(%rax), %rax
addq $0x88, %r12
cmpq %rax, %rbx
jl 0x3008
incq %rbp
movq 0x8(%rsp), %r15
movslq (%r15), %rax
cmpq %rax, %rbp
movq %rcx, %r12
jl 0x2fa9
movl 0x8(%r12), %esi
cmpl $0x3, %esi
jl 0x3121
movq 0x10(%r12), %rax
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 0x30d4
movq 0x8(%rax,%rdx,8), %r10
leal 0x1(%rdi), %r11d
movl $0x2, %r9d
cmpl %r11d, 0x4(%r10)
je 0x310a
movq 0x8(%rax,%rdx,8), %r9
movl 0x4(%r9), %r10d
movl $0x1, %r9d
cmpl %r10d, %esi
je 0x310a
cmpl %r8d, %esi
jne 0x30f8
movl $0x2, %r9d
cmpl %edi, %r10d
je 0x310a
xorl %edi, %esi
xorl %r8d, %r10d
xorl %r9d, %r9d
orl %esi, %r10d
sete %r9b
addl %r9d, %r9d
movl %r9d, (%rcx,%rdx,4)
incq %rdx
movslq 0x8(%r12), %rsi
leaq -0x1(%rsi), %rdi
cmpq %rdi, %rdx
jl 0x30a7
jmp 0x3124
leal -0x1(%rsi), %edi
movq 0x10(%r12), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
movslq %edi, %rdi
movq (%rax,%rdi,8), %r8
movl (%r8), %r9d
movl $0x2, %edi
cmpl (%rdx), %r9d
je 0x3186
movl 0x4(%r8), %r10d
movl 0x4(%rdx), %edx
movl $0x1, %edi
cmpl %edx, %r10d
je 0x3186
movl 0x4(%rcx), %r8d
leal -0x1(%r8), %r9d
cmpl %r9d, %r10d
jne 0x316c
movl $0x2, %edi
cmpl %r8d, %edx
je 0x3186
movslq %esi, %rsi
movq -0x8(%rax,%rsi,8), %rsi
xorl 0x4(%rsi), %r8d
xorl %r9d, %edx
xorl %edi, %edi
orl %r8d, %edx
sete %dil
addl %edi, %edi
movq 0x18(%r12), %rdx
movl %edi, (%rdx)
movslq 0x8(%r12), %rdx
movq -0x10(%rax,%rdx,8), %rsi
movl (%rsi), %edi
cmpl (%rcx), %edi
jne 0x31ac
movq 0x18(%r12), %rax
movl $0x2, -0x4(%rax,%rdx,4)
jmp 0x31c3
movl 0x4(%rsi), %esi
movl 0x4(%rcx), %ecx
cmpl %ecx, %esi
jne 0x31d2
movq 0x18(%r12), %rax
movl $0x1, -0x4(%rax,%rdx,4)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x8(%rax,%rdx,8), %rax
movl 0x4(%rax), %edi
leal -0x1(%rdi), %eax
cmpl %eax, %esi
jne 0x31e5
cmpl %edi, %ecx
je 0x319d
cmpl %edi, %esi
jne 0x31ed
cmpl %eax, %ecx
je 0x319d
movq 0x18(%r12), %rax
movl $0x0, -0x4(%rax,%rdx,4)
jmp 0x31c3