gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
automaticMeshSizeField.h
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 // Contributed by Arthur Bawin
7 
8 #ifndef AUTOMATIC_MESH_SIZE_FIELD_H
9 #define AUTOMATIC_MESH_SIZE_FIELD_H
10 
11 #include "GmshConfig.h"
12 #include "GModel.h"
13 #include "GRegion.h"
14 #include "MTriangle.h"
15 #include "MLine.h"
16 #include "Field.h"
17 #include "Context.h"
18 #include "STensor3.h"
19 #include "curvature.h"
20 
21 #include "rtree.h"
22 
23 #if defined(HAVE_P4EST)
24 // P4EST INCLUDES
25 #include <p4est_to_p8est.h>
26 #include <p8est_extended.h>
27 #endif
28 
29 #if defined(HAVE_HXT)
30 // HXT INCLUDES
31 extern "C" {
32 #include "hxt_tools.h"
33 #include "hxt_mesh.h"
34 #include "hxt_bbox.h"
35 }
36 #endif
37 
38 // Information needed to create and compute a forest of octrees
39 typedef struct ForestOptions {
40  int dim;
41  double hmax;
42  double hmin;
43  double hbulk;
44  double gradation;
47  double *bbox;
48  double (*sizeFunction)(double, double, double, double);
49  std::vector<double> *featureSizeAtVertices;
51 #ifdef HAVE_HXT
52  HXTMesh *mesh;
53 #endif
54  double *nodalCurvature;
55  double *nodeNormals;
56  // std::vector<std::function<double(double)>> *curvFunctions;
57  // std::vector<std::function<double(double)>> *xFunctions;
58  // std::vector<std::function<double(double)>> *yFunctions;
59  FILE *file1;
60  FILE *file2;
61  FILE *file3;
63 
64 // The structure containing the size field information (forest)
65 typedef struct Forest {
66 #ifdef HAVE_P4EST
67  p4est_t *p4est;
68 #endif
71 
72 // Data available on each tree cell
73 typedef struct size_data {
74  double size;
75 #ifdef HAVE_P4EST
76  double ds[3]; // Size gradient
77 #endif
78  double h; // Isotropic cell size
79  SMetric3 M; // Anisotropic size
80 
81  // DonnĂ©es pour l'interpolation des directions de courbure
84 
86 
87 // A node to search in the tree
88 typedef struct size_point {
89  double x;
90  double y;
91  double z;
92  double size;
94  bool isFound;
95  int parcourus;
97 
98 typedef struct interpolation_data {
99  double center[3];
102  double denom;
104 
105 #if defined(HAVE_HXT) && defined(HAVE_P4EST)
106 HXTStatus forestOptionsCreate(ForestOptions **forestOptions);
107 HXTStatus forestOptionsDelete(ForestOptions **forestOptions);
108 
109 HXTStatus forestCreate(int argc, char **argv, Forest **forest,
110  const char *filename, ForestOptions *forestOptions);
111 HXTStatus forestDelete(Forest **forest);
112 
113 HXTStatus forestSave(Forest *forest, const char *forestFile,
114  const char *dataFile);
115 HXTStatus forestExport(Forest *forest, const char *forestFile);
116 HXTStatus forestExport2D(Forest *forest, const char *forestFile);
117 HXTStatus forestLoad(Forest **forest, const char *forestFile,
118  const char *dataFile, ForestOptions *forestOptions);
119 
120 HXTStatus forestSearchOne(Forest *forest, double x, double y, double z,
121  double *size, int linear);
122 #endif
123 
125 #if defined(HAVE_HXT) && defined(HAVE_P4EST)
126  struct Forest *forest;
127  struct ForestOptions *forestOptions;
128  HXTStatus updateHXT();
129 #endif
130 
131  std::string _forestFile;
134  double _hmin, _hmax;
135  double _hbulk;
136  double _gradation;
138 
139 public:
142  std::string fFile = "",
143  int minElementsPerTwoPi = CTX::instance()->mesh.lcFromCurvature,
144  int nLayersPerGap = CTX::instance()->mesh.nLayersPerGap,
145  double gradation = CTX::instance()->mesh.gradation, double hmin = -1.0,
146  double hmax = -1.0, double hbulk = -1.0, int smoothing = true,
147  int gaps = true)
148 #if defined(HAVE_HXT) && defined(HAVE_P4EST)
149  : forest(nullptr), forestOptions(nullptr)
150 #endif
151  {
152  _forestFile = fFile;
153  _nPointsPerCircle = minElementsPerTwoPi ? minElementsPerTwoPi : 20;
154  _nPointsPerGap = nLayersPerGap ? nLayersPerGap : 0;
155  _hmin = hmin;
156  _hmax = hmax;
157  _hbulk = hbulk;
158  _gradation = (int)gradation ? gradation : 1.1;
159  _smoothing = smoothing;
160  _gaps = gaps;
161 
162  options["p4estFileToLoad"] = new FieldOptionString(
163  _forestFile, "p4est file containing the size field", &updateNeeded);
164 
165  options["nPointsPerCircle"] = new FieldOptionInt(
167  "Number of points per circle (adapt to curvature of surfaces)",
168  &updateNeeded);
169 
170  options["nPointsPerGap"] = new FieldOptionInt(
171  _nPointsPerGap, "Number of layers of elements in thin layers",
172  &updateNeeded);
173 
174  options["hMin"] =
175  new FieldOptionDouble(_hmin, "Minimum size", &updateNeeded);
176 
177  options["hMax"] =
178  new FieldOptionDouble(_hmax, "Maximum size", &updateNeeded);
179 
180  options["hBulk"] = new FieldOptionDouble(
181  _hbulk, "Default size where it is not prescribed", &updateNeeded);
182 
183  options["gradation"] = new FieldOptionDouble(
184  _gradation, "Maximum growth ratio for the edges lengths", &updateNeeded);
185 
186  options["smoothing"] = new FieldOptionBool(
187  _smoothing, "Enable size smoothing (should always be true)",
188  &updateNeeded);
189 
190  options["features"] = new FieldOptionBool(
191  _gaps, "Enable computation of local feature size (thin channels)",
192  &updateNeeded);
193 
194  updateNeeded = true;
195 
196  if(fFile != "") update();
197  }
198 
199  virtual bool isotropic() const { return false; }
200  const char *getName() { return "AutomaticMeshSizeField"; }
201 
202  std::string getDescription()
203  {
204  return "Compute a mesh size field that is quite automatic "
205  "Takes into account surface curvatures and closeness of objects";
206  }
207 
208  void update();
209  virtual double operator()(double X, double Y, double Z,
210  GEntity *ge = nullptr);
211  virtual void operator()(double x, double y, double z, SMetric3 &m,
212  GEntity *ge = nullptr);
213 };
214 
215 #endif
size_point::z
double z
Definition: automaticMeshSizeField.h:91
MTriangle.h
automaticMeshSizeField::_forestFile
std::string _forestFile
Definition: automaticMeshSizeField.h:131
size_point_t
struct size_point size_point_t
Field.h
ForestOptions::nodePerGap
int nodePerGap
Definition: automaticMeshSizeField.h:46
ForestOptions::gradation
double gradation
Definition: automaticMeshSizeField.h:44
ForestOptions::file1
FILE * file1
Definition: automaticMeshSizeField.h:59
SMetric3
Definition: STensor3.h:17
ForestOptions::file3
FILE * file3
Definition: automaticMeshSizeField.h:61
ForestOptions::dim
int dim
Definition: automaticMeshSizeField.h:40
Forest
struct Forest Forest
curvature.h
automaticMeshSizeField::_gaps
bool _gaps
Definition: automaticMeshSizeField.h:137
ForestOptions::featureSizeAtVertices
std::vector< double > * featureSizeAtVertices
Definition: automaticMeshSizeField.h:49
interpolation_data
Definition: automaticMeshSizeField.h:98
FieldOptionString
Definition: Field.h:265
automaticMeshSizeField::isotropic
virtual bool isotropic() const
Definition: automaticMeshSizeField.h:199
ForestOptions::hmin
double hmin
Definition: automaticMeshSizeField.h:42
size_point::x
double x
Definition: automaticMeshSizeField.h:89
ForestOptions::file2
FILE * file2
Definition: automaticMeshSizeField.h:60
SVector3
Definition: SVector3.h:16
automaticMeshSizeField::_smoothing
bool _smoothing
Definition: automaticMeshSizeField.h:137
ForestOptions::bbox
double * bbox
Definition: automaticMeshSizeField.h:47
ForestOptions
Definition: automaticMeshSizeField.h:39
Forest
Definition: automaticMeshSizeField.h:65
ForestOptions::hbulk
double hbulk
Definition: automaticMeshSizeField.h:43
MLine.h
GEntity
Definition: GEntity.h:31
rtree.h
size_point::parcourus
int parcourus
Definition: automaticMeshSizeField.h:95
interpolation_data::denom
double denom
Definition: automaticMeshSizeField.h:102
FieldOptionBool
Definition: Field.h:402
automaticMeshSizeField::operator()
virtual double operator()(double X, double Y, double Z, GEntity *ge=nullptr)
Definition: automaticMeshSizeField.cpp:2462
size_data_t
struct size_data size_data_t
ForestOptions::nodePerTwoPi
int nodePerTwoPi
Definition: automaticMeshSizeField.h:45
automaticMeshSizeField::update
void update()
Definition: automaticMeshSizeField.cpp:2949
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
contextMeshOptions::gradation
double gradation
Definition: Context.h:52
RTree< uint64_t, double, 3 >
interpolation_data::center
double center[3]
Definition: automaticMeshSizeField.h:99
GRegion.h
automaticMeshSizeField
Definition: automaticMeshSizeField.h:124
ForestOptions::nodalCurvature
double * nodalCurvature
Definition: automaticMeshSizeField.h:54
ForestOptions::nodeNormals
double * nodeNormals
Definition: automaticMeshSizeField.h:55
automaticMeshSizeField::_nPointsPerCircle
int _nPointsPerCircle
Definition: automaticMeshSizeField.h:132
ForestOptions::triRTree
RTree< uint64_t, double, 3 > * triRTree
Definition: automaticMeshSizeField.h:50
size_data::t2
SVector3 t2
Definition: automaticMeshSizeField.h:83
size_data::h
double h
Definition: automaticMeshSizeField.h:78
FieldOptionInt
Definition: Field.h:312
automaticMeshSizeField::_hbulk
double _hbulk
Definition: automaticMeshSizeField.h:135
automaticMeshSizeField::_gradation
double _gradation
Definition: automaticMeshSizeField.h:136
FieldOptionDouble
Definition: Field.h:288
CTX::mesh
contextMeshOptions mesh
Definition: Context.h:313
ForestOptions
struct ForestOptions ForestOptions
automaticMeshSizeField::_hmax
double _hmax
Definition: automaticMeshSizeField.h:134
Field
Definition: Field.h:103
size_point::size
double size
Definition: automaticMeshSizeField.h:92
interpolation_data::t2
SVector3 t2
Definition: automaticMeshSizeField.h:101
size_point
Definition: automaticMeshSizeField.h:88
automaticMeshSizeField::_hmin
double _hmin
Definition: automaticMeshSizeField.h:134
automaticMeshSizeField::_nPointsPerGap
int _nPointsPerGap
Definition: automaticMeshSizeField.h:133
size_data::M
SMetric3 M
Definition: automaticMeshSizeField.h:79
Forest::forestOptions
ForestOptions * forestOptions
Definition: automaticMeshSizeField.h:69
ForestOptions::sizeFunction
double(* sizeFunction)(double, double, double, double)
Definition: automaticMeshSizeField.h:48
interpolation_data_t
struct interpolation_data interpolation_data_t
Context.h
Field::options
std::map< std::string, FieldOption * > options
Definition: Field.h:112
z
const double z
Definition: GaussQuadratureQuad.cpp:56
STensor3.h
automaticMeshSizeField::~automaticMeshSizeField
~automaticMeshSizeField()
Definition: automaticMeshSizeField.cpp:2493
size_data::n
SVector3 n
Definition: automaticMeshSizeField.h:83
size_data::t1
SVector3 t1
Definition: automaticMeshSizeField.h:83
size_point::m
SMetric3 m
Definition: automaticMeshSizeField.h:93
size_point::isFound
bool isFound
Definition: automaticMeshSizeField.h:94
GModel.h
size_data::hasIntersection
bool hasIntersection
Definition: automaticMeshSizeField.h:82
ForestOptions::hmax
double hmax
Definition: automaticMeshSizeField.h:41
automaticMeshSizeField::getDescription
std::string getDescription()
Definition: automaticMeshSizeField.h:202
automaticMeshSizeField::getName
const char * getName()
Definition: automaticMeshSizeField.h:200
size_data::size
double size
Definition: automaticMeshSizeField.h:74
interpolation_data::t1
SVector3 t1
Definition: automaticMeshSizeField.h:100
automaticMeshSizeField::automaticMeshSizeField
automaticMeshSizeField(std::string fFile="", int minElementsPerTwoPi=CTX::instance() ->mesh.lcFromCurvature, int nLayersPerGap=CTX::instance() ->mesh.nLayersPerGap, double gradation=CTX::instance() ->mesh.gradation, double hmin=-1.0, double hmax=-1.0, double hbulk=-1.0, int smoothing=true, int gaps=true)
Definition: automaticMeshSizeField.h:141
size_data
Definition: automaticMeshSizeField.h:73
size_point::y
double y
Definition: automaticMeshSizeField.h:90
contextMeshOptions::nLayersPerGap
int nLayersPerGap
Definition: Context.h:51
Field::updateNeeded
bool updateNeeded
Definition: Field.h:129