// File: /workspace/github_c_makefile_star2_O3/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 %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x4965(%rip), %rdi      # 0xf443
callq 0x1060
leaq 0x49ac(%rip), %rdi      # 0xf496
callq 0x1060
leaq 0x49c5(%rip), %rdi      # 0xf4bb
callq 0x1060
leaq 0x4a14(%rip), %rdi      # 0xf516
callq 0x1060
movq (%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xcc2f
testq %rax, %rax
je 0xab48
movq 0x8(%r14), %rcx
movslq 0x10(%rax), %rdx
leaq (%rdx,%rdx,2), %rdx
movsd -0x18(%rcx,%rdx,8), %xmm0
movsd %xmm0, 0x38(%rax)
movsd %xmm0, 0x40(%rax)
movsd -0x8(%rcx,%rdx,8), %xmm0
movsd %xmm0, 0x48(%rax)
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0xab1c
movq %rbx, %rdi
callq 0x9dd8
movq 0x8(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xb570
testq %rax, %rax
je 0xafca
movq %rax, %r14
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x50(%rsp)
xorpd %xmm1, %xmm1
movapd %xmm1, 0x30(%rsp)
movq (%rbx), %rdi
movl 0x18(%r14), %edx
movl $0x2, %esi
callq 0xcc2f
movq %rax, %r15
movups 0x40(%rax), %xmm0
movaps %xmm0, 0x70(%rsp)
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, 0x20(%rsp)
callq 0x97c8
movaps %xmm0, 0xf0(%rsp)
movsd 0x20(%r15), %xmm0
movsd 0x28(%r15), %xmm1
movsd 0x30(%r15), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x97e5
movaps %xmm0, 0xe0(%rsp)
movsd 0x20(%r15), %xmm0
movsd 0x28(%r15), %xmm1
movsd 0x30(%r15), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x97fe
movaps %xmm0, 0x100(%rsp)
movq (%rbx), %rdi
movl 0x1c(%r14), %edx
movl $0x2, %esi
callq 0xcc2f
movq %rax, %r15
movupd 0x40(%rax), %xmm0
addpd 0x70(%rsp), %xmm0
movapd %xmm0, 0x60(%rsp)
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, 0x70(%rsp)
callq 0x97c8
movaps %xmm0, 0xc0(%rsp)
movsd 0x20(%r15), %xmm0
movsd 0x28(%r15), %xmm1
movsd 0x30(%r15), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x97e5
movaps %xmm0, 0xb0(%rsp)
movsd 0x20(%r15), %xmm0
movsd 0x28(%r15), %xmm1
movsd 0x30(%r15), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x97fe
movaps %xmm0, 0xd0(%rsp)
movq (%rbx), %rdi
movl 0x20(%r14), %edx
movl $0x2, %esi
callq 0xcc2f
movq %rax, %r15
movupd 0x40(%rax), %xmm0
addpd 0x60(%rsp), %xmm0
movapd %xmm0, 0xa0(%rsp)
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, 0x60(%rsp)
callq 0x97c8
movaps %xmm0, 0x90(%rsp)
movsd 0x20(%r15), %xmm0
movsd 0x28(%r15), %xmm1
movsd 0x30(%r15), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x97e5
movaps %xmm0, 0x80(%rsp)
movsd 0x20(%r15), %xmm0
movsd 0x28(%r15), %xmm1
movsd 0x30(%r15), %xmm2
movsd 0xa0(%r14), %xmm3
movsd 0xa8(%r14), %xmm4
movsd 0xb0(%r14), %xmm5
callq 0x97fe
movapd 0xf0(%rsp), %xmm1
unpcklpd 0xe0(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movapd 0xc0(%rsp), %xmm2
unpcklpd 0xb0(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
addpd %xmm1, %xmm2
movapd 0x90(%rsp), %xmm6
unpcklpd 0x80(%rsp), %xmm6       # xmm6 = xmm6[0],mem[0]
addpd %xmm2, %xmm6
movapd 0xa0(%rsp), %xmm4
shufpd $0x1, %xmm4, %xmm4      # xmm4 = xmm4[1,0]
movapd 0x35c4(%rip), %xmm5     # 0xe430
mulpd %xmm5, %xmm6
mulpd %xmm5, %xmm4
movsd 0xb8(%r14), %xmm2
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm2, %xmm6
mulpd %xmm2, %xmm4
movsd 0x30(%rbx), %xmm3
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm3, %xmm6
mulpd %xmm3, %xmm4
movapd %xmm4, %xmm1
movapd %xmm4, %xmm7
unpckhpd %xmm4, %xmm1            # xmm1 = xmm1[1],xmm4[1]
movapd %xmm6, %xmm4
movapd %xmm6, %xmm8
unpckhpd %xmm6, %xmm4            # xmm4 = xmm4[1],xmm6[1]
subsd %xmm4, %xmm1
movapd 0x20(%rsp), %xmm4
unpcklpd 0x100(%rsp), %xmm4      # xmm4 = xmm4[0],mem[0]
movapd 0x70(%rsp), %xmm6
unpcklpd 0xd0(%rsp), %xmm6       # xmm6 = xmm6[0],mem[0]
addpd %xmm4, %xmm6
movapd %xmm7, %xmm4
movapd 0x60(%rsp), %xmm7
unpcklpd %xmm0, %xmm7            # xmm7 = xmm7[0],xmm0[0]
addpd %xmm6, %xmm7
movapd %xmm8, %xmm6
mulpd %xmm5, %xmm7
movapd %xmm7, %xmm5
mulpd %xmm2, %xmm5
mulpd %xmm3, %xmm5
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
movapd %xmm4, %xmm2
subsd %xmm0, %xmm2
movapd %xmm5, %xmm0
subsd %xmm8, %xmm0
shufpd $0x2, %xmm4, %xmm1      # xmm1 = xmm1[0],xmm4[1]
mulpd %xmm1, %xmm1
unpcklpd %xmm5, %xmm0            # xmm0 = xmm0[0],xmm5[0]
mulpd %xmm0, %xmm0
addpd %xmm1, %xmm0
unpcklpd %xmm4, %xmm2            # xmm2 = xmm2[0],xmm4[0]
mulpd %xmm2, %xmm2
addpd %xmm0, %xmm2
sqrtpd %xmm2, %xmm0
movapd 0x50(%rsp), %xmm3
movapd %xmm3, %xmm1
cmplepd %xmm0, %xmm1
movapd %xmm0, %xmm2
andpd %xmm1, %xmm2
andnpd %xmm3, %xmm1
orpd %xmm2, %xmm1
movapd %xmm1, 0x50(%rsp)
ucomisd %xmm0, %xmm1
jbe 0xaf6d
movl 0x14(%r14), %ebp
movapd 0x10(%rsp), %xmm1
addpd %xmm6, %xmm1
movapd %xmm1, 0x10(%rsp)
movapd 0x40(%rsp), %xmm1
addpd %xmm4, %xmm1
movapd %xmm1, 0x40(%rsp)
movapd 0x30(%rsp), %xmm1
addpd %xmm5, %xmm1
movsd 0x8(%rsp), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
movq 0x8(%r14), %r14
testq %r14, %r14
jne 0xab91
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
movapd %xmm0, 0x20(%rsp)
movapd %xmm1, 0x30(%rsp)
jmp 0xaffa
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movapd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x8(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x50(%rsp)
leaq 0x4543(%rip), %rdi      # 0xf544
callq 0x1060
movaps 0x10(%rsp), %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
leaq 0x42e7(%rip), %rdi      # 0xf300
movaps 0x20(%rsp), %xmm2
movb $0x3, %al
callq 0x1090
movaps 0x40(%rsp), %xmm2
movaps %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
movaps %xmm1, 0x20(%rsp)
leaq 0x42fe(%rip), %rdi      # 0xf33b
movaps 0x30(%rsp), %xmm0
movb $0x3, %al
callq 0x1090
movapd 0x50(%rsp), %xmm3
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
movapd %xmm3, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
divsd %xmm3, %xmm0
movapd 0x20(%rsp), %xmm1
divsd %xmm3, %xmm1
movapd 0x40(%rsp), %xmm2
divsd %xmm3, %xmm2
leaq 0x42f8(%rip), %rdi      # 0xf376
movb $0x3, %al
callq 0x1090
leaq 0x44cb(%rip), %rdi      # 0xf557
callq 0x1060
movapd 0x50(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
leaq 0x430d(%rip), %rdi      # 0xf3b1
movl %ebp, %esi
movb $0x1, %al
callq 0x1090
xorps %xmm1, %xmm1
cvtsi2sdl 0x24(%rbx), %xmm1
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
leaq 0x431f(%rip), %rdi      # 0xf3eb
movb $0x1, %al
callq 0x1090
movapd 0x20(%rsp), %xmm1
mulsd %xmm1, %xmm1
movapd 0x30(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movapd 0x40(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x24(%rbx), %xmm1
divsd %xmm1, %xmm0
divsd 0x10(%rsp), %xmm0
leaq 0x42fd(%rip), %rdi      # 0xf417
movb $0x1, %al
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1090