Nektar++
CADSurfCFI.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: CADSurfCFI.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: cad object surface methods.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include "CADSurfCFI.h"
36 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 namespace NekMeshUtils
42 {
43 
44 std::string CADSurfCFI::key = GetCADSurfFactory().RegisterCreatorFunction(
45  "cfi", CADSurfCFI::create, "CADSurfCFI");
46 
47 void CADSurfCFI::Initialise(int i, cfi::Face *in, NekDouble s)
48 {
49  m_cfiSurface = in;
50  m_id = i;
51  m_scal = s;
52 }
53 
54 Array<OneD, NekDouble> CADSurfCFI::GetBounds()
55 {
57 
58  cfi::UVBox bx = m_cfiSurface->calcUVBox();
59  b[0] = bx.uLower * m_scal;
60  b[1] = bx.uUpper * m_scal;
61  b[2] = bx.vLower * m_scal;
62  b[3] = bx.vUpper * m_scal;
63 
64  return b;
65 }
66 
67 virtual void CADSurfCFI::GetBounds(NekDouble &umin, NekDouble &umax,
68  NekDouble &vmin, NekDouble &vmax)
69 {
70  cfi::UVBox bx = m_cfiSurface->calcUVBox();
71  umin = b[0];
72  umax = b[1];
73  vmin = b[2];
74  vmax = b[3];
75 }
76 
78  NekDouble &dist)
79 {
81  cfi::Position px;
82  px.x = p[0] / m_scal;
83  px.y = p[1] / m_scal;
84  px.z = p[2] / m_scal;
85 
86  boost::optional<cfi::UVPosition> r = m_cfiSurface->calcUVFromXYZ(px);
87 
88  uv[0] = r.value().u;
89  uv[1] = r.value().v;
90 
91  Array<OneD, NekDouble> p2 = P(uv);
92 
93  dist =
94  sqrt((p[0] - p2[0]) * (p[0] - p2[0]) + (p[1] - p2[1]) * (p[1] - p2[1]) +
95  (p[2] - p2[2]) * (p[2] - p2[2])) *
96  m_scal;
97 
98  return uv;
99 }
100 
101 NekDouble CADSurfCFI::Curvature(Array<OneD, NekDouble> uv)
102 {
103  cfi::UVPosition uvp(uv[0], uv[1]);
104  cfi::MaxMinCurvaturePair mxp = m_cfiSurface->calcCurvAtUV(uvp);
105 
106  return mxp.maxCurv.curvature * m_scal;
107 }
108 
110 {
111  cfi::UVPosition uvp(uv[0], uv[1]);
112  cfi::Position p = m_cfiSurface->calcXYZAtUV(uvp);
113  Array<OneD, NekDouble> out(3);
114  out[0] = p.x * m_scal;
115  out[1] = p.y * m_scal;
116  out[2] = p.z * m_scal;
117 
118  return out;
119 }
120 
122 {
123  cfi::UVPosition uvp(uv[0], uv[1]);
124  cfi::Position p = m_cfiSurface->calcXYZAtUV(uvp);
125  x = p.x * m_scal;
126  y = p.y * m_scal;
127  z = p.z * m_scal;
128 }
129 
131 {
132  cfi::UVPosition uvp(uv[0], uv[1]);
133  cfi::Direction d = m_cfiSurface->calcFaceNormalAtUV(uvp);
134 
135  Array<OneD, NekDouble> normal(3);
136  normal[0] = d.x;
137  normal[1] = d.y;
138  normal[2] = d.z;
139 
140  return normal;
141 }
142 
144 {
145  Array<OneD, NekDouble> p = P(uv);
146  cfi::UVPosition uvp(uv[0], uv[1]);
147  vector<cfi::DerivativeList> *l = m_cfiSurface->calcDerivAtUV(uvp);
149  r[0] = p[0] * m_scal; // x
150  r[1] = p[1] * m_scal; // y
151  r[2] = p[2] * m_scal; // z
152  r[3] = l->at(0).derivatives[0] * m_scal; // dx/dx
153  r[4] = l->at(0).derivatives[1] * m_scal; // dy/dy
154  r[5] = l->at(0).derivatives[2] * m_scal; // dz/dz
155  r[6] = l->at(0).derivatives[3] * m_scal; // dx/dx
156  r[7] = l->at(0).derivatives[4] * m_scal; // dy/dy
157  r[8] = l->at(0).derivatives[5] * m_scal; // dz/dz
158 
159  return r;
160 }
161 
163 {
164  Array<OneD, NekDouble> p = P(uv);
165  cfi::UVPosition uvp(uv[0], uv[1]);
166  vector<cfi::DerivativeList> *l = m_cfiSurface->calcDerivAtUV(uvp);
168  r[0] = p[0] * m_scal; // x
169  r[1] = p[1] * m_scal; // y
170  r[2] = p[2] * m_scal; // z
171  r[3] = l->at(0).derivatives[0] * m_scal; // dx/dx
172  r[4] = l->at(0).derivatives[1] * m_scal; // dy/dy
173  r[5] = l->at(0).derivatives[2] * m_scal; // dz/dz
174  r[6] = l->at(0).derivatives[3] * m_scal; // dx/dx
175  r[7] = l->at(0).derivatives[4] * m_scal; // dy/dy
176  r[8] = l->at(0).derivatives[5] * m_scal; // dz/dz
177  r[9] = l->at(1).derivatives[0] * m_scal; // d2x/du2
178  r[10] = l->at(1).derivatives[1] * m_scal; // d2y/du2
179  r[11] = l->at(1).derivatives[2] * m_scal; // d2z/du2
180  r[12] = l->at(1).derivatives[6] * m_scal; // d2x/dv2
181  r[13] = l->at(1).derivatives[7] * m_scal; // d2y/dv2
182  r[14] = l->at(1).derivatives[8] * m_scal; // d2z/dv2
183  r[15] = l->at(1).derivatives[3] * m_scal; // d2x/dudv
184  r[16] = l->at(1).derivatives[4] * m_scal; // d2y/dudv
185  r[17] = l->at(1).derivatives[5] * m_scal; // d2z/dudv
186 
187  return r;
188 }
189 }
190 }
STL namespace.
void P(Array< OneD, NekDouble > uv, NekDouble &x, NekDouble &y, NekDouble &z)
Definition: CADSurfCFI.cpp:121
CADSurfFactory & GetCADSurfFactory()
Definition: CADSystem.cpp:65
double NekDouble
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199