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
38namespace Nektar
39{
40
42{
43 static ArtificialDiffusionFactory instance;
44 return instance;
45}
46
50 const int spacedim)
51 : m_session(pSession), m_fields(pFields)
52{
53 // Create auxiliary object to convert variables
55 spacedim);
56
60 m_diffusion->InitObject(m_session, m_fields);
61
62 // Get constant scaling
63 m_session->LoadParameter("mu0", m_mu0, 1.0);
64}
65
66/**
67 *
68 */
70 const Array<OneD, const Array<OneD, NekDouble>> &inarray,
72{
73 int nvariables = inarray.size();
74 int npoints = m_fields[0]->GetNpoints();
75
76 Array<OneD, Array<OneD, NekDouble>> outarrayDiff(nvariables);
77
78 for (int i = 0; i < nvariables; ++i)
79 {
80 outarrayDiff[i] = Array<OneD, NekDouble>(npoints, 0.0);
81 }
82
83 m_diffusion->Diffuse(nvariables, m_fields, inarray, outarrayDiff);
84
85 for (int i = 0; i < nvariables; ++i)
86 {
87 Vmath::Vadd(npoints, outarray[i], 1, outarrayDiff[i], 1, outarray[i],
88 1);
89 }
90}
91
92/**
93 *
94 */
96 const Array<OneD, const Array<OneD, NekDouble>> &inarray,
98{
99 size_t nvariables = inarray.size();
100 size_t ncoeffs = m_fields[0]->GetNcoeffs();
101
102 Array<OneD, Array<OneD, NekDouble>> outarrayDiff{nvariables};
103
104 for (size_t i = 0; i < nvariables; ++i)
105 {
106 outarrayDiff[i] = Array<OneD, NekDouble>{ncoeffs, 0.0};
107 }
108
109 m_diffusion->DiffuseCoeffs(nvariables, m_fields, inarray, outarrayDiff);
110
111 for (size_t i = 0; i < nvariables; ++i)
112 {
113 Vmath::Vadd(ncoeffs, outarray[i], 1, outarrayDiff[i], 1, outarray[i],
114 1);
115 }
116}
117
118/**
119 * @brief Return the flux vector for the artificial viscosity operator.
120 */
122 const Array<OneD, Array<OneD, NekDouble>> &inarray,
123 const Array<OneD, Array<OneD, Array<OneD, NekDouble>>> &qfield,
124 Array<OneD, Array<OneD, Array<OneD, NekDouble>>> &viscousTensor)
125{
126 unsigned int nDim = qfield.size();
127 unsigned int nConvectiveFields = qfield[0].size();
128 unsigned int nPts = qfield[0][0].size();
129
130 // Get Artificial viscosity
131 Array<OneD, NekDouble> mu{nPts, 0.0};
132 GetArtificialViscosity(inarray, mu);
133
134 // Compute viscous tensor
135 for (unsigned int j = 0; j < nDim; ++j)
136 {
137 for (unsigned int i = 0; i < nConvectiveFields; ++i)
138 {
139 Vmath::Vmul(nPts, qfield[j][i], 1, mu, 1, viscousTensor[j][i], 1);
140 }
141 }
142}
143
144} // namespace Nektar
void GetArtificialViscosity(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, NekDouble > &mu)
Calculate the artificial viscosity.
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array of fields.
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
virtual void v_DoArtificialDiffusion(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
ArtificialDiffusion(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const int spacedim)
Constructor.
NekDouble m_mu0
Constant scaling.
VariableConverterSharedPtr m_varConv
Auxiliary object to convert variables.
virtual void v_DoArtificialDiffusionCoeff(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
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.
SolverUtils::DiffusionSharedPtr m_diffusion
LDG Diffusion operator.
Provides a generic Factory class.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
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:39
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.hpp:72
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.hpp:180