Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NodalTriEvenlySpaced.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File NodalTriEvenlySpaced.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: 2D Nodal Triangle Evenly Spaced Point Definitions
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
42 #include <vector>
43 
44 
45 
46 namespace Nektar
47 {
48  namespace LibUtilities
49  {
50  namespace
51  {
52  // construct the geometory and set the coordinate of triangle
53  // edges and vertices are ordered as anticlockwise
54  bool isVertex(int i, int j, int npts){
55  return (i==0 && j==0) || (i==(npts-1) && j==0) || (i==0 && j==(npts-1));
56  }
57 
58  bool isEdge(int i, int j, int npts){
59  return i==0 || j==0 || i+j==npts-1; //i+j=tot num of steps
60  }
61 
62  bool isEdge_1(int i, int j, int npts){
63  return i==0;
64  }
65 
66  bool isEdge_2(int i, int j, int npts){
67  return i+j==npts-1;
68  }
69  }
70 
71 
73  {
74  // Allocate the storage for points
76 
77  // Populate m_points
78  unsigned int npts = GetNumPoints();
79  NekDouble delta = 2.0/(npts - 1.0);
80  for(int i=0, index=0; i<npts; ++i){ // y-direction
81  for(int j=0; j<npts-i; ++j,++index){ // x-direction
82  NekDouble x = -1.0 + j*delta;
83  NekDouble y = -1.0 + i*delta;
84  m_points[0][index] = x;
85  m_points[1][index] = y;
86  }
87  }
88 
90 
92  npts - 1, m_points[0], m_points[1]);
93  }
94 
95 
97  {
98  // Allocate the storage for points
100 
101  typedef DataType T;
102 
103  // Solve the Vandermonde system of integrals for the weight vector
104  NekVector<T> w = m_util->GetWeights();
105 
106  m_weights = Array<OneD,T>( w.GetRows(), w.GetPtr() );
107 
108  }
109 
110 
111  // ////////////////////////////////////////
112  // CalculateInterpMatrix()
114  const Array<OneD, const NekDouble>& yia,
115  Array<OneD, NekDouble>& interp)
116  {
118  xi[0] = xia;
119  xi[1] = yia;
120 
121  boost::shared_ptr<NekMatrix<NekDouble> > mat =
122  m_util->GetInterpolationMatrix(xi);
123  Vmath::Vcopy(mat->GetRows() * mat->GetColumns(), mat->GetRawPtr(),
124  1, &interp[0], 1);
125  }
126 
127  // ////////////////////////////////////////
128  // CalculateDerivMatrix()
130  {
131 
132  // Allocate the derivative matrix.
134 
135  m_derivmatrix[0] = m_util->GetDerivMatrix(0);
136  m_derivmatrix[1] = m_util->GetDerivMatrix(1);
137  }
138 
139  boost::shared_ptr<PointsBaseType> NodalTriEvenlySpaced::Create(const PointsKey &key)
140  {
141  boost::shared_ptr<PointsBaseType> returnval(MemoryManager<NodalTriEvenlySpaced>::AllocateSharedPtr(key));
142 
143  returnval->Initialize();
144 
145  return returnval;
146  }
147 
149  {
150  unsigned int npts = GetNumPoints();
151  using std::vector;
152  vector<int> vertex;
153  vector<int> iEdge_1; // interior edge points on the bottom triangle edge
154  vector<int> iEdge_2; // interior edge points on the right triangle edge
155  vector<int> iEdge_3; // interior edge points on the left triangle edge
156  vector<int> interiorPoints;
157  vector<int> map;
158 
159  // Build the lattice triangle left to right - bottom to top
160  for(int i=0, index=0; i<npts; ++i){ // y-direction
161  for(int j=0; j<npts-i; ++j,++index){ // x-direction
162 
163  if( isVertex(i,j,npts) ) {
164 
165  vertex.push_back(index);
166 
167  } else if( isEdge(i,j,npts) ) { // interior edge
168 
169  if(isEdge_1(i,j,npts)){ // bottom edge
170 
171  iEdge_1.push_back(index);
172 
173  }else if(isEdge_2(i,j,npts)){ // right edge
174 
175  iEdge_2.push_back(index);
176 
177  }else // left edge
178  {
179  // Add backwards. This is because of counter clockwise.
180  iEdge_3.insert(iEdge_3.begin(), index);
181  }
182 
183  } else { // Interior points
184 
185  interiorPoints.push_back(index);
186  }
187  }
188  }
189 
190  // Mapping the vertex, edges, and interior points using the permutation matrix,
191  // so the points are ordered anticlockwise.
192  for(unsigned int k=0; k<vertex.size(); ++k){
193 
194  map.push_back(vertex[k]);
195  }
196 
197  for(unsigned int k=0; k<iEdge_1.size(); ++k){
198 
199  map.push_back(iEdge_1[k]);
200  }
201 
202  for(unsigned int k=0; k<iEdge_2.size(); ++k){
203 
204  map.push_back(iEdge_2[k]);
205  }
206 
207  for(unsigned int k=0; k<iEdge_3.size(); ++k){
208 
209  map.push_back(iEdge_3[k]);
210  }
211 
212  for(unsigned int k=0; k<interiorPoints.size(); ++k){
213 
214  map.push_back(interiorPoints[k]);
215  }
216 
217 
218  Array<OneD,NekDouble> points[2];
219  points[0] = Array<OneD,NekDouble>(GetTotNumPoints());
220  points[1] = Array<OneD,NekDouble>(GetTotNumPoints());
221  for(unsigned int index=0; index<map.size(); ++index){
222  points[0][index] = m_points[0][index];
223  points[1][index] = m_points[1][index];
224  }
225 
226  for(unsigned int index=0; index<map.size(); ++index){
227  m_points[0][index] = points[0][map[index]];
228  m_points[1][index] = points[1][map[index]];
229  }
230 
231  }
232 
233  } // end of namespace
234 } // end of namespace
235 
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
boost::shared_ptr< NodalUtilTriangle > m_util
MatrixSharedPtrType m_derivmatrix[3]
Definition: Points.h:373
Array< OneD, DataType > m_points[3]
Definition: Points.h:371
void CalculateInterpMatrix(const Array< OneD, const NekDouble > &xi, const Array< OneD, const NekDouble > &yi, Array< OneD, NekDouble > &interp)
unsigned int GetNumPoints() const
Definition: Points.h:268
static std::string npts
Definition: InputFld.cpp:43
Array< OneD, DataType > m_weights
Definition: Points.h:372
Defines a specification for a set of points.
Definition: Points.h:58
double NekDouble
unsigned int GetRows() const
Definition: NekVector.cpp:218
unsigned int GetTotNumPoints() const
Definition: Points.h:273
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
static boost::shared_ptr< PointsBaseType > Create(const PointsKey &key)
Array< OneD, DataType > & GetPtr()
Definition: NekVector.cpp:230