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