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
38using namespace std;
39
40namespace Nektar
41{
43{
44 static ArtificialDiffusionFactory instance;
45 return instance;
46}
47
51 const int spacedim)
52 : m_session(pSession), m_fields(pFields)
53{
54 // Create auxiliary object to convert variables
56 spacedim);
57
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,
73{
74 v_DoArtificialDiffusion(inarray, outarray);
75}
76
77/**
78 *
79 */
81 const Array<OneD, const Array<OneD, NekDouble>> &inarray,
83{
84 int nvariables = inarray.size();
85 int npoints = m_fields[0]->GetNpoints();
86
87 Array<OneD, Array<OneD, NekDouble>> outarrayDiff(nvariables);
88
89 for (int i = 0; i < nvariables; ++i)
90 {
91 outarrayDiff[i] = Array<OneD, NekDouble>(npoints, 0.0);
92 }
93
94 m_diffusion->Diffuse(nvariables, m_fields, inarray, outarrayDiff);
95
96 for (int i = 0; i < nvariables; ++i)
97 {
98 Vmath::Vadd(npoints, outarray[i], 1, outarrayDiff[i], 1, outarray[i],
99 1);
100 }
101}
102
103/**
104 *
105 */
107 const Array<OneD, const Array<OneD, NekDouble>> &inarray,
109{
110 v_DoArtificialDiffusionCoeff(inarray, outarray);
111}
112
113/**
114 *
115 */
117 const Array<OneD, const Array<OneD, NekDouble>> &inarray,
119{
120 size_t nvariables = inarray.size();
121 size_t ncoeffs = m_fields[0]->GetNcoeffs();
122
123 Array<OneD, Array<OneD, NekDouble>> outarrayDiff{nvariables};
124
125 for (size_t i = 0; i < nvariables; ++i)
126 {
127 outarrayDiff[i] = Array<OneD, NekDouble>{ncoeffs, 0.0};
128 }
129
130 m_diffusion->DiffuseCoeffs(nvariables, m_fields, inarray, outarrayDiff);
131
132 for (size_t i = 0; i < nvariables; ++i)
133 {
134 Vmath::Vadd(ncoeffs, outarray[i], 1, outarrayDiff[i], 1, outarray[i],
135 1);
136 }
137}
138
139/**
140 *
141 */
143 const Array<OneD, Array<OneD, NekDouble>> &physfield,
145{
146 v_GetArtificialViscosity(physfield, mu);
147}
148
149/**
150 * @brief Return the flux vector for the artificial viscosity operator.
151 */
153 const Array<OneD, Array<OneD, NekDouble>> &inarray,
154 const Array<OneD, Array<OneD, Array<OneD, NekDouble>>> &qfield,
155 Array<OneD, Array<OneD, Array<OneD, NekDouble>>> &viscousTensor)
156{
157 unsigned int nDim = qfield.size();
158 unsigned int nConvectiveFields = qfield[0].size();
159 unsigned int nPts = qfield[0][0].size();
160
161 // Get Artificial viscosity
162 Array<OneD, NekDouble> mu{nPts, 0.0};
163 GetArtificialViscosity(inarray, mu);
164
165 // Compute viscous tensor
166 for (unsigned int j = 0; j < nDim; ++j)
167 {
168 for (unsigned int i = 0; i < nConvectiveFields; ++i)
169 {
170 Vmath::Vmul(nPts, qfield[j][i], 1, mu, 1, viscousTensor[j][i], 1);
171 }
172 }
173}
174
175} // namespace Nektar
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_GetArtificialViscosity(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, NekDouble > &mu)=0
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 DoArtificialDiffusion(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
Apply the artificial diffusion.
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
STL namespace.