gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
sizeField.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 "GmshConfig.h"
7 #include "sizeField.h"
8 #include "GModel.h"
9 #include "GFace.h"
10 #include "MVertex.h"
11 #include "MTriangle.h"
12 #include "BackgroundMeshTools.h"
13 
14 #if defined(HAVE_QUADMESHINGTOOLS)
15 #include "cppUtils.h"
16 #include "qmtMeshUtils.h"
17 #include "qmtCrossField.h"
18 #include "qmtSizeMap.h"
19 #endif
20 
21 static void printSizeField(const char *fn, std::vector<MTriangle *> &triangles,
22  std::unordered_map<MVertex *, double> &sizeField)
23 {
24  FILE *f = fopen(fn, "w");
25  fprintf(f, "View\"SIZE FIELD\"{\n");
26  for(auto t : triangles) {
27  fprintf(f,
28  "ST(%12.5E,%12.5E,%12.5E,%12.5E,%12.5E,%12.5E,%12.5E,%12.5E,%12.5E)"
29  "{%12.5E,%12.5E,%12.5E};\n",
30  t->getVertex(0)->x(), t->getVertex(0)->y(), t->getVertex(0)->z(),
31  t->getVertex(1)->x(), t->getVertex(1)->y(), t->getVertex(1)->z(),
32  t->getVertex(2)->x(), t->getVertex(2)->y(), t->getVertex(2)->z(),
33  sizeField[t->getVertex(0)], sizeField[t->getVertex(1)],
34  sizeField[t->getVertex(2)]);
35  }
36  fprintf(f, "};\n");
37  fclose(f);
38 }
39 
40 int createSizeFieldFromExistingMesh(GModel *gm, bool computeCrosses)
41 {
42  return 0;
43 #if defined(HAVE_QUADMESHINGTOOLS)
44 
45  std::vector<MTriangle *> triangles;
46  for(auto itf = gm->firstFace(); itf != gm->lastFace(); ++itf) {
47  // quadsToTriangles(gf, minqual);
48  if((*itf)->tag() < 100000)
49  triangles.insert(triangles.end(), (*itf)->triangles.begin(),
50  (*itf)->triangles.end());
51  }
52 
53  std::unordered_map<MVertex *, std::vector<MVertex *> > v2v;
54  buildVertexToVertexMap(triangles, v2v);
55 
56  std::unordered_map<MVertex *, double> sizeField;
57 
58  for(auto it : v2v) {
59  MVertex *v = it.first;
60  double size = 1.e22, U, V;
61  if(v->onWhat()->dim() == 1) {
62  v->getParameter(0, U);
63  size = BGM_MeshSize(v->onWhat(), U, 0., v->x(), v->y(), v->z());
64  }
65  else if(v->onWhat()->dim() == 2) {
66  v->getParameter(0, U);
67  v->getParameter(1, V);
68  size = BGM_MeshSize(v->onWhat(), U, V, v->x(), v->y(), v->z());
69  }
70  else
71  size = BGM_MeshSize(v->onWhat(), 0., 0., v->x(), v->y(), v->z());
72  sizeField[v] = size;
73  }
74 
75  printSizeField("size_field.pos", triangles, sizeField);
76  int sows = sizeMapOneWaySmoothing(triangles, sizeField, 1.2);
77  if(sows != 0) {
78  Msg::Warning("failed to smooth size map");
79  return sows;
80  }
81  printSizeField("smoothed_size_field.pos", triangles, sizeField);
82 #endif
83  return 0;
84 }
MTriangle.h
GFace.h
MVertex
Definition: MVertex.h:24
Msg::Warning
static void Warning(const char *fmt,...)
Definition: GmshMessage.cpp:543
MVertex::z
double z() const
Definition: MVertex.h:62
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition: orthogonalBasis.cpp:77
createSizeFieldFromExistingMesh
int createSizeFieldFromExistingMesh(GModel *gm, bool computeCrosses)
Definition: sizeField.cpp:40
MVertex::onWhat
GEntity * onWhat() const
Definition: MVertex.h:82
GModel::lastFace
fiter lastFace()
Definition: GModel.h:359
MVertex.h
GModel
Definition: GModel.h:44
BGM_MeshSize
double BGM_MeshSize(GEntity *ge, double U, double V, double X, double Y, double Z)
Definition: BackgroundMeshTools.cpp:255
GModel::firstFace
fiter firstFace()
Definition: GModel.h:355
printSizeField
static void printSizeField(const char *fn, std::vector< MTriangle * > &triangles, std::unordered_map< MVertex *, double > &sizeField)
Definition: sizeField.cpp:21
MVertex::getParameter
virtual bool getParameter(int i, double &par) const
Definition: MVertex.h:97
sizeField.h
BackgroundMeshTools.h
GModel.h
MVertex::y
double y() const
Definition: MVertex.h:61
GEntity::dim
virtual int dim() const
Definition: GEntity.h:196
MVertex::x
double x() const
Definition: MVertex.h:60