Nektar++
ExpList2DHomogeneous2D.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ExpList2DHomogeneous2D.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 ExpList1D which is homogeneous in 2 directions and so
32 // uses much of the functionality from a ExpList2D and its daughters
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #include <boost/core/ignore_unused.hpp>
37 
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44 namespace MultiRegions
45 {
46 // Forward declaration for typedefs
47 ExpList2DHomogeneous2D::ExpList2DHomogeneous2D() : ExpListHomogeneous2D(eNoType)
48 {
49 }
50 
51 // Constructor for ExpList2DHomogeneous2D to act as a Explist1D field
54  const LibUtilities::BasisKey &HomoBasis_y,
55  const LibUtilities::BasisKey &HomoBasis_z, const NekDouble lhom_y,
56  const NekDouble lhom_z, const bool useFFT, const bool dealiasing,
57  const Array<OneD, ExpListSharedPtr> &points)
58  : ExpListHomogeneous2D(eNoType, pSession, HomoBasis_y, HomoBasis_z, lhom_y,
59  lhom_z, useFFT, dealiasing)
60 {
61  int n;
62 
63  ASSERTL1(m_ny * m_nz == points.size(),
64  "Size of basis number of points and number of lines are "
65  "not the same");
66 
67  for (n = 0; n < points.size(); ++n)
68  {
69  m_lines[n] = points[n];
70  (*m_exp).push_back(points[n]->GetExp(0));
71  }
72 
73  SetCoeffPhys();
74 }
75 
76 /**
77  * @param In ExpList2DHomogeneous2D object to copy.
78  */
81 {
82  for (int n = 0; n < m_lines.size(); ++n)
83  {
84  m_lines[n] = In.m_lines[n];
85  }
86 
87  SetCoeffPhys();
88 }
89 
90 /**
91  * Destructor
92  */
94 {
95 }
96 
98 {
99  int i, n, cnt;
100  int ncoeffs_per_line = m_lines[0]->GetNcoeffs();
101  int npoints_per_line = m_lines[0]->GetTotPoints();
102 
103  int nyzlines = m_lines.size();
104 
105  // Set total coefficients and points
106  m_ncoeffs = ncoeffs_per_line * nyzlines;
107  m_npoints = npoints_per_line * nyzlines;
108 
109  m_coeffs = Array<OneD, NekDouble>{size_t(m_ncoeffs), 0.0};
110  m_phys = Array<OneD, NekDouble>{size_t(m_npoints), 0.0};
111 
112  int nel = m_lines[0]->GetExpSize();
113  m_coeff_offset = Array<OneD, int>(nel * nyzlines);
114  m_phys_offset = Array<OneD, int>(nel * nyzlines);
115  Array<OneD, NekDouble> tmparray;
116 
117  for (cnt = n = 0; n < nyzlines; ++n)
118  {
119  m_lines[n]->SetCoeffsArray(tmparray = m_coeffs + ncoeffs_per_line * n);
120  m_lines[n]->SetPhysArray(tmparray = m_phys + npoints_per_line * n);
121 
122  for (i = 0; i < nel; ++i)
123  {
124  m_coeff_offset[cnt] =
125  m_lines[n]->GetCoeff_Offset(i) + n * ncoeffs_per_line;
126  m_phys_offset[cnt++] =
127  m_lines[n]->GetPhys_Offset(i) + n * npoints_per_line;
128  }
129  }
130 }
131 
136 {
137  boost::ignore_unused(eid);
138 
139  int n, m, j;
140  Array<OneD, NekDouble> tmp_xc;
141  int nylines = m_homogeneousBasis_y->GetNumPoints();
142  int nzlines = m_homogeneousBasis_z->GetNumPoints();
143  int npoints = 1;
144 
145  // Fill x-y-z-direction
148 
149  Array<OneD, NekDouble> x(npoints);
150  Array<OneD, NekDouble> y(nylines);
151  Array<OneD, NekDouble> z(nzlines);
152 
153  Vmath::Smul(nylines, m_lhom_y / 2.0, pts_y, 1, y, 1);
154  Vmath::Sadd(nylines, m_lhom_y / 2.0, y, 1, y, 1);
155 
156  Vmath::Smul(nzlines, m_lhom_z / 2.0, pts_z, 1, z, 1);
157  Vmath::Sadd(nzlines, m_lhom_z / 2.0, z, 1, z, 1);
158 
159  m_lines[0]->GetCoords(x);
160 
161  for (m = 0; m < nzlines; ++m)
162  {
163  for (j = 0; j < nylines; ++j)
164  {
165  for (n = 0; n < npoints; ++n)
166  {
167  Vmath::Fill(1, x[n],
168  tmp_xc = xc0 + n + (j * npoints) +
169  (m * npoints * nylines),
170  1);
171  Vmath::Fill(1, y[j],
172  tmp_xc = xc1 + n + (j * npoints) +
173  (m * npoints * nylines),
174  1);
175  Vmath::Fill(1, z[m],
176  tmp_xc = xc2 + n + (j * npoints) +
177  (m * npoints * nylines),
178  1);
179  }
180  }
181  }
182 }
183 
185  const Array<OneD, const NekDouble> &inarray,
186  Array<OneD, NekDouble> &outarray)
187 {
188  // just have a point expansion so copy inarray to outarray
189  Vmath::Vcopy(m_npoints, inarray, 1, outarray, 1);
190 
191  if (!m_WaveSpace)
192  {
193  HomogeneousFwdTrans(m_npoints, outarray, outarray);
194  }
195 }
196 
198  const Array<OneD, const NekDouble> &inarray,
199  Array<OneD, NekDouble> &outarray)
200 {
201  v_FwdTrans(inarray, outarray);
202 }
203 
205  const Array<OneD, const NekDouble> &inarray,
206  Array<OneD, NekDouble> &outarray)
207 {
208  v_FwdTrans(inarray, outarray);
209 }
210 
211 /**
212  * The operation calls the 2D plane coordinates through the
213  * function ExpList#GetCoords and then evaluated the third
214  * coordinate using the member \a m_lhom
215  *
216  * @param coord_0 After calculation, the \f$x_1\f$ coordinate
217  * will be stored in this array.
218  *
219  * @param coord_1 After calculation, the \f$x_2\f$ coordinate
220  * will be stored in this array. This
221  * coordinate might be evaluated using the
222  * predefined value \a m_lhom
223  *
224  * @param coord_2 After calculation, the \f$x_3\f$ coordinate
225  * will be stored in this array. This
226  * coordinate is evaluated using the
227  * predefined value \a m_lhom
228  */
232 {
233  int n, m, j;
234  Array<OneD, NekDouble> tmp_xc;
235  int npoints = 1;
236 
237  int nylines = m_homogeneousBasis_y->GetNumPoints();
238  int nzlines = m_homogeneousBasis_z->GetNumPoints();
239 
240  // Fill z-direction
243 
244  Array<OneD, NekDouble> x(npoints);
245  Array<OneD, NekDouble> y(nylines);
246  Array<OneD, NekDouble> z(nzlines);
247 
248  m_lines[0]->GetCoords(x);
249 
250  Vmath::Smul(nylines, m_lhom_y / 2.0, pts_y, 1, y, 1);
251  Vmath::Sadd(nylines, m_lhom_y / 2.0, y, 1, y, 1);
252 
253  Vmath::Smul(nzlines, m_lhom_z / 2.0, pts_z, 1, z, 1);
254  Vmath::Sadd(nzlines, m_lhom_z / 2.0, z, 1, z, 1);
255 
256  for (m = 0; m < nzlines; ++m)
257  {
258  for (j = 0; j < nylines; ++j)
259  {
260  for (n = 0; n < npoints; ++n)
261  {
262  Vmath::Fill(1, x[n],
263  tmp_xc = xc0 + n + (j * npoints) +
264  (m * npoints * nylines),
265  1);
266  Vmath::Fill(1, y[j],
267  tmp_xc = xc1 + n + (j * npoints) +
268  (m * npoints * nylines),
269  1);
270  Vmath::Fill(1, z[m],
271  tmp_xc = xc2 + n + (j * npoints) +
272  (m * npoints * nylines),
273  1);
274  }
275  }
276  }
277 }
278 
279 /**
280  * Write Tecplot Files Zone
281  * @param outfile Output file name.
282  * @param expansion Expansion that is considered
283  */
285  int expansion)
286 {
287  int i, j;
288 
289  int nquad0 = 1;
290  int nquad1 = m_homogeneousBasis_y->GetNumPoints();
291  int nquad2 = m_homogeneousBasis_z->GetNumPoints();
292 
293  Array<OneD, NekDouble> coords[3];
294 
295  coords[0] = Array<OneD, NekDouble>(3 * nquad0 * nquad1 * nquad2);
296  coords[1] = coords[0] + nquad0 * nquad1 * nquad2;
297  coords[2] = coords[1] + nquad0 * nquad1 * nquad2;
298 
299  GetCoords(expansion, coords[0], coords[1], coords[2]);
300 
301  outfile << "Zone, I=" << nquad1 << ", J=" << nquad0 * nquad2 << ", F=Block"
302  << std::endl;
303 
304  for (j = 0; j < nquad1; ++j)
305  {
306  for (i = 0; i < nquad2 * GetCoordim(0) + 1; ++i)
307  {
308  outfile << coords[j][i] << " ";
309  }
310  outfile << std::endl;
311  }
312 }
313 
315  int expansion, int istrip)
316 {
317  boost::ignore_unused(istrip);
318 
319  int i, j;
320 
321  int nquad0 = 1;
322  int nquad1 = m_homogeneousBasis_y->GetNumPoints();
323  int nquad2 = m_homogeneousBasis_z->GetNumPoints();
324 
325  int ntot = nquad0 * nquad1 * nquad2;
326  int ntotminus = (nquad0) * (nquad1 - 1) * (nquad2 - 1);
327 
328  Array<OneD, NekDouble> coords[3];
329  coords[0] = Array<OneD, NekDouble>(ntot);
330  coords[1] = Array<OneD, NekDouble>(ntot);
331  coords[2] = Array<OneD, NekDouble>(ntot);
332  GetCoords(expansion, coords[0], coords[1], coords[2]);
333 
334  outfile << " <Piece NumberOfPoints=\"" << ntot << "\" NumberOfCells=\""
335  << ntotminus << "\">" << endl;
336  outfile << " <Points>" << endl;
337  outfile << " <DataArray type=\"Float32\" "
338  << "NumberOfComponents=\"3\" format=\"ascii\">" << endl;
339  outfile << " ";
340  for (i = 0; i < ntot; ++i)
341  {
342  for (j = 0; j < 3; ++j)
343  {
344  outfile << coords[j][i] << " ";
345  }
346  outfile << endl;
347  }
348  outfile << endl;
349  outfile << " </DataArray>" << endl;
350  outfile << " </Points>" << endl;
351  outfile << " <Cells>" << endl;
352  outfile << " <DataArray type=\"Int32\" "
353  << "Name=\"connectivity\" format=\"ascii\">" << endl;
354  for (i = 0; i < nquad0; ++i)
355  {
356  for (j = 0; j < nquad1 - 1; ++j)
357  {
358  outfile << j * nquad0 + i << " " << j * nquad0 + i + 1 << " "
359  << (j + 1) * nquad0 + i + 1 << " " << (j + 1) * nquad0 + i
360  << endl;
361  }
362  }
363  outfile << endl;
364  outfile << " </DataArray>" << endl;
365  outfile << " <DataArray type=\"Int32\" "
366  << "Name=\"offsets\" format=\"ascii\">" << endl;
367  for (i = 0; i < ntotminus; ++i)
368  {
369  outfile << i * 4 + 4 << " ";
370  }
371  outfile << endl;
372  outfile << " </DataArray>" << endl;
373  outfile << " <DataArray type=\"UInt8\" "
374  << "Name=\"types\" format=\"ascii\">" << endl;
375  for (i = 0; i < ntotminus; ++i)
376  {
377  outfile << "9 ";
378  }
379  outfile << endl;
380  outfile << " </DataArray>" << endl;
381  outfile << " </Cells>" << endl;
382  outfile << " <PointData>" << endl;
383 }
384 
385 } // namespace MultiRegions
386 } // namespace Nektar
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
Describes the specification for a Basis.
Definition: Basis.h:50
Abstraction of a one-dimensional multi-elemental expansion which is merely a collection of local expa...
void SetCoeffPhys(void)
Definition of the total number of degrees of freedom and quadrature points. Sets up the storage for m...
virtual void v_FwdTransBndConstrained(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
virtual void v_WriteTecplotZone(std::ostream &outfile, int expansion) override
virtual void v_FwdTransLocalElmt(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
virtual void v_GetCoords(Array< OneD, NekDouble > &coord_0, Array< OneD, NekDouble > &coord_1, Array< OneD, NekDouble > &coord_2) override
virtual void v_WriteVtkPieceHeader(std::ostream &outfile, int expansion, int istrip) override
virtual void v_FwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Abstraction of a two-dimensional multi-elemental expansion which is merely a collection of local expa...
int m_nz
Number of modes = number of poitns in z direction.
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.
int m_ny
Number of modes = number of poitns in y direction.
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:1076
Array< OneD, int > m_coeff_offset
Offset of elemental data into the array m_coeffs.
Definition: ExpList.h:1120
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 .
Definition: ExpList.h:1728
int m_ncoeffs
The total number of local degrees of freedom. m_ncoeffs .
Definition: ExpList.h:1056
const std::shared_ptr< LocalRegions::ExpansionVector > GetExp() const
This function returns the vector of elements in the expansion.
Definition: ExpList.h:2029
Array< OneD, int > m_phys_offset
Offset of elemental data into the array m_phys.
Definition: ExpList.h:1122
Array< OneD, NekDouble > m_phys
The global expansion evaluated at the quadrature points.
Definition: ExpList.h:1092
void HomogeneousFwdTrans(const int npts, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, bool Shuff=true, bool UnShuff=true)
Definition: ExpList.h:1798
int GetCoordim(int eid)
This function returns the dimension of the coordinates of the element eid.
Definition: ExpList.h:1861
std::shared_ptr< SessionReader > SessionReaderSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
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:248
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 scalar y = alpha + x.
Definition: Vmath.cpp:384
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255