gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
ExtrudeParams.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 "GmshMessage.h"
7 #include "Geo.h"
8 #include "ExtrudeParams.h"
9 
10 smooth_data *ExtrudeParams::normals[2] = {nullptr, nullptr};
11 std::vector<SPoint3> ExtrudeParams::normalsCoherence;
12 
13 // Scale last layer size locally If one section of the boundary layer index = 0
14 // or 1 is not supposed to be scaled...that section's normals will have
15 // scaleFactor = 1.0 (exactly 1.0 to all sig figs) ...however, if that
16 // non-scaled section borders a scaled section, the boundary normals will
17 // extrude consistently (an average of scaled and non-scaled heights).
19 
21 {
22  geo.Mode = ModeEx;
23  geo.Source = -1;
24  mesh.ExtrudeMesh = false;
25  mesh.Recombine = false;
26  mesh.QuadToTri = NO_QUADTRI;
27  // determines if a layer is scaled by source grid size (1) or not (0)...only
28  // meant for boundary layers
29  mesh.ScaleLast = false;
30  mesh.ViewIndex = -1;
31  mesh.BoundaryLayerIndex = 0;
32 }
33 
34 void ExtrudeParams::fill(int type, double T0, double T1, double T2, double A0,
35  double A1, double A2, double X0, double X1, double X2,
36  double angle)
37 {
38  geo.trans[0] = T0;
39  geo.trans[1] = T1;
40  geo.trans[2] = T2;
41  geo.axe[0] = A0;
42  geo.axe[1] = A1;
43  geo.axe[2] = A2;
44  geo.pt[0] = X0;
45  geo.pt[1] = X1;
46  geo.pt[2] = X2;
47  geo.angle = angle;
48  geo.Type = type;
49 }
50 
51 void ExtrudeParams::Extrude(int iLayer, int iElemLayer, double &x, double &y,
52  double &z)
53 {
54  double t = u(iLayer, iElemLayer);
55  // This definitely relies on fixing lateral boundary extruded surfaces if
56  // mesh.ScaleLast is changed by ReplaceDuplicates. This is done in
57  // BoundaryLayers.cpp right now.
58  if(geo.Type == BOUNDARY_LAYER && iLayer == mesh.NbLayer - 1 &&
59  mesh.BoundaryLayerIndex >= 0 && mesh.BoundaryLayerIndex <= 1 &&
60  calcLayerScaleFactor[mesh.BoundaryLayerIndex] &&
61  normals[mesh.BoundaryLayerIndex]) {
62  double scale = 1.0;
63  normals[mesh.BoundaryLayerIndex]->get_scale(x, y, z, &scale);
64  if(fabs(scale - 1.0) <= xyzv::eps)
65  scale = 1.0;
66  else {
67  if(mesh.NbLayer <= 1)
68  t = t * scale;
69  else
70  t = (t - mesh.hLayer[mesh.NbLayer - 2]) * scale +
71  mesh.hLayer[mesh.NbLayer - 2];
72  }
73  }
74 
75  Extrude(t, x, y, z);
76 }
77 
78 void ExtrudeParams::Extrude(double t, double &x, double &y, double &z)
79 {
80  double dx, dy, dz, angle;
81  double n[3] = {0., 0., 0.};
82 
83  switch(geo.Type) {
84  case TRANSLATE:
85  dx = geo.trans[0] * t;
86  dy = geo.trans[1] * t;
87  dz = geo.trans[2] * t;
88  x += dx;
89  y += dy;
90  z += dz;
91  break;
92  case ROTATE:
93  angle = geo.angle;
94  geo.angle = geo.angle * t;
95  ProtudeXYZ(x, y, z, this);
96  geo.angle = angle;
97  break;
98  case TRANSLATE_ROTATE:
99  angle = geo.angle;
100  geo.angle = geo.angle * t;
101  ProtudeXYZ(x, y, z, this);
102  geo.angle = angle;
103  dx = geo.trans[0] * t;
104  dy = geo.trans[1] * t;
105  dz = geo.trans[2] * t;
106  x += dx;
107  y += dy;
108  z += dz;
109  break;
110  case BOUNDARY_LAYER:
111  if(mesh.BoundaryLayerIndex >= 0 && mesh.BoundaryLayerIndex <= 1 &&
112  normals[mesh.BoundaryLayerIndex])
113  normals[mesh.BoundaryLayerIndex]->get(x, y, z, 3, n);
114  x += n[0] * t;
115  y += n[1] * t;
116  z += n[2] * t;
117  break;
118  default: Msg::Error("Unknown extrusion type"); break;
119  }
120 }
121 
122 double ExtrudeParams::u(int iLayer, int iElemLayer)
123 {
124  double t0, t1;
125 
126  if(!iLayer) {
127  t0 = 0.0;
128  t1 = mesh.hLayer[0];
129  }
130  else {
131  t0 = mesh.hLayer[iLayer - 1];
132  t1 = mesh.hLayer[iLayer];
133  }
134  double t = (double)iElemLayer / (double)mesh.NbElmLayer[iLayer];
135  return t0 + t * (t1 - t0);
136 }
137 
138 void ExtrudeParams::GetAffineTransform(std::vector<double> &tfo)
139 {
140  tfo.clear();
141  double v[3], m1[4][4], m2[4][4], m3[4][4];
142  switch(geo.Type) {
143  case TRANSLATE:
144  SetTranslationMatrix(m1, geo.trans);
145  tfo.resize(16);
146  for(int i = 0; i < 4; i++)
147  for(int j = 0; j < 4; j++) tfo[i * 4 + j] = m1[i][j];
148  break;
149  case ROTATE:
150  case TRANSLATE_ROTATE:
151  v[0] = -geo.pt[0];
152  v[1] = -geo.pt[1];
153  v[2] = -geo.pt[2];
154  SetTranslationMatrix(m1, v);
155  SetRotationMatrix(m2, geo.axe, geo.angle);
156  for(int i = 0; i < 4; i++) {
157  for(int j = 0; j < 4; j++) {
158  m3[i][j] = 0;
159  for(int k = 0; k < 4; k++) { m3[i][j] += m1[i][k] * m2[k][j]; }
160  }
161  }
162  SetTranslationMatrix(m1, geo.pt);
163  for(int i = 0; i < 4; i++) {
164  for(int j = 0; j < 4; j++) {
165  m2[i][j] = 0;
166  for(int k = 0; k < 4; k++) { m2[i][j] += m3[i][k] * m1[k][j]; }
167  }
168  }
169  tfo.resize(16);
170  for(int i = 0; i < 4; i++)
171  for(int j = 0; j < 4; j++) tfo[i * 4 + j] = m2[i][j];
172  if(geo.Type == TRANSLATE_ROTATE) {
173  tfo[3] += geo.trans[0];
174  tfo[7] += geo.trans[1];
175  tfo[11] += geo.trans[2];
176  }
177  break;
178  }
179 }
Geo.h
ExtrudeParams::ExtrudeParams
ExtrudeParams(int Mode=EXTRUDED_ENTITY)
Definition: ExtrudeParams.cpp:20
NO_QUADTRI
#define NO_QUADTRI
Definition: GmshDefines.h:263
angle
double angle(const SVector3 &a, const SVector3 &b)
Definition: SVector3.h:157
ProtudeXYZ
void ProtudeXYZ(double &x, double &y, double &z, ExtrudeParams *e)
Definition: Geo.cpp:2542
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
smooth_data::get
bool get(double x, double y, double z, int n, double *vals) const
Definition: SmoothData.cpp:112
SetTranslationMatrix
void SetTranslationMatrix(double matrix[4][4], double T[3])
Definition: Geo.cpp:1250
GmshMessage.h
ExtrudeParams::geo
struct ExtrudeParams::@15 geo
TRANSLATE_ROTATE
#define TRANSLATE_ROTATE
Definition: ExtrudeParams.h:23
ExtrudeParams::mesh
struct ExtrudeParams::@14 mesh
ExtrudeParams::normalsCoherence
static std::vector< SPoint3 > normalsCoherence
Definition: ExtrudeParams.h:65
ExtrudeParams::fill
void fill(int type, double T0, double T1, double T2, double A0, double A1, double A2, double X0, double X1, double X2, double angle)
Definition: ExtrudeParams.cpp:34
ExtrudeParams.h
ExtrudeParams::GetAffineTransform
void GetAffineTransform(std::vector< double > &tfo)
Definition: ExtrudeParams.cpp:138
smooth_data
Definition: SmoothData.h:53
ROTATE
#define ROTATE
Definition: ExtrudeParams.h:22
ExtrudeParams::Extrude
void Extrude(int iLayer, int iElemLayer, double &dx, double &dy, double &dz)
Definition: ExtrudeParams.cpp:51
ExtrudeParams::u
double u(int iLayer, int iElemLayer)
Definition: ExtrudeParams.cpp:122
SetRotationMatrix
void SetRotationMatrix(double matrix[4][4], double Axe[3], double alpha)
Definition: Geo.cpp:1316
z
const double z
Definition: GaussQuadratureQuad.cpp:56
xyzv::eps
static double eps
Definition: SmoothData.h:23
smooth_data::get_scale
bool get_scale(double x, double y, double z, double *scale_val) const
Definition: SmoothData.cpp:121
ExtrudeParams::calcLayerScaleFactor
static bool calcLayerScaleFactor[2]
Definition: ExtrudeParams.h:62
BOUNDARY_LAYER
#define BOUNDARY_LAYER
Definition: ExtrudeParams.h:24
ExtrudeParams::angle
double angle
Definition: ExtrudeParams.h:53
TRANSLATE
#define TRANSLATE
Definition: ExtrudeParams.h:21
ExtrudeParams::normals
static smooth_data * normals[2]
Definition: ExtrudeParams.h:64
scale
static void scale(std::vector< double > &x, double s)
Definition: ConjugateGradients.cpp:21