Nektar++
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 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 namespace NekMeshUtils
42 {
43 
44 std::string CADCurveCFI::key = GetCADCurveFactory().RegisterCreatorFunction(
45  "cfi", CADCurveCFI::create, "CADCurveCFI");
46 
47 void 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 
56 NekDouble CADCurveCFI::tAtArcLength(NekDouble s)
57 {
58  s /= m_scal;
59  Array<OneD, NekDouble> 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  Array<OneD, NekDouble> drdt1, drdt2;
68  drdt1 = D2(t);
69  t += dt;
70  drdt2 = D2(t);
71 
72  NekDouble mag1 = sqrt(drdt1[3] * drdt1[3] + drdt1[4] * drdt1[4] +
73  drdt1[5] * drdt1[5]);
74  NekDouble mag2 = sqrt(drdt2[3] * drdt2[3] + drdt2[4] * drdt2[4] +
75  drdt2[5] * drdt2[5]);
76 
77  len += (mag1 + mag2) / 2.0 * dt;
78  }
79 
80  return t - dt;
81 }
82 
83 NekDouble CADCurveCFI::loct(Array<OneD, NekDouble> xyz, 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 
97 NekDouble CADCurveCFI::Length(NekDouble ti, NekDouble tf)
98 {
99  Array<OneD, NekDouble> 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  Array<OneD, NekDouble> drdt1, drdt2;
108  drdt1 = D2(t);
109  t += dt;
110  drdt2 = D2(t);
111 
112  NekDouble mag1 = sqrt(drdt1[3] * drdt1[3] + drdt1[4] * drdt1[4] +
113  drdt1[5] * drdt1[5]);
114  NekDouble mag2 = sqrt(drdt2[3] * drdt2[3] + drdt2[4] * drdt2[4] +
115  drdt2[5] * drdt2[5]);
116 
117  len += (mag1 + mag2) / 2.0 * dt;
118  }
119 
120  return len * m_scal;
121 }
122 
124 {
125  cfi::Position p = m_cfiEdge->calcXYZAtT(t);
126 
127  Array<OneD, NekDouble> out(3);
128 
129  out[0] = p.x * m_scal;
130  out[1] = p.y * m_scal;
131  out[2] = p.z * m_scal;
132 
133  return out;
134 }
135 
137 {
138  cfi::Position p = m_cfiEdge->calcXYZAtT(t);
139 
140  x = p.x * m_scal;
141  y = p.y * m_scal;
142  z = p.z * m_scal;
143 }
144 
146 {
147  vector<cfi::DerivativeList> *d = m_cfiEdge->calcDerivAtT(t);
148  cfi::Position p = m_cfiEdge->calcXYZAtT(t);
149 
150  Array<OneD, NekDouble> out(9);
151 
152  out[0] = p.x * m_scal;
153  out[1] = p.y * m_scal;
154  out[2] = p.z * m_scal;
155 
156  cfi::DerivativeList d1 = d->at(0);
157  cfi::DerivativeList d2 = d->at(1);
158 
159  out[3] = d1.getDeriv(0) * m_scal;
160  out[4] = d1.getDeriv(1) * m_scal;
161  out[5] = d1.getDeriv(2) * m_scal;
162  out[6] = d2.getDeriv(0) * m_scal;
163  out[7] = d2.getDeriv(1) * m_scal;
164  out[8] = d2.getDeriv(2) * m_scal;
165 
166  return out;
167 }
168 
169 Array<OneD, NekDouble> CADCurveCFI::GetBounds()
170 {
172  t[0] = 0.0;
173  t[1] = 1.0;
174 
175  return t;
176 }
177 
178 void CADCurveCFI::GetBounds(NekDouble &tmin, NekDouble &tmax)
179 {
180  tmin = 0.0;
181  tmax = 1.0;
182 }
183 
184 Array<OneD, NekDouble> CADCurveCFI::GetMinMax()
185 {
186  Array<OneD, NekDouble> bds = GetBounds();
187 
188  cfi::Position x1 = m_cfiEdge->calcXYZAtT(bds[0]);
189  cfi::Position x2 = m_cfiEdge->calcXYZAtT(bds[1]);
190 
191  Array<OneD, NekDouble> locs(6);
192 
193  locs[0] = x1.x * m_scal;
194  locs[1] = x1.y * m_scal;
195  locs[2] = x1.z * m_scal;
196  locs[3] = x2.x * m_scal;
197  locs[4] = x2.y * m_scal;
198  locs[5] = x2.z * m_scal;
199 
200  return locs;
201 }
202 }
203 }
CADCurveFactory & GetCADCurveFactory()
Definition: CADSystem.cpp:59
STL namespace.
void P(NekDouble t, NekDouble &x, NekDouble &y, NekDouble &z)
double NekDouble
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199