// File: /workspace/github_c_makefile_star2_O1/markpeerdeman[P]mbemm/src/emath/post.c
// Function: O_write_deformed_elements_as_faces
void O_write_deformed_elements_as_faces(mesh themesh)
{ double zx, zy, zz; /* midpoint coordinates */
  matrix stress;
  double s1, s2, s3, mises, mismax, mismin;
  element e; point node1, node2, node3;
  mismax = 0.0;    // no stress
  mismin = 1000.0; // ridiculously high stress

  stress = (matrix)newmatrix(3,3);

  printf("# Output created by mbemm - boundary elements method software\n");
  printf("# Element topology is lost.\n");
  printf("# element colors indicate Von Mises stress\n");
  printf("mtllib materials.mtl\n");

e=(element)element_dll(themesh->mesh_e,START,0);
while (e!=(element)NULL)
{
  node1 = (point)point_dll(themesh->mesh_p,SEARCH,e->p1);
  node2 = (point)point_dll(themesh->mesh_p,SEARCH,e->p2);
  node3 = (point)point_dll(themesh->mesh_p,SEARCH,e->p3);

  zx = 1.0/3.0 * ( node1->x + node2->x + node3->x );
  zy = 1.0/3.0 * ( node1->y + node2->y + node3->y );
  zz = 1.0/3.0 * ( node1->z + node2->z + node3->z );

  M(stress,1,1) = zx;
  M(stress,2,2) = zy;
  M(stress,1,2) = M(stress,2,1) = zy;

  /* calculate the von Mises stress for this element: */

  s2 = 0.0;
  s1 = 0.5*(M(stress,1,1)+M(stress,2,2)+sqrt( (M(stress,1,1)-M(stress,2,2))*(M(stress,1,1)-M(stress,2,2)) +
       4.0*(M(stress,1,2)*M(stress,1,2))));
  s3 = 0.5*(M(stress,1,1)+M(stress,2,2)-sqrt( (M(stress,1,1)-M(stress,2,2))*(M(stress,1,1)-M(stress,2,2)) +
       4.0*(M(stress,1,2)*M(stress,1,2))));

  mises = 1.0/sqrt(2.0)*sqrt( (s1-s2)*(s1-s2)+(s1-s3)*(s1-s3)+(s2-s3)*(s2-s3) );

  if (mises<mismin) mismin=mises;
  if (mises>mismax) mismax=mises;

  if (mises>255.0) { mises=255.0; }

    printf(" usemtl mat%d\n",(int)mises);
    printf(" v  % 5.8E  % 5.8E  % 5.8E \n", node1->dx+node1->x, 
      node1->dy+node1->y, node1->dz+node1->z );
    printf(" v  % 5.8E  % 5.8E  % 5.8E \n", node2->dx+node2->x, 
      node2->dy+node2->y, node2->dz+node2->z );
    printf(" v  % 5.8E  % 5.8E  % 5.8E \n", node3->dx+node3->x, 
      node3->dy+node3->y, node3->dz+node3->z );
    printf(" f -3 -2 -1\n");

  e=e->NEXT;
}

printf("# Maximum Von Mises Stress: %f\n",mismax);
printf("# Minimum Von Mises Stress: %f\n",mismin);

  delmatrix(stress);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
movl $0x3, %edi
movl $0x3, %esi
callq 0xbcb0
movq %rax, %rbx
leaq 0x8e3a(%rip), %rdi      # 0xeda7
callq 0x1060
leaq 0x8e6c(%rip), %rdi      # 0xede5
callq 0x1060
leaq 0x8e7c(%rip), %rdi      # 0xee01
callq 0x1060
leaq 0x8e9b(%rip), %rdi      # 0xee2c
callq 0x1060
movq 0x8(%r14), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xb834
testq %rax, %rax
je 0x626c
movq %rax, %r15
movsd 0x84d1(%rip), %xmm2     # 0xe488
xorps %xmm1, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm2, (%rsp)
movq (%r14), %rdi
movl 0x18(%r15), %edx
movl $0x2, %esi
callq 0xcf07
movq %rax, %r13
movq (%r14), %rdi
movl 0x1c(%r15), %edx
movl $0x2, %esi
callq 0xcf07
movq %rax, %rbp
movq (%r14), %rdi
movl 0x20(%r15), %edx
movl $0x2, %esi
callq 0xcf07
movq %rax, %r12
movsd 0x20(%r13), %xmm0
addsd 0x20(%rbp), %xmm0
addsd 0x20(%rax), %xmm0
movsd 0x28(%r13), %xmm1
movsd 0x8431(%rip), %xmm2     # 0xe450
mulsd %xmm2, %xmm0
addsd 0x28(%rbp), %xmm1
addsd 0x28(%rax), %xmm1
mulsd %xmm2, %xmm1
movq 0x8(%rbx), %rax
movq (%rax), %rcx
movsd %xmm0, (%rcx)
movq 0x8(%rax), %rax
movsd %xmm1, 0x8(%rax)
movsd %xmm1, (%rax)
movsd %xmm1, 0x8(%rcx)
movsd (%rcx), %xmm2
movsd 0x8(%rax), %xmm3
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
mulsd %xmm1, %xmm1
mulsd 0x8415(%rip), %xmm1     # 0xe480
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x83dd(%rip), %xmm0     # 0xe458
jb 0x6083
sqrtsd %xmm0, %xmm0
jmp 0x60a0
movsd %xmm2, 0x18(%rsp)
movsd %xmm3, 0x10(%rsp)
callq 0x11b0
movsd 0x10(%rsp), %xmm3
movsd 0x18(%rsp), %xmm2
addsd %xmm3, %xmm2
addsd %xmm0, %xmm2
mulsd 0x83b8(%rip), %xmm2     # 0xe468
movq 0x8(%rbx), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movsd 0x8(%rax), %xmm4
movsd (%rcx), %xmm3
movsd 0x8(%rcx), %xmm1
movapd %xmm3, %xmm0
subsd %xmm4, %xmm0
mulsd %xmm1, %xmm1
mulsd 0x83a3(%rip), %xmm1     # 0xe480
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x836b(%rip), %xmm0     # 0xe458
jb 0x60f5
sqrtsd %xmm0, %xmm0
jmp 0x611e
movsd %xmm2, 0x18(%rsp)
movsd %xmm3, 0x10(%rsp)
movsd %xmm4, 0x20(%rsp)
callq 0x11b0
movsd 0x20(%rsp), %xmm4
movsd 0x10(%rsp), %xmm3
movsd 0x18(%rsp), %xmm2
addsd %xmm4, %xmm3
subsd %xmm0, %xmm3
mulsd 0x833a(%rip), %xmm3     # 0xe468
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm2, %xmm2
addsd %xmm0, %xmm2
xorpd %xmm0, %xmm0
subsd %xmm3, %xmm0
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
ucomisd 0x82fe(%rip), %xmm0     # 0xe458
jb 0x6165
xorps %xmm2, %xmm2
sqrtsd %xmm0, %xmm2
jmp 0x616e
callq 0x11b0
movapd %xmm0, %xmm2
movsd 0x8(%rsp), %xmm1
mulsd 0x82fc(%rip), %xmm2     # 0xe478
movapd %xmm2, %xmm0
minsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x82fe(%rip), %xmm0     # 0xe490
minsd %xmm2, %xmm0
maxsd %xmm1, %xmm2
movsd %xmm2, 0x8(%rsp)
cvttsd2si %xmm0, %esi
leaq 0x853b(%rip), %rdi      # 0xe6e6
xorl %eax, %eax
callq 0x1090
movsd 0x50(%r13), %xmm0
movsd 0x58(%r13), %xmm1
addsd 0x20(%r13), %xmm0
addsd 0x28(%r13), %xmm1
movsd 0x60(%r13), %xmm2
addsd 0x30(%r13), %xmm2
leaq 0x8518(%rip), %r13      # 0xe6f5
movq %r13, %rdi
movb $0x3, %al
callq 0x1090
movsd 0x50(%rbp), %xmm0
movsd 0x58(%rbp), %xmm1
addsd 0x20(%rbp), %xmm0
addsd 0x28(%rbp), %xmm1
movsd 0x60(%rbp), %xmm2
addsd 0x30(%rbp), %xmm2
movq %r13, %rdi
movb $0x3, %al
callq 0x1090
movsd 0x50(%r12), %xmm0
movsd 0x58(%r12), %xmm1
addsd 0x20(%r12), %xmm0
addsd 0x28(%r12), %xmm1
movsd 0x60(%r12), %xmm2
addsd 0x30(%r12), %xmm2
movq %r13, %rdi
movb $0x3, %al
callq 0x1090
leaq 0x8bf7(%rip), %rdi      # 0xee41
callq 0x1060
movsd 0x8(%rsp), %xmm0
movq 0x8(%r15), %r15
movaps %xmm0, %xmm1
movsd (%rsp), %xmm2
testq %r15, %r15
jne 0x5fba
jmp 0x627c
xorps %xmm0, %xmm0
movsd 0x8211(%rip), %xmm1     # 0xe488
movsd %xmm1, (%rsp)
leaq 0x848f(%rip), %rdi      # 0xe712
movb $0x1, %al
callq 0x1090
leaq 0x84a1(%rip), %rdi      # 0xe732
movsd (%rsp), %xmm0
movb $0x1, %al
callq 0x1090
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbe4b