gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
GModelIO_POS.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 <stdio.h>
7 #include "GModel.h"
8 #include "OS.h"
9 #include "MElement.h"
10 
11 int GModel::writePOS(const std::string &name, bool printElementary,
12  bool printElementNumber, bool printSICN, bool printSIGE,
13  bool printGamma, bool printDisto, bool saveAll,
14  double scalingFactor)
15 {
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  /*
23  bool printVertices = true;
24  if(printVertices){
25  fprintf(fp, "View \"Vertices\" {\n");
26  std::vector<GEntity*> entities;
27  getEntities(entities);
28  for(std::size_t i = 0; i < entities.size(); i++)
29  for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++){
30  MVertex *v = entities[i]->mesh_vertices[j];
31  fprintf(fp, "SP(%g,%g,%g){1};\n", v->x(), v->y(), v->z());
32  }
33  fprintf(fp, "};\n");
34  fclose(fp);
35  return 1;
36  }
37  */
38 
39  bool first = true;
40  std::string names;
41  if(printElementary) {
42  if(first)
43  first = false;
44  else
45  names += ",";
46  names += "\"Elementary Entity\"";
47  }
48  if(printElementNumber) {
49  if(first)
50  first = false;
51  else
52  names += ",";
53  names += "\"Element Number\"";
54  }
55  if(printSICN) {
56  if(first)
57  first = false;
58  else
59  names += ",";
60  names += "\"SICN\"";
61  }
62  if(printSIGE) {
63  if(first)
64  first = false;
65  else
66  names += ",";
67  names += "\"SIGE\"";
68  }
69  if(printGamma) {
70  if(first)
71  first = false;
72  else
73  names += ",";
74  names += "\"Gamma\"";
75  }
76  if(printDisto) {
77  if(first)
78  first = false;
79  else
80  names += ",";
81  names += "\"Disto\"";
82  }
83 
84  if(names.empty()) {
85  fclose(fp);
86  return 0;
87  }
88 
89  if(noPhysicalGroups()) saveAll = true;
90 
91  fprintf(fp, "View \"Statistics\" {\n");
92  fprintf(fp, "T2(1.e5,30,%d){%s};\n", (1 << 16) | (4 << 8), names.c_str());
93 
94  std::vector<GEntity *> entities;
95  getEntities(entities);
96  for(std::size_t i = 0; i < entities.size(); i++)
97  if(saveAll || entities[i]->physicals.size())
98  for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++)
99  entities[i]->getMeshElement(j)->writePOS(
100  fp, printElementary, printElementNumber, printSICN, printSIGE,
101  printGamma, printDisto, scalingFactor, entities[i]->tag());
102  fprintf(fp, "};\n");
103 
104  fclose(fp);
105  return 1;
106 }
OS.h
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
Fopen
FILE * Fopen(const char *f, const char *mode)
Definition: OS.cpp:273
GModel::getEntities
void getEntities(std::vector< GEntity * > &entities, int dim=-1) const
Definition: GModel.cpp:651
GModel::writePOS
int writePOS(const std::string &name, bool printElementary, bool printElementNumber, bool printSICN, bool printSIGE, bool printGamma, bool printDisto, bool saveAll=false, double scalingFactor=1.0)
Definition: GModelIO_POS.cpp:11
MElement.h
GModel::noPhysicalGroups
bool noPhysicalGroups()
Definition: GModel.cpp:828
GModel.h