Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // 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: LDG diffusion 3DHomogeneous1D class.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 #include <iostream>
38 #include <iomanip>
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44  namespace SolverUtils
45  {
46  std::string Diffusion3DHomogeneous1D::type[] = {
48  "LDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
50  "LFRDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
52  "LFRSD3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
54  "LFRHU3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
56  "LFRcmin3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
58  "LFRcinf3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
60  "LDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
62  "LFRDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
64  "LFRSDNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
66  "LFRHUNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
68  "LFRcminNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
70  "LFRcinfNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create)
71  };
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  string name = diffType.substr(0, diffType.length()-15);
83  m_planeDiff = GetDiffusionFactory().CreateInstance(name, name);
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.num_elements();
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.num_elements();
112  m_numPointsPlane = m_numPoints/m_numPlanes;
113  m_homoLen = pFields[0]->GetHomoLen();
114  m_trans = pFields[0]->GetTransposition();
115  m_planeCounter = 0;
116  m_planeDiff->SetFluxVectorNS(m_fluxVectorNS);
117 
119  (nConvectiveFields);
120 
121  if (m_fluxVectorNS)
122  {
123  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
124  (nConvectiveFields - 1);
125  }
126  else
127  {
128  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
129  (nConvectiveFields);
130  }
131  m_outarrayPlane = Array<OneD, Array<OneD, NekDouble> >
132  (nConvectiveFields);
133  m_planePos = Array<OneD, unsigned int> (m_numPlanes);
134 
135  for (int i = 0; i < m_numPlanes; ++i)
136  {
137  m_planePos[i] = i * m_numPointsPlane;
138  }
139 
140  if (m_fluxVectorNS)
141  {
142  m_homoDerivStore = Array<OneD, Array<OneD, NekDouble> >(
143  nConvectiveFields);
144  m_homoDerivPlane = Array<OneD, Array<OneD, Array<OneD, NekDouble> > >(
145  m_numPlanes);
146 
147  for (int i = 0; i < nConvectiveFields; ++i)
148  {
149  m_homoDerivStore[i] = Array<OneD, NekDouble>(m_numPoints);
150  }
151 
152  for (int i = 0; i < m_numPlanes; ++i)
153  {
154  m_homoDerivPlane[i] = Array<OneD, Array<OneD, NekDouble> >(nConvectiveFields);
155 
156  for (int j = 0; j < nConvectiveFields; ++j)
157  {
158  m_homoDerivPlane[i][j] = Array<OneD, NekDouble>(
159  m_numPointsPlane,
160  m_homoDerivStore[j] + m_planePos[i]);
161  }
162  }
163  }
164  }
165 
166  /**
167  * @brief Calculate WeakDG Diffusion for the linear problems
168  * using an LDG interface flux and the the flux in the third direction.
169  */
170  void Diffusion3DHomogeneous1D::v_Diffuse(
171  const int nConvectiveFields,
173  const Array<OneD, Array<OneD, NekDouble> > &inarray,
174  Array<OneD, Array<OneD, NekDouble> > &outarray,
175  const Array<OneD, Array<OneD, NekDouble> > &pFwd,
176  const Array<OneD, Array<OneD, NekDouble> > &pBwd)
177  {
178 
179  Array<OneD, NekDouble> tmp(m_numPoints), tmp2;
181  const int nPointsTot = fields[0]->GetNpoints();
182  int i, j;
183  NekDouble beta;
184 
185 
186  if (m_fluxVectorNS)
187  {
188  viscHComp = Array<OneD, Array<OneD, NekDouble> >(nConvectiveFields);
189  for (i = 0; i < nConvectiveFields - 1; ++i)
190  {
191  fields[0]->PhysDeriv(2, inarray[i], m_homoDerivStore[i]);
192  viscHComp[i] = Array<OneD, NekDouble>(m_numPoints);
193  }
194  }
195 
196 
197  for (i = 0; i < m_numPlanes; ++i)
198  {
199  // Set up memory references for fields, inarray and outarray for
200  // this plane.
201  for (int j = 0; j < inarray.num_elements(); ++j)
202  {
203  m_inarrayPlane [j] = Array<OneD, NekDouble>(
204  m_numPointsPlane, tmp2 = inarray [j] + m_planePos[i]);
205  }
206 
207  for (int j = 0; j < nConvectiveFields; ++j)
208  {
209  m_fieldsPlane [j] = fields[j]->GetPlane(i);
210  m_outarrayPlane[j] = Array<OneD, NekDouble>(
211  m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
212  }
213 
214 
215  if (m_fluxVectorNS)
216  {
217  m_planeDiff->SetHomoDerivs(m_homoDerivPlane[i]);
218  }
219 
220 
221 
222  m_planeDiff->Diffuse(nConvectiveFields,
223  m_fieldsPlane,
224  m_inarrayPlane,
225  m_outarrayPlane);
226 
227  if (m_fluxVectorNS)
228  {
229  Array<OneD, Array<OneD, Array<OneD, NekDouble> > > &viscTensor = m_planeDiff->GetFluxTensor();
230 
231  // Extract H (viscTensor[2])
232  for (int j = 0; j < nConvectiveFields - 1; ++j)
233  {
234  Vmath::Vcopy(m_numPointsPlane,
235  viscTensor[2][j+1], 1,
236  tmp2 = viscHComp[j] + m_planePos[i], 1);
237  }
238  }
239  }
240 
241 
242 
243  if (m_fluxVectorNS)
244  {
245  for (j = 0; j < nConvectiveFields - 1; ++j)
246  {
247  fields[j+1]->PhysDeriv(2, viscHComp[j], tmp);
248  Vmath::Vadd(nPointsTot, outarray[j+1], 1, tmp, 1, outarray[j+1], 1);
249  }
250  }
251  else
252  {
253  for (j = 0; j < nConvectiveFields; ++j)
254  {
255  fields[j]->HomogeneousFwdTrans(inarray[j], tmp);
256 
257  for (i = 0; i < m_numPlanes; ++i)
258  {
259  beta = 2*M_PI*m_trans->GetK(i)/m_homoLen;
260  beta *= beta;
261 
262  Vmath::Smul(m_numPointsPlane,
263  beta,
264  &tmp[0] + i*m_numPointsPlane, 1,
265  &tmp[0] + i*m_numPointsPlane, 1);
266  }
267 
268  fields[0]->HomogeneousBwdTrans(tmp, tmp);
269 
270  Vmath::Vsub(nPointsTot, outarray[j], 1, tmp, 1,
271  outarray[j], 1);
272  }
273  }
274  }
275  }// close namespace SolverUtils
276 }// close namespace nektar++
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
DiffusionFactory & GetDiffusionFactory()
Definition: Diffusion.cpp:42
STL namespace.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
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:213
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:343
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
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:299
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215