// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %rdi, %rbx
movq 0x2b33(%rip), %rdi      # 0x5fd8
leaq 0xd0e(%rip), %rsi       # 0x41ba
callq 0x2170
movq %rax, %rdi
callq 0x20c0
leaq 0xd0e(%rip), %rdi       # 0x41ce
callq 0x2140
movl 0x84(%rbx), %eax
cltd
idivl 0x70(%rbx)
movl %eax, %r15d
movl 0x88(%rbx), %eax
cltd
idivl 0x74(%rbx)
movl %eax, %r12d
movl 0x7c(%rbx), %esi
movl 0x80(%rbx), %edx
movq (%rbx), %rcx
movq 0x48(%rbx), %r8
movq 0x50(%rbx), %r9
andl $0x0, (%rsp)
callq 0x3828
movslq %r12d, %rax
movq %rax, -0x48(%rbp)
movslq %r15d, %rax
movq %rax, -0x40(%rbp)
pushq $0x1
popq %r15
xorl %eax, %eax
cmpl 0x78(%rbx), %eax
jge 0x37f0
movl %eax, -0x2c(%rbp)
cvtsi2sd %eax, %xmm0
movsd 0x58(%rbx), %xmm2
movsd %xmm0, -0x50(%rbp)
mulsd %xmm0, %xmm2
subsd 0x68(%rbx), %xmm2
movsd 0x60(%rbx), %xmm0
movapd %xmm0, %xmm1
xorpd 0xbfc(%rip), %xmm1      # 0x4140
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm0
movapd %xmm0, -0x70(%rbp)
movsd %xmm2, -0x58(%rbp)
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
callq 0x2280
movsd 0xbf0(%rip), %xmm11     # 0x4160
movsd 0xbdf(%rip), %xmm10     # 0x4158
movl 0x80(%rbx), %ecx
movslq %ecx, %rdx
movq %rdx, -0x38(%rbp)
decq %rdx
movslq 0x7c(%rbx), %rsi
decq %rsi
movq %r15, %rdi
cmpq %rdx, %rdi
jge 0x36b3
movq (%rbx), %r8
movq 0x8(%rbx), %r9
cvtsi2sdl 0x70(%rbx), %xmm1
cvtsi2sdl 0x74(%rbx), %xmm2
movq 0x20(%rbx), %r10
movq 0x28(%rbx), %r11
movq 0x10(%rbx), %r13
movq %r15, %r14
cmpq %rsi, %r14
jge 0x36ab
movq -0x8(%r8,%rdi,8), %rax
movq (%r8,%rdi,8), %r12
movsd (%r12,%r14,8), %xmm3
movsd 0x8(%r12,%r14,8), %xmm4
subsd %xmm3, %xmm4
divsd %xmm1, %xmm4
movapd %xmm3, %xmm6
subsd -0x8(%r12,%r14,8), %xmm6
divsd %xmm1, %xmm6
movq 0x8(%r8,%rdi,8), %r12
movsd (%r12,%r14,8), %xmm7
subsd %xmm3, %xmm7
divsd %xmm2, %xmm7
movapd %xmm3, %xmm8
subsd (%rax,%r14,8), %xmm8
divsd %xmm2, %xmm8
movq (%r10,%rdi,8), %rax
movapd %xmm10, %xmm5
divsd (%rax,%r14,8), %xmm5
movq -0x8(%r10,%rdi,8), %r12
movapd %xmm11, %xmm9
divsd -0x8(%rax,%r14,8), %xmm9
mulsd %xmm6, %xmm9
mulsd %xmm5, %xmm4
addsd %xmm9, %xmm4
divsd %xmm1, %xmm4
movapd %xmm11, %xmm6
divsd (%r12,%r14,8), %xmm6
mulsd %xmm8, %xmm6
mulsd %xmm7, %xmm5
addsd %xmm6, %xmm5
divsd %xmm2, %xmm5
addsd %xmm4, %xmm5
movq (%r9,%rdi,8), %rax
addsd %xmm3, %xmm3
subsd (%rax,%r14,8), %xmm3
movq (%r11,%rdi,8), %rax
movsd (%rax,%r14,8), %xmm4
mulsd %xmm4, %xmm4
movsd 0x58(%rbx), %xmm6
mulsd %xmm6, %xmm6
mulsd %xmm4, %xmm6
mulsd %xmm5, %xmm6
addsd %xmm3, %xmm6
movq (%r13,%rdi,8), %rax
movsd %xmm6, (%rax,%r14,8)
incq %r14
jmp 0x35bc
incq %rdi
jmp 0x3593
movsd -0x58(%rbp), %xmm1
mulsd 0xa90(%rip), %xmm1      # 0x4150
mulsd -0x70(%rbp), %xmm1
mulsd %xmm1, %xmm0
movq 0x10(%rbx), %rsi
movq -0x48(%rbp), %rax
movq (%rsi,%rax,8), %rax
movsd 0x58(%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movq -0x40(%rbp), %rdi
addsd (%rax,%rdi,8), %xmm1
movsd %xmm1, (%rax,%rdi,8)
movslq 0x7c(%rbx), %rdi
testl %edx, %edx
movl $0x0, %r8d
cmovgl %edx, %r8d
xorl %edx, %edx
cmpq %rdx, %r8
je 0x371a
movq (%rsi,%rdx,8), %rax
andq $0x0, (%rax)
andq $0x0, -0x8(%rax,%rdi,8)
incq %rdx
jmp 0x3702
decl %edi
cmpl %edi, %r8d
jl 0x380a
movl -0x2c(%rbp), %eax
cltd
idivl 0x8c(%rbx)
testl %edx, %edx
jne 0x3787
movl %eax, %r13d
movq 0x289b(%rip), %rdi      # 0x5fd8
leaq 0xa9b(%rip), %rsi       # 0x41df
callq 0x2170
movsd -0x50(%rbp), %xmm0
mulsd 0x58(%rbx), %xmm0
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x20c0
movl 0x7c(%rbx), %esi
movl 0x80(%rbx), %edx
movq 0x10(%rbx), %rcx
movq 0x48(%rbx), %r8
movq 0x50(%rbx), %r9
movl %r13d, (%rsp)
callq 0x3828
movl 0x80(%rbx), %ecx
movl 0x7c(%rbx), %eax
testl %eax, %eax
movl $0x0, %edx
cmovlel %edx, %eax
testl %ecx, %ecx
cmovlel %edx, %ecx
xorl %edx, %edx
cmpq %rcx, %rdx
je 0x37e6
movq (%rbx), %rsi
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %r8
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x37e1
movq (%rsi,%rdx,8), %r10
movsd (%r10,%r9,8), %xmm0
movq (%rdi,%rdx,8), %r11
movsd %xmm0, (%r11,%r9,8)
movq (%r8,%rdx,8), %r11
movsd (%r11,%r9,8), %xmm0
movsd %xmm0, (%r10,%r9,8)
andq $0x0, (%r11,%r9,8)
incq %r9
jmp 0x37ae
incq %rdx
jmp 0x379b
movl -0x2c(%rbp), %eax
incl %eax
jmp 0x3510
leaq 0x9f1(%rip), %rdi       # 0x41e8
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140
movq (%rsi), %rcx
movq -0x38(%rbp), %rax
movq -0x8(%rsi,%rax,8), %rax
xorl %edx, %edx
andq $0x0, (%rcx,%rdx)
andq $0x0, (%rax,%rdx)
addq $0x8, %rdx
jmp 0x3818