Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Advection3DHomogeneous1D.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Advection3DHomogeneous1D.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: FR advection 3DHomogeneous1D class.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
38 #include <iostream>
39 #include <iomanip>
40 
41 namespace Nektar
42 {
43  namespace SolverUtils
44  {
45  std::string Advection3DHomogeneous1D::type[] = {
47  "WeakDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
49  "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
51  "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
53  "FRSD3DHomogeneous1D", Advection3DHomogeneous1D::create),
55  "FRHU3DHomogeneous1D", Advection3DHomogeneous1D::create),
57  "FRcmin3DHomogeneous1D", Advection3DHomogeneous1D::create),
59  "FRcinf3DHomogeneous1D", Advection3DHomogeneous1D::create)
60  };
61 
62  /**
63  * @brief AdvectionFR uses the Flux Reconstruction (FR) approach to
64  * compute the advection term. The implementation is only for segments,
65  * quadrilaterals and hexahedra at the moment.
66  *
67  * \todo Extension to triangles, tetrahedra and other shapes.
68  * (Long term objective)
69  */
71  : m_advType(advType)
72  {
73  // Strip trailing string "3DHomogeneous1D" to determine 2D advection
74  // type, and create an advection object for the plane.
75  string advName = advType.substr(0, advType.length()-15);
76  m_planeAdv = GetAdvectionFactory().CreateInstance(advName, advName);
77  }
78 
79  /**
80  * @brief Initiliase Advection3DHomogeneous1D objects and store them
81  * before starting the time-stepping.
82  *
83  * @param pSession Pointer to session reader.
84  * @param pFields Pointer to fields.
85  */
88  Array<OneD, MultiRegions::ExpListSharedPtr> pFields)
89  {
90  int nConvectiveFields = pFields.num_elements();
91 
92  Array<OneD, MultiRegions::ExpListSharedPtr> pFields_plane0(
93  nConvectiveFields);
94 
95  // Initialise the plane advection object.
96  for (int i = 0; i < nConvectiveFields; ++i)
97  {
98  pFields_plane0[i] = pFields[i]->GetPlane(0);
99  }
100  m_planeAdv->InitObject(pSession, pFields_plane0);
101 
102  m_numPoints = pFields[0]->GetTotPoints();
103  m_planes = pFields[0]->GetZIDs();
104  m_numPlanes = m_planes.num_elements();
106 
107  // Set Riemann solver and flux vector callback for this plane.
108  m_planeAdv->SetRiemannSolver(m_riemann);
109  m_planeAdv->SetFluxVector (
111  m_planeCounter = 0;
112 
113  // Override Riemann solver scalar and vector callbacks.
116  map<string, RSScalarFuncType> scalars = m_riemann->GetScalars();
117  map<string, RSVecFuncType> vectors = m_riemann->GetVectors();
118 
119  for (it1 = scalars.begin(); it1 != scalars.end(); ++it1)
120  {
121  boost::shared_ptr<HomoRSScalar> tmp = MemoryManager<HomoRSScalar>
122  ::AllocateSharedPtr(it1->second, m_numPlanes);
123  m_riemann->SetScalar(it1->first, &HomoRSScalar::Exec, tmp);
124  }
125 
126  for (it2 = vectors.begin(); it2 != vectors.end(); ++it2)
127  {
128  boost::shared_ptr<HomoRSVector> tmp = MemoryManager<HomoRSVector>
129  ::AllocateSharedPtr(it2->second, m_numPlanes, it2->first);
130  m_riemann->SetVector(it2->first, &HomoRSVector::Exec, tmp);
131  }
132 
133  m_fluxVecStore = Array<OneD, Array<OneD, Array<OneD, NekDouble> > >(
134  nConvectiveFields);
135 
136  // Set up storage for flux vector.
137  for (int i = 0; i < nConvectiveFields; ++i)
138  {
139  m_fluxVecStore[i] = Array<OneD, Array<OneD, NekDouble> >(3);
140  for (int j = 0; j < 3; ++j)
141  {
142  m_fluxVecStore[i][j] = Array<OneD, NekDouble>(m_numPoints);
143  }
144  }
145 
146  m_fluxVecPlane = Array<OneD, Array<OneD,
147  Array<OneD, Array<OneD, NekDouble> > > >(m_numPlanes);
148  m_fieldsPlane = Array<OneD, MultiRegions::ExpListSharedPtr>
149  (nConvectiveFields);
150  m_inarrayPlane = Array<OneD, Array<OneD, NekDouble> >
151  (nConvectiveFields);
152  m_outarrayPlane = Array<OneD, Array<OneD, NekDouble> >
153  (nConvectiveFields);
154  m_planePos = Array<OneD, unsigned int> (m_numPlanes);
155  m_advVelPlane = Array<OneD, Array<OneD, NekDouble> > (3);
156 
157  // Set up memory reference which links fluxVecPlane to fluxVecStore.
158  for (int i = 0; i < m_numPlanes; ++i)
159  {
160  m_planePos[i] = i * m_numPointsPlane;
161  m_fluxVecPlane[i] =
162  Array<OneD, Array<OneD, Array<OneD, NekDouble> > >(
163  nConvectiveFields);
164 
165  for (int j = 0; j < nConvectiveFields; ++j)
166  {
167  m_fluxVecPlane[i][j] =
168  Array<OneD, Array<OneD, NekDouble> >(3);
169  for (int k = 0; k < 3; ++k)
170  {
171  m_fluxVecPlane[i][j][k] = Array<OneD, NekDouble>(
173  m_fluxVecStore[j][k] + m_planePos[i]);
174  }
175  }
176  }
177  }
178 
179  /**
180  * @brief Compute the advection operator for a given input @a inarray
181  * and put the result in @a outarray.
182  *
183  * @param nConvectiveFields Number of fields to advect.
184  * @param fields Pointer to fields.
185  * @param advVel Advection velocities.
186  * @param inarray Input which will be advected.
187  * @param outarray Computed advection.
188  */
190  const int nConvectiveFields,
191  const Array<OneD, MultiRegions::ExpListSharedPtr> &fields,
192  const Array<OneD, Array<OneD, NekDouble> > &advVel,
193  const Array<OneD, Array<OneD, NekDouble> > &inarray,
194  Array<OneD, Array<OneD, NekDouble> > &outarray)
195  {
196  Array<OneD, NekDouble> tmp(m_numPoints), tmp2;
197  int nVel = advVel.num_elements();
198 
199  // Call solver's flux vector function to compute the flux vector on
200  // the entire domain.
201  m_fluxVector(inarray, m_fluxVecStore);
202 
203  // Loop over each plane.
204  for (int i = 0; i < m_numPlanes; ++i)
205  {
206  // Set up memory references for fields, inarray and outarray for
207  // this plane.
208  for (int j = 0; j < nConvectiveFields; ++j)
209  {
210  m_fieldsPlane [j] = fields[j]->GetPlane(i);
211  m_inarrayPlane [j] = Array<OneD, NekDouble>(
212  m_numPointsPlane, tmp2 = inarray [j] + m_planePos[i]);
213  m_outarrayPlane[j] = Array<OneD, NekDouble>(
214  m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
215  }
216 
217  for (int j = 0; j < nVel; ++j)
218  {
219  if (advVel[j].num_elements() != 0)
220  {
221  m_advVelPlane[j] = Array<OneD, NekDouble>(
222  m_numPointsPlane, tmp2 = advVel[j] + m_planePos[i]);
223  }
224  }
225 
226  // Compute advection term for this plane.
227  m_planeAdv->Advect(nConvectiveFields, m_fieldsPlane,
230  }
231 
232  // Calculate Fourier derivative and add to final result.
233  for (int i = 0; i < nConvectiveFields; ++i)
234  {
235  fields[0]->PhysDeriv(2, m_fluxVecStore[i][2], tmp);
236 
237  Vmath::Vadd(m_numPoints, outarray[i], 1, tmp, 1,
238  outarray[i], 1);
239  }
240  }
241 
243  const Array<OneD, Array<OneD, NekDouble> > &inarray,
244  Array<OneD, Array<OneD, Array<OneD, NekDouble> > > &outarray)
245  {
246  // Return section of flux vector for this plane.
247  outarray = m_fluxVecPlane[m_planeCounter];
248 
249  // Increment the plane counter.
251  }
252  }
253 }