Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AdvectionWeakDG.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: AdvectionWeakDG.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: Weak DG advection class.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 #include <iostream>
38 #include <iomanip>
39 
40 namespace Nektar
41 {
42  namespace SolverUtils
43  {
45  RegisterCreatorFunction("WeakDG", AdvectionWeakDG::create);
46 
48  {
49  }
50 
51  /**
52  * @brief Initialise AdvectionWeakDG objects and store them before
53  * starting the time-stepping.
54  *
55  * @param pSession Pointer to session reader.
56  * @param pFields Pointer to fields.
57  */
60  Array<OneD, MultiRegions::ExpListSharedPtr> pFields)
61  {
62  Advection::v_InitObject(pSession, pFields);
63  }
64 
65  /**
66  * @brief Compute the advection term at each time-step using the
67  * Discontinuous Glaerkin approach (DG).
68  *
69  * @param nConvectiveFields Number of fields.
70  * @param fields Pointer to fields.
71  * @param advVel Advection velocities.
72  * @param inarray Solution at the previous time-step.
73  * @param outarray Advection term to be passed at the
74  * time integration class.
75  */
77  const int nConvectiveFields,
78  const Array<OneD, MultiRegions::ExpListSharedPtr> &fields,
79  const Array<OneD, Array<OneD, NekDouble> > &advVel,
80  const Array<OneD, Array<OneD, NekDouble> > &inarray,
81  Array<OneD, Array<OneD, NekDouble> > &outarray)
82  {
83  int nDim = fields[0]->GetCoordim(0);
84  int nPointsTot = fields[0]->GetTotPoints();
85  int nCoeffs = fields[0]->GetNcoeffs();
86  int nTracePointsTot = fields[0]->GetTrace()->GetTotPoints();
87  int i, j;
88 
89  Array<OneD, Array<OneD, NekDouble> > tmp(nConvectiveFields);
90  Array<OneD, Array<OneD, Array<OneD, NekDouble> > > fluxvector(
91  nConvectiveFields);
92 
93  // Allocate storage for flux vector F(u).
94  for (i = 0; i < nConvectiveFields; ++i)
95  {
96  fluxvector[i] =
97  Array<OneD, Array<OneD, NekDouble> >(m_spaceDim);
98  for (j = 0; j < m_spaceDim; ++j)
99  {
100  fluxvector[i][j] = Array<OneD, NekDouble>(nPointsTot);
101  }
102  }
103 
105  "Riemann solver must be provided for AdvectionWeakDG.");
106 
107  m_fluxVector(inarray, fluxvector);
108 
109  // Get the advection part (without numerical flux)
110  for(i = 0; i < nConvectiveFields; ++i)
111  {
112  tmp[i] = Array<OneD, NekDouble>(nCoeffs, 0.0);
113 
114  for (j = 0; j < nDim; ++j)
115  {
116  fields[i]->IProductWRTDerivBase(j, fluxvector[i][j],
117  outarray[i]);
118  Vmath::Vadd(nCoeffs, outarray[i], 1, tmp[i], 1, tmp[i], 1);
119  }
120  }
121 
122  // Store forwards/backwards space along trace space
123  Array<OneD, Array<OneD, NekDouble> > Fwd (nConvectiveFields);
124  Array<OneD, Array<OneD, NekDouble> > Bwd (nConvectiveFields);
125  Array<OneD, Array<OneD, NekDouble> > numflux(nConvectiveFields);
126 
127  for(i = 0; i < nConvectiveFields; ++i)
128  {
129  Fwd[i] = Array<OneD, NekDouble>(nTracePointsTot, 0.0);
130  Bwd[i] = Array<OneD, NekDouble>(nTracePointsTot, 0.0);
131  numflux[i] = Array<OneD, NekDouble>(nTracePointsTot, 0.0);
132  fields[i]->GetFwdBwdTracePhys(inarray[i], Fwd[i], Bwd[i]);
133  }
134 
135  m_riemann->Solve(m_spaceDim, Fwd, Bwd, numflux);
136 
137  // Evaulate <\phi, \hat{F}\cdot n> - OutField[i]
138  for(i = 0; i < nConvectiveFields; ++i)
139  {
140  Vmath::Neg (nCoeffs, tmp[i], 1);
141  fields[i]->AddTraceIntegral (numflux[i], tmp[i]);
142  fields[i]->MultiplyByElmtInvMass(tmp[i], tmp[i]);
143  fields[i]->BwdTrans (tmp[i], outarray[i]);
144  }
145  }
146  }//end of namespace SolverUtils
147 }//end of namespace Nektar