gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
GModelIO_MAIL.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include "GModel.h"
7 #include "OS.h"
8 #include "MTriangle.h"
9 
10 int GModel::writeMAIL(const std::string &name, bool saveAll,
11  double scalingFactor)
12 {
13  // CEA triangulation (.mail format) for Eric Darrigrand. Note that
14  // we currently don't save the edges of the triangulation (the last
15  // part of the file).
16  FILE *fp = Fopen(name.c_str(), "w");
17  if(!fp) {
18  Msg::Error("Unable to open file '%s'", name.c_str());
19  return 0;
20  }
21 
22  if(noPhysicalGroups()) saveAll = true;
23 
24  int numVertices = indexMeshVertices(saveAll), numTriangles = 0;
25  for(auto it = firstFace(); it != lastFace(); ++it)
26  if(saveAll || (*it)->physicals.size())
27  numTriangles += (*it)->triangles.size();
28 
29  fprintf(fp, " %d %d\n", numVertices, numTriangles);
30 
31  std::vector<GEntity *> entities;
32  getEntities(entities);
33  for(std::size_t i = 0; i < entities.size(); i++) {
34  for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++) {
35  MVertex *v = entities[i]->mesh_vertices[j];
36  fprintf(fp, " %19.10E %19.10E %19.10E\n", v->x() * scalingFactor,
37  v->y() * scalingFactor, v->z() * scalingFactor);
38  }
39  }
40 
41  for(auto it = firstFace(); it != lastFace(); ++it) {
42  if(saveAll || (*it)->physicals.size()) {
43  for(std::size_t i = 0; i < (*it)->triangles.size(); i++) {
44  MTriangle *t = (*it)->triangles[i];
45  fprintf(fp, " %ld %ld %ld\n", t->getVertex(0)->getIndex(),
46  t->getVertex(1)->getIndex(), t->getVertex(2)->getIndex());
47  }
48  }
49  }
50 
51  // TODO write edges (with signs)
52  for(auto it = firstFace(); it != lastFace(); ++it) {
53  if(saveAll || (*it)->physicals.size()) {
54  for(std::size_t i = 0; i < (*it)->triangles.size(); i++) {
55  // MTriangle *t = (*it)->triangles[i];
56  fprintf(fp, " %d %d %d\n", 0, 0, 0);
57  }
58  }
59  }
60 
61  fclose(fp);
62  return 1;
63 }
MTriangle.h
GModel::writeMAIL
int writeMAIL(const std::string &name, bool saveAll, double scalingFactor)
Definition: GModelIO_MAIL.cpp:10
OS.h
MVertex
Definition: MVertex.h:24
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
MVertex::z
double z() const
Definition: MVertex.h:62
MTriangle::getVertex
virtual MVertex * getVertex(int num)
Definition: MTriangle.h:62
Fopen
FILE * Fopen(const char *f, const char *mode)
Definition: OS.cpp:273
GModel::lastFace
fiter lastFace()
Definition: GModel.h:359
GModel::firstFace
fiter firstFace()
Definition: GModel.h:355
GModel::getEntities
void getEntities(std::vector< GEntity * > &entities, int dim=-1) const
Definition: GModel.cpp:651
MTriangle
Definition: MTriangle.h:26
MVertex::getIndex
long int getIndex() const
Definition: MVertex.h:93
GModel::noPhysicalGroups
bool noPhysicalGroups()
Definition: GModel.cpp:828
GModel.h
MVertex::y
double y() const
Definition: MVertex.h:61
GModel::indexMeshVertices
std::size_t indexMeshVertices(bool all, int singlePartition=0, bool renumber=true)
Definition: GModel.cpp:2135
MVertex::x
double x() const
Definition: MVertex.h:60