gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
GModelIO_IR3.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 "MElement.h"
9 
10 int GModel::writeIR3(const std::string &name, int elementTagType, bool saveAll,
11  double scalingFactor)
12 {
13  FILE *fp = Fopen(name.c_str(), "w");
14  if(!fp) {
15  Msg::Error("Unable to open file '%s'", name.c_str());
16  return 0;
17  }
18 
19  if(noPhysicalGroups()) saveAll = true;
20 
21  int numVertices = indexMeshVertices(saveAll), num2D = 0, num3D = 0;
22  for(auto it = firstFace(); it != lastFace(); ++it)
23  if(saveAll || (*it)->physicals.size()) num2D += (*it)->getNumMeshElements();
24  for(auto it = firstRegion(); it != lastRegion(); ++it)
25  if(saveAll || (*it)->physicals.size()) num3D += (*it)->getNumMeshElements();
26 
27  fprintf(fp, "33\n");
28  if(num2D && num3D)
29  fprintf(fp, "%d %d %d\n", numVertices, num2D, num3D);
30  else
31  fprintf(fp, "%d %d\n", numVertices, num2D ? num2D : num3D);
32 
33  std::vector<GEntity *> entities;
34  getEntities(entities);
35 
36  for(std::size_t i = 0; i < entities.size(); i++)
37  for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++)
38  if(entities[i]->mesh_vertices[j]->getIndex() >= 0)
39  fprintf(fp, "%ld %.16g %.16g %.16g\n",
40  entities[i]->mesh_vertices[j]->getIndex(),
41  entities[i]->mesh_vertices[j]->x() * scalingFactor,
42  entities[i]->mesh_vertices[j]->y() * scalingFactor,
43  entities[i]->mesh_vertices[j]->z() * scalingFactor);
44 
45  int iElement = 1;
46  for(auto it = firstFace(); it != lastFace(); ++it) {
47  int numPhys = (*it)->physicals.size();
48  if(saveAll || numPhys)
49  for(std::size_t i = 0; i < (*it)->getNumMeshElements(); i++)
50  (*it)->getMeshElement(i)->writeIR3(fp, elementTagType, iElement++,
51  (*it)->tag(),
52  numPhys ? (*it)->physicals[0] : 0);
53  }
54 
55  iElement = 1;
56  for(auto it = firstRegion(); it != lastRegion(); ++it) {
57  int numPhys = (*it)->physicals.size();
58  if(saveAll || numPhys)
59  for(std::size_t i = 0; i < (*it)->getNumMeshElements(); i++)
60  (*it)->getMeshElement(i)->writeIR3(fp, elementTagType, iElement++,
61  (*it)->tag(),
62  numPhys ? (*it)->physicals[0] : 0);
63  }
64 
65  fclose(fp);
66  return 1;
67 }
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::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
GModel::firstRegion
riter firstRegion()
Definition: GModel.h:354
GModel::lastRegion
riter lastRegion()
Definition: GModel.h:358
z
const double z
Definition: GaussQuadratureQuad.cpp:56
MElement.h
GModel::noPhysicalGroups
bool noPhysicalGroups()
Definition: GModel.cpp:828
GModel.h
GModel::indexMeshVertices
std::size_t indexMeshVertices(bool all, int singlePartition=0, bool renumber=true)
Definition: GModel.cpp:2135
GModel::writeIR3
int writeIR3(const std::string &name, int elementTagType, bool saveAll, double scalingFactor)
Definition: GModelIO_IR3.cpp:10