Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ExpList2DHomogeneous1D.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File ExpList2DHomogeneous1D.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: An ExpList2D which is homogeneous in 1 direction and so
33 // uses much of the functionality from a ExpList1D and its daughters
34 //
35 ///////////////////////////////////////////////////////////////////////////////
36 
38 #include <MultiRegions/ExpList1D.h>
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44  namespace MultiRegions
45  {
46  // Forward declaration for typedefs
47  ExpList2DHomogeneous1D::ExpList2DHomogeneous1D():
49  {
50  }
51 
52  // Constructor for ExpList2DHomogeneous1D to act as a Explist2D field
55  const LibUtilities::BasisKey &HomoBasis,
56  const NekDouble lhom,
57  const bool useFFT,
58  const bool dealiasing,
59  const Array<OneD, ExpListSharedPtr> &planes)
60  : ExpListHomogeneous1D(pSession,HomoBasis,lhom,useFFT,dealiasing)
61  {
62  int i, n, cnt, nel;
63 
64  ASSERTL1(m_planes.num_elements() == planes.num_elements(),
65  "Size of basis number of points and number"
66  "of planes are not the same");
67 
68  // Set up expansion list with elements from all planes.
71  planes.num_elements() * planes[0]->GetExpSize());
72 
73  for(cnt = n = 0; n < planes.num_elements(); ++n)
74  {
75  m_planes[n] = planes[n];
76  for (i = 0; i < planes[n]->GetExpSize(); ++i)
77  {
78  (*m_exp)[cnt++] = planes[n]->GetExp(i);
79  }
80  }
81 
82  // Setup Default optimisation information.
83  nel = GetExpSize();
86 
87  SetCoeffPhys();
88  }
89 
90  // Constructor for ExpList2DHomogeneous1D to act as a Explist2D field
93  const LibUtilities::BasisKey &HomoBasis,
94  const NekDouble lhom,
95  const bool useFFT,
96  const bool dealiasing,
98  const Collections::ImplementationType ImpType):
99  ExpListHomogeneous1D(pSession,HomoBasis,lhom,useFFT,dealiasing)
100  {
101  int n, j, nel;
102  ExpList1DSharedPtr plane_zero;
103 
104  // note that nzplanes can be larger than nzmodes
105  m_planes[0] = plane_zero = MemoryManager<ExpList1D>::
106  AllocateSharedPtr(m_session, graph1D, false, ImpType);
107 
109 
110  nel = m_planes[0]->GetExpSize();
111 
112  for (j = 0; j < nel; ++j)
113  {
114  (*m_exp).push_back(m_planes[0]->GetExp(j));
115  }
116 
117  for (n = 1; n < m_planes.num_elements(); ++n)
118  {
120  AllocateSharedPtr(*plane_zero, false);
121  for(j = 0; j < nel; ++j)
122  {
123  (*m_exp).push_back((*m_exp)[j]);
124  }
125  }
126 
127  // Setup Default optimisation information.
128  nel = GetExpSize();
131 
132  SetCoeffPhys();
133  }
134 
135 
136  /**
137  * @param In ExpList2DHomogeneous1D object to copy.
138  */
140  const ExpList2DHomogeneous1D &In):
142  {
143  ExpList1DSharedPtr zero_plane =
144  boost::dynamic_pointer_cast<ExpList1D> (In.m_planes[0]);
145 
146  for (int n = 0; n < m_planes.num_elements(); ++n)
147  {
149  AllocateSharedPtr(*zero_plane, false);
150  }
151 
152  SetCoeffPhys();
153  }
154 
155  /**
156  * Destructor
157  */
159  {
160  }
161 
163  {
164  int i, n, cnt;
165  int ncoeffs_per_plane = m_planes[0]->GetNcoeffs();
166  int npoints_per_plane = m_planes[0]->GetTotPoints();
167 
168  int nzplanes = m_planes.num_elements();
169 
170  // Set total coefficients and points
171  m_ncoeffs = ncoeffs_per_plane*nzplanes;
172  m_npoints = npoints_per_plane*nzplanes;
173 
176 
177  int nel = m_planes[0]->GetExpSize();
178  m_coeff_offset = Array<OneD,int>(nel*nzplanes);
179  m_phys_offset = Array<OneD,int>(nel*nzplanes);
180  Array<OneD, NekDouble> tmparray;
181 
182  for (cnt = n = 0; n < nzplanes; ++n)
183  {
184  m_planes[n]->SetCoeffsArray(
185  tmparray= m_coeffs + ncoeffs_per_plane*n);
186  m_planes[n]->SetPhysArray(
187  tmparray = m_phys + npoints_per_plane*n);
188 
189  for(i = 0; i < nel; ++i)
190  {
191  m_coeff_offset[cnt] = m_planes[n]->GetCoeff_Offset(i)
192  + n*ncoeffs_per_plane;
193  m_phys_offset[cnt++] = m_planes[n]->GetPhys_Offset(i)
194  + n*npoints_per_plane;
195  }
196  }
197  }
198 
200  const int eid,
204  {
205  int n, coordim;
206  Array<OneD, NekDouble> tmp_xc,xhom;
207  int nyplanes = m_planes.num_elements();
208  int npoints = GetTotPoints(eid);
209 
210  switch(coordim = GetCoordim(0))
211  {
212  case 1:
213  {
214  (*m_exp)[eid]->GetCoords(xc0);
215  xhom = xc1;
216  }
217  break;
218  case 2:
219  ASSERTL0(xc1.num_elements() != 0,
220  "output coord_1 is not defined");
221  {
222  (*m_exp)[eid]->GetCoords(xc0,xc1);
223  xhom = xc2;
224  }
225  break;
226  default:
227  ASSERTL0(false, "Cannot have coordim being three dimensions"
228  "in a homogeneous field");
229  break;
230  }
231 
232  // Fill homogeneous-direction
234  Array<OneD, NekDouble> z(nyplanes);
235 
236  Array<OneD, NekDouble> local_pts(m_planes.num_elements());
237 
238  for(n = 0; n < m_planes.num_elements(); n++)
239  {
240  local_pts[n] = pts[m_transposition->GetPlaneID(n)];
241  }
242 
243  Vmath::Smul(nyplanes,m_lhom/2.0,local_pts,1,z,1);
244  Vmath::Sadd(nyplanes,m_lhom/2.0,z,1,z,1);
245 
246  for (n = 0; n < nyplanes; ++n)
247  {
248  Vmath::Fill(npoints,z[n],tmp_xc = xhom + npoints*n,1);
249  if(n)
250  {
251  Vmath::Vcopy(npoints,xc0,1,tmp_xc = xc0+npoints*n,1);
252  if(coordim == 2)
253  {
254  Vmath::Vcopy(npoints,xc1,1,tmp_xc = xc1+npoints*n,1);
255  }
256  }
257  }
258  }
259 
260  /**
261  * The operation calls the 2D plane coordinates through the
262  * function ExpList#GetCoords and then evaluated the third
263  * coordinate using the member \a m_lhom
264  *
265  * @param coord_0 After calculation, the \f$x_1\f$ coordinate
266  * will be stored in this array.
267  *
268  * @param coord_1 After calculation, the \f$x_2\f$ coordinate
269  * will be stored in this array. This
270  * coordinate might be evaluated using the
271  * predefined value \a m_lhom
272  *
273  * @param coord_2 After calculation, the \f$x_3\f$ coordinate
274  * will be stored in this array. This
275  * coordinate is evaluated using the
276  * predefined value \a m_lhom
277  */
282  {
283  int n,coordim;
284  Array<OneD, NekDouble> tmp_xc, xhom;
285  int nyplanes = m_planes.num_elements();
286  int npoints = m_planes[0]->GetTotPoints();
287 
288  m_planes[0]->GetCoords(xc0,xc1);
289 
290  if((coordim = GetCoordim(0)) == 1)
291  {
292  xhom = xc1;
293  }
294  else
295  {
296  xhom = xc2;
297  }
298 
299  // Fill z-direction
301  Array<OneD, NekDouble> z(nyplanes);
302  Array<OneD, NekDouble> local_pts(m_planes.num_elements());
303 
304  for(n = 0; n < m_planes.num_elements(); n++)
305  {
306  local_pts[n] = pts[m_transposition->GetPlaneID(n)];
307  }
308 
309  Vmath::Smul(nyplanes,m_lhom/2.0,local_pts,1,z,1);
310  Vmath::Sadd(nyplanes,m_lhom/2.0,z,1,z,1);
311 
312  for(n = 0; n < nyplanes; ++n)
313  {
314  Vmath::Fill(npoints,z[n],tmp_xc = xhom + npoints*n,1);
315  if(n)
316  {
317  Vmath::Vcopy(npoints,xc0,1,tmp_xc = xc0+npoints*n,1);
318  if(coordim == 2)
319  {
320  Vmath::Vcopy(npoints,xc1,1,tmp_xc = xc1+npoints*n,1);
321  }
322  }
323  }
324  }
325 
326 
327  /**
328  * Write Tecplot Files Zone
329  * @param outfile Output file name.
330  * @param expansion Expansion that is considered
331  */
333  std::ostream &outfile,
334  int expansion)
335  {
336  int i, j;
337 
338  int nquad0 = (*m_exp)[expansion]->GetNumPoints(0);
339  int nquad1 = m_planes.num_elements();
340 
341  Array<OneD,NekDouble> coords[3];
342 
343  coords[0] = Array<OneD,NekDouble>(3*nquad0*nquad1);
344  coords[1] = coords[0] + nquad0*nquad1;
345  coords[2] = coords[1] + nquad0*nquad1;
346 
347  GetCoords(expansion,coords[0],coords[1],coords[2]);
348 
349  outfile << "Zone, I=" << nquad0 << ", J=" << nquad1
350  << ", F=Block" << std::endl;
351 
352  for(j = 0; j < GetCoordim(0)+1; ++j)
353  {
354  for(i = 0; i < nquad0*nquad1; ++i)
355  {
356  outfile << coords[j][i] << " ";
357  }
358  outfile << std::endl;
359  }
360  }
361 
362 
364  std::ostream &outfile,
365  int expansion,
366  int istrip)
367  {
368  // If there is only one plane (e.g. HalfMode), we write a 2D plane.
369  if (m_planes.num_elements() == 1)
370  {
371  m_planes[0]->WriteVtkPieceHeader(outfile, expansion);
372  return;
373  }
374 
375  // If we are using Fourier points, output extra plane to fill domain
376  int outputExtraPlane = 0;
377  if ( m_homogeneousBasis->GetBasisType() == LibUtilities::eFourier
378  && m_homogeneousBasis->GetPointsType() ==
380  {
381  outputExtraPlane = 1;
382  }
383  int i, j;
384  int nquad0 = (*m_exp)[expansion]->GetNumPoints(0);
385  int nquad1 = m_planes.num_elements() + outputExtraPlane;
386  int ntot = nquad0*nquad1;
387  int ntotminus = (nquad0-1)*(nquad1-1);
388 
389  Array<OneD,NekDouble> coords[3];
390  coords[0] = Array<OneD,NekDouble>(ntot);
391  coords[1] = Array<OneD,NekDouble>(ntot);
392  coords[2] = Array<OneD,NekDouble>(ntot);
393  GetCoords(expansion,coords[0],coords[1],coords[2]);
394 
395  if (outputExtraPlane)
396  {
397  // Copy coords[0] and coords[1] to extra plane
399  Vmath::Vcopy (nquad0, coords[0], 1,
400  tmp = coords[0] + (nquad1-1)*nquad0, 1);
401  Vmath::Vcopy (nquad0, coords[1], 1,
402  tmp = coords[1] + (nquad1-1)*nquad0, 1);
403  // Fill coords[2] for extra plane
404  NekDouble z = coords[2][nquad0*m_planes.num_elements()-1] +
405  (coords[2][nquad0] - coords[2][0]);
406  Vmath::Fill(nquad0, z, tmp = coords[2] + (nquad1-1)*nquad0, 1);
407  }
408 
409  outfile << " <Piece NumberOfPoints=\""
410  << ntot << "\" NumberOfCells=\""
411  << ntotminus << "\">" << endl;
412  outfile << " <Points>" << endl;
413  outfile << " <DataArray type=\"Float64\" "
414  << "NumberOfComponents=\"3\" format=\"ascii\">" << endl;
415  outfile << " ";
416  for (i = 0; i < ntot; ++i)
417  {
418  for (j = 0; j < 3; ++j)
419  {
420  outfile << coords[j][i] << " ";
421  }
422  outfile << endl;
423  }
424  outfile << endl;
425  outfile << " </DataArray>" << endl;
426  outfile << " </Points>" << endl;
427  outfile << " <Cells>" << endl;
428  outfile << " <DataArray type=\"Int32\" "
429  << "Name=\"connectivity\" format=\"ascii\">" << endl;
430  for (i = 0; i < nquad0-1; ++i)
431  {
432  for (j = 0; j < nquad1-1; ++j)
433  {
434  outfile << j*nquad0 + i << " "
435  << j*nquad0 + i + 1 << " "
436  << (j+1)*nquad0 + i + 1 << " "
437  << (j+1)*nquad0 + i << endl;
438  }
439  }
440  outfile << endl;
441  outfile << " </DataArray>" << endl;
442  outfile << " <DataArray type=\"Int32\" "
443  << "Name=\"offsets\" format=\"ascii\">" << endl;
444  for (i = 0; i < ntotminus; ++i)
445  {
446  outfile << i*4+4 << " ";
447  }
448  outfile << endl;
449  outfile << " </DataArray>" << endl;
450  outfile << " <DataArray type=\"UInt8\" "
451  << "Name=\"types\" format=\"ascii\">" << endl;
452  for (i = 0; i < ntotminus; ++i)
453  {
454  outfile << "9 ";
455  }
456  outfile << endl;
457  outfile << " </DataArray>" << endl;
458  outfile << " </Cells>" << endl;
459  outfile << " <PointData>" << endl;
460  }
461 
463  Array<OneD, Array<OneD, NekDouble> > &normals)
464  {
465  int nPlanes = m_planes.num_elements();
466  int nPtsPlane = m_planes[0]->GetNpoints();
467  int nDim = GetCoordim(0) + 1;
468 
469  ASSERTL1(normals.num_elements() >= nDim,
470  "Output vector does not have sufficient dimensions to"
471  "match coordim");
472  ASSERTL1(normals[0].num_elements() >= nPtsPlane,
473  "Output vector does not have sufficient dimensions to"
474  "match coordim");
475 
476  // Calculate normals from plane 0.
477  m_planes[0]->GetNormals(normals);
478 
479  // Copy remaining planes.
480  for (int i = 0; i < nDim; ++i)
481  {
482  for (int n = 1; n < nPlanes; ++n)
483  {
484  Vmath::Vcopy(nPtsPlane, &normals[i][0], 1,
485  &normals[i][n*nPtsPlane], 1);
486  }
487  }
488  }
489  } //end of namespace
490 } //end of namespace
Abstraction of a two-dimensional multi-elemental expansion which is merely a collection of local expa...
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
NekOptimize::GlobalOptParamSharedPtr m_globalOptParam
Definition: ExpList.h:1052
LibUtilities::TranspositionSharedPtr m_transposition
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:46
const boost::shared_ptr< LocalRegions::ExpansionVector > GetExp() const
This function returns the vector of elements in the expansion.
Definition: ExpList.h:2067
STL namespace.
virtual void v_WriteTecplotZone(std::ostream &outfile, int expansion)
NekDouble m_lhom
Width of homogeneous direction.
Array< OneD, NekDouble > m_phys
The global expansion evaluated at the quadrature points.
Definition: ExpList.h:1015
Fourier Expansion .
Definition: BasisType.h:52
Array< OneD, NekDouble > m_coeffs
Concatenation of all local expansion coefficients.
Definition: ExpList.h:998
int GetExpSize(void)
This function returns the number of elements in the expansion.
Definition: ExpList.h:2046
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
Abstraction of a two-dimensional multi-elemental expansion which is merely a collection of local expa...
Array< OneD, int > m_coeff_offset
Offset of elemental data into the array m_coeffs.
Definition: ExpList.h:1047
LibUtilities::BasisSharedPtr m_homogeneousBasis
Definition of the total number of degrees of freedom and quadrature points. Sets up the storage for m...
1D Evenly-spaced points using Fourier Fit
Definition: PointsType.h:66
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Definition: Vmath.cpp:213
boost::shared_ptr< LocalRegions::ExpansionVector > m_exp
The list of local expansions.
Definition: ExpList.h:1036
int GetTotPoints(void) const
Returns the total number of quadrature points m_npoints .
Definition: ExpList.h:1535
boost::shared_ptr< ExpList1D > ExpList1DSharedPtr
Shared pointer to an ExpList1D object.
Definition: ExpList1D.h:50
Array< OneD, int > m_phys_offset
Offset of elemental data into the array m_phys.
Definition: ExpList.h:1050
int m_ncoeffs
The total number of local degrees of freedom. m_ncoeffs .
Definition: ExpList.h:976
LibUtilities::SessionReaderSharedPtr m_session
Session.
Definition: ExpList.h:969
virtual void v_GetCoords(Array< OneD, NekDouble > &coord_0, Array< OneD, NekDouble > &coord_1, Array< OneD, NekDouble > &coord_2)
Array< OneD, ExpListSharedPtr > m_planes
double NekDouble
virtual void v_GetNormals(Array< OneD, Array< OneD, NekDouble > > &normals)
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition: Vmath.cpp:315
void SetCoeffPhys(void)
Definition of the total number of degrees of freedom and quadrature points. Sets up the storage for m...
This class is the abstraction of a one-dimensional multi-elemental expansions which is merely a colle...
Definition: ExpList1D.h:61
int GetCoordim(int eid)
This function returns the dimension of the coordinates of the element eid.
Definition: ExpList.h:1898
void GetCoords(Array< OneD, NekDouble > &coord_0, Array< OneD, NekDouble > &coord_1=NullNekDouble1DArray, Array< OneD, NekDouble > &coord_2=NullNekDouble1DArray)
This function calculates the coordinates of all the elemental quadrature points . ...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:228
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:442
virtual void v_WriteVtkPieceHeader(std::ostream &outfile, int expansion, int istrip)
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
Describes the specification for a Basis.
Definition: Basis.h:50