Nektar++
Forcing.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Forcing.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 forcing terms.
32//
33///////////////////////////////////////////////////////////////////////////////
34
37
38namespace Nektar::SolverUtils
39{
40
42{
43 static ForcingFactory instance;
44 return instance;
45}
46
48 const std::weak_ptr<EquationSystem> &pEquation)
49 : m_session(pSession), m_equ(pEquation)
50{
51}
52
54 [[maybe_unused]] const Array<OneD, MultiRegions::ExpListSharedPtr> &fields,
55 const Array<OneD, Array<OneD, NekDouble>> &inarray,
57 [[maybe_unused]] const NekDouble &time)
58{
59 if (&inarray != &outarray)
60 {
61 int nvar = std::min(inarray.size(), outarray.size());
62 for (int i = 0; i < nvar; ++i)
63 {
64 if (&inarray[i] != &outarray[i])
65 {
66 int np = std::min(inarray[i].size(), outarray[i].size());
67 Vmath::Vcopy(np, inarray[i], 1, outarray[i], 1);
68 }
69 }
70 }
71}
72
73/**
74 *
75 */
76std::vector<ForcingSharedPtr> Forcing::Load(
78 const std::weak_ptr<EquationSystem> &pEquation,
80 const unsigned int &pNumForcingFields)
81{
82 std::vector<ForcingSharedPtr> vForceList;
83
84 if (!pSession->DefinesElement("Nektar/Forcing"))
85 {
86 return vForceList;
87 }
88
89 TiXmlElement *vForcing = pSession->GetElement("Nektar/Forcing");
90 if (vForcing)
91 {
92 unsigned int vNumForcingFields = pNumForcingFields;
93 if (!pNumForcingFields)
94 {
95 vNumForcingFields = pFields.size();
96 }
97
98 TiXmlElement *vForce = vForcing->FirstChildElement("FORCE");
99 while (vForce)
100 {
101 std::string vType = vForce->Attribute("TYPE");
102
103 TiXmlElement *vForceParam = vForce;
105 vForceParam, pSession->GetTimeLevel(), false);
106 vForceList.push_back(GetForcingFactory().CreateInstance(
107 vType, pSession, pEquation, pFields, vNumForcingFields,
108 vForceParam));
109
110 vForce = vForce->NextSiblingElement("FORCE");
111 }
112 }
113 return vForceList;
114}
115
117{
118 return m_Forcing;
119}
120
122{
123 return m_Forcing;
124}
125
127 LibUtilities::SessionReaderSharedPtr pSession, std::string pFieldName,
128 Array<OneD, NekDouble> &pArray, const std::string &pFunctionName,
129 NekDouble pTime)
130{
131 ASSERTL0(pSession->DefinesFunction(pFunctionName),
132 "Function '" + pFunctionName + "' does not exist.");
133
135 pSession->GetFunction(pFunctionName, pFieldName);
136
137 EvaluateTimeFunction(pTime, ffunc, pArray);
138}
139
143{
144 // dummy array of zero pts.
145 Array<OneD, NekDouble> x0(pArray.size(), 0.0);
146
147 pEqn->Evaluate(x0, x0, x0, pTime, pArray);
148}
149
152 const LibUtilities::SessionReaderSharedPtr &pSession, std::string pName,
153 bool pCache)
154{
155 if (pCache)
156 {
157 if ((m_sessionFunctions.find(pName) == m_sessionFunctions.end()) ||
158 (m_sessionFunctions[pName]->GetSession() != pSession) ||
159 (m_sessionFunctions[pName]->GetExpansion() != pFields[0]))
160 {
161 m_sessionFunctions[pName] =
163 pSession, pFields[0], pName, pCache);
164 }
165
166 return m_sessionFunctions[pName];
167 }
168 else
169 {
171 new SessionFunction(pSession, pFields[0], pName, pCache));
172 }
173}
174
176 [[maybe_unused]] const Array<OneD, MultiRegions::ExpListSharedPtr> &fields,
177 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &inarray,
178 [[maybe_unused]] Array<OneD, Array<OneD, NekDouble>> &outarray,
179 [[maybe_unused]] const NekDouble &time)
180{
181 ASSERTL0(false, "v_ApplyCoeff not defined");
182}
183} // namespace Nektar::SolverUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
Provides a generic Factory class.
static void GetXMLElementTimeLevel(TiXmlElement *&element, const size_t timeLevel, const bool enableCheck=true)
Get XML elment time level (Parallel-in-Time)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
virtual SOLVER_UTILS_EXPORT void v_PreApply(const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
Definition: Forcing.cpp:53
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:127
static SOLVER_UTILS_EXPORT std::vector< ForcingSharedPtr > Load(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields=0)
Definition: Forcing.cpp:76
SOLVER_UTILS_EXPORT Array< OneD, Array< OneD, NekDouble > > & UpdateForces()
Definition: Forcing.cpp:116
SOLVER_UTILS_EXPORT const Array< OneD, const Array< OneD, NekDouble > > & GetForces()
Definition: Forcing.cpp:121
std::map< std::string, SolverUtils::SessionFunctionSharedPtr > m_sessionFunctions
Map of known SessionFunctions.
Definition: Forcing.h:132
SOLVER_UTILS_EXPORT void EvaluateTimeFunction(LibUtilities::SessionReaderSharedPtr pSession, std::string pFieldName, Array< OneD, NekDouble > &pArray, const std::string &pFunctionName, NekDouble pTime=NekDouble(0))
Definition: Forcing.cpp:126
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:150
SOLVER_UTILS_EXPORT Forcing(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
Constructor.
Definition: Forcing.cpp:47
virtual SOLVER_UTILS_EXPORT void v_ApplyCoeff(const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
Definition: Forcing.cpp:175
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:125
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:41
std::shared_ptr< SessionFunction > SessionFunctionSharedPtr
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825