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 namespace Nektar
41 {
42  namespace SolverUtils
43  {
44  std::string Diffusion3DHomogeneous1D::type[] = {
46  "LDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
48  "LFRDG3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
50  "LFRSD3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
52  "LFRHU3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
54  "LFRcmin3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
56  "LFRcinf3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
58  "LDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
60  "LFRDGNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
62  "LFRSDNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
64  "LFRHUNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
66  "LFRcminNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create),
68  "LFRcinfNS3DHomogeneous1D", Diffusion3DHomogeneous1D::create)
69  };
70 
71  /**
72  * @brief Diffusion3DHomogeneous1D uses the 2D WeakDG approach
73  * to compute the diffusion term looping on the planes in the z
74  * direction and adding the flux in z direction at the end.
75  */
77  {
78  // Strip trailing string "3DHomogeneous1D" to determine 2D diffusion
79  // type, and create a diffusion object for the plane.
80  string name = diffType.substr(0, diffType.length()-15);
82  }
83 
84  /**
85  * @brief Initiliase Diffusion3DHomogeneous1D objects and store
86  * them before starting the time-stepping.
87  *
88  * @param pSession Pointer to session reader.
89  * @param pFields Pointer to fields.
90  */
93  Array<OneD, MultiRegions::ExpListSharedPtr> pFields)
94  {
95  int nConvectiveFields = pFields.num_elements();
96 
97  Array<OneD, MultiRegions::ExpListSharedPtr> pFields_plane0(
98  nConvectiveFields);
99 
100  // Initialise the plane advection object.
101  for (int i = 0; i < nConvectiveFields; ++i)
102  {
103  pFields_plane0[i] = pFields[i]->GetPlane(0);
104  }
105  m_planeDiff->InitObject(pSession, pFields_plane0);
106 
107  m_numPoints = pFields[0]->GetTotPoints();
108  m_planes = pFields[0]->GetZIDs();
109  m_numPlanes = m_planes.num_elements();
111  m_homoLen = pFields[0]->GetHomoLen();
112  m_trans = pFields[0]->GetTransposition();
113  m_planeCounter = 0;
114  m_planeDiff->SetFluxVectorNS(m_fluxVectorNS);
115 
116  if (m_riemann)
117  {
118  // Set Riemann solver and flux vector callback for this plane.
119  m_planeDiff->SetRiemannSolver(m_riemann);
120 
121  // Override Riemann solver scalar and vector callbacks.
123  map<string, RSScalarFuncType> scalars = m_riemann->GetScalars();
124 
125  for (it1 = scalars.begin(); it1 != scalars.end(); ++it1)
126  {
127  boost::shared_ptr<HomoRSScalar> tmp =
129  ::AllocateSharedPtr(it1->second, m_numPlanes);
130  m_riemann->SetScalar(it1->first, &HomoRSScalar::Exec, tmp);
131  }
132  }
133 
134  m_fieldsPlane = Array<OneD, MultiRegions::ExpListSharedPtr>
135  (nConvectiveFields);
136 
137 
138  if (m_fluxVectorNS)
139  {
140  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
141  (nConvectiveFields - 1);
142  }
143  else
144  {
145  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
146  (nConvectiveFields);
147  }
148  m_outarrayPlane = Array<OneD, Array<OneD, NekDouble> >
149  (nConvectiveFields);
150  m_planePos = Array<OneD, unsigned int> (m_numPlanes);
151 
152  for (int i = 0; i < m_numPlanes; ++i)
153  {
154  m_planePos[i] = i * m_numPointsPlane;
155  }
156 
157  if (m_fluxVectorNS)
158  {
159  m_homoDerivStore = Array<OneD, Array<OneD, NekDouble> >(
160  nConvectiveFields);
161  m_homoDerivPlane = Array<OneD, Array<OneD, Array<OneD, NekDouble> > >(
162  m_numPlanes);
163 
164  for (int i = 0; i < nConvectiveFields; ++i)
165  {
166  m_homoDerivStore[i] = Array<OneD, NekDouble>(m_numPoints);
167  }
168 
169  for (int i = 0; i < m_numPlanes; ++i)
170  {
171  m_homoDerivPlane[i] = Array<OneD, Array<OneD, NekDouble> >(nConvectiveFields);
172 
173  for (int j = 0; j < nConvectiveFields; ++j)
174  {
175  m_homoDerivPlane[i][j] = Array<OneD, NekDouble>(
177  m_homoDerivStore[j] + m_planePos[i]);
178  }
179  }
180  }
181  }
182 
183  /**
184  * @brief Calculate WeakDG Diffusion for the linear problems
185  * using an LDG interface flux and the the flux in the third direction.
186  */
188  const int nConvectiveFields,
189  const Array<OneD, MultiRegions::ExpListSharedPtr> &fields,
190  const Array<OneD, Array<OneD, NekDouble> > &inarray,
191  Array<OneD, Array<OneD, NekDouble> > &outarray)
192  {
193 
194  Array<OneD, NekDouble> tmp(m_numPoints), tmp2;
195  Array<OneD, Array<OneD, NekDouble> > viscHComp;
196  const int nPointsTot = fields[0]->GetNpoints();
197  int i, j;
198  NekDouble beta;
199 
200 
201  if (m_fluxVectorNS)
202  {
203  viscHComp = Array<OneD, Array<OneD, NekDouble> >(nConvectiveFields);
204  for (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 
212  for (i = 0; i < m_numPlanes; ++i)
213  {
214  // Set up memory references for fields, inarray and outarray for
215  // this plane.
216  for (int j = 0; j < inarray.num_elements(); ++j)
217  {
218  m_inarrayPlane [j] = Array<OneD, NekDouble>(
219  m_numPointsPlane, tmp2 = inarray [j] + m_planePos[i]);
220  }
221 
222  for (int j = 0; j < nConvectiveFields; ++j)
223  {
224  m_fieldsPlane [j] = fields[j]->GetPlane(i);
225  m_outarrayPlane[j] = Array<OneD, NekDouble>(
226  m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
227  }
228 
229 
230  if (m_fluxVectorNS)
231  {
232  m_planeDiff->SetHomoDerivs(m_homoDerivPlane[i]);
233  }
234 
235 
236 
237  m_planeDiff->Diffuse(nConvectiveFields,
241 
242  if (m_fluxVectorNS)
243  {
244  Array<OneD, Array<OneD, Array<OneD, NekDouble> > > &viscTensor = m_planeDiff->GetFluxTensor();
245 
246  // Extract H (viscTensor[2])
247  for (int j = 0; j < nConvectiveFields - 1; ++j)
248  {
250  viscTensor[2][j+1], 1,
251  tmp2 = viscHComp[j] + m_planePos[i], 1);
252  }
253  }
254  }
255 
256 
257 
258  if (m_fluxVectorNS)
259  {
260  for (j = 0; j < nConvectiveFields - 1; ++j)
261  {
262  fields[j+1]->PhysDeriv(2, viscHComp[j], tmp);
263  Vmath::Vadd(nPointsTot, outarray[j+1], 1, tmp, 1, outarray[j+1], 1);
264  }
265  }
266  else
267  {
268  for (j = 0; j < nConvectiveFields; ++j)
269  {
270  fields[j]->HomogeneousFwdTrans(inarray[j], tmp);
271 
272  for (i = 0; i < m_numPlanes; ++i)
273  {
274  beta = 2*M_PI*m_trans->GetK(i)/m_homoLen;
275  beta *= beta;
276 
278  beta,
279  &tmp[0] + i*m_numPointsPlane, 1,
280  &tmp[0] + i*m_numPointsPlane, 1);
281  }
282 
283  fields[0]->HomogeneousBwdTrans(tmp, tmp);
284 
285  Vmath::Vsub(nPointsTot, outarray[j], 1, tmp, 1,
286  outarray[j], 1);
287  }
288  }
289  }
290  }// close namespace SolverUtils
291 }// close namespace nektar++