Nektar++
Loading...
Searching...
No Matches
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
37using namespace std;
38
39namespace Nektar
40{
41namespace NekMesh
42{
43
45 "cfi", CADSurfCFI::create, "CADSurfCFI");
46
47void CADSurfCFI::Initialise(int i, cfi::Face *in, NekDouble s)
48{
49 m_cfiSurface = in;
50 m_id = i;
51 m_scal = s;
52}
53
54std::array<NekDouble, 4> CADSurfCFI::GetBounds()
55{
56 cfi::UVBox bx = m_cfiSurface->calcUVBox();
57
58 return {bx.uLower, bx.uUpper, bx.vLower, bx.vUpper};
59}
60
62 NekDouble &vmax)
63{
64 cfi::UVBox bx = m_cfiSurface->calcUVBox();
65 umin = bx.uLower;
66 umax = bx.uUpper;
67 vmin = bx.vLower;
68 vmax = bx.vUpper;
69}
70
71std::array<NekDouble, 2> CADSurfCFI::locuv(std::array<NekDouble, 3> p,
72 NekDouble &dist)
73{
74 std::array<NekDouble, 2> uv;
75 cfi::Position px;
76 px.x = p[0] / m_scal;
77 px.y = p[1] / m_scal;
78 px.z = p[2] / m_scal;
79
80 boost::optional<cfi::UVPosition> r = m_cfiSurface->calcUVFromXYZ(px);
81
82 uv[0] = r.value().u;
83 uv[1] = r.value().v;
84
85 auto p2 = P(uv);
86
87 dist =
88 sqrt((p[0] - p2[0]) * (p[0] - p2[0]) + (p[1] - p2[1]) * (p[1] - p2[1]) +
89 (p[2] - p2[2]) * (p[2] - p2[2])) *
90 m_scal;
91
92 return uv;
93}
94
95NekDouble CADSurfCFI::Curvature(std::array<NekDouble, 2> uv)
96{
97 cfi::UVPosition uvp(uv[0], uv[1]);
98 cfi::MaxMinCurvaturePair mxp = m_cfiSurface->calcCurvAtUV(uvp);
99
100 return mxp.maxCurv.curvature * m_scal;
101}
102
103std::array<NekDoble, 3> CADSurfCFI::P(std::array<NekDoble, 2> uv)
104{
105 cfi::UVPosition uvp(uv[0], uv[1]);
106 cfi::Position p = m_cfiSurface->calcXYZAtUV(uvp);
107
108 return {p.x * m_scal, p.y * m_scal, p.z * m_scal};
109}
110
111void CADSurfCFI::P(std::array<NekDoble, 2> uv, NekDouble &x, NekDouble &y,
112 NekDouble &z)
113{
114 cfi::UVPosition uvp(uv[0], uv[1]);
115 cfi::Position p = m_cfiSurface->calcXYZAtUV(uvp);
116 x = p.x * m_scal;
117 y = p.y * m_scal;
118 z = p.z * m_scal;
119}
120
121std::array<NekDouble, 3> CADSurfCFI::N(std::array<NekDouble, 2> uv)
122{
123 cfi::UVPosition uvp(uv[0], uv[1]);
124 cfi::Direction d = m_cfiSurface->calcFaceNormalAtUV(uvp);
125
126 return {d.x, d.y, d.z};
127}
128
129std::array<NekDouble, 9> CADSurfCFI::D1(std::array<NekDouble, 2> uv)
130{
131 auto p = P(uv);
132 cfi::UVPosition uvp(uv[0], uv[1]);
133 vector<cfi::DerivativeList> *l = m_cfiSurface->calcDerivAtUV(uvp);
134 std::array<NekDouble, 9> r;
135 r[0] = p[0] * m_scal; // x
136 r[1] = p[1] * m_scal; // y
137 r[2] = p[2] * m_scal; // z
138 r[3] = l->at(0).derivatives[0] * m_scal; // dx/dx
139 r[4] = l->at(0).derivatives[1] * m_scal; // dy/dy
140 r[5] = l->at(0).derivatives[2] * m_scal; // dz/dz
141 r[6] = l->at(0).derivatives[3] * m_scal; // dx/dx
142 r[7] = l->at(0).derivatives[4] * m_scal; // dy/dy
143 r[8] = l->at(0).derivatives[5] * m_scal; // dz/dz
144
145 return r;
146}
147
148std::array<NekDouble, 18> CADSurfCFI::D2(std::array<NekDouble, 2> uv)
149{
150 auto p = P(uv);
151 cfi::UVPosition uvp(uv[0], uv[1]);
152 vector<cfi::DerivativeList> *l = m_cfiSurface->calcDerivAtUV(uvp);
153 std::array<NekDouble, 18> r;
154 r[0] = p[0] * m_scal; // x
155 r[1] = p[1] * m_scal; // y
156 r[2] = p[2] * m_scal; // z
157 r[3] = l->at(0).derivatives[0] * m_scal; // dx/dx
158 r[4] = l->at(0).derivatives[1] * m_scal; // dy/dy
159 r[5] = l->at(0).derivatives[2] * m_scal; // dz/dz
160 r[6] = l->at(0).derivatives[3] * m_scal; // dx/dx
161 r[7] = l->at(0).derivatives[4] * m_scal; // dy/dy
162 r[8] = l->at(0).derivatives[5] * m_scal; // dz/dz
163 r[9] = l->at(1).derivatives[0] * m_scal; // d2x/du2
164 r[10] = l->at(1).derivatives[1] * m_scal; // d2y/du2
165 r[11] = l->at(1).derivatives[2] * m_scal; // d2z/du2
166 r[12] = l->at(1).derivatives[6] * m_scal; // d2x/dv2
167 r[13] = l->at(1).derivatives[7] * m_scal; // d2y/dv2
168 r[14] = l->at(1).derivatives[8] * m_scal; // d2z/dv2
169 r[15] = l->at(1).derivatives[3] * m_scal; // d2x/dudv
170 r[16] = l->at(1).derivatives[4] * m_scal; // d2y/dudv
171 r[17] = l->at(1).derivatives[5] * m_scal; // d2z/dudv
172
173 return r;
174}
175} // namespace NekMesh
176} // namespace Nektar
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::array< NekDouble, 9 > D1(std::array< NekDouble, 2 > uv)
std::array< NekDouble, 4 > GetBounds()
static CADSurfSharedPtr create()
Definition CADSurfCFI.h:50
NekDouble Curvature(std::array< NekDouble, 2 > uv)
std::array< NekDouble, 2 > locuv(std::array< NekDouble 3 > p, NekDouble &dist)
std::array< NekDouble, 3 > P(std::array< NekDouble, 2 > uv)
static std::string key
Definition CADSurfCFI.h:55
void Initialise(int i, cfi::Face *in, NekDouble s)
std::array< NekDouble, 3 > N(std::array< NekDouble, 2 > uv)
cfi::Face * m_cfiSurface
CFI object for surface.
Definition CADSurfCFI.h:110
std::array< NekDouble, 18 > D2(std::array< NekDouble, 2 > uv)
CADSurfFactory & GetCADSurfFactory()
Definition CADSystem.cpp:60
STL namespace.
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:289