// File: /workspace/github_cpp_makefile_star2_O1/Gilaverbuch[P]FD_2D_WAVE/Field.cpp
// Function: Field::Propagator()
void Field::Propagator(){
	
	double source, d2x, d2y, A, B, C, D;
	int i, j, k, itteration, pos_s_x, pos_s_y;
	std::cout << "wave propagation!!!" << std::endl;
	system("rm results/*.txt");


	pos_s_x = int(x_source/dx);
	pos_s_y = int(y_source/dy);
	itteration = 0;
	print_to_file(elements_x, elements_y, U, x, y, itteration);


	// propagator

	for (i=0; i<steps; i++){
		source = -2 * (i*dt - source_time_delay) * pow(frequency, 2) * exp(-1 * pow(frequency, 2) * pow((i*dt - source_time_delay), 2));
		

		for (j=1; j<(elements_y-1); j++){
			for (k=1; k<(elements_x-1); k++){

				A = (U[j][k+1] - U[j][k])/dx;
				B = (U[j][k] - U[j][k-1])/dx;
				C = (U[j+1][k] - U[j][k])/dy;
				D = (U[j][k] - U[j-1][k])/dy;

				d2x = ((1/rho[j][k])*A - (1/rho[j][k-1])*B)/(dx);
				d2y = ((1/rho[j][k])*C - (1/rho[j-1][k])*D)/(dy);

				// d2x = (U[j][k-1] - 2*U[j][k] + U[j][k+1])/(pow(dx,2));

				// d2y =  (U[j-1][k] - 2*U[j][k] + U[j+1][k])/(pow(dy,2));

				U_future[j][k] = 2*U[j][k] - U_past[j][k] + pow(vel[j][k],2) * pow(dt,2) * (d2y + d2x);
			}
		}

		U_future[pos_s_y][pos_s_x] = U_future[pos_s_y][pos_s_x] + pow(dt,2) * source;


		for (j=0; j<(elements_y-1); j++){
			U_future[j][0] = 0;
			U_future[j][elements_x-1] = 0;

		} 

		for (k=0; j<(elements_x-1); k++){
			U_future[0][k] = 0;
			U_future[elements_y-1][k] = 0;

		} 
		

		if (i%print_every==0){
			itteration = i/print_every;
			std::cout << "time is " << i*dt << std::endl;

			print_to_file(elements_x, elements_y, U_future, x, y, itteration);
		}

		for (j=0; j<elements_y; j++){
			for (k=0; k<elements_x; k++){

				U_past[j][k] = U[j][k];
				U[j][k] = U_future[j][k];
				U_future[j][k] = 0;
			}
		}

	}


	system("mv wave_signal*.txt results/");	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movq 0x356f(%rip), %r14      # 0x6fd8
leaq 0x1772(%rip), %rsi      # 0x51e2
movl $0x13, %edx
movq %r14, %rdi
callq 0x21b0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leaq 0x174b(%rip), %rdi      # 0x51f6
callq 0x2140
movl 0x84(%rbx), %r14d
movl 0x70(%rbx), %r12d
movl 0x88(%rbx), %r15d
movl 0x74(%rbx), %r13d
movl 0x7c(%rbx), %esi
movl 0x80(%rbx), %edx
movq (%rbx), %rcx
movq 0x48(%rbx), %r8
movq 0x50(%rbx), %r9
movl $0x0, (%rsp)
callq 0x3e9a
cmpl $0x0, 0x78(%rbx)
jle 0x3e7f
movl %r15d, %eax
cltd
idivl %r13d
movl %eax, %ecx
movl %r14d, %eax
cltd
idivl %r12d
movslq %ecx, %rcx
movq %rcx, -0x40(%rbp)
cltq
movq %rax, -0x38(%rbp)
xorl %r12d, %r12d
movl %r12d, -0x2c(%rbp)
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
movsd 0x58(%rbx), %xmm0
movsd %xmm1, -0x48(%rbp)
mulsd %xmm1, %xmm0
subsd 0x68(%rbx), %xmm0
movapd %xmm0, %xmm1
mulsd 0x1625(%rip), %xmm1     # 0x5160
movsd %xmm1, -0x50(%rbp)
movsd 0x60(%rbx), %xmm2
movapd %xmm2, %xmm1
xorpd 0x162f(%rip), %xmm1     # 0x5180
movapd %xmm2, -0x90(%rbp)
mulsd %xmm2, %xmm1
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm0
callq 0x2280
movsd 0x15fd(%rip), %xmm11    # 0x5170
movsd 0x15ec(%rip), %xmm10    # 0x5168
movslq 0x80(%rbx), %rdx
leal -0x1(%rdx), %eax
movl %eax, %ecx
movq %rdx, -0x58(%rbp)
cmpq $0x3, %rdx
jl 0x3cf9
movl 0x7c(%rbx), %eax
movq %rax, -0x80(%rbp)
decl %eax
movq (%rbx), %rsi
xorps %xmm1, %xmm1
cvtsi2sdl 0x70(%rbx), %xmm1
movq 0x8(%rbx), %rdx
movq %rdx, -0x78(%rbp)
xorps %xmm2, %xmm2
cvtsi2sdl 0x74(%rbx), %xmm2
movq 0x20(%rbx), %rdx
movq %rdx, -0x70(%rbp)
movq 0x28(%rbx), %rdx
movq %rdx, -0x68(%rbp)
movq 0x10(%rbx), %rdx
movq %rdx, -0x60(%rbp)
leaq -0x8(,%rax,8), %r11
movl $0x1, %r15d
cmpl $0x3, -0x80(%rbp)
jl 0x3ced
movq -0x8(%rsi,%r15,8), %r13
movq (%rsi,%r15,8), %rax
movq 0x8(%rsi,%r15,8), %r12
movq -0x70(%rbp), %rdx
movq -0x8(%rdx,%r15,8), %rdi
movq (%rdx,%r15,8), %r9
movq -0x78(%rbp), %rdx
movq (%rdx,%r15,8), %r10
movq -0x68(%rbp), %rdx
movq (%rdx,%r15,8), %r14
movq -0x60(%rbp), %rdx
movq (%rdx,%r15,8), %rdx
xorl %r8d, %r8d
movsd 0x8(%rax,%r8), %xmm3
movsd 0x10(%rax,%r8), %xmm4
subsd %xmm3, %xmm4
movapd %xmm3, %xmm6
subsd (%rax,%r8), %xmm6
divsd %xmm1, %xmm4
divsd %xmm1, %xmm6
movsd 0x8(%r12,%r8), %xmm7
subsd %xmm3, %xmm7
divsd %xmm2, %xmm7
movapd %xmm3, %xmm8
subsd 0x8(%r13,%r8), %xmm8
divsd %xmm2, %xmm8
movapd %xmm10, %xmm5
divsd 0x8(%r9,%r8), %xmm5
movapd %xmm11, %xmm9
divsd (%r9,%r8), %xmm9
mulsd %xmm6, %xmm9
mulsd %xmm5, %xmm4
addsd %xmm9, %xmm4
divsd %xmm1, %xmm4
movapd %xmm11, %xmm6
divsd 0x8(%rdi,%r8), %xmm6
mulsd %xmm8, %xmm6
mulsd %xmm7, %xmm5
addsd %xmm6, %xmm5
divsd %xmm2, %xmm5
addsd %xmm4, %xmm5
addsd %xmm3, %xmm3
subsd 0x8(%r10,%r8), %xmm3
movsd 0x8(%r14,%r8), %xmm4
mulsd %xmm4, %xmm4
movsd 0x58(%rbx), %xmm6
mulsd %xmm6, %xmm6
mulsd %xmm4, %xmm6
mulsd %xmm5, %xmm6
addsd %xmm3, %xmm6
movsd %xmm6, 0x8(%rdx,%r8)
addq $0x8, %r8
cmpq %r8, %r11
jne 0x3c20
incq %r15
cmpq %rcx, %r15
jne 0x3be0
movapd -0x90(%rbp), %xmm2
mulsd %xmm2, %xmm2
movsd -0x50(%rbp), %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x10(%rbx), %rdx
movq -0x40(%rbp), %rax
movq (%rdx,%rax,8), %rax
movsd 0x58(%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movq -0x38(%rbp), %rsi
addsd (%rax,%rsi,8), %xmm1
movsd %xmm1, (%rax,%rsi,8)
xorl %eax, %eax
movq -0x58(%rbp), %r9
cmpl $0x2, %r9d
movl $0x0, %r8d
movl -0x2c(%rbp), %r12d
jl 0x3d69
movslq 0x7c(%rbx), %rsi
xorl %eax, %eax
movq (%rdx,%rax,8), %rdi
movq %r8, (%rdi)
movq %r8, -0x8(%rdi,%rsi,8)
incq %rax
cmpq %rax, %rcx
jne 0x3d55
movl 0x7c(%rbx), %ecx
decl %ecx
cmpl %ecx, %eax
jge 0x3d8c
movq (%rdx), %rsi
movq -0x8(%rdx,%r9,8), %rdx
xorl %edi, %edi
movq %r8, (%rsi,%rdi)
movq %r8, (%rdx,%rdi)
addq $0x8, %rdi
cmpl %ecx, %eax
jl 0x3d7c
movl %r12d, %eax
cltd
idivl 0x8c(%rbx)
testl %edx, %edx
jne 0x3e12
movl %eax, %r13d
movl $0x8, %edx
movq 0x322f(%rip), %r14      # 0x6fd8
movq %r14, %rdi
leaq 0x1454(%rip), %rsi      # 0x5207
callq 0x21b0
movsd -0x48(%rbp), %xmm0
mulsd 0x58(%rbx), %xmm0
movq %r14, %rdi
callq 0x2230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl 0x7c(%rbx), %esi
movl 0x80(%rbx), %edx
movq 0x10(%rbx), %rcx
movq 0x48(%rbx), %r8
movq 0x50(%rbx), %r9
movl %r13d, (%rsp)
callq 0x3e9a
movslq 0x80(%rbx), %rax
testq %rax, %rax
jle 0x3e72
movl 0x7c(%rbx), %ecx
movq (%rbx), %rdx
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdi
xorl %r8d, %r8d
testl %ecx, %ecx
jle 0x3e6a
movq (%rdx,%r8,8), %r9
movq (%rsi,%r8,8), %r10
movq (%rdi,%r8,8), %r11
xorl %r14d, %r14d
movsd (%r9,%r14,8), %xmm0
movsd %xmm0, (%r10,%r14,8)
movsd (%r11,%r14,8), %xmm0
movsd %xmm0, (%r9,%r14,8)
movq $0x0, (%r11,%r14,8)
incq %r14
cmpq %r14, %rcx
jne 0x3e42
incq %r8
cmpq %rax, %r8
jne 0x3e2f
incl %r12d
cmpl 0x78(%rbx), %r12d
jl 0x3b10
leaq 0x138a(%rip), %rdi      # 0x5210
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140
nop