Nektar++
ArtificialDiffusion.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ArtificialDiffusion.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: Abstract base class for compressible solver artificial diffusion
32 // used for shock capturing artificial diffusion.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #include "ArtificialDiffusion.h"
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
43 {
44  static ArtificialDiffusionFactory instance;
45  return instance;
46 }
47 
48 ArtificialDiffusion::ArtificialDiffusion(
51  const int spacedim)
52  : m_session(pSession),
53  m_fields(pFields)
54 {
55  // Create auxiliary object to convert variables
57  m_session, spacedim);
58 
60  .CreateInstance("LDG", "LDG");
61  m_diffusion->SetFluxVector(&ArtificialDiffusion::GetFluxVector, this);
62  m_diffusion->InitObject (m_session, m_fields);
63 
64  // Get constant scaling
65  m_session->LoadParameter("mu0", m_mu0, 1.0);
66 
67  // Init h/p scaling
68  int nElements = m_fields[0]->GetExpSize();
69  m_hOverP = Array<OneD, NekDouble>(nElements, 1.0);
70 }
71 
72 /**
73  *
74  */
76  const Array<OneD, const Array<OneD, NekDouble> > &inarray,
77  Array<OneD, Array<OneD, NekDouble> > &outarray)
78 {
79  v_DoArtificialDiffusion(inarray, outarray);
80 }
81 
82 /**
83  *
84  */
86  const Array<OneD, const Array<OneD, NekDouble> > &inarray,
87  Array<OneD, Array<OneD, NekDouble> > &outarray)
88 {
89  int i;
90  int nvariables = inarray.num_elements();
91  int npoints = m_fields[0]->GetNpoints();
92 
93  Array<OneD, Array<OneD, NekDouble> > outarrayDiff(nvariables);
94 
95  for (i = 0; i < nvariables; ++i)
96  {
97  outarrayDiff[i] = Array<OneD, NekDouble>(npoints, 0.0);
98  }
99 
100  m_diffusion->Diffuse(nvariables, m_fields, inarray, outarrayDiff);
101 
102  for (i = 0; i < nvariables; ++i)
103  {
104  Vmath::Vadd(npoints,
105  outarray[i], 1,
106  outarrayDiff[i], 1,
107  outarray[i], 1);
108  }
109 }
110 
111 /**
112  *
113  */
115  const Array<OneD, Array<OneD, NekDouble> > &physfield,
117 {
118  v_GetArtificialViscosity(physfield, mu);
119 }
120 
121 /**
122  *
123  */
125 {
126  m_hOverP = hOverP;
127 }
128 
129 /**
130  * @brief Return the flux vector for the artificial viscosity operator.
131  */
133  const Array<OneD, Array<OneD, NekDouble> > &inarray,
134  const Array<OneD, Array<OneD, Array<OneD, NekDouble> > >&qfield,
135  Array<OneD, Array<OneD, Array<OneD, NekDouble> > >&viscousTensor)
136 {
137  unsigned int nDim = qfield.num_elements();
138  unsigned int nConvectiveFields = qfield[0].num_elements();
139  unsigned int nPts = qfield[0][0].num_elements();
140 
141  // Get Artificial viscosity
142  Array<OneD, NekDouble> mu{nPts, 0.0};
143  GetArtificialViscosity(inarray, mu);
144 
145  // Compute viscous tensor
146  for (unsigned int j = 0; j < nDim; ++j)
147  {
148  for (unsigned int i = 0; i < nConvectiveFields; ++i)
149  {
150  Vmath::Vmul(nPts, qfield[j][i], 1, mu , 1, viscousTensor[j][i], 1);
151  }
152  }
153 }
154 
155 
156 }
void SetElmtHP(const Array< OneD, NekDouble > &hOverP)
Set h/p scaling.
void DoArtificialDiffusion(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
Apply the artificial diffusion.
DiffusionFactory & GetDiffusionFactory()
Definition: Diffusion.cpp:41
STL namespace.
Array< OneD, NekDouble > m_hOverP
h/p scaling
SolverUtils::DiffusionSharedPtr m_diffusion
LDG Diffusion operator.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
virtual void v_GetArtificialViscosity(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, NekDouble > &mu)=0
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
ArtificialDiffusionFactory & GetArtificialDiffusionFactory()
Declaration of the artificial diffusion factory singleton.
void GetFluxVector(const Array< OneD, Array< OneD, NekDouble > > &inarray, const Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &qfield, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &viscousTensor)
Return the flux vector for the artificial viscosity operator.
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
NekDouble m_mu0
Constant scaling.
virtual void v_DoArtificialDiffusion(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
void GetArtificialViscosity(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, NekDouble > &mu)
Calculate the artificial viscosity.
VariableConverterSharedPtr m_varConv
Auxiliary object to convert variables.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array of fields.
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:302
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:186
Provides a generic Factory class.
Definition: NekFactory.hpp:103