Nektar++
ForcingQuasi1D.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: ForcingQuasi1D.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: Forcing for quasi-1D nozzle flow.
32//
33///////////////////////////////////////////////////////////////////////////////
34
36
37using namespace std;
38
39namespace Nektar
40{
41std::string ForcingQuasi1D::className =
43 "Quasi1D", ForcingQuasi1D::create, "Quasi-1D nozzle Forcing");
44
47 const std::weak_ptr<SolverUtils::EquationSystem> &pEquation)
48 : Forcing(pSession, pEquation)
49{
50}
51
54 const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
55{
56 m_NumVariable = pNumForcingFields;
57 m_varConv =
59
60 ASSERTL0(pFields[0]->GetGraph()->GetSpaceDimension() == 1,
61 "ForcingQuasi1D requires a 1D problem.");
62
63 const TiXmlElement *funcNameElmt = pForce->FirstChildElement("AREAFCN");
64 if (!funcNameElmt)
65 {
66 ASSERTL0(funcNameElmt,
67 "Requires AREAFCN tag "
68 "specifying function name which prescribes nozzle area.");
69 }
70
71 string funcName = funcNameElmt->GetText();
72 ASSERTL0(m_session->DefinesFunction(funcName),
73 "Function '" + funcName + "' not defined.");
74
75 // Evaluate geometrical term -Ax/A for forcing
76 m_geomFactor = Array<OneD, NekDouble>(pFields[0]->GetTotPoints(), 0.0);
77 Array<OneD, NekDouble> tmp(pFields[0]->GetTotPoints(), 0.0);
78
79 std::string sFieldStr = m_session->GetVariable(0);
80 ASSERTL0(m_session->DefinesFunction(funcName, sFieldStr),
81 "Variable '" + sFieldStr + "' not defined.");
82 GetFunction(pFields, m_session, funcName, true)
83 ->Evaluate(sFieldStr, m_geomFactor, 0.0);
84
85 // Check if DADXFCN is defined
86 const TiXmlElement *dAFuncNameElmt = pForce->FirstChildElement("DADXFCN");
87 if (dAFuncNameElmt)
88 {
89 funcName = dAFuncNameElmt->GetText();
90 ASSERTL0(m_session->DefinesFunction(funcName),
91 "Function '" + funcName + "' not defined.");
92 ASSERTL0(m_session->DefinesFunction(funcName, sFieldStr),
93 "Variable '" + sFieldStr + "' not defined.");
94 GetFunction(pFields, m_session, funcName, true)
95 ->Evaluate(sFieldStr, tmp, 0.0);
96 }
97 else
98 {
99 // Numerically evaluate dA/dX
100 pFields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0], m_geomFactor,
101 tmp);
102 }
103
104 Vmath::Vdiv(pFields[0]->GetTotPoints(), tmp, 1, m_geomFactor, 1,
105 m_geomFactor, 1);
106 Vmath::Neg(pFields[0]->GetTotPoints(), m_geomFactor, 1);
107
108 // Project m_geomFactor to solution space
109 Array<OneD, NekDouble> tmpCoeff(pFields[0]->GetNcoeffs(), 0.0);
110 pFields[0]->FwdTransLocalElmt(m_geomFactor, tmpCoeff);
111 pFields[0]->BwdTrans(tmpCoeff, m_geomFactor);
112
114 for (int i = 0; i < m_NumVariable; ++i)
115 {
116 m_Forcing[i] = Array<OneD, NekDouble>(pFields[0]->GetTotPoints(), 0.0);
117 }
118}
119
122 const Array<OneD, Array<OneD, NekDouble>> &inarray,
124 [[maybe_unused]] const NekDouble &time)
125{
126 int nPoints = pFields[0]->GetTotPoints();
127
128 // Get (E+p)
129 Array<OneD, NekDouble> tmp(nPoints, 0.0);
130 m_varConv->GetPressure(inarray, tmp);
131 Vmath::Vadd(nPoints, tmp, 1, inarray[2], 1, tmp, 1);
132
133 // F-rho = -Ax/A *rhou
134 Vmath::Vmul(nPoints, m_geomFactor, 1, inarray[1], 1, m_Forcing[0], 1);
135
136 // F-rhou = -Ax/A *rhou*u
137 Vmath::Vmul(nPoints, m_geomFactor, 1, inarray[1], 1, m_Forcing[1], 1);
138 Vmath::Vmul(nPoints, m_Forcing[1], 1, inarray[1], 1, m_Forcing[1], 1);
139 Vmath::Vdiv(nPoints, m_Forcing[1], 1, inarray[0], 1, m_Forcing[1], 1);
140
141 // F-E = -Ax/A *(E+p)*u
142 Vmath::Vmul(nPoints, m_geomFactor, 1, inarray[1], 1, m_Forcing[2], 1);
143 Vmath::Vmul(nPoints, m_Forcing[2], 1, tmp, 1, m_Forcing[2], 1);
144 Vmath::Vdiv(nPoints, m_Forcing[2], 1, inarray[0], 1, m_Forcing[2], 1);
145
146 // Apply forcing
147 for (int i = 0; i < m_NumVariable; i++)
148 {
149 Vmath::Vadd(nPoints, outarray[i], 1, m_Forcing[i], 1, outarray[i], 1);
150 }
151}
152
153} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce) override
VariableConverterSharedPtr m_varConv
Array< OneD, NekDouble > m_geomFactor
static SolverUtils::ForcingSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< SolverUtils::EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Creates an instance of this class.
void v_Apply(const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time) override
ForcingQuasi1D(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< SolverUtils::EquationSystem > &pEquation)
static std::string className
Name of the class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Defines a forcing term to be explicitly applied.
Definition: Forcing.h:71
int m_NumVariable
Number of variables.
Definition: Forcing.h:121
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:119
SOLVER_UTILS_EXPORT SessionFunctionSharedPtr GetFunction(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, std::string pName, bool pCache=false)
Get a SessionFunction by name.
Definition: Forcing.cpp:192
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:115
std::shared_ptr< SessionReader > SessionReaderSharedPtr
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:86
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:42
double NekDouble
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 Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.hpp:292
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
void Vdiv(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:126