HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
IBWriteBodySTL.c File Reference

Writes a 3D body surface to STL file. More...

#include <stdio.h>
#include <stdlib.h>
#include <basic.h>
#include <mpivars.h>
#include <immersedboundaries.h>

Go to the source code of this file.

Functions

int IBWriteBodySTL (Body3D *body, char *filename, void *m, int rank, int *stat)
 

Detailed Description

Writes a 3D body surface to STL file.

Author
Debojyoti Ghosh

Definition in file IBWriteBodySTL.c.

Function Documentation

◆ IBWriteBodySTL()

int IBWriteBodySTL ( Body3D body,
char *  filename,
void *  m,
int  rank,
int *  stat 
)

Function to write a 3D surface from a STL file. See https://en.wikipedia.org/wiki/STL_(file_format) for details of the STL file format. Notes:

  • This function only writes ASCII STL files.

It is assumed that all MPI ranks have the body data. The MPI rank specified as the input rank will actually write the file.

Parameters
body3D body to write to file
filenameFilename
mMPI object of type MPIVariables
rankMPI rank that does the writing
statStatus (0: success; non-0: failure)

Definition at line 23 of file IBWriteBodySTL.c.

30 {
31  MPIVariables *mpi = (MPIVariables*) m;
32 
33  if (mpi->rank == rank) {
34  FILE *out;
35  out = fopen(filename,"w");
36  if (!out) {
37  fprintf(stderr,"Error in IBWriteBodySTL(): Unable to open file ");
38  fprintf(stderr,"%s for writing on rank %d.\n",filename,mpi->rank);
39  *stat = 1;
40  } else {
41  fprintf(out,"solid TEST\n");
42  int n;
43  for (n = 0; n < body->nfacets; n++) {
44  fprintf(out," facet normal %1.16e %1.16e %1.16e\n",
45  body->surface[n].nx,body->surface[n].ny,body->surface[n].nz);
46  fprintf(out," outer loop\n");
47  fprintf(out," vertex %1.16e %1.16e %1.16e\n",
48  body->surface[n].x1,body->surface[n].y1,body->surface[n].z1);
49  fprintf(out," vertex %1.16e %1.16e %1.16e\n",
50  body->surface[n].x2,body->surface[n].y2,body->surface[n].z2);
51  fprintf(out," vertex %1.16e %1.16e %1.16e\n",
52  body->surface[n].x3,body->surface[n].y3,body->surface[n].z3);
53  fprintf(out," endloop\n");
54  fprintf(out," endfacet\n");
55  }
56  fprintf(out,"endsolid TEST\n");
57  *stat = 0;
58  }
59  }
60  return(0);
61 }
Facet3D * surface
Structure of MPI-related variables.