gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
meshMetric.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 #ifndef MESH_METRIC_H
7 #define MESH_METRIC_H
8 
9 #include <map>
10 #include <algorithm>
11 #include "STensor3.h"
12 #include "Field.h"
13 #include "meshGFaceOptimize.h"
14 
15 template <class scalar> class simpleFunction;
16 class MVertex;
17 class gLevelset;
18 class MElementOctree;
19 class STensor3;
20 
22 class meshMetric : public Field {
23 public:
24  typedef enum {
25  LEVELSET = 1,
26  HESSIAN = 2,
27  FREY = 3,
32 
33 private:
34  // intersect all metrics added in "setOfMetrics", preserve eigendirections of
35  // the "most anisotropic" metric
36  void updateMetrics();
37  int _dim;
38  double _epsilon, _e, _e_moins, _np;
42  double hmin, hmax;
44 
45  std::vector<MElement *> _elements;
48  std::map<int, MVertex *> _vertexMap;
49 
50  std::map<MVertex *, double> vals;
51  std::map<MVertex *, SVector3> grads;
52  std::map<MVertex *, SMetric3> hessians;
53 
54 public:
55  typedef std::map<MVertex *, SMetric3> nodalMetricTensor;
56  typedef std::map<MVertex *, double> nodalField;
57 
58 private:
61 
62  std::map<int, nodalMetricTensor> setOfMetrics;
63  std::map<int, nodalField> setOfSizes;
64  std::map<int, bool> setOfRecomputeBoolean;
65  std::map<int, simpleFunction<double> *> setOfFcts;
66  std::map<int, std::vector<double> > setOfParameters;
67  std::map<int, int> setOfTechniques;
68  // std::map<int,nodalField> setOfDetMetric;
69 
70 public:
71  meshMetric(std::vector<MElement *> elements);
72  meshMetric(GModel *gm);
73 
74  ~meshMetric();
75 
76  // compute a new metric and add it to the set of metrics
77  // parameters[1] = lcmin (default : in global gmsh options
78  // CTX::instance()->mesh.lcMin) parameters[2] = lcmax (default : in global
79  // gmsh options CTX::instance()->mesh.lcMax) Available algorithms
80  // ("techniques"): 1: fct is a LS, metric based on Coupez technique
81  // parameters[0] = thickness of the interface (mandatory)
82  // 2: metric based on the hessian of fct
83  // parameters[0] = the final number of elements
84  // 3: fct is a LS, variant of (1) based on Frey technique (combines Coupez and
85  // curvature)
86  // parameters[0] = thickness of the interface (mandatory)
87  // parameters[3] = the required minimum number of elements to represent a
88  // circle - used for curvature-based metric (default: = 15)
89  // 4: fct is a LS, variant of (3), metric computed in LS eigendirections
90  // parameters[0] = thickness of the interface in the positive ls direction
91  // (mandatory) parameters[4] = thickness of the interface in the negative
92  // ls direction (default: =parameters[0] if not specified) parameters[3] =
93  // the required minimum number of elements to represent a circle - used for
94  // curvature-based metric (default: = 15)
95  // 5: same as 4, except that the transition in band E uses linear
96  // interpolation of h, instead of linear interpolation of metric 6: fct is a
97  // LS, metric is isotropic with linear interpolation of h in band E 7: metric
98  // based on the Hessian of fct, scaled so that the smallest element has size
99  // lcmin
100  void addMetric(int technique, simpleFunction<double> *fct,
101  const std::vector<double> &parameters);
102 
104  {
106  return _nodalMetrics[v];
107  }
108  // this function scales the mesh metric in order
109  // to reach a target number of elements
110  void scaleMetric(int nbElementsTarget, nodalMetricTensor &nmt);
111 
112  void computeMetric(int metricNumber);
113  void computeMetricLevelSet(MVertex *ver, SMetric3 &hessian, SMetric3 &metric,
114  double &size, double x = 0.0, double y = 0.0,
115  double z = 0.0);
116  void computeMetricHessian(MVertex *ver, SMetric3 &hessian, SMetric3 &metric,
117  double &size, double x = 0.0, double y = 0.0,
118  double z = 0.0);
119  void computeMetricFrey(MVertex *ver, SMetric3 &hessian, SMetric3 &metric,
120  double &size, double x = 0.0, double y = 0.0,
121  double z = 0.0);
122  void computeMetricEigenDir(MVertex *ver, SMetric3 &hessian, SMetric3 &metric,
123  double &size, double x = 0.0, double y = 0.0,
124  double z = 0.0);
125  void computeMetricIsoLinInterp(MVertex *ver, SMetric3 &hessian,
126  SMetric3 &metric, double &size, double x = 0.0,
127  double y = 0.0, double z = 0.0);
128 
129  void computeValues();
130  void computeHessian();
131 
132  double getLaplacian(MVertex *v);
134  virtual bool isotropic() const { return false; }
135  virtual const char *getName() { return "metricField"; }
136  virtual std::string getDescription()
137  {
138  return "Anisotropic size field based on hessian of a given function";
139  }
140 
141  // get metric at point(x,y,z) (previously computes intersection of metrics if
142  // not done yet)
143  virtual double operator()(double x, double y, double z,
144  GEntity *ge = nullptr);
145  virtual void operator()(double x, double y, double z, SMetric3 &metr,
146  GEntity *ge = nullptr);
147 
148  // export pos files of fct, fct gradients (fct is the lattest fct passed to
149  // meshMetric !!) and resulting metric (intersection of all computed metrics)
150  void exportInfo(const char *fileendname);
151 };
152 
153 #endif
meshMetric::setOfFcts
std::map< int, simpleFunction< double > * > setOfFcts
Definition: meshMetric.h:65
meshMetric::_octree
MElementOctree * _octree
Definition: meshMetric.h:47
Field.h
meshMetric::_dim
int _dim
Definition: meshMetric.h:37
SMetric3
Definition: STensor3.h:17
meshMetric::isotropic
virtual bool isotropic() const
Definition: meshMetric.h:134
meshMetric::_vertexMap
std::map< int, MVertex * > _vertexMap
Definition: meshMetric.h:48
meshMetric::ISOTROPIC_LINEARINTERP_H
@ ISOTROPIC_LINEARINTERP_H
Definition: meshMetric.h:30
meshMetric::getDescription
virtual std::string getDescription()
Definition: meshMetric.h:136
meshMetric::EIGENDIRECTIONS_LINEARINTERP_H
@ EIGENDIRECTIONS_LINEARINTERP_H
Definition: meshMetric.h:29
meshMetric::exportInfo
void exportInfo(const char *fileendname)
Definition: meshMetric.cpp:105
meshMetric::setOfSizes
std::map< int, nodalField > setOfSizes
Definition: meshMetric.h:63
meshMetric::needMetricUpdate
bool needMetricUpdate
Definition: meshMetric.h:39
meshMetric::_technique
meshMetric::MetricComputationTechnique _technique
Definition: meshMetric.h:41
MVertex
Definition: MVertex.h:24
STensor3
Definition: STensor3.h:97
meshMetric::setOfMetrics
std::map< int, nodalMetricTensor > setOfMetrics
Definition: meshMetric.h:62
meshMetric::computeMetricEigenDir
void computeMetricEigenDir(MVertex *ver, SMetric3 &hessian, SMetric3 &metric, double &size, double x=0.0, double y=0.0, double z=0.0)
Definition: meshMetric.cpp:517
SVector3
Definition: SVector3.h:16
meshGFaceOptimize.h
meshMetric::updateMetrics
void updateMetrics()
Definition: meshMetric.cpp:79
meshMetric::_epsilon
double _epsilon
Definition: meshMetric.h:38
meshMetric::setOfParameters
std::map< int, std::vector< double > > setOfParameters
Definition: meshMetric.h:66
v2t_cont
std::map< MVertex *, std::vector< MElement * >, MVertexPtrLessThan > v2t_cont
Definition: meshGFaceOptimize.h:31
meshMetric::_nodalMetrics
nodalMetricTensor _nodalMetrics
Definition: meshMetric.h:59
GEntity
Definition: GEntity.h:31
meshMetric::computeMetricLevelSet
void computeMetricLevelSet(MVertex *ver, SMetric3 &hessian, SMetric3 &metric, double &size, double x=0.0, double y=0.0, double z=0.0)
Definition: meshMetric.cpp:354
meshMetric::_adj
v2t_cont _adj
Definition: meshMetric.h:46
meshMetric::_fct
simpleFunction< double > * _fct
Definition: meshMetric.h:43
meshMetric::MetricComputationTechnique
MetricComputationTechnique
Definition: meshMetric.h:24
meshMetric::computeMetricIsoLinInterp
void computeMetricIsoLinInterp(MVertex *ver, SMetric3 &hessian, SMetric3 &metric, double &size, double x=0.0, double y=0.0, double z=0.0)
Definition: meshMetric.cpp:651
meshMetric::HESSIAN
@ HESSIAN
Definition: meshMetric.h:26
simpleFunction
Definition: GModel.h:30
meshMetric::computeMetricFrey
void computeMetricFrey(MVertex *ver, SMetric3 &hessian, SMetric3 &metric, double &size, double x=0.0, double y=0.0, double z=0.0)
Definition: meshMetric.cpp:452
gLevelset
Definition: gmshLevelset.h:64
meshMetric::scaleMetric
void scaleMetric(int nbElementsTarget, nodalMetricTensor &nmt)
Definition: meshMetric.cpp:706
meshMetric::hasAnalyticalMetric
bool hasAnalyticalMetric
Definition: meshMetric.h:40
meshMetric::_e
double _e
Definition: meshMetric.h:38
meshMetric::_np
double _np
Definition: meshMetric.h:38
meshMetric::_elements
std::vector< MElement * > _elements
Definition: meshMetric.h:45
GModel
Definition: GModel.h:44
meshMetric::meshMetric
meshMetric(std::vector< MElement * > elements)
Definition: meshMetric.cpp:46
meshMetric::nodalMetricTensor
std::map< MVertex *, SMetric3 > nodalMetricTensor
Definition: meshMetric.h:55
MElementOctree
Definition: MElementOctree.h:15
meshMetric::_e_moins
double _e_moins
Definition: meshMetric.h:38
meshMetric
Definition: meshMetric.h:22
meshMetric::computeMetric
void computeMetric(int metricNumber)
Definition: meshMetric.cpp:748
meshMetric::setOfRecomputeBoolean
std::map< int, bool > setOfRecomputeBoolean
Definition: meshMetric.h:64
meshMetric::hessians
std::map< MVertex *, SMetric3 > hessians
Definition: meshMetric.h:52
Field
Definition: Field.h:103
meshMetric::computeMetricHessian
void computeMetricHessian(MVertex *ver, SMetric3 &hessian, SMetric3 &metric, double &size, double x=0.0, double y=0.0, double z=0.0)
Definition: meshMetric.cpp:406
meshMetric::getGradient
SVector3 getGradient(MVertex *v)
Definition: meshMetric.cpp:945
meshMetric::nodalField
std::map< MVertex *, double > nodalField
Definition: meshMetric.h:56
meshMetric::getLaplacian
double getLaplacian(MVertex *v)
Definition: meshMetric.cpp:937
meshMetric::LEVELSET
@ LEVELSET
Definition: meshMetric.h:25
meshMetric::_detMetric
nodalField _detMetric
Definition: meshMetric.h:60
z
const double z
Definition: GaussQuadratureQuad.cpp:56
meshMetric::metricAtVertex
SMetric3 metricAtVertex(MVertex *v)
Definition: meshMetric.h:103
STensor3.h
meshMetric::operator()
virtual double operator()(double x, double y, double z, GEntity *ge=nullptr)
Definition: meshMetric.cpp:792
meshMetric::FREY
@ FREY
Definition: meshMetric.h:27
meshMetric::~meshMetric
~meshMetric()
Definition: meshMetric.cpp:210
meshMetric::computeHessian
void computeHessian()
Definition: meshMetric.cpp:275
meshMetric::hmin
double hmin
Definition: meshMetric.h:42
meshMetric::_nodalSizes
nodalField _nodalSizes
Definition: meshMetric.h:60
meshMetric::setOfTechniques
std::map< int, int > setOfTechniques
Definition: meshMetric.h:67
meshMetric::getName
virtual const char * getName()
Definition: meshMetric.h:135
meshMetric::grads
std::map< MVertex *, SVector3 > grads
Definition: meshMetric.h:51
meshMetric::hmax
double hmax
Definition: meshMetric.h:42
meshMetric::addMetric
void addMetric(int technique, simpleFunction< double > *fct, const std::vector< double > &parameters)
Definition: meshMetric.cpp:64
meshMetric::computeValues
void computeValues()
Definition: meshMetric.cpp:216
meshMetric::EIGENDIRECTIONS
@ EIGENDIRECTIONS
Definition: meshMetric.h:28
meshMetric::vals
std::map< MVertex *, double > vals
Definition: meshMetric.h:50