Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // 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 ExpList which is homogeneous in 2 directions and so
33 // uses much of the functionality from a ExpList1D and its daughters
34 //
35 ///////////////////////////////////////////////////////////////////////////////
36 
38 #include <MultiRegions/ExpList1D.h>
39 
40 namespace Nektar
41 {
42  namespace MultiRegions
43  {
44  // Forward declaration for typedefs
47  {
49  }
50 
52  const LibUtilities::BasisKey &HomoBasis_y,
53  const LibUtilities::BasisKey &HomoBasis_z,
54  const NekDouble lhom_y,
55  const NekDouble lhom_z,
56  const bool useFFT,
57  const bool dealiasing):
58  ExpListHomogeneous2D(pSession,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,useFFT,dealiasing)
59  {
61  }
62 
63  // Constructor for ExpList3DHomogeneous2D to act as a Explist1D field
65  const LibUtilities::BasisKey &HomoBasis_y,
66  const LibUtilities::BasisKey &HomoBasis_z,
67  const NekDouble lhom_y,
68  const NekDouble lhom_z,
69  const bool useFFT,
70  const bool dealiasing,
71  const SpatialDomains::MeshGraphSharedPtr &graph1D):
72  ExpListHomogeneous2D(pSession,HomoBasis_y,HomoBasis_z,lhom_y,lhom_z,useFFT,dealiasing)
73  {
75 
76  int n,j,nel;
77  bool False = false;
78  ExpList1DSharedPtr line_zero;
79 
80  //
82  False);
83 
85  nel = m_lines[0]->GetExpSize();
86 
87  for(j = 0; j < nel; ++j)
88  {
89  (*m_exp).push_back(m_lines[0]->GetExp(j));
90  }
91 
92  int ny = m_homogeneousBasis_y->GetNumPoints();
93  int nz = m_homogeneousBasis_z->GetNumPoints();
94 
95  for(n = 1; n < (ny*nz); ++n)
96  {
98  for(j = 0; j < nel; ++j)
99  {
100  (*m_exp).push_back((*m_exp)[j]);
101  }
102  }
103 
104  // Setup Default optimisation information.
105  nel = GetExpSize();
108 
109  SetCoeffPhys();
110  }
111 
112 
113  /**
114  * @param In ExpList3DHomogeneous2D object to copy.
115  */
116  ExpList3DHomogeneous2D::ExpList3DHomogeneous2D(const ExpList3DHomogeneous2D &In, const bool DeclareLinesSetCoeffPhys):
118  {
120 
121  if(DeclareLinesSetCoeffPhys)
122  {
123  bool False = false;
124  ExpList1DSharedPtr zero_line = boost::dynamic_pointer_cast<ExpList1D> (In.m_lines[0]);
125 
126  for(int n = 0; n < m_lines.num_elements(); ++n)
127  {
129  }
130 
131  SetCoeffPhys();
132  }
133  }
134 
135  /**
136  *
137  */
139  const std::vector<unsigned int> &eIDs,
140  const bool DeclareLinesSetCoeffPhys):
142  {
144 
145  if(DeclareLinesSetCoeffPhys)
146  {
147  bool False = false;
148  std::vector<unsigned int> eIDsLine;
149  int nel = eIDs.size()/m_lines.num_elements();
150 
151  for (int i = 0; i < nel; ++i)
152  {
153  eIDsLine.push_back(eIDs[i]);
154  }
155 
156  ExpList1DSharedPtr zero_line_old =
157  boost::dynamic_pointer_cast<ExpList1D> (In.m_lines[0]);
158 
159  ExpList1DSharedPtr zero_line =
160  MemoryManager<ExpList1D>::AllocateSharedPtr(*(zero_line_old), eIDsLine);
161 
162  for(int n = 0; n < m_lines.num_elements(); ++n)
163  {
165  }
166 
167  SetCoeffPhys();
168  }
169  }
170 
171  /**
172  * Destructor
173  */
175  {
176  }
177 
179  {
180  int i,n,cnt;
181  int ncoeffs_per_line = m_lines[0]->GetNcoeffs();
182  int npoints_per_line = m_lines[0]->GetTotPoints();
183 
184  int nyzlines = m_lines.num_elements();
185 
186  // Set total coefficients and points
187  m_ncoeffs = ncoeffs_per_line*nyzlines;
188  m_npoints = npoints_per_line*nyzlines;
189 
192 
193  int nel = m_lines[0]->GetExpSize();
194  m_coeff_offset = Array<OneD,int>(nel*nyzlines);
195  m_phys_offset = Array<OneD,int>(nel*nyzlines);
196  m_offset_elmt_id = 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  m_offset_elmt_id[cnt++] = m_lines[n]->GetOffset_Elmt_Id(i) + n*nel;
209  }
210  }
211  }
212 
217  {
218  int n,m,j;
219  Array<OneD, NekDouble> tmp_xc;
220  int nylines = m_homogeneousBasis_y->GetNumPoints();
221  int nzlines = m_homogeneousBasis_z->GetNumPoints();
222 
223  int npoints = GetTotPoints(eid);
224 
225  // Fill x-y-z-direction
228 
229  Array<OneD, NekDouble> x(npoints);
230  Array<OneD, NekDouble> y(nylines);
231  Array<OneD, NekDouble> z(nzlines);
232 
233  Vmath::Smul(nylines,m_lhom_y/2.0,pts_y,1,y,1);
234  Vmath::Sadd(nylines,m_lhom_y/2.0,y,1,y,1);
235 
236  Vmath::Smul(nzlines,m_lhom_z/2.0,pts_z,1,z,1);
237  Vmath::Sadd(nzlines,m_lhom_z/2.0,z,1,z,1);
238 
239  (*m_exp)[eid]->GetCoords(x);
240 
241 
242  for(m = 0; m < nzlines; ++m)
243  {
244  for(j = 0; j < nylines; ++j)
245  {
246  for(n = 0; n < npoints; ++n)
247  {
248  Vmath::Fill(1,x[n],tmp_xc = xc0 + n +(j*npoints) + (m*npoints*nylines), 1);
249  Vmath::Fill(1,y[j],tmp_xc = xc1 + n +(j*npoints) + (m*npoints*nylines), 1);
250  Vmath::Fill(1,z[m],tmp_xc = xc2 + n +(j*npoints) + (m*npoints*nylines), 1);
251  }
252  }
253  }
254  }
255 
256  /**
257  * The operation calls the 2D plane coordinates through the
258  * function ExpList#GetCoords and then evaluated the third
259  * coordinate using the member \a m_lhom
260  *
261  * @param coord_0 After calculation, the \f$x_1\f$ coordinate
262  * will be stored in this array.
263  *
264  * @param coord_1 After calculation, the \f$x_2\f$ coordinate
265  * will be stored in this array.
266  *
267  * @param coord_2 After calculation, the \f$x_3\f$ coordinate
268  * will be stored in this array. This
269  * coordinate is evaluated using the
270  * predefined value \a m_lhom
271  */
275  {
276  int n,m,j;
277  Array<OneD, NekDouble> tmp_xc;
278  int npoints = m_lines[0]->GetTotPoints();
279 
280  int nylines = m_homogeneousBasis_y->GetNumPoints();
281  int nzlines = m_homogeneousBasis_z->GetNumPoints();
282 
283  // Fill z-direction
286 
287  Array<OneD, NekDouble> x(npoints);
288  Array<OneD, NekDouble> y(nylines);
289  Array<OneD, NekDouble> z(nzlines);
290 
291  m_lines[0]->GetCoords(x);
292 
293  Vmath::Smul(nylines,m_lhom_y/2.0,pts_y,1,y,1);
294  Vmath::Sadd(nylines,m_lhom_y/2.0,y,1,y,1);
295 
296  Vmath::Smul(nzlines,m_lhom_z/2.0,pts_z,1,z,1);
297  Vmath::Sadd(nzlines,m_lhom_z/2.0,z,1,z,1);
298 
299  for(m = 0; m < nzlines; ++m)
300  {
301  for(j = 0; j < nylines; ++j)
302  {
303  for(n = 0; n < npoints; ++n)
304  {
305  Vmath::Fill(1,x[n],tmp_xc = xc0 + n +(j*npoints) + (m*npoints*nylines), 1);
306  Vmath::Fill(1,y[j],tmp_xc = xc1 + n +(j*npoints) + (m*npoints*nylines), 1);
307  Vmath::Fill(1,z[m],tmp_xc = xc2 + n +(j*npoints) + (m*npoints*nylines), 1);
308  }
309  }
310  }
311  }
312 
313 
314  /**
315  * Write Tecplot Files Zone
316  * @param outfile Output file name.
317  * @param expansion Expansion that is considered
318  */
319  void ExpList3DHomogeneous2D::v_WriteTecplotZone(std::ostream &outfile, int expansion)
320  {
321  int i,j;
322 
323  int nquad0 = (*m_exp)[expansion]->GetNumPoints(0);
324  int nquad1 = m_homogeneousBasis_y->GetNumPoints();
325  int nquad2 = m_homogeneousBasis_z->GetNumPoints();
326 
327  Array<OneD,NekDouble> coords[3];
328 
329  coords[0] = Array<OneD,NekDouble>(3*nquad0*nquad1*nquad2);
330  coords[1] = coords[0] + nquad0*nquad1*nquad2;
331  coords[2] = coords[1] + nquad0*nquad1*nquad2;
332 
333  GetCoords(expansion,coords[0],coords[1],coords[2]);
334 
335  outfile << "Zone, I=" << nquad0 << ", J=" << nquad1 <<",K="
336  << nquad2 << ", F=Block" << std::endl;
337 
338  for(j = 0; j < 3; ++j)
339  {
340  for(i = 0; i < nquad0*nquad1*nquad2; ++i)
341  {
342  outfile << coords[j][i] << " ";
343  }
344  outfile << std::endl;
345  }
346  }
347 
348 
349  void ExpList3DHomogeneous2D::v_WriteVtkPieceHeader(std::ostream &outfile, int expansion, int)
350  {
351  int i,j,k;
352  int nquad0 = (*m_exp)[expansion]->GetNumPoints(0);
353  int nquad1 = m_homogeneousBasis_y->GetNumPoints();
354  int nquad2 = m_homogeneousBasis_z->GetNumPoints();
355  int ntot = nquad0*nquad1*nquad2;
356  int ntotminus = (nquad0-1)*(nquad1-1)*(nquad2-1);
357 
358  Array<OneD,NekDouble> coords[3];
359  coords[0] = Array<OneD,NekDouble>(ntot);
360  coords[1] = Array<OneD,NekDouble>(ntot);
361  coords[2] = Array<OneD,NekDouble>(ntot);
362  GetCoords(expansion,coords[0],coords[1],coords[2]);
363 
364  outfile << " <Piece NumberOfPoints=\""
365  << ntot << "\" NumberOfCells=\""
366  << ntotminus << "\">" << endl;
367  outfile << " <Points>" << endl;
368  outfile << " <DataArray type=\"Float32\" "
369  << "NumberOfComponents=\"3\" format=\"ascii\">" << endl;
370  outfile << " ";
371  for (i = 0; i < ntot; ++i)
372  {
373  for (j = 0; j < 3; ++j)
374  {
375  outfile << coords[j][i] << " ";
376  }
377  outfile << endl;
378  }
379  outfile << endl;
380  outfile << " </DataArray>" << endl;
381  outfile << " </Points>" << endl;
382  outfile << " <Cells>" << endl;
383  outfile << " <DataArray type=\"Int32\" "
384  << "Name=\"connectivity\" format=\"ascii\">" << endl;
385  for (i = 0; i < nquad0-1; ++i)
386  {
387  for (j = 0; j < nquad1-1; ++j)
388  {
389  for (k = 0; k < nquad2-1; ++k)
390  {
391  outfile << k*nquad0*nquad1 + j*nquad0 + i << " "
392  << k*nquad0*nquad1 + j*nquad0 + i + 1 << " "
393  << k*nquad0*nquad1 + (j+1)*nquad0 + i + 1 << " "
394  << k*nquad0*nquad1 + (j+1)*nquad0 + i << " "
395  << (k+1)*nquad0*nquad1 + j*nquad0 + i << " "
396  << (k+1)*nquad0*nquad1 + j*nquad0 + i + 1 << " "
397  << (k+1)*nquad0*nquad1 + (j+1)*nquad0 + i + 1 << " "
398  << (k+1)*nquad0*nquad1 + (j+1)*nquad0 + i << " " << endl;
399  }
400  }
401  }
402  outfile << endl;
403  outfile << " </DataArray>" << endl;
404  outfile << " <DataArray type=\"Int32\" "
405  << "Name=\"offsets\" format=\"ascii\">" << endl;
406  for (i = 0; i < ntotminus; ++i)
407  {
408  outfile << i*8+8 << " ";
409  }
410  outfile << endl;
411  outfile << " </DataArray>" << endl;
412  outfile << " <DataArray type=\"UInt8\" "
413  << "Name=\"types\" format=\"ascii\">" << endl;
414  for (i = 0; i < ntotminus; ++i)
415  {
416  outfile << "12 ";
417  }
418  outfile << endl;
419  outfile << " </DataArray>" << endl;
420  outfile << " </Cells>" << endl;
421  outfile << " <PointData>" << endl;
422  }
423 
424 
426  const Array<OneD, const NekDouble> &inarray,
427  const Array<OneD, const NekDouble> &soln)
428  {
429  int cnt = 0;
430  NekDouble errL2,err = 0.0;
433 
434  int nylines = m_homogeneousBasis_y->GetNumPoints();
435  int nzlines = m_homogeneousBasis_z->GetNumPoints();
436 
437  for(int m = 0; m < nzlines; ++m)
438  {
439  for(int n = 0; n < nylines; ++n)
440  {
441  errL2 = m_lines[n+(m*nylines)]->L2(inarray + cnt, soln + cnt);
442  cnt += m_lines[n+(m*nylines)]->GetTotPoints();
443  err += errL2*errL2*w_y[n]*m_lhom_y*0.5*w_z[m]*m_lhom_z*0.5;
444  }
445  }
446 
447  return sqrt(err);
448  }
449  } //end of namespace
450 } //end of namespace
Abstraction of a two-dimensional multi-elemental expansion which is merely a collection of local expa...
virtual void v_WriteTecplotZone(std::ostream &outfile, int expansion)
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
NekOptimize::GlobalOptParamSharedPtr m_globalOptParam
Definition: ExpList.h:1001
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:1917
Array< OneD, NekDouble > m_phys
The global expansion evaluated at the quadrature points.
Definition: ExpList.h:956
NekDouble m_lhom_z
Width of homogeneous direction z.
Array< OneD, NekDouble > m_coeffs
Concatenation of all local expansion coefficients.
Definition: ExpList.h:939
int GetExpSize(void)
This function returns the number of elements in the expansion.
Definition: ExpList.h:1896
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
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:988
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:199
boost::shared_ptr< LocalRegions::ExpansionVector > m_exp
The list of local expansions.
Definition: ExpList.h:977
int GetTotPoints(void) const
Returns the total number of quadrature points m_npoints .
Definition: ExpList.h:1453
boost::shared_ptr< ExpList1D > ExpList1DSharedPtr
Shared pointer to an ExpList1D object.
Definition: ExpList1D.h:50
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:991
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:917
Array< OneD, int > m_offset_elmt_id
Array containing the element id m_offset_elmt_id[n] that the n^th consecutive block of data in m_coef...
Definition: ExpList.h:999
NekDouble m_lhom_y
Width of homogeneous direction y.
LibUtilities::SessionReaderSharedPtr m_session
Session.
Definition: ExpList.h:910
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:301
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:61
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:251
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:442
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:477
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:50