Nektar++
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 // 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: FR advection 3DHomogeneous1D class.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
39 #include <iostream>
40 #include <iomanip>
41 
42 using namespace std;
43 
44 namespace Nektar
45 {
46  namespace SolverUtils
47  {
48  std::string Advection3DHomogeneous1D::type[] = {
50  "WeakDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
52  "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
54  "FRDG3DHomogeneous1D", Advection3DHomogeneous1D::create),
56  "FRSD3DHomogeneous1D", Advection3DHomogeneous1D::create),
58  "FRHU3DHomogeneous1D", Advection3DHomogeneous1D::create),
60  "FRcmin3DHomogeneous1D", Advection3DHomogeneous1D::create),
62  "FRcinf3DHomogeneous1D", Advection3DHomogeneous1D::create)
63  };
64 
65  /**
66  * @brief AdvectionFR uses the Flux Reconstruction (FR) approach to
67  * compute the advection term. The implementation is only for segments,
68  * quadrilaterals and hexahedra at the moment.
69  *
70  * \todo Extension to triangles, tetrahedra and other shapes.
71  * (Long term objective)
72  */
73  Advection3DHomogeneous1D::Advection3DHomogeneous1D(std::string advType)
74  : m_advType(advType)
75  {
76  // Strip trailing string "3DHomogeneous1D" to determine 2D advection
77  // type, and create an advection object for the plane.
78  string advName = advType.substr(0, advType.length()-15);
79  m_planeAdv = GetAdvectionFactory().CreateInstance(advName, advName);
80  }
81 
82  /**
83  * @brief Initiliase Advection3DHomogeneous1D objects and store them
84  * before starting the time-stepping.
85  *
86  * @param pSession Pointer to session reader.
87  * @param pFields Pointer to fields.
88  */
92  {
93  int nConvectiveFields = pFields.size();
94 
96  nConvectiveFields);
97 
98  // Initialise the plane advection object.
99  for (int i = 0; i < nConvectiveFields; ++i)
100  {
101  pFields_plane0[i] = pFields[i]->GetPlane(0);
102  }
103  m_planeAdv->InitObject(pSession, pFields_plane0);
104 
105  m_numPoints = pFields[0]->GetTotPoints();
106  m_planes = pFields[0]->GetZIDs();
107  m_numPlanes = m_planes.size();
109 
110  // Set Riemann solver and flux vector callback for this plane.
111  m_planeAdv->SetRiemannSolver(m_riemann);
112  m_planeAdv->SetFluxVector (
114  m_planeCounter = 0;
115 
116  // Override Riemann solver scalar and vector callbacks.
117  map<string, RSScalarFuncType> scalars = m_riemann->GetScalars();
118  map<string, RSVecFuncType> vectors = m_riemann->GetVectors();
119 
120  for (auto &it1 : scalars)
121  {
122  std::shared_ptr<HomoRSScalar> tmp = MemoryManager<HomoRSScalar>
123  ::AllocateSharedPtr(it1.second, m_numPlanes);
124  m_riemann->SetScalar(it1.first, &HomoRSScalar::Exec, tmp);
125  }
126 
127  for (auto &it2 : vectors)
128  {
129  std::shared_ptr<HomoRSVector> tmp = MemoryManager<HomoRSVector>
130  ::AllocateSharedPtr(it2.second, m_numPlanes, it2.first);
131  m_riemann->SetVector(it2.first, &HomoRSVector::Exec, tmp);
132  }
133 
135  nConvectiveFields);
136 
137  // Set up storage for flux vector.
138  for (int i = 0; i < nConvectiveFields; ++i)
139  {
141  for (int j = 0; j < 3; ++j)
142  {
144  }
145  }
146 
150  (nConvectiveFields);
152  (nConvectiveFields);
154  (nConvectiveFields);
157 
158  // Set up memory reference which links fluxVecPlane to fluxVecStore.
159  for (int i = 0; i < m_numPlanes; ++i)
160  {
161  m_planePos[i] = i * m_numPointsPlane;
162  m_fluxVecPlane[i] =
164  nConvectiveFields);
165 
166  for (int j = 0; j < nConvectiveFields; ++j)
167  {
168  m_fluxVecPlane[i][j] =
170  for (int k = 0; k < 3; ++k)
171  {
174  m_fluxVecStore[j][k] + m_planePos[i]);
175  }
176  }
177  }
178  }
179 
180  /**
181  * @brief Compute the advection operator for a given input @a inarray
182  * and put the result in @a outarray.
183  *
184  * @param nConvectiveFields Number of fields to advect.
185  * @param fields Pointer to fields.
186  * @param advVel Advection velocities.
187  * @param inarray Input which will be advected.
188  * @param outarray Computed advection.
189  */
191  const int nConvectiveFields,
193  const Array<OneD, Array<OneD, NekDouble> > &advVel,
194  const Array<OneD, Array<OneD, NekDouble> > &inarray,
195  Array<OneD, Array<OneD, NekDouble> > &outarray,
196  const NekDouble &time,
197  const Array<OneD, Array<OneD, NekDouble> > &pFwd,
198  const Array<OneD, Array<OneD, NekDouble> > &pBwd)
199  {
200  boost::ignore_unused(pFwd, pBwd);
201 
203  int nVel = advVel.size();
204 
205  // Call solver's flux vector function to compute the flux vector on
206  // the entire domain.
207  m_fluxVector(inarray, m_fluxVecStore);
208 
209  // Loop over each plane.
210  for (int i = 0; i < m_numPlanes; ++i)
211  {
212  // Set up memory references for fields, inarray and outarray for
213  // this plane.
214  for (int j = 0; j < nConvectiveFields; ++j)
215  {
216  m_fieldsPlane [j] = fields[j]->GetPlane(i);
218  m_numPointsPlane, tmp2 = inarray [j] + m_planePos[i]);
220  m_numPointsPlane, tmp2 = outarray[j] + m_planePos[i]);
221  }
222 
223  for (int j = 0; j < nVel; ++j)
224  {
225  if (advVel[j].size() != 0)
226  {
228  m_numPointsPlane, tmp2 = advVel[j] + m_planePos[i]);
229  }
230  }
231 
232  // Compute advection term for this plane.
233  m_planeAdv->Advect(nConvectiveFields, m_fieldsPlane,
235  m_outarrayPlane, time);
236  }
237 
238  // Calculate Fourier derivative and add to final result.
239  for (int i = 0; i < nConvectiveFields; ++i)
240  {
241  fields[0]->PhysDeriv(2, m_fluxVecStore[i][2], tmp);
242 
243  Vmath::Vadd(m_numPoints, outarray[i], 1, tmp, 1,
244  outarray[i], 1);
245  }
246  }
247 
249  const Array<OneD, Array<OneD, NekDouble> > &inarray,
250  Array<OneD, Array<OneD, Array<OneD, NekDouble> > > &outarray)
251  {
252  boost::ignore_unused(inarray);
253 
254  // Return section of flux vector for this plane.
255  outarray = m_fluxVecPlane[m_planeCounter];
256 
257  // Increment the plane counter.
259  }
260  }
261 }
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:145
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Array< OneD, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > > m_fluxVecPlane
void ModifiedFluxVector(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &flux)
Array< OneD, Array< OneD, NekDouble > > m_outarrayPlane
virtual void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields)
Initiliase Advection3DHomogeneous1D objects and store them before starting the time-stepping.
Array< OneD, Array< OneD, NekDouble > > m_advVelPlane
Array< OneD, Array< OneD, NekDouble > > m_inarrayPlane
Array< OneD, MultiRegions::ExpListSharedPtr > m_fieldsPlane
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > m_fluxVecStore
virtual void v_Advect(const int nConvField, const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &advVel, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time, const Array< OneD, Array< OneD, NekDouble > > &pFwd=NullNekDoubleArrayOfArray, const Array< OneD, Array< OneD, NekDouble > > &pBwd=NullNekDoubleArrayOfArray)
Compute the advection operator for a given input inarray and put the result in outarray.
AdvectionFluxVecCB m_fluxVector
Callback function to the flux vector (set when advection is in conservative form).
Definition: Advection.h:221
RiemannSolverSharedPtr m_riemann
Riemann solver for DG-type schemes.
Definition: Advection.h:223
const Array< OneD, const NekDouble > & Exec()
const Array< OneD, const Array< OneD, NekDouble > > & Exec()
std::shared_ptr< SessionReader > SessionReaderSharedPtr
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:47
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
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:322