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), m_fields(pFields)
53 {
54  // Create auxiliary object to convert variables
56  spacedim);
57 
58  m_diffusion =
60  m_diffusion->SetFluxVector(&ArtificialDiffusion::GetFluxVector, this);
61  m_diffusion->InitObject(m_session, m_fields);
62 
63  // Get constant scaling
64  m_session->LoadParameter("mu0", m_mu0, 1.0);
65 }
66 
67 /**
68  *
69  */
71  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
72  Array<OneD, Array<OneD, NekDouble>> &outarray)
73 {
74  v_DoArtificialDiffusion(inarray, outarray);
75 }
76 
77 /**
78  *
79  */
81  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
82  Array<OneD, Array<OneD, NekDouble>> &outarray)
83 {
84  int i;
85  int nvariables = inarray.size();
86  int npoints = m_fields[0]->GetNpoints();
87 
88  Array<OneD, Array<OneD, NekDouble>> outarrayDiff(nvariables);
89 
90  for (i = 0; i < nvariables; ++i)
91  {
92  outarrayDiff[i] = Array<OneD, NekDouble>(npoints, 0.0);
93  }
94 
95  m_diffusion->Diffuse(nvariables, m_fields, inarray, outarrayDiff);
96 
97  for (i = 0; i < nvariables; ++i)
98  {
99  Vmath::Vadd(npoints, outarray[i], 1, outarrayDiff[i], 1, outarray[i],
100  1);
101  }
102 }
103 
105  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
106  Array<OneD, Array<OneD, NekDouble>> &outarray)
107 {
108  v_DoArtificialDiffusionCoeff(inarray, outarray);
109 }
110 
112  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
113  Array<OneD, Array<OneD, NekDouble>> &outarray)
114 {
115  size_t nvariables = inarray.size();
116  size_t ncoeffs = m_fields[0]->GetNcoeffs();
117 
118  Array<OneD, Array<OneD, NekDouble>> outarrayDiff{nvariables};
119 
120  for (int i = 0; i < nvariables; ++i)
121  {
122  outarrayDiff[i] = Array<OneD, NekDouble>{ncoeffs, 0.0};
123  }
124 
125  m_diffusion->DiffuseCoeffs(nvariables, m_fields, inarray, outarrayDiff);
126 
127  for (int i = 0; i < nvariables; ++i)
128  {
129  Vmath::Vadd(ncoeffs, outarray[i], 1, outarrayDiff[i], 1, outarray[i],
130  1);
131  }
132 }
133 
135  const Array<OneD, Array<OneD, NekDouble>> &physfield,
137 {
138  v_GetArtificialViscosity(physfield, mu);
139 }
140 
141 /**
142  * @brief Return the flux vector for the artificial viscosity operator.
143  */
145  const Array<OneD, Array<OneD, NekDouble>> &inarray,
146  const Array<OneD, Array<OneD, Array<OneD, NekDouble>>> &qfield,
147  Array<OneD, Array<OneD, Array<OneD, NekDouble>>> &viscousTensor)
148 {
149  unsigned int nDim = qfield.size();
150  unsigned int nConvectiveFields = qfield[0].size();
151  unsigned int nPts = qfield[0][0].size();
152 
153  // Get Artificial viscosity
154  Array<OneD, NekDouble> mu{nPts, 0.0};
155  GetArtificialViscosity(inarray, mu);
156 
157  // Compute viscous tensor
158  for (unsigned int j = 0; j < nDim; ++j)
159  {
160  for (unsigned int i = 0; i < nConvectiveFields; ++i)
161  {
162  Vmath::Vmul(nPts, qfield[j][i], 1, mu, 1, viscousTensor[j][i], 1);
163  }
164  }
165 }
166 
167 } // namespace Nektar
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array of fields.
virtual void v_DoArtificialDiffusion(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
void DoArtificialDiffusion(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
Apply the artificial diffusion.
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
NekDouble m_mu0
Constant scaling.
VariableConverterSharedPtr m_varConv
Auxiliary object to convert variables.
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.
virtual void v_GetArtificialViscosity(const Array< OneD, Array< OneD, NekDouble >> &physfield, Array< OneD, NekDouble > &mu)=0
void GetArtificialViscosity(const Array< OneD, Array< OneD, NekDouble >> &physfield, Array< OneD, NekDouble > &mu)
Calculate the artificial viscosity.
void DoArtificialDiffusionCoeff(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
Apply the artificial diffusion the outarray is in coeff space.
virtual void v_DoArtificialDiffusionCoeff(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
SolverUtils::DiffusionSharedPtr m_diffusion
LDG Diffusion operator.
Provides a generic Factory class.
Definition: NekFactory.hpp:105
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DiffusionFactory & GetDiffusionFactory()
Definition: Diffusion.cpp:41
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
ArtificialDiffusionFactory & GetArtificialDiffusionFactory()
Declaration of the artificial diffusion factory singleton.
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:209
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:359