// File: /workspace/github_cpp_makefile_star2_O1/jamesliu516[P]amrdg2d/spatial_discretization.cpp
// Function: spatial_discretize_v(bodygridclass*)
void spatial_discretize_v(OctCell* un)
{
   double tmp92=0.0;
   double tmp93=0.0;
   double tmp94=0.0;  
   double tmpx=0.0, tmpy=0.0;
   
   double uapp[4][3][3]={0.0};
   double dx,dy, dxpdy;
   dx=un->dx;
   dy=un->dy;
   dxpdy=dx*dy;
   
   for(short j=0; j<4; j++) {
      for(short imm=0; imm<3;imm++) {
	   for(short jmm=0; jmm<3; jmm++) {
	       uapp[j][jmm][imm]=approx_sol(gspt[jmm], gspt[imm], un->dof[j], nDOF);  //u(x,y)
	    }
	}
   }
	
  double pre[3][3]={0.0};
  double pre1[3][3]={0.0};	
  	
  for(short imm=0; imm<3;imm++) {
     for(short jmm=0; jmm<3; jmm++) {
	      pre[jmm][imm]=GAM11 *(uapp[3][jmm][imm]-0.5*(uapp[1][jmm][imm]*uapp[1][jmm][imm]/uapp[0][jmm][imm]
	          + uapp[2][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm]));	          
     }
  }
          
  double flxfunx[4][3][3]={0.0};
  double flxfuny[4][3][3]={0.0};
  
  for(short imm=0; imm<3;imm++) {
     for(short jmm=0; jmm<3; jmm++) {

	         flxfunx[0][jmm][imm]=uapp[1][jmm][imm]; 
	         flxfuny[0][jmm][imm]=uapp[2][jmm][imm]; 	
	                  
	         flxfunx[1][jmm][imm]=uapp[1][jmm][imm]*uapp[1][jmm][imm]/uapp[0][jmm][imm] + pre[jmm][imm];

	         flxfunx[2][jmm][imm] = flxfuny[1][jmm][imm] = uapp[1][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm];
	         
	         flxfuny[2][jmm][imm]=uapp[2][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm] + pre[jmm][imm];	
	         
	         flxfunx[3][jmm][imm] = (uapp[3][jmm][imm] + pre[jmm][imm])* uapp[1][jmm][imm]/uapp[0][jmm][imm];
	         flxfuny[3][jmm][imm] = (uapp[3][jmm][imm] + pre[jmm][imm])* uapp[2][jmm][imm]/uapp[0][jmm][imm];
	           	         	              	     
	      }
  }
  
//体积积分项
     
// euler equation for aerodynamics 
//uapp[j][jmm][imm]
    for(short j=0; j<4;++j) {
       tmp92=0.0;
	tmp93=0.0;
	tmp94=0.0;	
	tmpx=tmpy=0.0;	
	
//base function: phi_i(x)  &  psi_j(y)
	for(short imm=0; imm < 3;imm++) {
	   for(short jmm=0; jmm < 3; jmm++) {
	      tmp92 += flxfunx[j][jmm][imm]*wei[imm]*wei[jmm];
	      
	      tmp93 += flxfuny[j][jmm][imm]*wei[imm]*wei[jmm];
	      }
	 }	 

	 tmp92 *=  0.25*dxpdy;
	 tmp93 *=  0.25*dxpdy;	 
	       
        un->residual[j][1] -= 2.0/dx * tmp92;
        un->residual[j][2] -= 2.0/dy * tmp93;
        
        tmp92=tmp93=0.0;
  
  //base function: phi_i(x)*psi_j(y), phi_i(x)^2-1.0/3.0, &  psi_j(y)^2-1.0/3
     if(nDOF==6) {
	 for(short imm=0; imm<3;imm++) {
	   for(short jmm=0; jmm<3; jmm++) {
	      tmp93 += flxfuny[j][jmm][imm] *gspt[jmm]*wei[imm]*wei[jmm];   //fy*x 
	      
	      tmp94 += flxfunx[j][jmm][imm] *gspt[imm]*wei[imm]*wei[jmm];   //fx*y 
	      
	      tmpx += flxfunx[j][jmm][imm] *gspt[jmm]*wei[imm]*wei[jmm];  //fx*x
	      tmpy += flxfuny[j][jmm][imm] *gspt[imm]*wei[imm]*wei[jmm];	//fy*y      
	      }
	  }

	  tmp94 *= 0.25*dxpdy;
	  tmp93 *= 0.25*dxpdy;
	  tmpx *= 0.25*dxpdy;
	  tmpy *= 0.25*dxpdy;

	  un->residual[j][3] -= 2.0/dx * tmp94 + 2.0/dy * tmp93;
	
	  un->residual[j][4] -= 4.0/dx * tmpx;
	  un->residual[j][5] -= 4.0/dy * tmpy;  
	  	
       }
    } //end for
//=====
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3f8, %rsp            # imm = 0x3F8
movq %rdi, %rbx
leaq 0x2d0(%rsp), %r14
xorl %r15d, %r15d
movl $0x120, %edx            # imm = 0x120
movq %r14, %rdi
xorl %esi, %esi
callq 0x3120
movups 0x288(%rbx), %xmm0
movaps %xmm0, 0x30(%rsp)
movq %rbx, 0x8(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0xddeb(%rip), %r12      # 0x1e850
movq %r15, 0x18(%rsp)
leaq (%r15,%r15,2), %r15
shlq $0x4, %r15
addq 0x10(%rsp), %r15
movq %r14, 0x20(%rsp)
movq %r14, %rbx
xorl %ebp, %ebp
movsd (%r12,%rbp,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbx, %r14
xorl %r13d, %r13d
movsd (%r13,%r12), %xmm0
movsd 0x28(%rsp), %xmm1
movq %r15, %rdi
movl $0x6, %esi
callq 0xdc4c
movsd %xmm0, (%r14)
addq $0x8, %r13
addq $0x18, %r14
cmpq $0x18, %r13
jne 0x10a93
incq %rbp
addq $0x8, %rbx
cmpq $0x3, %rbp
jne 0x10a81
movq 0x18(%rsp), %r15
incq %r15
movq 0x20(%rsp), %r14
addq $0x48, %r14
cmpq $0x4, %r15
jne 0x10a65
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rax
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
movq $0x0, 0x40(%rax)
leaq 0x3a8(%rsp), %rcx
xorl %edx, %edx
movsd 0xd62b(%rip), %xmm0     # 0x1e140
movsd 0xd68b(%rip), %xmm1     # 0x1e1a8
movq $-0x48, %rsi
movsd -0x90(%rcx,%rsi), %xmm2
movsd -0x48(%rcx,%rsi), %xmm3
movhpd (%rcx,%rsi), %xmm3      # xmm3 = xmm3[0],mem[0]
mulpd %xmm3, %xmm3
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm3
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
addsd %xmm3, %xmm2
mulsd %xmm0, %xmm2
addsd 0x48(%rcx,%rsi), %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, 0x48(%rax,%rsi)
addq $0x18, %rsi
jne 0x10b24
incq %rdx
addq $0x8, %rcx
addq $0x8, %rax
cmpq $0x3, %rdx
jne 0x10b1d
leaq 0x1b0(%rsp), %r14
xorl %r13d, %r13d
movl $0x120, %edx            # imm = 0x120
movq %r14, %rdi
xorl %esi, %esi
callq 0x3120
leaq 0x90(%rsp), %r15
movl $0x120, %edx            # imm = 0x120
movq %r15, %rdi
xorl %esi, %esi
callq 0x3120
leaq 0x2d0(%rsp), %rax
leaq 0x40(%rsp), %rcx
movq 0x8(%rsp), %r11
xorl %edx, %edx
movsd 0x48(%rax,%rdx), %xmm0
movsd %xmm0, (%r14,%rdx)
movsd 0x90(%rax,%rdx), %xmm1
movsd %xmm1, (%r15,%rdx)
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
movsd (%rax,%rdx), %xmm3
divsd %xmm3, %xmm2
movsd (%rcx,%rdx), %xmm4
addsd %xmm4, %xmm2
movsd %xmm2, 0x48(%r14,%rdx)
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm3, %xmm2
movsd %xmm2, 0x48(%r15,%rdx)
movsd %xmm2, 0x90(%r14,%rdx)
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm3, %xmm2
addsd %xmm4, %xmm2
movsd %xmm2, 0x90(%r15,%rdx)
addsd 0xd8(%rax,%rdx), %xmm4
mulsd %xmm4, %xmm0
divsd %xmm3, %xmm0
movsd %xmm0, 0xd8(%r14,%rdx)
mulsd %xmm1, %xmm4
divsd %xmm3, %xmm4
movsd %xmm4, 0xd8(%r15,%rdx)
addq $0x18, %rdx
cmpq $0x48, %rdx
jne 0x10bc0
incq %r13
addq $0x8, %rax
addq $0x8, %r14
addq $0x8, %r15
addq $0x8, %rcx
cmpq $0x3, %r13
jne 0x10bbe
movapd 0x30(%rsp), %xmm4
movapd %xmm4, %xmm0
unpckhpd %xmm4, %xmm0            # xmm0 = xmm0[1],xmm4[1]
mulsd %xmm4, %xmm0
mulsd 0xdb3b(%rip), %xmm0     # 0x1e7e0
addq $0x2a0, %r11            # imm = 0x2A0
movapd 0xdb5c(%rip), %xmm1     # 0x1e810
divpd %xmm4, %xmm1
movapd 0xd3e0(%rip), %xmm2     # 0x1e0a0
xorpd %xmm1, %xmm2
movapd 0xdb54(%rip), %xmm3     # 0x1e820
divpd %xmm4, %xmm3
movapd %xmm0, %xmm4
unpcklpd %xmm0, %xmm4            # xmm4 = xmm4[0],xmm0[0]
movapd %xmm1, %xmm5
unpckhpd %xmm1, %xmm5            # xmm5 = xmm5[1],xmm1[1]
xorl %eax, %eax
leaq 0xdb47(%rip), %rcx      # 0x1e830
xorl %edx, %edx
xorpd %xmm6, %xmm6
movq %rax, %rsi
xorl %edi, %edi
movsd (%rcx,%rdi,8), %xmm7
unpcklpd %xmm7, %xmm7            # xmm7 = xmm7[0,0]
movq %rsi, %r8
xorl %r9d, %r9d
movsd 0x1b0(%rsp,%r8), %xmm8
movhpd 0x90(%rsp,%r8), %xmm8   # xmm8 = xmm8[0],mem[0]
mulpd %xmm7, %xmm8
movsd (%r9,%rcx), %xmm9
unpcklpd %xmm9, %xmm9            # xmm9 = xmm9[0,0]
mulpd %xmm8, %xmm9
addpd %xmm9, %xmm6
addq $0x8, %r9
addq $0x18, %r8
cmpq $0x18, %r9
jne 0x10d03
incq %rdi
addq $0x8, %rsi
cmpq $0x3, %rdi
jne 0x10cf4
mulpd %xmm4, %xmm6
mulpd %xmm2, %xmm6
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
leaq (%r11,%rdi), %rsi
movupd 0x8(%r11,%rdi), %xmm7
addpd %xmm6, %xmm7
movupd %xmm7, 0x8(%r11,%rdi)
xorpd %xmm6, %xmm6
movq %rax, %rdi
xorl %r8d, %r8d
xorpd %xmm7, %xmm7
movsd (%rcx,%r8,8), %xmm8
unpcklpd %xmm8, %xmm8            # xmm8 = xmm8[0,0]
movhpd (%r12,%r8,8), %xmm9     # xmm9 = xmm9[0],mem[0]
movq %rdi, %r9
xorl %r10d, %r10d
movsd 0x1b0(%rsp,%r9), %xmm10
movsd 0x90(%rsp,%r9), %xmm11
movsd (%r10,%r12), %xmm12
movapd %xmm9, %xmm13
movsd %xmm12, %xmm13          # xmm13 = xmm12[0],xmm13[1]
unpcklpd %xmm11, %xmm12          # xmm12 = xmm12[0],xmm11[0]
unpcklpd %xmm10, %xmm11          # xmm11 = xmm11[0],xmm10[0]
mulpd %xmm11, %xmm13
mulpd %xmm8, %xmm13
movsd (%r10,%rcx), %xmm11
unpcklpd %xmm11, %xmm11          # xmm11 = xmm11[0,0]
mulpd %xmm11, %xmm13
addpd %xmm13, %xmm7
shufpd $0x2, %xmm9, %xmm10     # xmm10 = xmm10[0],xmm9[1]
mulpd %xmm12, %xmm10
mulpd %xmm8, %xmm10
mulpd %xmm11, %xmm10
addpd %xmm10, %xmm6
addq $0x8, %r10
addq $0x18, %r9
cmpq $0x18, %r10
jne 0x10d97
incq %r8
addq $0x8, %rdi
cmpq $0x3, %r8
jne 0x10d80
movapd %xmm0, %xmm8
mulsd %xmm7, %xmm8
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
mulsd %xmm0, %xmm7
mulpd %xmm4, %xmm6
mulpd %xmm3, %xmm6
mulsd %xmm5, %xmm8
mulsd %xmm1, %xmm7
addsd %xmm8, %xmm7
movsd 0x18(%rsi), %xmm8
subsd %xmm7, %xmm8
movsd %xmm8, 0x18(%rsi)
movupd 0x20(%rsi), %xmm7
addpd %xmm6, %xmm7
movupd %xmm7, 0x20(%rsi)
incq %rdx
addq $0x48, %rax
cmpq $0x4, %rdx
jne 0x10ceb
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq