gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
gmshSurface.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 "GmshMessage.h"
8 #include "gmshSurface.h"
9 #include "mathEvaluator.h"
10 
11 std::map<int, gmshSurface *> gmshSurface::allGmshSurfaces;
12 
13 SPoint2 gmshSurface::parFromPoint(double x, double y, double z)
14 {
15  Msg::Error("Parametric coordinate computation not implemented for this type "
16  "of surface");
17  return SPoint2();
18 }
19 
21 {
22  Msg::Error("Normal computation not implemented for this type of surface");
23  return SVector3();
24 }
25 
27 {
28  Msg::Error("First derivative not implemented for this type of surface");
29  return Pair<SVector3, SVector3>();
30 }
31 
33 {
34  Msg::Error("Metric eigenvalue not implemented for this type of surface");
35  return 0;
36 }
37 
38 gmshSurface *gmshSphere::NewSphere(int iSphere, double x, double y, double z,
39  double r)
40 {
41  gmshSphere *sph = new gmshSphere(x, y, z, r);
42 
43  if(allGmshSurfaces.find(iSphere) != allGmshSurfaces.end()) {
44  Msg::Error("Surface %d already exists", iSphere);
45  }
46 
47  allGmshSurfaces[iSphere] = sph;
48  return sph;
49 }
50 
52 {
53  auto it = allGmshSurfaces.find(iSurface);
54  if(it == allGmshSurfaces.end()) {
55  Msg::Error("Surface %d does not exist", iSurface);
56  return nullptr;
57  }
58  return it->second;
59 }
60 
61 SPoint3 gmshSphere::point(double par1, double par2) const
62 {
63  par2 += M_PI * .5;
64  const double x = xc + r * sin(par2) * cos(par1);
65  const double y = yc + r * sin(par2) * sin(par1);
66  const double z = zc - r * cos(par2);
67  return SPoint3(x, y, z);
68 }
69 
70 gmshSurface *gmshPolarSphere::NewPolarSphere(int iSphere, double x, double y,
71  double z, double r)
72 {
73  gmshPolarSphere *sph = new gmshPolarSphere(x, y, z, r);
74 
75  if(allGmshSurfaces.find(iSphere) != allGmshSurfaces.end()) {
76  Msg::Error("Surface %d already exists", iSphere);
77  }
78 
79  allGmshSurfaces[iSphere] = sph;
80  return sph;
81 }
82 
83 gmshPolarSphere::gmshPolarSphere(double x, double y, double z, double _r)
84  : r(_r), o(x, y, z)
85 {
86 }
87 
88 SPoint3 gmshPolarSphere::point(double u, double v) const
89 {
90  // stereographic projection from the south pole, origin of the axis
91  // at the center of the sphere
92  // u=-x/(r+z) v=-y/(r+z)
93  double rp2 = u * u + v * v;
94  SPoint3 p(-2 * r * u / (1 + rp2), -2 * r * v / (1 + rp2),
95  r * (1 - rp2) / (1 + rp2));
96  p += o;
97  return p;
98 }
99 
101  const char *valX,
102  const char *valY,
103  const char *valZ)
104 {
105  gmshParametricSurface *sph = new gmshParametricSurface(valX, valY, valZ);
106 
107  if(allGmshSurfaces.find(iSurf) != allGmshSurfaces.end()) {
108  Msg::Error("Surface %d already exists", iSurf);
109  }
110  allGmshSurfaces[iSurf] = sph;
111  return sph;
112 }
113 
115  const char *valY,
116  const char *valZ)
117 {
118  std::vector<std::string> expressions(3), variables(2);
119  expressions[0] = valX;
120  expressions[1] = valY;
121  expressions[2] = valZ;
122  variables[0] = "u";
123  variables[1] = "v";
124  _f = new mathEvaluator(expressions, variables);
125  if(expressions.empty()) {
126  delete _f;
127  _f = nullptr;
128  }
129 }
130 
132 {
133  if(_f) delete _f;
134 }
135 
136 SPoint3 gmshParametricSurface::point(double par1, double par2) const
137 {
138  if(_f) {
139  std::vector<double> values(2), res(3);
140  values[0] = par1;
141  values[1] = par2;
142  if(_f->eval(values, res)) return SPoint3(res[0], res[1], res[2]);
143  }
144  return SPoint3(0., 0., 0.);
145 }
146 
148 {
149  Msg::Error("Parameter bounds not available for parametric surface");
150  return Range<double>(0., 0.);
151 }
mathEvaluator
Definition: mathEvaluator.h:37
gmshPolarSphere::o
SPoint3 o
Definition: gmshSurface.h:105
mathEvaluator.h
SPoint2
Definition: SPoint2.h:12
gmshSphere::xc
double xc
Definition: gmshSurface.h:70
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
gmshPolarSphere::gmshPolarSphere
gmshPolarSphere(double x, double y, double z, double _r)
Definition: gmshSurface.cpp:83
gmshSurface::getSurface
static gmshSurface * getSurface(int tag)
Definition: gmshSurface.cpp:51
SPoint3
Definition: SPoint3.h:14
gmshParametricSurface::NewParametricSurface
static gmshSurface * NewParametricSurface(int iSurf, const char *, const char *, const char *)
Definition: gmshSurface.cpp:100
mathEvaluator::eval
bool eval(const std::vector< double > &values, std::vector< double > &res)
Definition: mathEvaluator.h:47
SVector3
Definition: SVector3.h:16
gmshSurface::getMetricEigenvalue
virtual double getMetricEigenvalue(const SPoint2 &)
Definition: gmshSurface.cpp:32
gmshSphere
Definition: gmshSurface.h:68
gmshSurface.h
gmshSphere::gmshSphere
gmshSphere(double _x, double _y, double _z, double _r)
Definition: gmshSurface.h:71
GmshMessage.h
gmshSurface::parFromPoint
virtual SPoint2 parFromPoint(double x, double y, double z)
Definition: gmshSurface.cpp:13
gmshSphere::yc
double yc
Definition: gmshSurface.h:70
gmshParametricSurface::gmshParametricSurface
gmshParametricSurface(const char *, const char *, const char *)
Definition: gmshSurface.cpp:114
gmshSurface::firstDer
virtual Pair< SVector3, SVector3 > firstDer(const SPoint2 &param)
Definition: gmshSurface.cpp:26
gmshParametricSurface::parBounds
virtual Range< double > parBounds(int i) const
Definition: gmshSurface.cpp:147
Range
Definition: Range.h:10
gmshSphere::r
double r
Definition: gmshSurface.h:70
gmshSurface
Definition: gmshSurface.h:22
gmshParametricSurface::point
virtual SPoint3 point(double par1, double par2) const
Definition: gmshSurface.cpp:136
gmshSurface::allGmshSurfaces
static std::map< int, gmshSurface * > allGmshSurfaces
Definition: gmshSurface.h:24
gmshSphere::NewSphere
static gmshSurface * NewSphere(int _iSphere, double _x, double _y, double _z, double _r)
Definition: gmshSurface.cpp:38
gmshParametricSurface
Definition: gmshSurface.h:138
gmshPolarSphere::point
virtual SPoint3 point(double par1, double par2) const
Definition: gmshSurface.cpp:88
gmshPolarSphere
Definition: gmshSurface.h:102
gmshSphere::point
virtual SPoint3 point(double par1, double par2) const
Definition: gmshSurface.cpp:61
z
const double z
Definition: GaussQuadratureQuad.cpp:56
gmshPolarSphere::r
double r
Definition: gmshSurface.h:104
Pair
Definition: Pair.h:10
gmshSurface::normal
virtual SVector3 normal(const SPoint2 &param) const
Definition: gmshSurface.cpp:20
gmshParametricSurface::~gmshParametricSurface
~gmshParametricSurface()
Definition: gmshSurface.cpp:131
gmshSphere::zc
double zc
Definition: gmshSurface.h:70
gmshParametricSurface::_f
mathEvaluator * _f
Definition: gmshSurface.h:140
gmshPolarSphere::NewPolarSphere
static gmshSurface * NewPolarSphere(int _iSphere, double _x, double _y, double _z, double _r)
Definition: gmshSurface.cpp:70