// File: 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
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq 0x5f4a(%rip), %rdi      # 0xafd8
leaq 0x2115(%rip), %rsi      # 0x71aa
callq 0x21a0
movq %rax, %rdi
movq 0x5f24(%rip), %rsi      # 0xafc8
callq 0x21d0
leaq 0x210e(%rip), %rdi      # 0x71be
callq 0x2170
movq -0x60(%rbp), %rdi
movl 0x84(%rdi), %eax
cltd
idivl 0x70(%rdi)
movl %eax, -0x54(%rbp)
movl 0x88(%rdi), %eax
cltd
idivl 0x74(%rdi)
movl %eax, -0x58(%rbp)
movl $0x0, -0x50(%rbp)
movl 0x7c(%rdi), %esi
movl 0x80(%rdi), %edx
movq (%rdi), %rcx
movq 0x48(%rdi), %r8
movq 0x50(%rdi), %r9
movl -0x50(%rbp), %eax
movl %eax, (%rsp)
callq 0x5780
movl $0x0, -0x44(%rbp)
movq -0x60(%rbp), %rcx
movl -0x44(%rbp), %eax
cmpl 0x78(%rcx), %eax
jge 0x5760
movq -0x60(%rbp), %rax
cvtsi2sdl -0x44(%rbp), %xmm1
movsd 0x58(%rax), %xmm2
movsd 0x68(%rax), %xmm0
movq %xmm0, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x1ffe(%rip), %xmm0     # 0x7148
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd 0x60(%rax), %xmm0
movsd 0x1fd8(%rip), %xmm1     # 0x7138
callq 0x22d0
movq -0x60(%rbp), %rax
movaps %xmm0, %xmm1
movsd -0x78(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x60(%rax), %xmm0
movsd 0x1fb1(%rip), %xmm1     # 0x7138
callq 0x22d0
movq -0x60(%rbp), %rax
movaps %xmm0, %xmm1
movsd 0x1fa5(%rip), %xmm0     # 0x7140
mulsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
cvtsi2sdl -0x44(%rbp), %xmm0
movsd 0x58(%rax), %xmm2
movsd 0x68(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x1f5e(%rip), %xmm1     # 0x7138
callq 0x22d0
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
mulsd %xmm1, %xmm0
callq 0x2300
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movl $0x1, -0x48(%rbp)
movq -0x60(%rbp), %rcx
movl -0x48(%rbp), %eax
movl 0x80(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x5502
movl $0x1, -0x4c(%rbp)
movq -0x60(%rbp), %rcx
movl -0x4c(%rbp), %eax
movl 0x7c(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x54f2
movq -0x60(%rbp), %rax
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl -0x4c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm0
cvtsi2sdl 0x70(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl -0x4c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
subsd (%rcx,%rdx,8), %xmm0
cvtsi2sdl 0x70(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq (%rax), %rcx
movl -0x48(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm0
cvtsi2sdl 0x74(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rcx
movl -0x48(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm0
cvtsi2sdl 0x74(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movq 0x20(%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd 0x1e0c(%rip), %xmm0     # 0x7150
divsd (%rcx,%rdx,8), %xmm0
movsd -0x28(%rbp), %xmm2
movq 0x20(%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl -0x4c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movsd 0x1de5(%rip), %xmm1     # 0x7150
divsd (%rcx,%rdx,8), %xmm1
mulsd -0x30(%rbp), %xmm1
movq %xmm1, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsi2sdl 0x70(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movq 0x20(%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd 0x1d96(%rip), %xmm0     # 0x7150
divsd (%rcx,%rdx,8), %xmm0
movsd -0x38(%rbp), %xmm2
movq 0x20(%rax), %rcx
movl -0x48(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd 0x1d6f(%rip), %xmm1     # 0x7150
divsd (%rcx,%rdx,8), %xmm1
mulsd -0x40(%rbp), %xmm1
movq %xmm1, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsi2sdl 0x74(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x8(%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm1
movq %xmm1, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movq 0x28(%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x1cb3(%rip), %xmm1     # 0x7138
callq 0x22d0
movq -0x60(%rbp), %rax
movsd %xmm0, -0x80(%rbp)
movsd 0x58(%rax), %xmm0
movsd 0x1c98(%rip), %xmm1     # 0x7138
callq 0x22d0
movsd -0x88(%rbp), %xmm1
movq -0x60(%rbp), %rax
movaps %xmm0, %xmm2
movsd -0x80(%rbp), %xmm0
mulsd %xmm2, %xmm0
movsd -0x20(%rbp), %xmm2
addsd -0x18(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x5227
jmp 0x54f4
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x5208
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
movslq -0x58(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x54(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd 0x58(%rax), %xmm0
movsd 0x1c08(%rip), %xmm1     # 0x7138
callq 0x22d0
movsd -0x90(%rbp), %xmm1
movq -0x60(%rbp), %rax
movsd -0x10(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rax), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x48(%rbp)
movq -0x60(%rbp), %rcx
movl -0x48(%rbp), %eax
movl 0x80(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x55bd
movq -0x60(%rbp), %rcx
movq 0x10(%rcx), %rax
movslq -0x48(%rbp), %rdx
movq (%rax,%rdx,8), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rcx), %rax
movslq -0x48(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl 0x7c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x556a
movl $0x0, -0x4c(%rbp)
movq -0x60(%rbp), %rcx
movl -0x48(%rbp), %eax
movl 0x7c(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x5617
movq -0x60(%rbp), %rcx
movq 0x10(%rcx), %rax
movq (%rax), %rax
movslq -0x4c(%rbp), %rdx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rdx,8)
movq 0x10(%rcx), %rax
movl 0x80(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x55c4
movq -0x60(%rbp), %rcx
movl -0x44(%rbp), %eax
cltd
idivl 0x8c(%rcx)
cmpl $0x0, %edx
jne 0x5697
movq -0x60(%rbp), %rcx
movl -0x44(%rbp), %eax
cltd
idivl 0x8c(%rcx)
movl %eax, -0x50(%rbp)
movq 0x5996(%rip), %rdi      # 0xafd8
leaq 0x1b86(%rip), %rsi      # 0x71cf
callq 0x21a0
movq %rax, %rdi
movq -0x60(%rbp), %rax
cvtsi2sdl -0x44(%rbp), %xmm0
mulsd 0x58(%rax), %xmm0
callq 0x2320
movq %rax, %rdi
movq 0x595a(%rip), %rsi      # 0xafc8
callq 0x21d0
movq -0x60(%rbp), %rdi
movl 0x7c(%rdi), %esi
movl 0x80(%rdi), %edx
movq 0x10(%rdi), %rcx
movq 0x48(%rdi), %r8
movq 0x50(%rdi), %r9
movl -0x50(%rbp), %eax
movl %eax, (%rsp)
callq 0x5780
movl $0x0, -0x48(%rbp)
movq -0x60(%rbp), %rcx
movl -0x48(%rbp), %eax
cmpl 0x80(%rcx), %eax
jge 0x5750
movl $0x0, -0x4c(%rbp)
movq -0x60(%rbp), %rcx
movl -0x4c(%rbp), %eax
cmpl 0x7c(%rcx), %eax
jge 0x5740
movq -0x60(%rbp), %rax
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x8(%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd %xmm0, (%rcx,%rdx,8)
movq 0x10(%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movsd %xmm0, (%rcx,%rdx,8)
movq 0x10(%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x56b8
jmp 0x5742
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x569e
jmp 0x5752
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x5100
leaq 0x1a71(%rip), %rdi      # 0x71d8
callq 0x2170
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)