Nektar++
Diffusion3DHomogeneous1D.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Diffusion3DHomogeneous1D.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: LDG diffusion 3DHomogeneous1D class.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <iomanip>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 
42 
43 namespace Nektar
44 {
45  namespace SolverUtils
46  {
47  std::string Diffusion3DHomogeneous1D::type[] = {
49  "LDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
51  "LFRDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
53  "LFRSD3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
55  "LFRHU3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
57  "LFRcmin3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
59  "LFRcinf3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
61  "LDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
63  "LFRDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
65  "LFRSDNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
67  "LFRHUNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
69  "LFRcminNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
71  "LFRcinfNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create)
72  };
73 
74  /**
75  * @brief Diffusion3DHomogeneous1D uses the 2D WeakDG approach
76  * to compute the diffusion term looping on the planes in the z
77  * direction and adding the flux in z direction at the end.
78  */
79  Diffusion3DHomogeneous1D::Diffusion3DHomogeneous1D(std::string diffType)
80  {
81  // Strip trailing string "3DHomogeneous1D" to determine 2D diffusion
82  // type, and create a diffusion object for the plane.
83  m_diffType = diffType.substr(0, diffType.length()-15);
84  m_planeDiff = GetDiffusionFactory().CreateInstance(m_diffType, m_diffType);
85  }
86 
87  /**
88  * @brief Initiliase Diffusion3DHomogeneous1D objects and store
89  * them before starting the time-stepping.
90  *
91  * @param pSession Pointer to session reader.
92  * @param pFields Pointer to fields.
93  */
94  void Diffusion3DHomogeneous1D::v_InitObject(
97  {
98  int nConvectiveFields = pFields.num_elements();
99 
101  nConvectiveFields);
102 
103  // Initialise the plane advection object.
104  for (int i = 0; i < nConvectiveFields; ++i)
105  {
106  pFields_plane0[i] = pFields[i]->GetPlane(0);
107  }
108  m_planeDiff->InitObject(pSession, pFields_plane0);
109 
110  m_numPoints = pFields[0]->GetTotPoints();
111  m_planes = pFields[0]->GetZIDs();
112  m_numPlanes = m_planes.num_elements();
113  m_numPointsPlane = m_numPoints/m_numPlanes;
114  m_homoLen = pFields[0]->GetHomoLen();
115  m_trans = pFields[0]->GetTransposition();
116  m_planeCounter = 0;
117 
118  if (m_diffType == "LDG")
119  {
120  // Set viscous flux for LDG
121  m_planeDiff->SetFluxVector(m_fluxVector);
122  }
123  else if (m_diffType == "LDGNS")
124  {
125  // Set viscous flux for LDGNS
126  m_planeDiff->SetFluxVectorNS(m_fluxVectorNS);
127  // Set penalty flux
128  m_planeDiff->SetFluxPenaltyNS(m_fluxPenaltyNS);
129  }
130  else if (m_diffType == "LFRDGNS" ||
131  m_diffType == "LFRHUNS" ||
132  m_diffType == "LFRSDNS" )
133  {
134  // Set viscous flux for FR cases
135  m_planeDiff->SetFluxVectorNS(m_fluxVectorNS);
136  }
137 
139  (nConvectiveFields);
140 
141  if (m_fluxVectorNS)
142  {
143  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
144  (nConvectiveFields - 1);
145  }
146  else
147  {
148  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
149  (nConvectiveFields);
150  }
151  m_outarrayPlane = Array<OneD, Array<OneD, NekDouble> >
152  (nConvectiveFields);
153  m_planePos = Array<OneD, unsigned int> (m_numPlanes);
154 
155  for (int i = 0; i < m_numPlanes; ++i)
156  {
157  m_planePos[i] = i * m_numPointsPlane;
158  }
159 
160  if (m_fluxVectorNS)
161  {
162  m_homoDerivStore = Array<OneD, Array<OneD, NekDouble> >(
163  nConvectiveFields);
164  m_homoDerivPlane = Array<OneD, Array<OneD, Array<OneD, NekDouble> > >(
165  m_numPlanes);
166 
167  for (int i = 0; i < nConvectiveFields; ++i)
168  {
169  m_homoDerivStore[i] = Array<OneD, NekDouble>(m_numPoints);
170  }
171 
172  for (int i = 0; i < m_numPlanes; ++i)
173  {
174  m_homoDerivPlane[i] = Array<OneD, Array<OneD, NekDouble> >(nConvectiveFields);
175 
176  for (int j = 0; j < nConvectiveFields; ++j)
177  {
178  m_homoDerivPlane[i][j] = Array<OneD, NekDouble>(
179  m_numPointsPlane,
180  m_homoDerivStore[j] + m_planePos[i]);
181  }
182  }
183  }
184  }
185 
186  /**
187  * @brief Calculate WeakDG Diffusion for the linear problems
188  * using an LDG interface flux and the the flux in the third direction.
189  */
190  void Diffusion3DHomogeneous1D::v_Diffuse(
191  const std::size_t nConvectiveFields,
193  const Array<OneD, Array<OneD, NekDouble> > &inarray,
194  Array<OneD, Array<OneD, NekDouble> > &outarray,
195  const Array<OneD, Array<OneD, NekDouble> > &pFwd,
196  const Array<OneD, Array<OneD, NekDouble> > &pBwd)
197  {
198  boost::ignore_unused(pFwd, pBwd);
199 
200  Array<OneD, NekDouble> tmp(m_numPoints), tmp2;
202  const int nPointsTot = fields[0]->GetNpoints();
203  NekDouble beta;
204 
205 
206  if (m_fluxVectorNS)
207  {
208  viscHComp = Array<OneD, Array<OneD, NekDouble> >(nConvectiveFields);
209  for (int i = 0; i < nConvectiveFields - 1; ++i)
210  {
211  fields[0]->PhysDeriv(2, inarray[i], m_homoDerivStore[i]);
212  viscHComp[i] = Array<OneD, NekDouble>(m_numPoints);
213  }
214  }
215 
216 
217  for (int i = 0; i < m_numPlanes; ++i)
218  {
219  // Set up memory references for fields, inarray and outarray for
220  // this plane.
221  for (int j = 0; j < inarray.num_elements(); ++j)
222  {
223  m_inarrayPlane [j] = Array<OneD, NekDouble>(
224  m_numPointsPlane, tmp2 = inarray [j] + m_planePos[i]);
225  }
226 
227  for (int j = 0; j < nConvectiveFields; ++j)
228  {
229  m_fieldsPlane [j] = fields[j]->GetPlane(i);
230  m_outarrayPlane[j] = Array<OneD, NekDouble>(
231  m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
232  }
233 
234 
235  if (m_fluxVectorNS)
236  {
237  m_planeDiff->SetHomoDerivs(m_homoDerivPlane[i]);
238  }
239 
240 
241  if (m_diffType == "LDGNS")
242  {
243  // Store plane Fwd/Bwd traces
244  std::size_t nTracePts = m_fieldsPlane[0]->GetTrace()
245  ->GetTotPoints();
246  std::size_t nScalar = m_inarrayPlane.num_elements();
247  Array<OneD, Array<OneD, NekDouble> > Fwd(nScalar);
248  Array<OneD, Array<OneD, NekDouble> > Bwd(nScalar);
249  {
250  for(std::size_t k = 0; k < nScalar; ++k)
251  {
252  Fwd[k] = Array<OneD, NekDouble>(nTracePts, 0.0);
253  Bwd[k] = Array<OneD, NekDouble>(nTracePts, 0.0);
254  m_fieldsPlane[k]->GetFwdBwdTracePhys(
255  m_inarrayPlane[k], Fwd[k], Bwd[k]);
256  }
257  }
258 
259  m_planeDiff->Diffuse(nConvectiveFields,
260  m_fieldsPlane,
261  m_inarrayPlane,
262  m_outarrayPlane,
263  Fwd,
264  Bwd);
265  }
266  else
267  {
268  m_planeDiff->Diffuse(nConvectiveFields,
269  m_fieldsPlane,
270  m_inarrayPlane,
271  m_outarrayPlane);
272  }
273 
274  if (m_fluxVectorNS)
275  {
277  &viscTensor = m_planeDiff->GetFluxTensor();
278 
279  // Extract H (viscTensor[2])
280  for (int j = 0; j < nConvectiveFields - 1; ++j)
281  {
282  Vmath::Vcopy(m_numPointsPlane,
283  viscTensor[2][j+1], 1,
284  tmp2 = viscHComp[j] + m_planePos[i], 1);
285  }
286  }
287  }
288 
289 
290 
291  if (m_fluxVectorNS)
292  {
293  for (int j = 0; j < nConvectiveFields - 1; ++j)
294  {
295  fields[j+1]->PhysDeriv(2, viscHComp[j], tmp);
296  Vmath::Vadd(nPointsTot, outarray[j+1], 1, tmp, 1,
297  outarray[j+1], 1);
298  }
299  }
300  else
301  {
302  for (int j = 0; j < nConvectiveFields; ++j)
303  {
304  fields[j]->HomogeneousFwdTrans(inarray[j], tmp);
305 
306  for (int i = 0; i < m_numPlanes; ++i)
307  {
308  beta = 2*M_PI*m_trans->GetK(i)/m_homoLen;
309  beta *= beta;
310 
311  Vmath::Smul(m_numPointsPlane,
312  beta,
313  &tmp[0] + i*m_numPointsPlane, 1,
314  &tmp[0] + i*m_numPointsPlane, 1);
315  }
316 
317  fields[0]->HomogeneousBwdTrans(tmp, tmp);
318 
319  Vmath::Vsub(nPointsTot, outarray[j], 1, tmp, 1,
320  outarray[j], 1);
321  }
322  }
323  }
324  }// close namespace SolverUtils
325 }// close namespace nektar++
DiffusionFactory & GetDiffusionFactory()
Definition: Diffusion.cpp:41
STL namespace.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
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
double NekDouble
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:346
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
std::shared_ptr< SessionReader > SessionReaderSharedPtr
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:302