Nektar++
ExpList3DHomogeneous2D.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File ExpList3DHomogeneous2D.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: An ExpList which is homogeneous in 2 directions and so
32 // uses much of the functionality from a ExpList1D and its daughters
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #include <boost/core/ignore_unused.hpp>
37 
39 #include <MultiRegions/ExpList1D.h>
40 
41 using namespace std;
42 
43 namespace Nektar
44 {
45  namespace MultiRegions
46  {
47  // Forward declaration for typedefs
48  ExpList3DHomogeneous2D::ExpList3DHomogeneous2D():
50  {
52  }
53 
56  const LibUtilities::BasisKey &HomoBasis_y,
57  const LibUtilities::BasisKey &HomoBasis_z,
58  const NekDouble lhom_y,
59  const NekDouble lhom_z,
60  const bool useFFT,
61  const bool dealiasing,
62  const Collections::ImplementationType ImpType):
63  ExpListHomogeneous2D(pSession,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,useFFT,dealiasing)
64  {
65  boost::ignore_unused(ImpType);
67  }
68 
69  // Constructor for ExpList3DHomogeneous2D to act as a Explist1D field
72  const LibUtilities::BasisKey &HomoBasis_y,
73  const LibUtilities::BasisKey &HomoBasis_z,
74  const NekDouble lhom_y,
75  const NekDouble lhom_z,
76  const bool useFFT,
77  const bool dealiasing,
79  const Collections::ImplementationType ImpType):
80  ExpListHomogeneous2D(pSession,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,useFFT,dealiasing)
81  {
83 
84  int n,j,nel;
85  bool False = false;
86  ExpList1DSharedPtr line_zero;
87 
88  //
89  m_lines[0] = line_zero = MemoryManager<ExpList1D>::
90  AllocateSharedPtr(m_session,graph1D, False,ImpType);
91 
94  nel = m_lines[0]->GetExpSize();
95 
96  for(j = 0; j < nel; ++j)
97  {
98  (*m_exp).push_back(m_lines[0]->GetExp(j));
99  }
100 
101  int ny = m_homogeneousBasis_y->GetNumPoints();
102  int nz = m_homogeneousBasis_z->GetNumPoints();
103 
104  for(n = 1; n < (ny*nz); ++n)
105  {
107  for(j = 0; j < nel; ++j)
108  {
109  (*m_exp).push_back((*m_exp)[j]);
110  }
111  }
112 
113  // Setup Default optimisation information.
114  nel = GetExpSize();
117 
118  SetCoeffPhys();
119  }
120 
121 
122  /**
123  * @param In ExpList3DHomogeneous2D object to copy.
124  */
126  const ExpList3DHomogeneous2D &In,
127  const bool DeclareLinesSetCoeffPhys):
129  {
131 
132  if(DeclareLinesSetCoeffPhys)
133  {
134  bool False = false;
135  ExpList1DSharedPtr zero_line = std::dynamic_pointer_cast<ExpList1D> (In.m_lines[0]);
136 
137  for(int n = 0; n < m_lines.num_elements(); ++n)
138  {
140  }
141 
142  SetCoeffPhys();
143  }
144  }
145 
146  /**
147  *
148  */
150  const ExpList3DHomogeneous2D &In,
151  const std::vector<unsigned int> &eIDs,
152  const bool DeclareLinesSetCoeffPhys,
153  const Collections::ImplementationType ImpType):
154  ExpListHomogeneous2D(In, eIDs)
155  {
157 
158  if(DeclareLinesSetCoeffPhys)
159  {
160  bool False = false;
161  std::vector<unsigned int> eIDsLine;
162  int nel = eIDs.size()/m_lines.num_elements();
163 
164  for (int i = 0; i < nel; ++i)
165  {
166  eIDsLine.push_back(eIDs[i]);
167  }
168 
169  ExpList1DSharedPtr zero_line_old =
170  std::dynamic_pointer_cast<ExpList1D> (In.m_lines[0]);
171 
172  ExpList1DSharedPtr zero_line =
173  MemoryManager<ExpList1D>::AllocateSharedPtr(*(zero_line_old), eIDsLine, ImpType);
174 
175  for(int n = 0; n < m_lines.num_elements(); ++n)
176  {
178  }
179 
180  SetCoeffPhys();
181  }
182  }
183 
184  /**
185  * Destructor
186  */
188  {
189  }
190 
192  {
193  int i,n,cnt;
194  int ncoeffs_per_line = m_lines[0]->GetNcoeffs();
195  int npoints_per_line = m_lines[0]->GetTotPoints();
196 
197  int nyzlines = m_lines.num_elements();
198 
199  // Set total coefficients and points
200  m_ncoeffs = ncoeffs_per_line*nyzlines;
201  m_npoints = npoints_per_line*nyzlines;
202 
205 
206  int nel = m_lines[0]->GetExpSize();
207  m_coeff_offset = Array<OneD,int>(nel*nyzlines);
208  m_phys_offset = Array<OneD,int>(nel*nyzlines);
209  Array<OneD, NekDouble> tmparray;
210 
211  for(cnt = n = 0; n < nyzlines; ++n)
212  {
213  m_lines[n]->SetCoeffsArray(tmparray= m_coeffs + ncoeffs_per_line*n);
214  m_lines[n]->SetPhysArray(tmparray = m_phys + npoints_per_line*n);
215 
216  for(i = 0; i < nel; ++i)
217  {
218  m_coeff_offset[cnt] = m_lines[n]->GetCoeff_Offset(i) + n*ncoeffs_per_line;
219  m_phys_offset[cnt++] = m_lines[n]->GetPhys_Offset(i) + n*npoints_per_line;
220  }
221  }
222  }
223 
228  {
229  int n,m,j;
230  Array<OneD, NekDouble> tmp_xc;
231  int nylines = m_homogeneousBasis_y->GetNumPoints();
232  int nzlines = m_homogeneousBasis_z->GetNumPoints();
233 
234  int npoints = GetTotPoints(eid);
235 
236  // Fill x-y-z-direction
239 
240  Array<OneD, NekDouble> x(npoints);
241  Array<OneD, NekDouble> y(nylines);
242  Array<OneD, NekDouble> z(nzlines);
243 
244  Vmath::Smul(nylines,m_lhom_y/2.0,pts_y,1,y,1);
245  Vmath::Sadd(nylines,m_lhom_y/2.0,y,1,y,1);
246 
247  Vmath::Smul(nzlines,m_lhom_z/2.0,pts_z,1,z,1);
248  Vmath::Sadd(nzlines,m_lhom_z/2.0,z,1,z,1);
249 
250  (*m_exp)[eid]->GetCoords(x);
251 
252 
253  for(m = 0; m < nzlines; ++m)
254  {
255  for(j = 0; j < nylines; ++j)
256  {
257  for(n = 0; n < npoints; ++n)
258  {
259  Vmath::Fill(1,x[n],tmp_xc = xc0 + n +(j*npoints) + (m*npoints*nylines), 1);
260  Vmath::Fill(1,y[j],tmp_xc = xc1 + n +(j*npoints) + (m*npoints*nylines), 1);
261  Vmath::Fill(1,z[m],tmp_xc = xc2 + n +(j*npoints) + (m*npoints*nylines), 1);
262  }
263  }
264  }
265  }
266 
267  /**
268  * The operation calls the 2D plane coordinates through the
269  * function ExpList#GetCoords and then evaluated the third
270  * coordinate using the member \a m_lhom
271  *
272  * @param coord_0 After calculation, the \f$x_1\f$ coordinate
273  * will be stored in this array.
274  *
275  * @param coord_1 After calculation, the \f$x_2\f$ coordinate
276  * will be stored in this array.
277  *
278  * @param coord_2 After calculation, the \f$x_3\f$ coordinate
279  * will be stored in this array. This
280  * coordinate is evaluated using the
281  * predefined value \a m_lhom
282  */
286  {
287  int n,m,j;
288  Array<OneD, NekDouble> tmp_xc;
289  int npoints = m_lines[0]->GetTotPoints();
290 
291  int nylines = m_homogeneousBasis_y->GetNumPoints();
292  int nzlines = m_homogeneousBasis_z->GetNumPoints();
293 
294  // Fill z-direction
297 
298  Array<OneD, NekDouble> x(npoints);
299  Array<OneD, NekDouble> y(nylines);
300  Array<OneD, NekDouble> z(nzlines);
301 
302  m_lines[0]->GetCoords(x);
303 
304  Vmath::Smul(nylines,m_lhom_y/2.0,pts_y,1,y,1);
305  Vmath::Sadd(nylines,m_lhom_y/2.0,y,1,y,1);
306 
307  Vmath::Smul(nzlines,m_lhom_z/2.0,pts_z,1,z,1);
308  Vmath::Sadd(nzlines,m_lhom_z/2.0,z,1,z,1);
309 
310  for(m = 0; m < nzlines; ++m)
311  {
312  for(j = 0; j < nylines; ++j)
313  {
314  for(n = 0; n < npoints; ++n)
315  {
316  Vmath::Fill(1,x[n],tmp_xc = xc0 + n +(j*npoints) + (m*npoints*nylines), 1);
317  Vmath::Fill(1,y[j],tmp_xc = xc1 + n +(j*npoints) + (m*npoints*nylines), 1);
318  Vmath::Fill(1,z[m],tmp_xc = xc2 + n +(j*npoints) + (m*npoints*nylines), 1);
319  }
320  }
321  }
322  }
323 
324 
325  /**
326  * Write Tecplot Files Zone
327  * @param outfile Output file name.
328  * @param expansion Expansion that is considered
329  */
330  void ExpList3DHomogeneous2D::v_WriteTecplotZone(std::ostream &outfile, int expansion)
331  {
332  int i,j;
333 
334  int nquad0 = (*m_exp)[expansion]->GetNumPoints(0);
335  int nquad1 = m_homogeneousBasis_y->GetNumPoints();
336  int nquad2 = m_homogeneousBasis_z->GetNumPoints();
337 
338  Array<OneD,NekDouble> coords[3];
339 
340  coords[0] = Array<OneD,NekDouble>(3*nquad0*nquad1*nquad2);
341  coords[1] = coords[0] + nquad0*nquad1*nquad2;
342  coords[2] = coords[1] + nquad0*nquad1*nquad2;
343 
344  GetCoords(expansion,coords[0],coords[1],coords[2]);
345 
346  outfile << "Zone, I=" << nquad0 << ", J=" << nquad1 <<",K="
347  << nquad2 << ", F=Block" << std::endl;
348 
349  for(j = 0; j < 3; ++j)
350  {
351  for(i = 0; i < nquad0*nquad1*nquad2; ++i)
352  {
353  outfile << coords[j][i] << " ";
354  }
355  outfile << std::endl;
356  }
357  }
358 
359 
360  void ExpList3DHomogeneous2D::v_WriteVtkPieceHeader(std::ostream &outfile, int expansion, int)
361  {
362  int i,j,k;
363  int nquad0 = (*m_exp)[expansion]->GetNumPoints(0);
364  int nquad1 = m_homogeneousBasis_y->GetNumPoints();
365  int nquad2 = m_homogeneousBasis_z->GetNumPoints();
366  int ntot = nquad0*nquad1*nquad2;
367  int ntotminus = (nquad0-1)*(nquad1-1)*(nquad2-1);
368 
369  Array<OneD,NekDouble> coords[3];
370  coords[0] = Array<OneD,NekDouble>(ntot);
371  coords[1] = Array<OneD,NekDouble>(ntot);
372  coords[2] = Array<OneD,NekDouble>(ntot);
373  GetCoords(expansion,coords[0],coords[1],coords[2]);
374 
375  outfile << " <Piece NumberOfPoints=\""
376  << ntot << "\" NumberOfCells=\""
377  << ntotminus << "\">" << endl;
378  outfile << " <Points>" << endl;
379  outfile << " <DataArray type=\"Float64\" "
380  << "NumberOfComponents=\"3\" format=\"ascii\">" << endl;
381  outfile << " ";
382  for (i = 0; i < ntot; ++i)
383  {
384  for (j = 0; j < 3; ++j)
385  {
386  outfile << coords[j][i] << " ";
387  }
388  outfile << endl;
389  }
390  outfile << endl;
391  outfile << " </DataArray>" << endl;
392  outfile << " </Points>" << endl;
393  outfile << " <Cells>" << endl;
394  outfile << " <DataArray type=\"Int32\" "
395  << "Name=\"connectivity\" format=\"ascii\">" << endl;
396  for (i = 0; i < nquad0-1; ++i)
397  {
398  for (j = 0; j < nquad1-1; ++j)
399  {
400  for (k = 0; k < nquad2-1; ++k)
401  {
402  outfile << k*nquad0*nquad1 + j*nquad0 + i << " "
403  << k*nquad0*nquad1 + j*nquad0 + i + 1 << " "
404  << k*nquad0*nquad1 + (j+1)*nquad0 + i + 1 << " "
405  << k*nquad0*nquad1 + (j+1)*nquad0 + i << " "
406  << (k+1)*nquad0*nquad1 + j*nquad0 + i << " "
407  << (k+1)*nquad0*nquad1 + j*nquad0 + i + 1 << " "
408  << (k+1)*nquad0*nquad1 + (j+1)*nquad0 + i + 1 << " "
409  << (k+1)*nquad0*nquad1 + (j+1)*nquad0 + i << " " << endl;
410  }
411  }
412  }
413  outfile << endl;
414  outfile << " </DataArray>" << endl;
415  outfile << " <DataArray type=\"Int32\" "
416  << "Name=\"offsets\" format=\"ascii\">" << endl;
417  for (i = 0; i < ntotminus; ++i)
418  {
419  outfile << i*8+8 << " ";
420  }
421  outfile << endl;
422  outfile << " </DataArray>" << endl;
423  outfile << " <DataArray type=\"UInt8\" "
424  << "Name=\"types\" format=\"ascii\">" << endl;
425  for (i = 0; i < ntotminus; ++i)
426  {
427  outfile << "12 ";
428  }
429  outfile << endl;
430  outfile << " </DataArray>" << endl;
431  outfile << " </Cells>" << endl;
432  outfile << " <PointData>" << endl;
433  }
434 
435 
437  const Array<OneD, const NekDouble> &inarray,
438  const Array<OneD, const NekDouble> &soln)
439  {
440  int cnt = 0;
441  NekDouble errL2,err = 0.0;
444 
445  int nylines = m_homogeneousBasis_y->GetNumPoints();
446  int nzlines = m_homogeneousBasis_z->GetNumPoints();
447 
448  for(int m = 0; m < nzlines; ++m)
449  {
450  for(int n = 0; n < nylines; ++n)
451  {
452  errL2 = m_lines[n+(m*nylines)]->L2(inarray + cnt, soln + cnt);
453  cnt += m_lines[n+(m*nylines)]->GetTotPoints();
454  err += errL2*errL2*w_y[n]*m_lhom_y*0.5*w_z[m]*m_lhom_z*0.5;
455  }
456  }
457 
458  return sqrt(err);
459  }
460  } //end of namespace
461 } //end of namespace
Abstraction of a two-dimensional multi-elemental expansion which is merely a collection of local expa...
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
virtual void v_WriteTecplotZone(std::ostream &outfile, int expansion)
std::shared_ptr< LocalRegions::ExpansionVector > m_exp
The list of local expansions.
Definition: ExpList.h:1090
NekOptimize::GlobalOptParamSharedPtr m_globalOptParam
Definition: ExpList.h:1106
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45
STL namespace.
Array< OneD, NekDouble > m_phys
The global expansion evaluated at the quadrature points.
Definition: ExpList.h:1069
NekDouble m_lhom_z
Width of homogeneous direction z.
Array< OneD, NekDouble > m_coeffs
Concatenation of all local expansion coefficients.
Definition: ExpList.h:1052
int GetExpSize(void)
This function returns the number of elements in the expansion.
Definition: ExpList.h:2170
const std::shared_ptr< LocalRegions::ExpansionVector > GetExp() const
This function returns the vector of elements in the expansion.
Definition: ExpList.h:2191
Array< OneD, ExpListSharedPtr > m_lines
Vector of ExpList, will be filled with ExpList1D.
virtual void v_WriteVtkPieceHeader(std::ostream &outfile, int expansion, int istrip)
Array< OneD, int > m_coeff_offset
Offset of elemental data into the array m_coeffs.
Definition: ExpList.h:1101
LibUtilities::BasisSharedPtr m_homogeneousBasis_z
Base expansion in z direction.
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:216
virtual NekDouble v_L2(const Array< OneD, const NekDouble > &inarray, const Array< OneD, const NekDouble > &soln=NullNekDouble1DArray)
void SetCoeffPhys(void)
Definition of the total number of degrees of freedom and quadrature points. Sets up the storage for m...
Array< OneD, int > m_phys_offset
Offset of elemental data into the array m_phys.
Definition: ExpList.h:1104
virtual void v_GetCoords(Array< OneD, NekDouble > &coord_0, Array< OneD, NekDouble > &coord_1, Array< OneD, NekDouble > &coord_2)
int m_ncoeffs
The total number of local degrees of freedom. m_ncoeffs .
Definition: ExpList.h:1030
NekDouble m_lhom_y
Width of homogeneous direction y.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
LibUtilities::SessionReaderSharedPtr m_session
Session.
Definition: ExpList.h:1023
double NekDouble
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:318
LibUtilities::BasisSharedPtr m_homogeneousBasis_y
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:58
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 . ...
void SetExpType(ExpansionType Type)
Returns the type of the expansion.
Definition: ExpList.cpp:279
int GetTotPoints(void) const
Returns the total number of quadrature points m_npoints .
Definition: ExpList.h:1608
NekDouble L2(const Array< OneD, const NekDouble > &inarray, const Array< OneD, const NekDouble > &soln=NullNekDouble1DArray)
This function calculates the error with respect to soln of the global spectral/hp element approximat...
Definition: ExpList.h:548
std::shared_ptr< ExpList1D > ExpList1DSharedPtr
Shared pointer to an ExpList1D object.
Definition: ExpList1D.h:49
Abstraction of a one-dimensional multi-elemental expansion which is merely a collection of local expa...
Describes the specification for a Basis.
Definition: Basis.h:49
std::shared_ptr< SessionReader > SessionReaderSharedPtr