// File: /workspace/github_c_makefile_star2_O2/markpeerdeman[P]mbemm/src/emath/mcheck.c
// Function: process_results
void process_results(mesh theMesh, vector resultvector)
{ point p;
  element e;
  double t1x, t1y, t1z; /* the calculated tractions on an element */
  double t2x, t2y, t2z;
  double t3x, t3y, t3z;
  double fx, fy, fz;    /* the calculated elemental force */
  double sfx=0.0;
  double sfy=0.0;
  double sfz=0.0;
  double a1x, a1y, a1z; /* the analytical tractions on an element */
  double a2x, a2y, a2z;
  double a3x, a3y, a3z;
  double ax, ay, az;    /* the analytical force on the element: */
  double sax=0.0;
  double say=0.0;
  double saz=0.0;
  double fmax=0.0;
  double dx, dy, dz;
  double dmax;
  int dmaxe;
  double sd=0.0;

  printf("\n\n================================================================================\n");
  printf(" VERIFICATION RESULTS FOR THIS MESH:\n");
  printf(" (A): analytical\n (C): calculated\n (N): normalized to the maximum calculated force modulus\n");
  printf(" (S): the error components are treated signed\n");
  
  /* copy the data from the results vector to the point_dll: */
  p=(point)point_dll(theMesh->mesh_p,START,0);
  while (p!=(point)NULL)
  { p->fx=V(resultvector,p->label*3-2);
    p->fy=V(resultvector,p->label*3-2);
    p->fz=V(resultvector,p->label*3  );
    p=p->NEXT;
  }

  scalesystemback(theMesh);

  /* scan through all elements and calculate the resulting element forces: */
  e = (element)element_dll(theMesh->mesh_e,START,0);
  while (e!=(element)NULL)
  {     /* get the traction forces at the three nodes of the element: */
        /* NODE 1: */
        p=(point)point_dll(theMesh->mesh_p,SEARCH,e->p1);
        t1x=p->fx; t1y=p->fy; t1z=p->fz;
        a1x=traction1(p->x,p->y,p->z,e->nx,e->ny,e->nz);
        a1y=traction2(p->x,p->y,p->z,e->nx,e->ny,e->nz);
        a1z=traction3(p->x,p->y,p->z,e->nx,e->ny,e->nz);
        /* NODE 2: */
        p=(point)point_dll(theMesh->mesh_p,SEARCH,e->p2);
        t2x=p->fx; t2y=p->fy; t2z=p->fz;
        a2x=traction1(p->x,p->y,p->z,e->nx,e->ny,e->nz);
        a2y=traction2(p->x,p->y,p->z,e->nx,e->ny,e->nz);
        a2z=traction3(p->x,p->y,p->z,e->nx,e->ny,e->nz);
        /* NODE 3: */
        p=(point)point_dll(theMesh->mesh_p,SEARCH,e->p3);
        t3x=p->fx; t3y=p->fy; t3z=p->fz;
        a3x=traction1(p->x,p->y,p->z,e->nx,e->ny,e->nz);
        a3y=traction2(p->x,p->y,p->z,e->nx,e->ny,e->nz);
        a3z=traction3(p->x,p->y,p->z,e->nx,e->ny,e->nz);

        fx= 1.0/3.0*(t1x+t2x+t3x)*e->area*theMesh->G_SCALE;
        fy= 1.0/3.0*(t1y+t2y+t3y)*e->area*theMesh->G_SCALE;
        fz= 1.0/3.0*(t1z+t2z+t3z)*e->area*theMesh->G_SCALE;
        ax= 1.0/3.0*(a1x+a2x+a3x)*e->area*theMesh->G_SCALE;
        ay= 1.0/3.0*(a1y+a2y+a3y)*e->area*theMesh->G_SCALE;
        az= 1.0/3.0*(a1z+a2z+a3z)*e->area*theMesh->G_SCALE;
        sfx+=fx; sfy+=fy; sfz+=fz;
        sax+=ax; say+=ay; saz+=az;
        fmax=maxof(fmax,sqrt(fx*fx+fy*fy+fz*fz));
        dx=fx-ax; dy=fy-ay; dz=fz-az;
        dmax=maxof(dmax,sqrt(dx*dx+dy*dy+dz*dz));
        if (dmax>sqrt(dx*dx+dy*dy+dz*dz)) dmaxe=e->label;
        sd+=sqrt(dx*dx+dy*dy+dz*dz);
        

        e=e->NEXT;
  }
  
  printf("\n REACTION FORCES:\n");
  printf(" Resulting net force vector (A):   [% 8.8E % 8.8E % 8.8E]\n",sax,say,saz);
  printf(" Resulting net force vector (C):   [% 8.8E % 8.8E % 8.8E]\n",sfx,sfy,sfz);
  printf(" Resulting net force vector (C,N): [% 8.8E % 8.8E % 8.8E]\n",sfx/fmax,sfy/fmax,sfz/fmax);
  printf("\n ERRORS:\n");
  printf(" Maximum traction error (N):        % 8.8E on element %d\n",dmax/fmax,dmaxe);
  printf(" Average traction error (N):        % 8.8E\n",(sd/theMesh->nr_of_elements)/fmax);
  printf(" Average traction error (S,N):      % 8.8E\n",(sqrt(sfx*sfx+sfy*sfy+sfz*sfz)/
                                                           theMesh->nr_of_elements)/fmax);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x170, %rsp            # imm = 0x170
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x417e(%rip), %rdi      # 0xe413
callq 0x1060
leaq 0x41c5(%rip), %rdi      # 0xe466
callq 0x1060
leaq 0x41de(%rip), %rdi      # 0xe48b
callq 0x1060
leaq 0x422d(%rip), %rdi      # 0xe4e6
callq 0x1060
movq (%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc14c
testq %rax, %rax
je 0xa2fc
movq 0x8(%r14), %rcx
movslq 0x10(%rax), %rdx
imulq $0x18, %rdx, %rdx
movsd -0x18(%rcx,%rdx), %xmm0
movsd %xmm0, 0x38(%rax)
movsd %xmm0, 0x40(%rax)
movsd -0x8(%rcx,%rdx), %xmm0
movsd %xmm0, 0x48(%rax)
movq 0x8(%rax), %rax
jmp 0xa2ca
movq %rbx, %rdi
callq 0x9154
movq 0x8(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xad45
movq %rax, %r14
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
pushq $0x2
popq %r15
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x40(%rsp)
movsd %xmm0, 0x38(%rsp)
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x48(%rsp)
testq %r14, %r14
je 0xa80c
movq (%rbx), %rdi
movl 0x18(%r14), %edx
movl %r15d, %esi
callq 0xc14c
movq %rax, %r12
movsd 0x20(%rax), %xmm0
movsd 0x28(%rax), %xmm1
movsd 0x30(%rax), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
movsd 0x38(%rax), %xmm6
movaps %xmm6, 0x140(%rsp)
movsd 0x40(%rax), %xmm6
movaps %xmm6, 0x150(%rsp)
movsd 0x48(%rax), %xmm6
movaps %xmm6, 0x160(%rsp)
callq 0x89f4
movaps %xmm0, 0x110(%rsp)
movsd 0x20(%r12), %xmm0
movsd 0x28(%r12), %xmm1
movsd 0x30(%r12), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x8a11
movaps %xmm0, 0x120(%rsp)
movsd 0x20(%r12), %xmm0
movsd 0x28(%r12), %xmm1
movsd 0x30(%r12), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x8a2a
movaps %xmm0, 0x130(%rsp)
movq (%rbx), %rdi
movl 0x1c(%r14), %edx
movl %r15d, %esi
callq 0xc14c
movq %rax, %r12
movsd 0x20(%rax), %xmm0
movsd 0x28(%rax), %xmm1
movsd 0x30(%rax), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
movsd 0x38(%rax), %xmm6
movaps %xmm6, 0xd0(%rsp)
movsd 0x40(%rax), %xmm6
movaps %xmm6, 0xf0(%rsp)
movsd 0x48(%rax), %xmm6
movaps %xmm6, 0x100(%rsp)
callq 0x89f4
movaps %xmm0, 0xb0(%rsp)
movsd 0x20(%r12), %xmm0
movsd 0x28(%r12), %xmm1
movsd 0x30(%r12), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x8a11
movaps %xmm0, 0xc0(%rsp)
movsd 0x20(%r12), %xmm0
movsd 0x28(%r12), %xmm1
movsd 0x30(%r12), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x8a2a
movaps %xmm0, 0xe0(%rsp)
movq (%rbx), %rdi
movl 0x20(%r14), %edx
movl %r15d, %esi
callq 0xc14c
movq %rax, %r12
movsd 0x20(%rax), %xmm0
movsd 0x28(%rax), %xmm1
movsd 0x30(%rax), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
movsd 0x38(%rax), %xmm6
movaps %xmm6, 0x90(%rsp)
movsd 0x40(%rax), %xmm6
movaps %xmm6, 0x80(%rsp)
movsd 0x48(%rax), %xmm6
movaps %xmm6, 0x70(%rsp)
callq 0x89f4
movaps %xmm0, 0x60(%rsp)
movsd 0x20(%r12), %xmm0
movsd 0x28(%r12), %xmm1
movsd 0x30(%r12), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x8a11
movaps %xmm0, 0xa0(%rsp)
movsd 0x20(%r12), %xmm0
movsd 0x28(%r12), %xmm1
movsd 0x30(%r12), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x8a2a
movapd 0x90(%rsp), %xmm9
movapd 0x80(%rsp), %xmm8
movapd 0x70(%rsp), %xmm7
movapd 0x140(%rsp), %xmm1
unpcklpd 0x110(%rsp), %xmm1      # xmm1 = xmm1[0],mem[0]
movapd 0xd0(%rsp), %xmm2
unpcklpd 0xb0(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
addpd %xmm1, %xmm2
unpcklpd 0x60(%rsp), %xmm9       # xmm9 = xmm9[0],mem[0]
addpd %xmm2, %xmm9
movapd 0x150(%rsp), %xmm1
unpcklpd 0x120(%rsp), %xmm1      # xmm1 = xmm1[0],mem[0]
movapd 0xf0(%rsp), %xmm2
unpcklpd 0xc0(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
addpd %xmm1, %xmm2
unpcklpd 0xa0(%rsp), %xmm8       # xmm8 = xmm8[0],mem[0]
movapd 0x2d9f(%rip), %xmm3     # 0xd430
mulpd %xmm3, %xmm9
addpd %xmm2, %xmm8
movsd 0xb8(%r14), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm1, %xmm9
movapd 0x160(%rsp), %xmm4
unpcklpd 0x130(%rsp), %xmm4      # xmm4 = xmm4[0],mem[0]
movsd 0x30(%rbx), %xmm2
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm2, %xmm9
mulpd %xmm3, %xmm8
mulpd %xmm1, %xmm8
mulpd %xmm2, %xmm8
movapd 0x100(%rsp), %xmm5
unpcklpd 0xe0(%rsp), %xmm5       # xmm5 = xmm5[0],mem[0]
addpd %xmm4, %xmm5
unpcklpd %xmm0, %xmm7            # xmm7 = xmm7[0],xmm0[0]
addpd %xmm5, %xmm7
mulpd %xmm3, %xmm7
mulpd %xmm1, %xmm7
mulpd %xmm2, %xmm7
movapd %xmm9, %xmm0
unpckhpd %xmm9, %xmm0            # xmm0 = xmm0[1],xmm9[1]
movapd %xmm8, %xmm1
unpckhpd %xmm8, %xmm1            # xmm1 = xmm1[1],xmm8[1]
movapd %xmm7, %xmm2
unpckhpd %xmm7, %xmm2            # xmm2 = xmm2[1],xmm7[1]
movapd %xmm9, %xmm3
subsd %xmm0, %xmm3
movapd %xmm8, %xmm4
subsd %xmm1, %xmm4
movapd %xmm7, %xmm5
subsd %xmm2, %xmm5
unpcklpd %xmm8, %xmm4            # xmm4 = xmm4[0],xmm8[0]
mulpd %xmm4, %xmm4
unpcklpd %xmm9, %xmm3            # xmm3 = xmm3[0],xmm9[0]
mulpd %xmm3, %xmm3
addpd %xmm4, %xmm3
unpcklpd %xmm7, %xmm5            # xmm5 = xmm5[0],xmm7[0]
mulpd %xmm5, %xmm5
addpd %xmm3, %xmm5
sqrtpd %xmm5, %xmm3
movapd 0x50(%rsp), %xmm6
movapd %xmm6, %xmm4
cmplepd %xmm3, %xmm4
movapd %xmm3, %xmm5
andpd %xmm4, %xmm5
andnpd %xmm6, %xmm4
orpd %xmm5, %xmm4
movapd %xmm4, 0x50(%rsp)
ucomisd %xmm3, %xmm4
jbe 0xa791
movl 0x14(%r14), %ebp
movsd 0x8(%rsp), %xmm4
addsd %xmm9, %xmm4
movsd %xmm4, 0x8(%rsp)
movsd 0x10(%rsp), %xmm4
addsd %xmm8, %xmm4
movsd %xmm4, 0x10(%rsp)
movsd 0x18(%rsp), %xmm4
addsd %xmm7, %xmm4
movsd %xmm4, 0x18(%rsp)
movsd 0x20(%rsp), %xmm4
addsd %xmm0, %xmm4
movsd %xmm4, 0x20(%rsp)
movsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x38(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x48(%rsp), %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x8(%r14), %r14
jmp 0xa350
leaq 0x3d01(%rip), %rdi      # 0xe514
callq 0x1060
leaq 0x3ab1(%rip), %rdi      # 0xe2d0
movsd 0x20(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movb $0x3, %al
callq 0x1090
leaq 0x3acc(%rip), %rdi      # 0xe30b
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movb $0x3, %al
callq 0x1090
movapd 0x50(%rsp), %xmm3
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
movapd %xmm3, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
divsd %xmm3, %xmm0
movsd 0x10(%rsp), %xmm1
divsd %xmm3, %xmm1
movsd 0x18(%rsp), %xmm2
divsd %xmm3, %xmm2
leaq 0x3ab9(%rip), %rdi      # 0xe346
movb $0x3, %al
callq 0x1090
leaq 0x3c8c(%rip), %rdi      # 0xe527
callq 0x1060
movapd 0x50(%rsp), %xmm0
divsd 0x20(%rsp), %xmm0
leaq 0x3ace(%rip), %rdi      # 0xe381
movl %ebp, %esi
movb $0x1, %al
callq 0x1090
cvtsi2sdl 0x24(%rbx), %xmm1
movsd 0x48(%rsp), %xmm0
divsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
leaq 0x3ae3(%rip), %rdi      # 0xe3bb
movb $0x1, %al
callq 0x1090
movsd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
cvtsi2sdl 0x24(%rbx), %xmm1
divsd %xmm1, %xmm0
divsd 0x20(%rsp), %xmm0
leaq 0x3ac8(%rip), %rdi      # 0xe3e7
movb $0x1, %al
addq $0x170, %rsp            # imm = 0x170
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1090