// File: /workspace/github_cpp_makefile_star2_O2/suhasjains[P]AMR-Solver/src/block.cpp
// Function: myOctree::Block::Block(double, double, double, double, double, double)
Block::Block( double x1, double x2, double y1, double y2, double z1, double z2 ) : x_min(x1), x_max(x2), y_min(y1), y_max(y2), z_min(z1), z_max(z2) {
//  		std::cerr << "Parametrized constructor of block is working" << std::endl;

	max_gradient = 0.0;

        dx = ( x_max - x_min ) / iNx;
        dy = ( y_max - y_min ) / iNy;
        dz = ( z_max - z_min ) / iNz;

	//std::cerr << dz << std::endl;

        //printf("dx=%g, dy=%g, dz=%g \n", dx, dy, dz);

        x_centre = (x_min + x_max ) / 2.0;
        y_centre = (y_min + y_max ) / 2.0;
        z_centre = (z_min + z_max ) / 2.0;

        //dynamical allocation of the objects
        VecField mesh_field(iNx+2*pad,iNy+2*pad,iNz+2*pad, "mesh");
        mesh = new VecField(mesh_field);
        
        Field field_field(iNx+2*pad,iNy+2*pad,iNz+2*pad, "field");
	field = new Field(field_field);

	scalarfields = new Field* [scalar_fields.size()];
	for(int i = 0; i<scalar_fields.size() ; i++) {
        	Field field_field(iNx+2*pad,iNy+2*pad,iNz+2*pad, scalar_fields[i]);
	       	scalarfields[i] = new Field(field_field);	
	}       

	vectorfields = new VecField* [vector_fields.size()];
	for(int i = 0; i<vector_fields.size() ; i++) {
        	VecField vec_field(iNx+2*pad,iNy+2*pad,iNz+2*pad, vector_fields[i]);
	       	vectorfields[i] = new VecField(vec_field);	
	}       

	//std::cerr << "Hi" << z_max << std::endl;
	
	//storing cell centre locations in mesh vector field
	for(int i=0;i<mesh->Nx;i++) {
		for(int j=0;j<mesh->Ny;j++) {
			for(int k=0;k<mesh->Nz;k++) {
				mesh->x[i][j][k] = x_min - pad*dx + dx*(i + 0.5);	 
				mesh->y[i][j][k] = y_min - pad*dy + dy*(j + 0.5);	 
				mesh->z[i][j][k] = z_min - pad*dz + dz*(k + 0.5);	 
			}
		}
	}

	//dynamic allocation of domain masking - stored here because it is common for all fields. 
	flag = new Mask** [iNx+2*pad];
	for(int i=0;i<(iNx+2*pad);i++) {
		flag[i] = new Mask* [iNy+2*pad];
 		for(int j=0;j<(iNy+2*pad);j++) {
                  	flag[i][j] = new Mask [iNz+2*pad];
           	}
        }

	set_domain_masking();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %rbx
movsd %xmm0, 0x40(%rdi)
movsd %xmm1, 0x48(%rdi)
movsd %xmm2, 0x50(%rdi)
movsd %xmm3, 0x58(%rdi)
movsd %xmm4, 0x60(%rdi)
movsd %xmm5, 0x68(%rdi)
andq $0x0, 0x20(%rdi)
movapd %xmm1, %xmm6
movl 0xeaeb(%rip), %r14d     # 0x13648
cvtsi2sd %r14d, %xmm7
subsd %xmm0, %xmm6
divsd %xmm7, %xmm6
movsd %xmm6, 0x70(%rdi)
movapd %xmm3, %xmm6
subsd %xmm2, %xmm6
movl 0xeace(%rip), %r15d     # 0x1364c
cvtsi2sd %r15d, %xmm7
divsd %xmm7, %xmm6
movsd %xmm6, 0x78(%rdi)
movapd %xmm5, %xmm6
subsd %xmm4, %xmm6
movl 0xeab5(%rip), %r12d     # 0x13650
cvtsi2sd %r12d, %xmm7
divsd %xmm7, %xmm6
movsd %xmm6, 0x80(%rdi)
addsd %xmm1, %xmm0
movsd 0xa5d0(%rip), %xmm1     # 0xf188
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rdi)
addsd %xmm3, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, 0x30(%rdi)
addsd %xmm5, %xmm4
mulsd %xmm1, %xmm4
movsd %xmm4, 0x38(%rdi)
movl 0xe5ee(%rip), %r13d     # 0x131d0
leaq 0xa607(%rip), %rsi      # 0xf1f0
leaq -0x80(%rbp), %rdi
leaq -0x1a0(%rbp), %rdx
callq 0x2d10
leal (%r12,%r13,2), %ecx
leal (%r15,%r13,2), %edx
leal (%r14,%r13,2), %esi
leaq -0x230(%rbp), %rdi
leaq -0x80(%rbp), %r8
callq 0x5d40
leaq -0x80(%rbp), %rdi
callq 0x2100
movl $0x90, %edi
callq 0x21e0
movq %rax, %r14
leaq -0x230(%rbp), %rsi
movq %rax, %rdi
callq 0x5fa8
movq %r14, (%rbx)
movl 0xea04(%rip), %r14d     # 0x13648
movl 0xe585(%rip), %r15d     # 0x131d0
movl 0xe9fa(%rip), %r12d     # 0x1364c
movl 0xe9f7(%rip), %r13d     # 0x13650
leaq 0xa595(%rip), %rsi      # 0xf1f5
leaq -0x60(%rbp), %rdi
leaq -0x1a0(%rbp), %rdx
callq 0x2d10
leal (%r13,%r15,2), %ecx
leal (%r12,%r15,2), %edx
leal (%r14,%r15,2), %esi
leaq -0x110(%rbp), %rdi
leaq -0x60(%rbp), %r8
callq 0x62b4
leaq -0x60(%rbp), %rdi
callq 0x2100
pushq $0x50
popq %rdi
callq 0x21e0
movq %rax, %r14
leaq -0x110(%rbp), %rsi
movq %rax, %rdi
callq 0x646c
movq %r14, 0x8(%rbx)
movq 0xe965(%rip), %r15      # 0x13620
movq 0xe956(%rip), %rcx      # 0x13618
movq %r15, %rax
movq %rcx, %r13
subq %rcx, %rax
movq %rax, %rdi
sarq $0x2, %rdi
testq %rax, %rax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, 0x10(%rbx)
xorl %eax, %eax
leaq -0xc0(%rbp), %r14
xorl %r12d, %r12d
movq %r13, %rsi
subq %rsi, %r15
sarq $0x5, %r15
cmpq %r12, %r15
jbe 0x4da9
movq %r12, -0x40(%rbp)
movl 0xe93a(%rip), %ecx      # 0x13648
movq %rcx, -0x30(%rbp)
movl 0xe4b7(%rip), %r12d     # 0x131d0
movl 0xe92c(%rip), %r15d     # 0x1364c
movl 0xe929(%rip), %r13d     # 0x13650
movq %rax, -0x38(%rbp)
addq %rax, %rsi
movq %r14, %rdi
callq 0x2270
leal (%r13,%r12,2), %ecx
leal (%r15,%r12,2), %edx
movq -0x30(%rbp), %rax
leal (%rax,%r12,2), %esi
leaq -0x1a0(%rbp), %r15
movq %r15, %rdi
movq %r14, %r8
callq 0x62b4
movq %r14, %rdi
callq 0x2100
pushq $0x50
popq %rdi
callq 0x21e0
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x646c
movq 0x10(%rbx), %rax
movq -0x40(%rbp), %r12
movq %r13, (%rax,%r12,8)
movq %r15, %rdi
callq 0x65b0
incq %r12
movq 0xe88b(%rip), %r15      # 0x13620
movq 0xe87c(%rip), %rsi      # 0x13618
movq -0x38(%rbp), %rax
addq $0x20, %rax
jmp 0x4cf4
movq 0xe888(%rip), %r15      # 0x13638
movq 0xe879(%rip), %rcx      # 0x13630
movq %r15, %rax
movq %rcx, %r13
subq %rcx, %rax
movq %rax, %rdi
sarq $0x2, %rdi
testq %rax, %rax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, 0x18(%rbx)
xorl %eax, %eax
leaq -0xa0(%rbp), %r14
xorl %r12d, %r12d
movq %r13, %rsi
subq %rsi, %r15
sarq $0x5, %r15
cmpq %r12, %r15
jbe 0x4ea2
movq %r12, -0x40(%rbp)
movl 0xe845(%rip), %ecx      # 0x13648
movq %rcx, -0x30(%rbp)
movl 0xe3c2(%rip), %r13d     # 0x131d0
movl 0xe837(%rip), %r15d     # 0x1364c
movl 0xe834(%rip), %r12d     # 0x13650
movq %rax, -0x38(%rbp)
addq %rax, %rsi
movq %r14, %rdi
callq 0x2270
leal (%r12,%r13,2), %ecx
leal (%r15,%r13,2), %edx
movq -0x30(%rbp), %rax
leal (%rax,%r13,2), %esi
leaq -0x1a0(%rbp), %r15
movq %r15, %rdi
movq %r14, %r8
callq 0x5d40
movq %r14, %rdi
callq 0x2100
movl $0x90, %edi
callq 0x21e0
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x5fa8
movq 0x18(%rbx), %rax
movq -0x40(%rbp), %rcx
movq %r12, (%rax,%rcx,8)
movq %rcx, %r12
movq %r15, %rdi
callq 0x61cc
incq %r12
movq 0xe7aa(%rip), %r15      # 0x13638
movq 0xe79b(%rip), %rsi      # 0x13630
movq -0x38(%rbp), %rax
addq $0x20, %rax
jmp 0x4de9
movq (%rbx), %rax
movslq 0xe324(%rip), %r14      # 0x131d0
cvtsi2sd %r14d, %xmm0
movl (%rax), %ecx
xorpd 0xa315(%rip), %xmm0     # 0xf1d0
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
xorl %esi, %esi
cmpq %rcx, %rsi
je 0x4fbd
movl 0x4(%rax), %edi
cvtsi2sd %esi, %xmm1
addsd 0xa2ac(%rip), %xmm1     # 0xf188
testl %edi, %edi
cmovlel %edx, %edi
xorl %r8d, %r8d
cmpq %rdi, %r8
je 0x4fb5
movl 0x8(%rax), %r9d
cvtsi2sd %r8d, %xmm2
addsd 0xa28a(%rip), %xmm2     # 0xf188
testl %r9d, %r9d
cmovlel %edx, %r9d
xorl %r10d, %r10d
cmpq %r10, %r9
je 0x4fad
movsd 0x70(%rbx), %xmm3
movapd %xmm0, %xmm4
mulsd %xmm3, %xmm4
addsd 0x40(%rbx), %xmm4
mulsd %xmm1, %xmm3
addsd %xmm4, %xmm3
movq 0x10(%rax), %r11
movq (%r11,%rsi,8), %r11
movq (%r11,%r8,8), %r11
movsd %xmm3, (%r11,%r10,8)
movsd 0x78(%rbx), %xmm3
movapd %xmm0, %xmm4
mulsd %xmm3, %xmm4
addsd 0x50(%rbx), %xmm4
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
movq 0x18(%rax), %r11
movq (%r11,%rsi,8), %r11
movq (%r11,%r8,8), %r11
movsd %xmm3, (%r11,%r10,8)
movsd 0x80(%rbx), %xmm3
movapd %xmm0, %xmm4
mulsd %xmm3, %xmm4
addsd 0x60(%rbx), %xmm4
cvtsi2sd %r10d, %xmm5
addsd 0xa1fd(%rip), %xmm5     # 0xf188
mulsd %xmm3, %xmm5
addsd %xmm4, %xmm5
movq 0x20(%rax), %r11
movq (%r11,%rsi,8), %r11
movq (%r11,%r8,8), %r11
movsd %xmm5, (%r11,%r10,8)
incq %r10
jmp 0x4f08
incq %r8
jmp 0x4ee4
incq %rsi
jmp 0x4ec4
movslq 0xe684(%rip), %rax      # 0x13648
leaq (%rax,%r14,2), %rax
movq %rax, %rdi
shlq $0x3, %rdi
movq %rax, -0x30(%rbp)
testl %eax, %eax
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
addq %r14, %r14
movq %rax, 0x88(%rbx)
movslq %r14d, %rax
addl 0xe657(%rip), %r14d     # 0x1364c
movslq %r14d, %r12
leaq (,%r12,8), %rdx
movslq 0xe649(%rip), %rcx      # 0x13650
addq %rax, %rcx
movq %rcx, %r15
shlq $0x2, %r15
testl %ecx, %ecx
pushq $-0x1
popq %rax
cmovsq %rax, %r15
xorl %r13d, %r13d
testl %r12d, %r12d
cmovsq %rax, %rdx
movq %rdx, -0x38(%rbp)
cmovlel %r13d, %r12d
movq -0x30(%rbp), %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movq %rax, -0x30(%rbp)
cmpq -0x30(%rbp), %r13
je 0x5081
movq -0x38(%rbp), %rdi
callq 0x2030
movq 0x88(%rbx), %rcx
movq %rax, (%rcx,%r13,8)
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x507c
movq %r15, %rdi
callq 0x2030
movq 0x88(%rbx), %rcx
movq (%rcx,%r13,8), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
jmp 0x505b
incq %r13
jmp 0x503e
movq %rbx, %rdi
callq 0x519c
leaq -0x110(%rbp), %rdi
callq 0x65b0
leaq -0x230(%rbp), %rdi
callq 0x61cc
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x50
popq %rsi
movq %r14, %rdi
callq 0x21f0
jmp 0x517b
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x2100
jmp 0x5187
jmp 0x50ee
movq %rax, %rbx
movl $0x90, %esi
movq %r14, %rdi
callq 0x21f0
jmp 0x5187
movq %rax, %rbx
jmp 0x5187
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x2100
jmp 0x5193
movq %rax, %rbx
jmp 0x5193
jmp 0x5178
jmp 0x5178
movq %rax, %rbx
movl $0x90, %esi
movq %r12, %rdi
callq 0x21f0
jmp 0x5128
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
callq 0x61cc
jmp 0x517b
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
jmp 0x516f
jmp 0x5178
movq %rax, %rbx
pushq $0x50
popq %rsi
movq %r13, %rdi
callq 0x21f0
jmp 0x5157
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
callq 0x65b0
jmp 0x517b
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x2100
jmp 0x517b
jmp 0x5178
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x65b0
leaq -0x230(%rbp), %rdi
callq 0x61cc
movq %rbx, %rdi
callq 0x2320
nop