Nektar++
Forcing.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Forcing.h
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 advection.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_SOLVERUTILS_FORCING
36#define NEKTAR_SOLVERUTILS_FORCING
37
38#include <string>
39
45
46namespace Nektar::SolverUtils
47{
48// Forward declaration
49class Forcing;
50class EquationSystem;
51
52/// A shared pointer to an EquationSystem object
53SOLVER_UTILS_EXPORT typedef std::shared_ptr<Forcing> ForcingSharedPtr;
54
55/// Declaration of the forcing factory
58 const std::weak_ptr<EquationSystem> &,
59 const Array<OneD, MultiRegions::ExpListSharedPtr> &, const unsigned int &,
60 const TiXmlElement *>
62
63/// Declaration of the forcing factory singleton
65
66/**
67 * @class Forcing
68 * @brief Defines a forcing term to be explicitly applied.
69 */
71{
72public:
73 /// Initialise the forcing object
76 const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
77 {
78 v_InitObject(pFields, pNumForcingFields, pForce);
79 }
80
81 /// Apply the forcing
84 const Array<OneD, Array<OneD, NekDouble>> &inarray,
85 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time)
86 {
87 v_Apply(fields, inarray, outarray, time);
88 }
89
90 /// Change the advection velocity before applying the forcing.
91 /// For example, subtracting the frame velocity from the
92 /// advection velocity in the MovingRefercenceFrame.
95 const Array<OneD, Array<OneD, NekDouble>> &inarray,
96 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time)
97 {
98 v_PreApply(fields, inarray, outarray, time);
99 }
100
101 /// Apply the forcing
104 const Array<OneD, Array<OneD, NekDouble>> &inarray,
105 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time)
106 {
107 v_ApplyCoeff(fields, inarray, outarray, time);
108 }
109
110 SOLVER_UTILS_EXPORT static std::vector<ForcingSharedPtr> Load(
112 const std::weak_ptr<EquationSystem> &pEquation,
114 const unsigned int &pNumForcingFields = 0);
115
117 GetForces();
118
120
121protected:
122 /// Session reader
124 /// Weak pointer to equation system using this forcing
125 const std::weak_ptr<EquationSystem> m_equ;
126 /// Evaluated forcing function
128 /// Number of variables
130 /// Map of known SessionFunctions
131 std::map<std::string, SolverUtils::SessionFunctionSharedPtr>
133
134 /// Constructor
137 const std::weak_ptr<EquationSystem> &pEquation);
138
139 SOLVER_UTILS_EXPORT virtual ~Forcing() = default;
140
143 const unsigned int &pNumForcingFields, const TiXmlElement *pForce) = 0;
144
147 const Array<OneD, Array<OneD, NekDouble>> &inarray,
149 const NekDouble &time) = 0;
150
151 SOLVER_UTILS_EXPORT virtual void v_PreApply(
153 const Array<OneD, Array<OneD, NekDouble>> &inarray,
154 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time);
155
158 const Array<OneD, Array<OneD, NekDouble>> &inarray,
159 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time);
160
161 /// Get a SessionFunction by name
165 std::string pName, bool pCache = false);
166
168 LibUtilities::SessionReaderSharedPtr pSession, std::string pFieldName,
169 Array<OneD, NekDouble> &pArray, const std::string &pFunctionName,
170 NekDouble pTime = NekDouble(0));
171
173 const NekDouble pTime, const LibUtilities::EquationSharedPtr &pEqn,
174 Array<OneD, NekDouble> &pArray);
175};
176} // namespace Nektar::SolverUtils
177
178#endif
#define SOLVER_UTILS_EXPORT
Provides a generic Factory class.
Defines a forcing term to be explicitly applied.
Definition: Forcing.h:71
virtual SOLVER_UTILS_EXPORT 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)=0
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
int m_NumVariable
Number of variables.
Definition: Forcing.h:129
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:127
virtual SOLVER_UTILS_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)=0
SOLVER_UTILS_EXPORT void InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Initialise the forcing object.
Definition: Forcing.h:74
SOLVER_UTILS_EXPORT void Apply(const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
Apply the forcing.
Definition: Forcing.h:82
virtual SOLVER_UTILS_EXPORT ~Forcing()=default
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 void PreApply(const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
Change the advection velocity before applying the forcing. For example, subtracting the frame velocit...
Definition: Forcing.h:93
const std::weak_ptr< EquationSystem > m_equ
Weak pointer to equation system using this forcing.
Definition: Forcing.h:125
SOLVER_UTILS_EXPORT void ApplyCoeff(const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
Apply the forcing.
Definition: Forcing.h:102
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
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:123
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:125
LibUtilities::NekFactory< std::string, Forcing, const LibUtilities::SessionReaderSharedPtr &, const std::weak_ptr< EquationSystem > &, const Array< OneD, MultiRegions::ExpListSharedPtr > &, const unsigned int &, const TiXmlElement * > ForcingFactory
Declaration of the forcing factory.
Definition: Forcing.h:61
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:41
std::shared_ptr< SessionFunction > SessionFunctionSharedPtr
SOLVER_UTILS_EXPORT typedef std::shared_ptr< Forcing > ForcingSharedPtr
A shared pointer to an EquationSystem object.
Definition: Forcing.h:53
double NekDouble