Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
118  if (m_riemann)
119  {
120  // Set Riemann solver and flux vector callback for this plane.
121  m_planeDiff->SetRiemannSolver(m_riemann);
122 
123  // Override Riemann solver scalar and vector callbacks.
125  map<string, RSScalarFuncType> scalars = m_riemann->GetScalars();
126 
127  for (it1 = scalars.begin(); it1 != scalars.end(); ++it1)
128  {
129  boost::shared_ptr<HomoRSScalar> tmp =
131  ::AllocateSharedPtr(it1->second, m_numPlanes);
132  m_riemann->SetScalar(it1->first, &HomoRSScalar::Exec, tmp);
133  }
134  }
135 
137  (nConvectiveFields);
138 
139 
140  if (m_fluxVectorNS)
141  {
142  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
143  (nConvectiveFields - 1);
144  }
145  else
146  {
147  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
148  (nConvectiveFields);
149  }
150  m_outarrayPlane = Array<OneD, Array<OneD, NekDouble> >
151  (nConvectiveFields);
152  m_planePos = Array<OneD, unsigned int> (m_numPlanes);
153 
154  for (int i = 0; i < m_numPlanes; ++i)
155  {
156  m_planePos[i] = i * m_numPointsPlane;
157  }
158 
159  if (m_fluxVectorNS)
160  {
161  m_homoDerivStore = Array<OneD, Array<OneD, NekDouble> >(
162  nConvectiveFields);
163  m_homoDerivPlane = Array<OneD, Array<OneD, Array<OneD, NekDouble> > >(
164  m_numPlanes);
165 
166  for (int i = 0; i < nConvectiveFields; ++i)
167  {
168  m_homoDerivStore[i] = Array<OneD, NekDouble>(m_numPoints);
169  }
170 
171  for (int i = 0; i < m_numPlanes; ++i)
172  {
173  m_homoDerivPlane[i] = Array<OneD, Array<OneD, NekDouble> >(nConvectiveFields);
174 
175  for (int j = 0; j < nConvectiveFields; ++j)
176  {
177  m_homoDerivPlane[i][j] = Array<OneD, NekDouble>(
178  m_numPointsPlane,
179  m_homoDerivStore[j] + m_planePos[i]);
180  }
181  }
182  }
183  }
184 
185  /**
186  * @brief Calculate WeakDG Diffusion for the linear problems
187  * using an LDG interface flux and the the flux in the third direction.
188  */
189  void Diffusion3DHomogeneous1D::v_Diffuse(
190  const int nConvectiveFields,
192  const Array<OneD, Array<OneD, NekDouble> > &inarray,
193  Array<OneD, Array<OneD, NekDouble> > &outarray)
194  {
195 
196  Array<OneD, NekDouble> tmp(m_numPoints), tmp2;
198  const int nPointsTot = fields[0]->GetNpoints();
199  int i, j;
200  NekDouble beta;
201 
202 
203  if (m_fluxVectorNS)
204  {
205  viscHComp = Array<OneD, Array<OneD, NekDouble> >(nConvectiveFields);
206  for (i = 0; i < nConvectiveFields - 1; ++i)
207  {
208  fields[0]->PhysDeriv(2, inarray[i], m_homoDerivStore[i]);
209  viscHComp[i] = Array<OneD, NekDouble>(m_numPoints);
210  }
211  }
212 
213 
214  for (i = 0; i < m_numPlanes; ++i)
215  {
216  // Set up memory references for fields, inarray and outarray for
217  // this plane.
218  for (int j = 0; j < inarray.num_elements(); ++j)
219  {
220  m_inarrayPlane [j] = Array<OneD, NekDouble>(
221  m_numPointsPlane, tmp2 = inarray [j] + m_planePos[i]);
222  }
223 
224  for (int j = 0; j < nConvectiveFields; ++j)
225  {
226  m_fieldsPlane [j] = fields[j]->GetPlane(i);
227  m_outarrayPlane[j] = Array<OneD, NekDouble>(
228  m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
229  }
230 
231 
232  if (m_fluxVectorNS)
233  {
234  m_planeDiff->SetHomoDerivs(m_homoDerivPlane[i]);
235  }
236 
237 
238 
239  m_planeDiff->Diffuse(nConvectiveFields,
240  m_fieldsPlane,
241  m_inarrayPlane,
242  m_outarrayPlane);
243 
244  if (m_fluxVectorNS)
245  {
246  Array<OneD, Array<OneD, Array<OneD, NekDouble> > > &viscTensor = m_planeDiff->GetFluxTensor();
247 
248  // Extract H (viscTensor[2])
249  for (int j = 0; j < nConvectiveFields - 1; ++j)
250  {
251  Vmath::Vcopy(m_numPointsPlane,
252  viscTensor[2][j+1], 1,
253  tmp2 = viscHComp[j] + m_planePos[i], 1);
254  }
255  }
256  }
257 
258 
259 
260  if (m_fluxVectorNS)
261  {
262  for (j = 0; j < nConvectiveFields - 1; ++j)
263  {
264  fields[j+1]->PhysDeriv(2, viscHComp[j], tmp);
265  Vmath::Vadd(nPointsTot, outarray[j+1], 1, tmp, 1, outarray[j+1], 1);
266  }
267  }
268  else
269  {
270  for (j = 0; j < nConvectiveFields; ++j)
271  {
272  fields[j]->HomogeneousFwdTrans(inarray[j], tmp);
273 
274  for (i = 0; i < m_numPlanes; ++i)
275  {
276  beta = 2*M_PI*m_trans->GetK(i)/m_homoLen;
277  beta *= beta;
278 
279  Vmath::Smul(m_numPointsPlane,
280  beta,
281  &tmp[0] + i*m_numPointsPlane, 1,
282  &tmp[0] + i*m_numPointsPlane, 1);
283  }
284 
285  fields[0]->HomogeneousBwdTrans(tmp, tmp);
286 
287  Vmath::Vsub(nPointsTot, outarray[j], 1, tmp, 1,
288  outarray[j], 1);
289  }
290  }
291  }
292  }// close namespace SolverUtils
293 }// 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
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
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:199
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:329
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047
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:285
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215