gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
FuncGradDisc.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 // Contributor(s):
7 // Boris Sedji
8 //
9 
10 #ifndef FUNCGRADDISC_H
11 #define FUNCGRADDISC_H
12 
13 #include "gmshLevelset.h"
14 #include "MVertex.h"
15 #include "GModel.h"
16 
17 template <class scalar> class simpleFunction;
18 
19 class FuncGradDisc : public simpleFunctionOnElement<double> {
20 private:
23 
24 public:
26  {
27  _ls = ls;
28  _pModel = pModel;
29  }
30 
31  double operator()(double x, double y, double z) const
32  {
33  // --- F2 --- //
34  MElement *e = getElement();
35  SPoint3 p(x, y, z);
36 
37  if(e->getParent()) e = e->getParent();
38  double xyz[3] = {x, y, z};
39  double uvw[3];
40  e->xyz2uvw(xyz, uvw);
41  double val[30];
42  e->getShapeFunctions(uvw[0], uvw[1], uvw[2], val);
43  double f = 0;
44  for(std::size_t i = 0; i < e->getNumShapeFunctions(); i++) {
45  MVertex *v = e->getShapeFunctionNode(i);
46  // std::cout<<"val[i] :" << val[i] << "\n";
47  // std::cout<<"ls(i) :" << (*_ls)(v->x(),v->y(),v->z()) << "\n";
48  f = f + std::abs((*_ls)(v->x(), v->y(), v->z())) * val[i];
49  }
50  f = f - std::abs((*_ls)(x, y, z));
51 
52  // std::cout<<"val f :" << f << "\n";
53  return f;
54 
55  // --- F1 --- //
56 
57  // SPoint3 p(x,y,z);
58  // if (e->getParent()) e = e->getParent();
59  // double xyz[3] = {x,y,z};
60  // double uvw[3];
61  // e->xyz2uvw(xyz,uvw);
62  // double val[30];
63  // e->getShapeFunctions(uvw[0], uvw[1], uvw[2], val);
64  // double f = 0;
65  // for (std::size_t i = 0; i < e->getNumShapeFunctions(); i++)
66  // {
67  // MVertex *v = e-<getShapeFunctionNode(i);
68  // f = f + (*_ls)(v->x(), v->y(), v->z()) * val[i];
69  // }
70  // f = std::abs(f);
71  // return f;
72  }
73 
74  void gradient(double x, double y, double z, double &dfdx, double &dfdy,
75  double &dfdz) const
76  {
77  // ---- F2 ---- //
78  MElement *e = getElement();
79  SPoint3 p(x, y, z);
80  if(e->getParent()) e = e->getParent();
81  double xyz[3] = {x, y, z};
82  double uvw[3];
83  e->xyz2uvw(xyz, uvw);
84  double gradsuvw[256][3];
85  e->getGradShapeFunctions(uvw[0], uvw[1], uvw[2], gradsuvw);
86 
87  double jac[3][3];
88  double invjac[3][3];
89  double dNdx;
90  double dNdy;
91  double dNdz;
92  const double detJ = e->getJacobian(uvw[0], uvw[1], uvw[2], jac);
93  inv3x3(jac, invjac);
94 
95  dfdx = 0;
96  dfdy = 0;
97  dfdz = 0;
98 
99  if((*_ls)(x, y, z) > 0) {
100  for(std::size_t i = 0; i < e->getNumShapeFunctions(); i++) {
101  dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] +
102  invjac[0][2] * gradsuvw[i][2];
103  dNdy = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] +
104  invjac[1][2] * gradsuvw[i][2];
105  dNdz = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] +
106  invjac[2][2] * gradsuvw[i][2];
107 
108  MVertex *v = e->getShapeFunctionNode(i);
109  dfdx = dfdx + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdx;
110  dfdx = dfdx - (*_ls)(v->x(), v->y(), v->z()) * dNdx;
111  dfdy = dfdy + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdy;
112  dfdy = dfdy - (*_ls)(v->x(), v->y(), v->z()) * dNdy;
113  dfdz = dfdz + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdz;
114  dfdz = dfdz - (*_ls)(v->x(), v->y(), v->z()) * dNdz;
115  }
116  }
117  else {
118  for(std::size_t i = 0; i < e->getNumShapeFunctions(); i++) {
119  dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] +
120  invjac[0][2] * gradsuvw[i][2];
121  dNdy = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] +
122  invjac[1][2] * gradsuvw[i][2];
123  dNdz = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] +
124  invjac[2][2] * gradsuvw[i][2];
125 
126  MVertex *v = e->getShapeFunctionNode(i);
127  dfdx = dfdx + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdx;
128  dfdx = dfdx + (*_ls)(v->x(), v->y(), v->z()) * dNdx;
129  dfdy = dfdy + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdy;
130  dfdy = dfdy + (*_ls)(v->x(), v->y(), v->z()) * dNdy;
131  dfdz = dfdz + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdz;
132  dfdz = dfdz + (*_ls)(v->x(), v->y(), v->z()) * dNdz;
133  }
134  }
135  }
136 
137  // ---- F1 ------ //
138 
139  //
140  // SPoint3 p(x,y,z);
141  // if (e->getParent()) e = e->getParent();
142  // double xyz[3] = {x,y,z};
143  // double uvw[3];
144  // e->xyz2uvw(xyz,uvw);
145  // double gradsuvw[256][3];
146  // e->getGradShapeFunctions(uvw[0],uvw[1],uvw[2],gradsuvw);
147  //
148  // double jac[3][3];
149  // double invjac[3][3];
150  // double dNdx;
151  // double dNdy;
152  // double dNdz;
153  // const double detJ = e->getJacobian(uvw[0], uvw[1], uvw[2], jac);
154  // inv3x3(jac, invjac);
155  //
156  // dfdx = 0;
157  // dfdy = 0;
158  // dfdz = 0;
159  //
160  // if ((*_ls)(x,y,z)>0)
161  // {
162  // for (std::size_t i = 0; i < e->getNumShapeFunctions(); i++)
163  // {
164  // dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] *
165  // gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; dNdy =
166  // invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] +
167  // invjac[1][2] * gradsuvw[i][2]; dNdz = invjac[2][0] *
168  // gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] *
169  // gradsuvw[i][2];
170  //
171  // MVertex *v = e->getShapeFunctionNode(i);
172  // dfdx = dfdx + (*_ls)(v->x(), v->y(), v->z()) * dNdx;
173  // dfdy = dfdy + (*_ls)(v->x(), v->y(), v->z()) * dNdy;
174  // dfdz = dfdz + (*_ls)(v->x(), v->y(), v->z()) * dNdz;
175  // }
176  // }else
177  // {
178  // for (std::size_t i = 0; i < e->getNumShapeFunctions(); i++)
179  // {
180  // dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] *
181  // gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; dNdy =
182  // invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] +
183  // invjac[1][2] * gradsuvw[i][2]; dNdz = invjac[2][0] *
184  // gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] *
185  // gradsuvw[i][2];
186  //
187  // MVertex *v = e->getShapeFunctionNode(i);
188  // dfdx = dfdx - (*_ls)(v->x(), v->y(), v->z()) * dNdx;
189  // dfdy = dfdy - (*_ls)(v->x(), v->y(), v->z()) * dNdy;
190  // dfdz = dfdz - (*_ls)(v->x(), v->y(), v->z()) * dNdz;
191  // }
192  // }
193  // }
194 };
195 
196 #endif
MElement::xyz2uvw
virtual void xyz2uvw(double xyz[3], double uvw[3]) const
Definition: MElement.cpp:1128
simpleFunctionOnElement
Definition: simpleFunction.h:60
inv3x3
double inv3x3(double mat[3][3], double inv[3][3])
Definition: Numeric.cpp:232
FuncGradDisc::_ls
gLevelset * _ls
Definition: FuncGradDisc.h:21
MVertex
Definition: MVertex.h:24
MVertex::z
double z() const
Definition: MVertex.h:62
SPoint3
Definition: SPoint3.h:14
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition: orthogonalBasis.cpp:77
MElement::getParent
virtual MElement * getParent() const
Definition: MElement.h:231
MElement::getShapeFunctionNode
virtual const MVertex * getShapeFunctionNode(int i) const
Definition: MElement.h:392
FuncGradDisc::operator()
double operator()(double x, double y, double z) const
Definition: FuncGradDisc.h:31
FuncGradDisc::gradient
void gradient(double x, double y, double z, double &dfdx, double &dfdy, double &dfdz) const
Definition: FuncGradDisc.h:74
simpleFunction
Definition: GModel.h:30
gLevelset
Definition: gmshLevelset.h:64
MVertex.h
GModel
Definition: GModel.h:44
MElement::getNumShapeFunctions
virtual std::size_t getNumShapeFunctions() const
Definition: MElement.h:387
MElement
Definition: MElement.h:30
simpleFunctionOnElement< double >::getElement
MElement * getElement(void) const
Definition: simpleFunction.h:69
FuncGradDisc::FuncGradDisc
FuncGradDisc(gLevelset *ls, GModel *pModel)
Definition: FuncGradDisc.h:25
FuncGradDisc
Definition: FuncGradDisc.h:19
FuncGradDisc::_pModel
GModel * _pModel
Definition: FuncGradDisc.h:22
z
const double z
Definition: GaussQuadratureQuad.cpp:56
MElement::getShapeFunctions
virtual void getShapeFunctions(double u, double v, double w, double s[], int order=-1) const
Definition: MElement.cpp:458
MElement::getJacobian
virtual double getJacobian(const fullMatrix< double > &gsf, double jac[3][3]) const
Definition: MElement.cpp:868
GModel.h
MVertex::y
double y() const
Definition: MVertex.h:61
gmshLevelset.h
MVertex::x
double x() const
Definition: MVertex.h:60
MElement::getGradShapeFunctions
virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int order=-1) const
Definition: MElement.cpp:468