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