Nektar++
SessionFunction.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: SessionFunction.h
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2017 Kilian Lackhove
10// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
11// Department of Aeronautics, Imperial College London (UK), and Scientific
12// Computing and Imaging Institute, University of Utah (USA).
13//
14// Permission is hereby granted, free of charge, to any person obtaining a
15// copy of this software and associated documentation files (the "Software"),
16// to deal in the Software without restriction, including without limitation
17// the rights to use, copy, modify, merge, publish, distribute, sublicense,
18// and/or sell copies of the Software, and to permit persons to whom the
19// Software is furnished to do so, subject to the following conditions:
20//
21// The above copyright notice and this permission notice shall be included
22// in all copies or substantial portions of the Software.
23//
24// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30// DEALINGS IN THE SOFTWARE.
31//
32// Description: Session Function
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#ifndef NEKTAR_SOLVERUTILS_SESSIONFUNCTION_H
37#define NEKTAR_SOLVERUTILS_SESSIONFUNCTION_H
38
49
50namespace Nektar
51{
52namespace FieldUtils
53{
54template <typename T> class Interpolator;
55}
56
57namespace SolverUtils
58{
59
61{
62public:
63 /// Representation of a FUNCTION defined in the session xml file.
66 const MultiRegions::ExpListSharedPtr &field, std::string functionName,
67 bool toCache = false);
68
69 /// Evaluates a function defined in the xml session file at each quadrature
70 /// point.
73 const NekDouble pTime = 0.0, const int domain = 0);
74
75 /// Evaluates a function defined in the xml session file at each quadrature
76 /// point.
78 std::vector<std::string> pFieldNames,
80 const NekDouble &pTime = 0.0, const int domain = 0);
81
82 /// Evaluates a function defined in the xml session file at each quadrature
83 /// point.
85 std::vector<std::string> pFieldNames,
87 const NekDouble &pTime = 0.0, const int domain = 0);
88
89 // Evaluates a function defined in the xml session file at each quadrature
90 // point.
91 SOLVER_UTILS_EXPORT void Evaluate(std::string pFieldName,
93 const NekDouble &pTime = 0.0,
94 const int domain = 0);
95
96 /// Provide a description of a function for a given field name.
97 SOLVER_UTILS_EXPORT std::string Describe(std::string pFieldName,
98 const int domain = 0);
99
101 {
102 return m_session;
103 }
104
106 {
107 return m_field;
108 }
109
110private:
111 /// The session reader
113 /// The expansion we want to evaluate this function for
115 // Name of this function
116 std::string m_name;
117 /// Store resulting arrays (and interpolators)
119 /// Last time the cache for this variable & domain combo was updated
120 std::map<std::pair<std::string, int>, NekDouble> m_lastCached;
121 /// Interpolator for pts file input for a variable & domain combination
122 std::map<std::string, FieldUtils::Interpolator<
123 std::vector<MultiRegions::ExpListSharedPtr>>>
125 /// Cached result arrays
126 std::map<std::pair<std::string, int>, Array<OneD, NekDouble>> m_arrays;
127
128 // Evaluates a function from expression
129 SOLVER_UTILS_EXPORT void EvaluateExp(std::string pFieldName,
131 const NekDouble &pTime = 0.0,
132 const int domain = 0);
133
134 // Evaluates a function from fld file
135 SOLVER_UTILS_EXPORT void EvaluateFld(std::string pFieldName,
137 const NekDouble &pTime = 0.0,
138 const int domain = 0);
139
140 /// Evaluates a function from pts file
141 SOLVER_UTILS_EXPORT void EvaluatePts(std::string pFieldName,
143 const NekDouble &pTime = 0.0,
144 const int domain = 0);
145
146 SOLVER_UTILS_EXPORT void PrintProgressbar(const int position,
147 const int goal) const
148 {
149 LibUtilities::PrintProgressbar(position, goal, "Interpolating");
150 }
151};
152
153typedef std::shared_ptr<SessionFunction> SessionFunctionSharedPtr;
155} // namespace SolverUtils
156} // namespace Nektar
157
158#endif
#define SOLVER_UTILS_EXPORT
A class that contains algorithms for interpolation between pts fields, expansions and different meshe...
std::map< std::string, FieldUtils::Interpolator< std::vector< MultiRegions::ExpListSharedPtr > > > m_interpolators
Interpolator for pts file input for a variable & domain combination.
MultiRegions::ExpListSharedPtr m_field
The expansion we want to evaluate this function for.
bool m_toCache
Store resulting arrays (and interpolators)
std::map< std::pair< std::string, int >, Array< OneD, NekDouble > > m_arrays
Cached result arrays.
SOLVER_UTILS_EXPORT void EvaluateFld(std::string pFieldName, Array< OneD, NekDouble > &pArray, const NekDouble &pTime=0.0, const int domain=0)
SOLVER_UTILS_EXPORT void Evaluate(Array< OneD, Array< OneD, NekDouble > > &pArray, const NekDouble pTime=0.0, const int domain=0)
Evaluates a function defined in the xml session file at each quadrature point.
SOLVER_UTILS_EXPORT void EvaluatePts(std::string pFieldName, Array< OneD, NekDouble > &pArray, const NekDouble &pTime=0.0, const int domain=0)
Evaluates a function from pts file.
SOLVER_UTILS_EXPORT SessionFunction(const LibUtilities::SessionReaderSharedPtr &session, const MultiRegions::ExpListSharedPtr &field, std::string functionName, bool toCache=false)
Representation of a FUNCTION defined in the session xml file.
SOLVER_UTILS_EXPORT void PrintProgressbar(const int position, const int goal) const
std::map< std::pair< std::string, int >, NekDouble > m_lastCached
Last time the cache for this variable & domain combo was updated.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
SOLVER_UTILS_EXPORT std::string Describe(std::string pFieldName, const int domain=0)
Provide a description of a function for a given field name.
SOLVER_UTILS_EXPORT const LibUtilities::SessionReaderSharedPtr & GetSession()
SOLVER_UTILS_EXPORT void EvaluateExp(std::string pFieldName, Array< OneD, NekDouble > &pArray, const NekDouble &pTime=0.0, const int domain=0)
SOLVER_UTILS_EXPORT const MultiRegions::ExpListSharedPtr & GetExpansion()
int PrintProgressbar(const int position, const int goal, const std::string message, int lastprogress=-1)
Prints a progressbar.
Definition: Progressbar.hpp:67
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
static SessionFunctionSharedPtr NullSessionFunction
std::shared_ptr< SessionFunction > SessionFunctionSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble