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
48
49namespace Nektar
50{
51namespace FieldUtils
52{
53template <typename T> class Interpolator;
54}
55
56namespace SolverUtils
57{
58
60{
61public:
62 /// Representation of a FUNCTION defined in the session xml file.
65 const MultiRegions::ExpListSharedPtr &field, std::string functionName,
66 bool toCache = false);
67
68 /// Evaluates a function defined in the xml session file at each quadrature
69 /// point.
72 const NekDouble pTime = 0.0, const int domain = 0);
73
74 /// Evaluates a function defined in the xml session file at each quadrature
75 /// point.
77 std::vector<std::string> pFieldNames,
79 const NekDouble &pTime = 0.0, const int domain = 0);
80
81 /// Evaluates a function defined in the xml session file at each quadrature
82 /// point.
84 std::vector<std::string> pFieldNames,
86 const NekDouble &pTime = 0.0, const int domain = 0);
87
88 // Evaluates a function defined in the xml session file at each quadrature
89 // point.
90 SOLVER_UTILS_EXPORT void Evaluate(std::string pFieldName,
92 const NekDouble &pTime = 0.0,
93 const int domain = 0);
94
95 /// Provide a description of a function for a given field name.
96 SOLVER_UTILS_EXPORT std::string Describe(std::string pFieldName,
97 const int domain = 0);
98
100 {
101 return m_session;
102 }
103
105 {
106 return m_field;
107 }
108
109private:
110 /// The session reader
112 /// The expansion we want to evaluate this function for
114 // Name of this function
115 std::string m_name;
116 /// Store resulting arrays (and interpolators)
118 /// Last time the cache for this variable & domain combo was updated
119 std::map<std::pair<std::string, int>, NekDouble> m_lastCached;
120 /// Interpolator for pts file input for a variable & domain combination
121 std::map<std::string, FieldUtils::Interpolator<
122 std::vector<MultiRegions::ExpListSharedPtr>>>
124 /// Cached result arrays
125 std::map<std::pair<std::string, int>, Array<OneD, NekDouble>> m_arrays;
126
127 // Evaluates a function from expression
128 SOLVER_UTILS_EXPORT void EvaluateExp(std::string pFieldName,
130 const NekDouble &pTime = 0.0,
131 const int domain = 0);
132
133 // Evaluates a function from fld file
134 SOLVER_UTILS_EXPORT void EvaluateFld(std::string pFieldName,
136 const NekDouble &pTime = 0.0,
137 const int domain = 0);
138
139 /// Evaluates a function from pts file
140 SOLVER_UTILS_EXPORT void EvaluatePts(std::string pFieldName,
142 const NekDouble &pTime = 0.0,
143 const int domain = 0);
144
145 SOLVER_UTILS_EXPORT void PrintProgressbar(const int position,
146 const int goal) const
147 {
148 LibUtilities::PrintProgressbar(position, goal, "Interpolating");
149 }
150};
151
152typedef std::shared_ptr<SessionFunction> SessionFunctionSharedPtr;
154} // namespace SolverUtils
155} // namespace Nektar
156
157#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:65
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
static SessionFunctionSharedPtr NullSessionFunction
std::shared_ptr< SessionFunction > SessionFunctionSharedPtr
double NekDouble