// File: /workspace/github_cpp_makefile_star2_O2/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 0x90(%rsp), %r14
xorl %r15d, %r15d
movl $0x120, %edx            # imm = 0x120
movq %r14, %rdi
xorl %esi, %esi
callq 0x3100
movups 0x288(%rbx), %xmm0
movaps %xmm0, 0x30(%rsp)
movq %rbx, (%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0xc621(%rip), %r12      # 0x1b860
pushq $0x6
popq %rbp
cmpq $0x4, %r15
je 0xf2c7
movq %r15, 0x10(%rsp)
imulq $0x30, %r15, %r15
addq 0x8(%rsp), %r15
movq %r14, 0x18(%rsp)
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0xf2b1
movsd (%r12,%rbx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r14, 0x20(%rsp)
xorl %r13d, %r13d
cmpq $0x18, %r13
je 0xf2a3
movsd (%r13,%r12), %xmm0
movsd 0x28(%rsp), %xmm1
movq %r15, %rdi
movl %ebp, %esi
callq 0xc9cc
movsd %xmm0, (%r14)
addq $0x8, %r13
addq $0x18, %r14
jmp 0xf277
incq %rbx
movq 0x20(%rsp), %r14
addq $0x8, %r14
jmp 0xf25d
movq 0x10(%rsp), %r15
incq %r15
movq 0x18(%rsp), %r14
addq $0x48, %r14
jmp 0xf242
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rax
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x20(%rax)
andq $0x0, 0x40(%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x168(%rsp), %r13
xorl %ecx, %ecx
pushq $-0x48
popq %rdx
movsd 0xbe78(%rip), %xmm0     # 0x1b170
movsd 0xbf28(%rip), %xmm1     # 0x1b228
movq %r13, %rsi
cmpq $0x3, %rcx
je 0xf364
movq %rdx, %rdi
testq %rdi, %rdi
je 0xf357
movsd -0x90(%rsi,%rdi), %xmm2
movsd -0x48(%rsi,%rdi), %xmm3
movhpd (%rsi,%rdi), %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(%rsi,%rdi), %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, 0x48(%rax,%rdi)
addq $0x18, %rdi
jmp 0xf30c
incq %rcx
addq $0x8, %rax
addq $0x8, %rsi
jmp 0xf303
leaq 0x2d0(%rsp), %r14
xorl %ebp, %ebp
movl $0x120, %edx            # imm = 0x120
movq %r14, %rdi
xorl %esi, %esi
callq 0x3100
leaq 0x1b0(%rsp), %r15
movl $0x120, %edx            # imm = 0x120
movq %r15, %rdi
xorl %esi, %esi
callq 0x3100
movl $0xd8, %eax
leaq (%r14,%rax), %rcx
addq %r15, %rax
leaq 0x40(%rsp), %rdx
pushq $-0x48
popq %rsi
cmpq $0x3, %rbp
je 0xf474
movq %rsi, %rdi
testq %rdi, %rdi
je 0xf45c
movsd -0x48(%r13,%rdi), %xmm1
movsd %xmm1, -0x90(%rcx,%rdi)
movsd (%r13,%rdi), %xmm0
movsd %xmm0, -0x90(%rax,%rdi)
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
movsd -0x90(%r13,%rdi), %xmm3
divsd %xmm3, %xmm2
movsd 0x48(%rdx,%rdi), %xmm4
addsd %xmm4, %xmm2
movsd %xmm2, -0x48(%rcx,%rdi)
movapd %xmm1, %xmm2
mulsd %xmm0, %xmm2
divsd %xmm3, %xmm2
movsd %xmm2, -0x48(%rax,%rdi)
movsd %xmm2, (%rcx,%rdi)
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
divsd %xmm3, %xmm2
addsd %xmm4, %xmm2
addsd 0x48(%r13,%rdi), %xmm4
movsd %xmm2, (%rax,%rdi)
mulsd %xmm4, %xmm1
divsd %xmm3, %xmm1
movsd %xmm1, 0x48(%rcx,%rdi)
mulsd %xmm0, %xmm4
divsd %xmm3, %xmm4
movsd %xmm4, 0x48(%rax,%rdi)
addq $0x18, %rdi
jmp 0xf3b5
incq %rbp
addq $0x8, %rax
addq $0x8, %rcx
addq $0x8, %r13
addq $0x8, %rdx
jmp 0xf3a8
movapd 0x30(%rsp), %xmm4
movapd %xmm4, %xmm0
unpckhpd %xmm4, %xmm0            # xmm0 = xmm0[1],xmm4[1]
mulsd %xmm4, %xmm0
mulsd 0xc3a2(%rip), %xmm0     # 0x1b830
movq (%rsp), %r11
addq $0x2a0, %r11            # imm = 0x2A0
movapd 0xc36f(%rip), %xmm1     # 0x1b810
divpd %xmm4, %xmm1
movapd 0xbbf3(%rip), %xmm2     # 0x1b0a0
xorpd %xmm1, %xmm2
movapd 0xc367(%rip), %xmm3     # 0x1b820
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 0xc36a(%rip), %rcx      # 0x1b840
cmpq $0x4, %rax
je 0xf66f
xorpd %xmm6, %xmm6
movq %r14, %rdx
movq %r15, %rsi
xorl %edi, %edi
cmpq $0x3, %rdi
je 0xf543
movsd (%rcx,%rdi,8), %xmm7
unpcklpd %xmm7, %xmm7            # xmm7 = xmm7[0,0]
movq %rcx, %r8
xorl %r9d, %r9d
cmpq $0x9, %r9
je 0xf536
movsd (%rdx,%r9,8), %xmm8
movhpd (%rsi,%r9,8), %xmm8     # xmm8 = xmm8[0],mem[0]
mulpd %xmm7, %xmm8
movsd (%r8), %xmm9
unpcklpd %xmm9, %xmm9            # xmm9 = xmm9[0,0]
mulpd %xmm8, %xmm9
addpd %xmm9, %xmm6
addq $0x3, %r9
addq $0x8, %r8
jmp 0xf501
incq %rdi
addq $0x8, %rsi
addq $0x8, %rdx
jmp 0xf4ec
mulpd %xmm4, %xmm6
mulpd %xmm2, %xmm6
imulq $0x30, %rax, %rsi
leaq (%r11,%rsi), %rdx
movupd 0x8(%r11,%rsi), %xmm7
addpd %xmm6, %xmm7
movupd %xmm7, 0x8(%r11,%rsi)
xorpd %xmm6, %xmm6
movq %r15, %rsi
movq %r14, %rdi
xorl %r8d, %r8d
xorpd %xmm7, %xmm7
cmpq $0x3, %r8
je 0xf61a
movsd (%r12,%r8,8), %xmm8
movsd (%rcx,%r8,8), %xmm9
unpcklpd %xmm9, %xmm9            # xmm9 = xmm9[0,0]
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpq $0x9, %r10
je 0xf60a
movsd (%rdi,%r10,8), %xmm10
movsd (%rsi,%r10,8), %xmm11
movapd %xmm10, %xmm12
unpcklpd %xmm11, %xmm12          # xmm12 = xmm12[0],xmm11[0]
movsd (%r9,%r12), %xmm13
movapd %xmm8, %xmm14
unpcklpd %xmm13, %xmm14          # xmm14 = xmm14[0],xmm13[0]
mulpd %xmm12, %xmm14
mulpd %xmm9, %xmm14
movsd (%r9,%rcx), %xmm12
unpcklpd %xmm12, %xmm12          # xmm12 = xmm12[0,0]
mulpd %xmm12, %xmm14
addpd %xmm14, %xmm7
unpcklpd %xmm11, %xmm13          # xmm13 = xmm13[0],xmm11[0]
unpcklpd %xmm8, %xmm10           # xmm10 = xmm10[0],xmm8[0]
mulpd %xmm13, %xmm10
mulpd %xmm9, %xmm10
mulpd %xmm12, %xmm10
addpd %xmm10, %xmm6
addq $0x3, %r10
addq $0x8, %r9
jmp 0xf597
incq %r8
addq $0x8, %rdi
addq $0x8, %rsi
jmp 0xf576
movapd %xmm0, %xmm8
mulsd %xmm7, %xmm8
unpckhpd %xmm7, %xmm7            # xmm7 = xmm7[1,1]
mulsd %xmm0, %xmm7
mulpd %xmm4, %xmm6
mulpd %xmm3, %xmm6
mulsd %xmm5, %xmm7
mulsd %xmm1, %xmm8
addsd %xmm7, %xmm8
movsd 0x18(%rdx), %xmm7
subsd %xmm8, %xmm7
movsd %xmm7, 0x18(%rdx)
movupd 0x20(%rdx), %xmm7
addpd %xmm6, %xmm7
movupd %xmm7, 0x20(%rdx)
incq %rax
addq $0x48, %r15
addq $0x48, %r14
jmp 0xf4d6
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq