gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
GModelIO_CELUM.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 #include "MQuadrangle.h"
10 
11 class CelumInfo {
12 public:
14  double curvMax, curvMin;
15 };
16 
17 int GModel::writeCELUM(const std::string &name, bool saveAll,
18  double scalingFactor)
19 {
20  std::string namef = name + "_f";
21  FILE *fpf = Fopen(namef.c_str(), "w");
22  if(!fpf) {
23  Msg::Error("Unable to open file '%s'", namef.c_str());
24  return 0;
25  }
26 
27  std::string names = name + "_s";
28  FILE *fps = Fopen(names.c_str(), "w");
29  if(!fps) {
30  Msg::Error("Unable to open file '%s'", names.c_str());
31  fclose(fpf);
32  return 0;
33  }
34 
35  if(noPhysicalGroups()) saveAll = true;
36 
37  // count faces and vertices; the CELUM format duplicates vertices on the
38  // boundary of CAD patches
39  int numf = 0, nums = 0;
40  for(auto it = firstFace(); it != lastFace(); it++) {
41  GFace *f = *it;
42  if(!saveAll && f->physicals.empty()) continue;
43  numf += f->triangles.size();
44  std::set<MVertex *> vset;
45  for(std::size_t i = 0; i < f->triangles.size(); i++) {
46  for(int j = 0; j < 3; j++) vset.insert(f->triangles[i]->getVertex(j));
47  }
48  nums += vset.size();
49  }
50 
51  Msg::Info("Writing %d triangles and %d nodes", numf, nums);
52 
53  int idf = 1, ids = 1;
54  /*
55  * a file with faces
56  - number of faces
57  - empty line
58  ... for each face
59  - number of the face (starts at 1 : used for read errors)
60  - char string (name of geom part, material,... )
61  - list of 3 vertex nums
62  - empty line
63  ...
64  * a file with vertices
65  - number of vertices
66  - conversion factor
67  - empty line
68  ... for each vertex
69  - number of the vertex (starts at 1 : used for read errors)
70  - cartesian coordinates of the vertex
71  - componants of the exterior oriented normal
72  - value of 1st principal curvature
73  - value of second princpal curvature
74  - components of 1st principal direction
75  - components of 2nd principal direction
76  - empty line
77  ...
78  */
79  fprintf(fpf, "%d\n\n", numf);
80  fprintf(fps, "%d %g\n\n", nums, 1.0);
81  for(auto it = firstFace(); it != lastFace(); it++) {
82  GFace *f = *it;
83  if(!saveAll && f->physicals.empty()) continue;
84  std::vector<MVertex *> vvec;
85  std::map<MVertex *, CelumInfo> vmap;
86  for(std::size_t i = 0; i < f->triangles.size(); i++) {
87  fprintf(fpf, "%d \"face %d\"", idf++, f->tag());
88  for(int j = 0; j < 3; j++) {
89  MVertex *v = f->triangles[i]->getVertex(j);
90  if(!vmap.count(v)) {
91  v->setIndex(ids++);
92  SPoint2 param;
93  bool ok = reparamMeshVertexOnFace(v, f, param);
94  if(!ok)
95  Msg::Warning("Could not reparamtrize node %d on surface %d",
96  v->getNum(), f->tag());
97  CelumInfo info;
98  info.normal = f->normal(param);
99  f->curvatures(param, info.dirMax, info.dirMin, info.curvMax,
100  info.curvMin);
101  vmap[v] = info;
102  vvec.push_back(v);
103  }
104  fprintf(fpf, " %ld", v->getIndex());
105  }
106  fprintf(fpf, "\n\n");
107  }
108  for(std::size_t i = 0; i < vvec.size(); i++) {
109  MVertex *v = vvec[i];
110  auto it = vmap.find(v);
111  fprintf(fps, "%ld %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n\n",
112  it->first->getIndex(), it->first->x(), it->first->y(),
113  it->first->z(), it->second.normal.x(), it->second.normal.y(),
114  it->second.normal.z(), it->second.curvMin, it->second.curvMax,
115  it->second.dirMin.x(), it->second.dirMin.y(),
116  it->second.dirMin.z(), it->second.dirMax.x(),
117  it->second.dirMax.y(), it->second.dirMax.z());
118  }
119  }
120 
121  fclose(fpf);
122  fclose(fps);
123  return 1;
124 }
MTriangle.h
GFace
Definition: GFace.h:33
Msg::Info
static void Info(const char *fmt,...)
Definition: GmshMessage.cpp:587
SPoint2
Definition: SPoint2.h:12
OS.h
MVertex
Definition: MVertex.h:24
Msg::Warning
static void Warning(const char *fmt,...)
Definition: GmshMessage.cpp:543
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
reparamMeshVertexOnFace
bool reparamMeshVertexOnFace(MVertex const *v, const GFace *gf, SPoint2 &param, bool onSurface, bool failOnSeam, int dir)
Definition: MVertex.cpp:522
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition: orthogonalBasis.cpp:77
MVertex::getNum
std::size_t getNum() const
Definition: MVertex.h:86
SVector3
Definition: SVector3.h:16
GModel::writeCELUM
int writeCELUM(const std::string &name, bool saveAll=false, double scalingFactor=1.0)
Definition: GModelIO_CELUM.cpp:17
vset
void vset(double *v, double x, double y, double z)
Definition: Trackball.cpp:85
Fopen
FILE * Fopen(const char *f, const char *mode)
Definition: OS.cpp:273
CelumInfo::dirMin
SVector3 dirMin
Definition: GModelIO_CELUM.cpp:13
GModel::lastFace
fiter lastFace()
Definition: GModel.h:359
CelumInfo
Definition: GModelIO_CELUM.cpp:11
MVertex::setIndex
void setIndex(long int index)
Definition: MVertex.h:94
CelumInfo::dirMax
SVector3 dirMax
Definition: GModelIO_CELUM.cpp:13
CelumInfo::curvMax
double curvMax
Definition: GModelIO_CELUM.cpp:14
GModel::firstFace
fiter firstFace()
Definition: GModel.h:355
MVertex::getIndex
long int getIndex() const
Definition: MVertex.h:93
MQuadrangle.h
CelumInfo::normal
SVector3 normal
Definition: GModelIO_CELUM.cpp:13
GModel::noPhysicalGroups
bool noPhysicalGroups()
Definition: GModel.cpp:828
GModel.h
CelumInfo::curvMin
double curvMin
Definition: GModelIO_CELUM.cpp:14