Nektar++
Loading...
Searching...
No Matches
CADCurveCFI.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: CADCurveCFI.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 curve methods.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include "CADCurveCFI.h"
36
37using namespace std;
38
39namespace Nektar
40{
41namespace NekMesh
42{
43
44std::string CADCurveCFI::key = GetCADCurveFactory().RegisterCreatorFunction(
45 "cfi", CADCurveCFI::create, "CADCurveCFI");
46
47void CADCurveCFI::Initialise(int i, cfi::Line *in, NekDouble s)
48{
49 m_cfiEdge = in;
50 m_scal = s;
51 m_length = m_cfiEdge->calcLength() * m_scal;
52
53 m_id = i;
54}
55
57{
58 s /= m_scal;
59 auto bds = GetBounds();
60 NekDouble dt = (bds[1] - bds[0]) / 1000;
61
62 NekDouble t = bds[0];
63 NekDouble len = 0.0;
64
65 while (len <= s)
66 {
67 auto drdt1 = D2(t);
68 t += dt;
69 auto drdt2 = D2(t);
70
71 NekDouble mag1 = sqrt(drdt1[3] * drdt1[3] + drdt1[4] * drdt1[4] +
72 drdt1[5] * drdt1[5]);
73 NekDouble mag2 = sqrt(drdt2[3] * drdt2[3] + drdt2[4] * drdt2[4] +
74 drdt2[5] * drdt2[5]);
75
76 len += (mag1 + mag2) / 2.0 * dt;
77 }
78
79 return t - dt;
80}
81
82NekDouble CADCurveCFI::loct(std::array<NekDouble, 3> xyz, NekDouble > xyz,
83 NekDouble &t)
84{
85 cfi::Position p;
86 p.x = xyz[0] / m_scal;
87 p.y = xyz[1] / m_scal;
88 p.z = xyz[2] / m_scal;
89
90 boost::optional<cfi::Projected<double>> pj = m_cfiEdge->calcTFromXYZ(p, -1);
91
92 t = pj.value().parameters;
93
94 return pj.value().distance * m_scal;
95}
96
98{
99 auto bds = GetBounds();
100 NekDouble dt = (bds[1] - bds[0]) / 1000;
101
102 NekDouble t = ti;
103 NekDouble len = 0.0;
104
105 while (t <= tf)
106 {
107 auto drdt1 = D2(t);
108 t += dt;
109 auto drdt2 = D2(t);
110
111 NekDouble mag1 = sqrt(drdt1[3] * drdt1[3] + drdt1[4] * drdt1[4] +
112 drdt1[5] * drdt1[5]);
113 NekDouble mag2 = sqrt(drdt2[3] * drdt2[3] + drdt2[4] * drdt2[4] +
114 drdt2[5] * drdt2[5]);
115
116 len += (mag1 + mag2) / 2.0 * dt;
117 }
118
119 return len * m_scal;
120}
121
122std::array<NekDouble, 3> CADCurveCFI::P(NekDouble t)
123{
124 cfi::Position p = m_cfiEdge->calcXYZAtT(t);
125
126 return {p.x * m_scal, p.y * m_scal, p.z * m_scal};
127}
128
130{
131 cfi::Position p = m_cfiEdge->calcXYZAtT(t);
132
133 x = p.x * m_scal;
134 y = p.y * m_scal;
135 z = p.z * m_scal;
136}
137
138std::array<NekDouble, 9> CADCurveCFI::D2(NekDouble t)
139{
140 vector<cfi::DerivativeList> *d = m_cfiEdge->calcDerivAtT(t);
141 cfi::Position p = m_cfiEdge->calcXYZAtT(t);
142
143 cfi::DerivativeList d1 = d->at(0);
144 cfi::DerivativeList d2 = d->at(1);
145
146 return {p.x * m_scal,
147 p.y * m_scal,
148 p.z * m_scal,
149 d1.getDeriv(0) * m_scal,
150 d1.getDeriv(1) * m_scal,
151 d1.getDeriv(2) * m_scal,
152 d2.getDeriv(0) * m_scal,
153 d2.getDeriv(0) * m_scal,
154 d2.getDeriv(0) * m_scal};
155}
156
157std::array<NekDouble, 2> CADCurveCFI::GetBounds()
158{
159 std::array<NekDouble, 2> t;
160 t[0] = 0.0;
161 t[1] = 1.0;
162
163 return t;
164}
165
167{
168 tmin = 0.0;
169 tmax = 1.0;
170}
171
172std::array<NekDouble, 6> CADCurveCFI::GetMinMax()
173{
174 auto bds = GetBounds();
175
176 cfi::Position x1 = m_cfiEdge->calcXYZAtT(bds[0]);
177 cfi::Position x2 = m_cfiEdge->calcXYZAtT(bds[1]);
178
179 return {x1.x * m_scal, x1.y * m_scal, x1.z * m_scal,
180 x2.x * m_scal, x2.y * m_scal, x2.z * m_scal};
181}
182} // namespace NekMesh
183} // namespace Nektar
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
virtual std::array< NekDouble, 3 > P(NekDouble t)
virtual std::array< NekDouble, 9 > D2(NekDouble t)
void Initialise(int i, cfi::Line *in, NekDouble s)
static std::string key
Definition CADCurveCFI.h:56
static CADCurveSharedPtr create()
Definition CADCurveCFI.h:51
virtual std::array< NekDouble, 2 > GetBounds()
virtual NekDouble tAtArcLength(NekDouble s)
virtual NekDouble Length(NekDouble ti, NekDouble tf)
virtual NekDouble loct(std::array< NekDouble, 3 > xyz, NekDouble &t)
virtual std::array< NekDouble, 6 > GetMinMax()
cfi::Line * m_cfiEdge
cfi object
Definition CADCurveCFI.h:95
STL namespace.
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:289