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 
47 #include <MultiRegions/ExpList.h>
49 
50 namespace Nektar
51 {
52 namespace FieldUtils
53 {
54 class Interpolator;
55 }
56 
57 namespace SolverUtils
58 {
59 
61 {
62 public:
63  /// Representation of a FUNCTION defined in the session xml file.
66  const MultiRegions::ExpListSharedPtr &field,
67  std::string functionName,
68  bool toCache = false);
69 
70  /// Evaluates a function defined in the xml session file at each quadrature point.
71  SOLVER_UTILS_EXPORT void Evaluate(
73  const NekDouble pTime = 0.0,
74  const int domain = 0);
75 
76  /// Evaluates a function defined in the xml session file at each quadrature point.
77  SOLVER_UTILS_EXPORT void Evaluate(
78  std::vector<std::string> pFieldNames,
80  const NekDouble &pTime = 0.0,
81  const int domain = 0);
82 
83  /// Evaluates a function defined in the xml session file at each quadrature point.
84  SOLVER_UTILS_EXPORT void Evaluate(
85  std::vector<std::string> pFieldNames,
87  const NekDouble &pTime = 0.0,
88  const int domain = 0);
89 
90  // Evaluates a function defined in the xml session file at each quadrature point.
91  SOLVER_UTILS_EXPORT void Evaluate(std::string pFieldName,
92  Array<OneD, NekDouble> &pArray,
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 
110 private:
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)
118  bool m_toCache;
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> m_interpolators;
123  /// Cached result arrays
124  std::map<std::pair<std::string, int>, Array<OneD, NekDouble> > m_arrays;
125 
126  // Evaluates a function from expression
127  SOLVER_UTILS_EXPORT void EvaluateExp(std::string pFieldName,
128  Array<OneD, NekDouble> &pArray,
129  const NekDouble &pTime = 0.0,
130  const int domain = 0);
131 
132  // Evaluates a function from fld file
133  SOLVER_UTILS_EXPORT void EvaluateFld(std::string pFieldName,
134  Array<OneD, NekDouble> &pArray,
135  const NekDouble &pTime = 0.0,
136  const int domain = 0);
137 
138  /// Evaluates a function from pts file
139  SOLVER_UTILS_EXPORT void EvaluatePts(std::string pFieldName,
140  Array<OneD, NekDouble> &pArray,
141  const NekDouble &pTime = 0.0,
142  const int domain = 0);
143 
144  SOLVER_UTILS_EXPORT void PrintProgressbar(const int position,
145  const int goal) const
146  {
147  LibUtilities::PrintProgressbar(position, goal, "Interpolating");
148  }
149 };
150 
151 typedef std::shared_ptr<SessionFunction> SessionFunctionSharedPtr;
152 static SessionFunctionSharedPtr NullSessionFunction;
153 }
154 }
155 
156 #endif
bool m_toCache
Store resulting arrays (and interpolators)
std::map< std::pair< std::string, int >, NekDouble > m_lastCached
Last time the cache for this variable & domain combo was updated.
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< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
SOLVER_UTILS_EXPORT void PrintProgressbar(const int position, const int goal) const
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
std::map< std::pair< std::string, int >, Array< OneD, NekDouble > > m_arrays
Cached result arrays.
double NekDouble
SOLVER_UTILS_EXPORT const LibUtilities::SessionReaderSharedPtr & GetSession()
#define SOLVER_UTILS_EXPORT
std::map< std::string, FieldUtils::Interpolator > m_interpolators
Interpolator for pts file input for a variable & domain combination.
std::shared_ptr< SessionFunction > SessionFunctionSharedPtr
static SessionFunctionSharedPtr NullSessionFunction
MultiRegions::ExpListSharedPtr m_field
The expansion we want to evaluate this function for.
SOLVER_UTILS_EXPORT const MultiRegions::ExpListSharedPtr & GetExpansion()
std::shared_ptr< SessionReader > SessionReaderSharedPtr