// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x3
popq %rdi
movl %edi, %esi
callq 0xb24c
movq %rax, %rbx
leaq 0x9588(%rip), %rdi      # 0xdda7
callq 0x1060
leaq 0x95ba(%rip), %rdi      # 0xdde5
callq 0x1060
leaq 0x95ca(%rip), %rdi      # 0xde01
callq 0x1060
leaq 0x95e9(%rip), %rdi      # 0xde2c
callq 0x1060
movq 0x8(%r14), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xad45
movq %rax, %r15
movsd 0x8c28(%rip), %xmm0     # 0xd488
movsd %xmm0, 0x18(%rsp)
xorps %xmm0, %xmm0
testq %r15, %r15
je 0x4af1
movsd %xmm0, 0x10(%rsp)
movq (%r14), %rdi
movl 0x18(%r15), %edx
pushq $0x2
popq %r12
movl %r12d, %esi
callq 0xc14c
movq %rax, %r13
movq (%r14), %rdi
movl 0x1c(%r15), %edx
movl %r12d, %esi
callq 0xc14c
movq %rax, %rbp
movq (%r14), %rdi
movl 0x20(%r15), %edx
movl %r12d, %esi
callq 0xc14c
movq %rax, %r12
movsd 0x20(%r13), %xmm0
addsd 0x20(%rbp), %xmm0
addsd 0x20(%rax), %xmm0
movsd 0x28(%r13), %xmm1
movsd 0x8b80(%rip), %xmm2     # 0xd450
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 0x8b5c(%rip), %xmm1     # 0xd478
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x8b54(%rip), %xmm0     # 0xd480
jb 0x4934
sqrtsd %xmm0, %xmm0
jmp 0x494f
movsd %xmm2, 0x8(%rsp)
movsd %xmm3, (%rsp)
callq 0x11a0
movsd (%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
addsd %xmm3, %xmm2
addsd %xmm0, %xmm2
mulsd 0x8b01(%rip), %xmm2     # 0xd460
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 0x8aec(%rip), %xmm1     # 0xd478
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x8ae4(%rip), %xmm0     # 0xd480
jb 0x49a4
sqrtsd %xmm0, %xmm0
jmp 0x49cb
movsd %xmm2, 0x8(%rsp)
movsd %xmm3, (%rsp)
movsd %xmm4, 0x20(%rsp)
callq 0x11a0
movsd 0x20(%rsp), %xmm4
movsd (%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
addsd %xmm4, %xmm3
subsd %xmm0, %xmm3
mulsd 0x8a85(%rip), %xmm3     # 0xd460
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
sqrtsd %xmm0, %xmm1
mulsd 0x8a65(%rip), %xmm1     # 0xd470
movapd %xmm1, %xmm0
minsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x8a6d(%rip), %xmm0     # 0xd490
minsd %xmm1, %xmm0
maxsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
cvttsd2si %xmm0, %esi
leaq 0x8ca8(%rip), %rdi      # 0xd6e6
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 0x8c85(%rip), %r13      # 0xd6f5
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 0x9364(%rip), %rdi      # 0xde41
callq 0x1060
movq 0x8(%r15), %r15
movsd 0x10(%rsp), %xmm0
jmp 0x4869
leaq 0x8c1a(%rip), %rdi      # 0xd712
movb $0x1, %al
callq 0x1090
leaq 0x8c2c(%rip), %rdi      # 0xd732
movsd 0x18(%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 0xb3b2