Nektar++
SegGeom.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: SegGeom.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:
32 //
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <SpatialDomains/SegGeom.h>
38 
40 #include <StdRegions/StdSegExp.h>
41 #include <LibUtilities/Foundations/ManagerAccess.h> // for PointsManager, etc
42 
43 namespace Nektar
44 {
45 namespace SpatialDomains
46 {
48 {
50 }
51 
53  const int coordim,
54  const PointGeomSharedPtr vertex[],
55  const CurveSharedPtr curve)
56  : Geometry1D(coordim)
57 {
59  m_globalID = id;
61  m_curve = curve;
62 
63  m_verts[0] = vertex[0];
64  m_verts[1] = vertex[1];
65 }
66 
68  : Geometry1D(in)
69 {
70  // From Geometry class
72 
73  // info from EdgeComponent class
75  m_xmap = in.m_xmap;
76  SetUpCoeffs(m_xmap->GetNcoeffs());
77 
78  // info from SegGeom class
79  m_coordim = in.m_coordim;
80  m_verts[0] = in.m_verts[0];
81  m_verts[1] = in.m_verts[1];
82 
83  m_state = in.m_state;
84 }
85 
87 {
88  if (m_curve)
89  {
90  int npts = m_curve->m_points.size();
91  LibUtilities::PointsKey pkey(npts + 1,
95  }
96  else
97  {
98  const LibUtilities::BasisKey B(
100  2,
103  }
104 }
105 
106 /**
107  * \brief Generate a one dimensional space segment geometry where the vert[0]
108  * has the same x value and vert[1] is set to vert[0] plus the length of the
109  * original segment
110  **/
112 {
114 
115  // info about numbering
116  returnval->m_globalID = m_globalID;
117 
118  // geometric information.
119  returnval->m_coordim = 1;
120  NekDouble x0 = (*m_verts[0])[0];
122  1, m_verts[0]->GetGlobalID(), x0, 0.0, 0.0);
123  vert0->SetGlobalID(vert0->GetGlobalID());
124  returnval->m_verts[0] = vert0;
125 
126  // Get information to calculate length.
128  m_xmap->GetBase();
130  v.push_back(base[0]->GetPointsKey());
132 
133  const Array<OneD, const NekDouble> jac = m_geomFactors->GetJac(v);
134 
135  NekDouble len = 0.0;
136  if (jac.num_elements() == 1)
137  {
138  len = jac[0] * 2.0;
139  }
140  else
141  {
142  Array<OneD, const NekDouble> w0 = base[0]->GetW();
143  len = 0.0;
144 
145  for (int i = 0; i < jac.num_elements(); ++i)
146  {
147  len += jac[i] * w0[i];
148  }
149  }
150  // Set up second vertex.
152  1, m_verts[1]->GetGlobalID(), x0 + len, 0.0, 0.0);
153  vert1->SetGlobalID(vert1->GetGlobalID());
154 
155  returnval->m_verts[1] = vert1;
156 
157  // at present just use previous m_xmap[0];
158  returnval->m_xmap = m_xmap;
159  returnval->SetUpCoeffs(m_xmap->GetNcoeffs());
160  returnval->m_state = eNotFilled;
161 
162  return returnval;
163 }
164 
166 {
167 }
168 
170 {
171  return LibUtilities::eSegment;
172 }
173 
175  const Array<OneD, const NekDouble> &Lcoord)
176 {
177  ASSERTL1(m_state == ePtsFilled, "Geometry is not in physical space");
178 
179  Array<OneD, NekDouble> tmp(m_xmap->GetTotPoints());
180  m_xmap->BwdTrans(m_coeffs[i], tmp);
181 
182  return m_xmap->PhysEvaluate(Lcoord, tmp);
183 }
184 
185 /**
186  * @brief Get the orientation of @p edge1.
187  *
188  * If @p edge1 is connected to @p edge2 in the same direction as the points
189  * comprising @p edge1 then it is forward, otherwise it is backward.
190  *
191  * For example, assume @p edge1 is comprised of points 1 and 2, and @p edge2 is
192  * comprised of points 2 and 3, then @p edge1 is forward.
193  *
194  * If @p edge1 is comprised of points 2 and 1 and @p edge2 is comprised of
195  * points 3 and 2, then @p edge1 is backward.
196  *
197  * Since both edges are passed, it does not need any information from the
198  * EdgeComponent instance.
199  */
201  const SegGeom &edge2)
202 {
204 
205  if ((*edge1.GetVertex(0) == *edge2.GetVertex(0)) ||
206  (*edge1.GetVertex(0) == *edge2.GetVertex(1)))
207  {
208  // Backward direction. Vertex 0 is connected to edge 2.
209  returnval = StdRegions::eBackwards;
210  }
211  else if ((*edge1.GetVertex(1) != *edge2.GetVertex(0)) &&
212  (*edge1.GetVertex(1) != *edge2.GetVertex(1)))
213  {
214  // Not forward either, then we have a problem.
215  std::ostringstream errstrm;
216  errstrm << "Connected edges do not share a vertex. Edges ";
217  errstrm << edge1.GetGlobalID() << ", " << edge2.GetGlobalID();
218  ASSERTL0(false, errstrm.str());
219  }
220 
221  return returnval;
222 }
223 
225 {
226  if(!m_setupState)
227  {
229  }
230 
232  {
235 
236  if (m_xmap->GetBasisNumModes(0) != 2)
237  {
238  gType = eDeformed;
239  }
240 
242  gType, m_coordim, m_xmap, m_coeffs);
244  }
245 }
246 
248 {
249  if (m_state != ePtsFilled)
250  {
251  int i;
252 
253  if (m_coordim > 0 && m_curve)
254  {
255  int npts = m_curve->m_points.size();
256  LibUtilities::PointsKey pkey(npts + 1,
258  Array<OneD, NekDouble> tmp(npts);
259 
260  if (m_verts[0]->dist(*(m_curve->m_points[0])) >
262  {
263  std::string err =
264  "Vertex 0 is separated from first point by more than ";
265  std::stringstream strstrm;
266  strstrm << NekConstants::kVertexTheSameDouble << " in edge "
267  << m_globalID;
268  err += strstrm.str();
269  NEKERROR(ErrorUtil::ewarning, err.c_str());
270  }
271 
272  if (m_verts[1]->dist(*(m_curve->m_points[npts - 1])) >
274  {
275  std::string err =
276  "Vertex 1 is separated from last point by more than ";
277  std::stringstream strstrm;
278  strstrm << NekConstants::kVertexTheSameDouble << " in edge "
279  << m_globalID;
280  err += strstrm.str();
281  NEKERROR(ErrorUtil::ewarning, err.c_str());
282  }
283 
284  LibUtilities::PointsKey fkey(npts, m_curve->m_ptype);
285  DNekMatSharedPtr I0 =
286  LibUtilities::PointsManager()[fkey]->GetI(pkey);
287  NekVector<NekDouble> out(npts + 1);
288 
289  for (int i = 0; i < m_coordim; ++i)
290  {
291  // Load up coordinate values into tmp
292  for (int j = 0; j < npts; ++j)
293  {
294  tmp[j] = (m_curve->m_points[j]->GetPtr())[i];
295  }
296 
297  // Interpolate to GLL points
298  NekVector<NekDouble> in(npts, tmp, eWrapper);
299  out = (*I0) * in;
300 
301  m_xmap->FwdTrans(out.GetPtr(), m_coeffs[i]);
302  }
303  }
304 
305  for (i = 0; i < m_coordim; ++i)
306  {
307  m_coeffs[i][0] = (*m_verts[0])[i];
308  m_coeffs[i][1] = (*m_verts[1])[i];
309  }
310 
312  }
313 }
314 
315 void SegGeom::v_Reset(CurveMap &curvedEdges, CurveMap &curvedFaces)
316 {
317  Geometry::v_Reset(curvedEdges, curvedFaces);
318  CurveMap::iterator it = curvedEdges.find(m_globalID);
319 
320  if (it != curvedEdges.end())
321  {
322  m_curve = it->second;
323  }
324 
325  SetUpXmap();
326  SetUpCoeffs(m_xmap->GetNcoeffs());
327 }
328 
330 {
331  if(!m_setupState)
332  {
333  SetUpXmap();
334  SetUpCoeffs(m_xmap->GetNcoeffs());
335  m_setupState = true;
336  }
337 }
338 
340  Array<OneD, NekDouble> &Lcoords)
341 {
342  int i;
343  NekDouble resid = 0.0;
345 
346  // calculate local coordinate for coord
347  if (GetMetricInfo()->GetGtype() == eRegular)
348  {
349  NekDouble len = 0.0;
350  NekDouble xi = 0.0;
351 
352  const int npts = m_xmap->GetTotPoints();
353  Array<OneD, NekDouble> pts(npts);
354 
355  for (i = 0; i < m_coordim; ++i)
356  {
357  m_xmap->BwdTrans(m_coeffs[i], pts);
358  len += (pts[npts - 1] - pts[0]) * (pts[npts - 1] - pts[0]);
359  xi += (coords[i] - pts[0]) * (pts[npts-1] - pts[0]);
360  }
361 
362  Lcoords[0] = 2 * xi / len - 1.0;
363  }
364  else
365  {
367  "inverse mapping must be set up to use this call");
368  }
369  return resid;
370 }
371 
373  Array<OneD, NekDouble> &stdCoord,
374  NekDouble tol,
375  NekDouble &resid)
376 {
377  //Rough check if within twice min/max point
378  if (GetMetricInfo()->GetGtype() != eRegular)
379  {
380  if (!MinMaxCheck(gloCoord))
381  {
382  return false;
383  }
384  }
385 
386  // Convert to the local (eta) coordinates.
387  resid = GetLocCoords(gloCoord, stdCoord);
388 
389  if (stdCoord[0] >= -(1 + tol) && stdCoord[0] <= 1 + tol)
390  {
391  return true;
392  }
393 
394  //Clamp local coords
395  ClampLocCoords(stdCoord, tol);
396 
397  return false;
398 }
399 
401 {
402  PointGeomSharedPtr returnval;
403 
404  if (i >= 0 && i < kNverts)
405  {
406  returnval = m_verts[i];
407  }
408 
409  return returnval;
410 }
411 
413 {
414  return kNverts;
415 }
416 
418 {
419  return kNedges;
420 }
421 
422 }
423 }
StdRegions::StdExpansionSharedPtr m_xmap
mapping containing isoparametric transformation.
Definition: Geometry.h:189
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
virtual PointGeomSharedPtr v_GetVertex(const int i) const
Definition: SegGeom.cpp:400
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:246
GeomFactorsSharedPtr m_geomFactors
Geometric factors.
Definition: Geometry.h:185
std::unordered_map< int, CurveSharedPtr > CurveMap
Definition: Curve.hpp:62
bool MinMaxCheck(const Array< OneD, const NekDouble > &gloCoord)
Check if given global coord is within twice the min/max distance of the element.
Definition: Geometry.cpp:435
virtual NekDouble v_GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Determine the local collapsed coordinates that correspond to a given Cartesian coordinate for this ge...
Definition: SegGeom.cpp:339
Principle Modified Functions .
Definition: BasisType.h:48
virtual void v_Reset(CurveMap &curvedEdges, CurveMap &curvedFaces)
Reset this geometry object: unset the current state, zero Geometry::m_coeffs and remove allocated Geo...
Definition: Geometry.cpp:335
void ClampLocCoords(Array< OneD, NekDouble > &locCoord, NekDouble tol)
Clamp local coords to be within standard regions [-1, 1]^dim.
Definition: Geometry.cpp:478
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:69
static const NekDouble kVertexTheSameDouble
GeomState m_geomFactorsState
State of the geometric factors.
Definition: Geometry.h:187
static StdRegions::Orientation GetEdgeOrientation(const SegGeom &edge1, const SegGeom &edge2)
Get the orientation of edge1.
Definition: SegGeom.cpp:200
int GetGlobalID(void) const
Get the ID of this object.
Definition: Geometry.h:314
virtual int v_GetNumVerts() const
Get the number of vertices of this object.
Definition: SegGeom.cpp:412
SegGeomSharedPtr GenerateOneSpaceDimGeom(void)
Generate a one dimensional space segment geometry where the vert[0] has the same x value and vert[1] ...
Definition: SegGeom.cpp:111
virtual void v_GenGeomFactors()
Definition: SegGeom.cpp:224
Geometric information has not been generated.
static const int kNedges
Definition: SegGeom.h:79
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
PointsManagerT & PointsManager(void)
Defines a specification for a set of points.
Definition: Points.h:59
double NekDouble
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:59
bool m_setupState
Wether or not the setup routines have been run.
Definition: Geometry.h:193
SpatialDomains::PointGeomSharedPtr m_verts[kNverts]
Definition: SegGeom.h:82
virtual bool v_ContainsPoint(const Array< OneD, const NekDouble > &gloCoord, Array< OneD, NekDouble > &locCoord, NekDouble tol, NekDouble &resid)
Definition: SegGeom.cpp:372
virtual LibUtilities::ShapeType v_GetShapeType() const
Definition: SegGeom.cpp:169
1D geometry information
Definition: Geometry1D.h:54
Array< OneD, Array< OneD, NekDouble > > m_coeffs
Array containing expansion coefficients of m_xmap.
Definition: Geometry.h:201
CurveSharedPtr m_curve
Boolean indicating whether object owns the data.
Definition: SegGeom.h:107
Geometry is straight-sided with constant geometric factors.
std::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:61
virtual int v_GetNumEdges() const
Get the number of edges of this object.
Definition: SegGeom.cpp:417
NekDouble GetLocCoords(const Array< OneD, const NekDouble > &coords, Array< OneD, NekDouble > &Lcoords)
Determine the local collapsed coordinates that correspond to a given Cartesian coordinate for this ge...
Definition: Geometry.h:534
virtual NekDouble v_GetCoord(const int i, const Array< OneD, const NekDouble > &Lcoord)
Given local collapsed coordinate Lcoord, return the value of physical coordinate in direction i...
Definition: SegGeom.cpp:174
LibUtilities::ShapeType m_shapeType
Type of shape.
Definition: Geometry.h:197
virtual void v_FillGeom()
Populate the coordinate mapping Geometry::m_coeffs information from any children geometry elements...
Definition: SegGeom.cpp:247
virtual void v_Reset(CurveMap &curvedEdges, CurveMap &curvedFaces)
Reset this geometry object: unset the current state, zero Geometry::m_coeffs and remove allocated Geo...
Definition: SegGeom.cpp:315
Geometric information has been generated.
void SetUpCoeffs(const int nCoeffs)
Initialise the Geometry::m_coeffs array.
Definition: Geometry.h:643
GeomFactorsSharedPtr GetMetricInfo()
Get the geometric factors for this object.
Definition: Geometry.h:298
GeomType
Indicates the type of element geometry.
GeomState m_state
Enumeration to dictate whether coefficients are filled.
Definition: Geometry.h:191
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
std::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:62
Geometry is curved or has non-constant factors.
PointGeomSharedPtr GetVertex(int i) const
Returns vertex i of this object.
Definition: Geometry.h:343
int m_coordim
Coordinate dimension of this geometry object.
Definition: Geometry.h:183
Describes the specification for a Basis.
Definition: Basis.h:49
Array< OneD, DataType > & GetPtr()
Definition: NekVector.cpp:227
1D Gauss-Lobatto-Legendre quadrature points
Definition: PointsType.h:51
static const int kNverts
Definition: SegGeom.h:78