WARPXM v1.10.0
Loading...
Searching...
No Matches
wmunstructuredapp.h
Go to the documentation of this file.
1#ifndef __wmunstructuredapp__h__
2#define __wmunstructuredapp__h__
3
4// STD libraries
5#include <iostream>
6#include <vector>
7
8// WarpX includes
9#include "lib/wxcryptset.h"
10
11// WarpM includes
14
15// Used for generating strings from cl code snippits
16#define STRINGIFY_CL_CODE(src) ("\n" + std::string(#src) + "\n")
17
18// These are placement identifiers
19enum
20{
25 WMCALLTYPE_EXTERNAL = 1 << 4
26};
27
29
31{
32public:
34
36
37 virtual void setup(const WxCryptSet& wxc);
38
39 // This generates the string for the function call
40 virtual std::string generateSourceCall(const WmUnstructuredEquationSet& eqSet,
41 unsigned int callType) const = 0;
42
43 // This generates the source code for the entire app
44 virtual std::string generateSource(const WmUnstructuredEquationSet& eqSet) const = 0;
45
46 // Used to grab variables required by app
47 virtual void consolidateVariables(variableList_t& varList, unsigned int callType);
48
49 typedef std::map<std::string, std::string> replaceMap_t;
50 static void replaceKeys(std::string& string, const replaceMap_t& map);
51
52protected:
53 std::string
54 fillAllocationAtIndex(const std::string& indentation,
55 const WmKernelVariable* kVars[],
56 int numKVars,
57 int startIndex = 0,
58 const std::string& allocationName = "pPVS->rA") const;
59
60 template<typename T> T readVal(const WxCryptSet& wxc, const std::string& name) const
61 {
62 return wxc.get<T>(name);
63 }
64
65 template<typename T>
66 std::vector<T> readVec(const WxCryptSet& wxc, const std::string& name) const
67 {
68 return wxc.getVec<T>(name);
69 }
70
71 template<typename T>
72 T readVal(const WxCryptSet& wxc, const std::string& name, const T& defaultValue) const
73 {
74 if (wxc.has(name))
75 {
76 return wxc.get<T>(name);
77 }
78 else
79 {
80 return defaultValue;
81 }
82 }
83
84 static void indent(std::string& indentation)
85 {
86 indentation += "\t";
87 }
88
89 static void outdent(std::string& indentation)
90 {
91 unsigned found = indentation.find_last_of("\t");
92 indentation = indentation.substr(0, found);
93 }
94
95 template<typename T> static std::string toStr(const T& val)
96 {
97 std::stringstream ss;
98 ss << val;
99 return ss.str();
100 }
101
102 // variables required by flux apps
103 variableList_t _fluxVariables;
104
105 // variables required by source apps
106 variableList_t _sourceVariables;
107
108 // variables required by external apps
109 variableList_t _externalVariables;
110
111 // Allocations required by all apps (private variable set)
112 variableList_t _privateVariables;
113
114private:
115 WmUnstructuredApp& operator=(const WmUnstructuredApp& var);
117};
118
119#endif // __wmunstructuredapp__h__
Definition: wmunstructuredapp.h:31
variableList_t _fluxVariables
Definition: wmunstructuredapp.h:103
T readVal(const WxCryptSet &wxc, const std::string &name) const
Definition: wmunstructuredapp.h:60
std::string fillAllocationAtIndex(const std::string &indentation, const WmKernelVariable *kVars[], int numKVars, int startIndex=0, const std::string &allocationName="pPVS->rA") const
variableList_t _sourceVariables
Definition: wmunstructuredapp.h:106
virtual void setup(const WxCryptSet &wxc)
virtual void consolidateVariables(variableList_t &varList, unsigned int callType)
std::map< std::string, std::string > replaceMap_t
Definition: wmunstructuredapp.h:49
static void replaceKeys(std::string &string, const replaceMap_t &map)
std::vector< T > readVec(const WxCryptSet &wxc, const std::string &name) const
Definition: wmunstructuredapp.h:66
static std::string toStr(const T &val)
Definition: wmunstructuredapp.h:95
virtual std::string generateSourceCall(const WmUnstructuredEquationSet &eqSet, unsigned int callType) const =0
variableList_t _privateVariables
Definition: wmunstructuredapp.h:112
virtual std::string generateSource(const WmUnstructuredEquationSet &eqSet) const =0
static void indent(std::string &indentation)
Definition: wmunstructuredapp.h:84
variableList_t _externalVariables
Definition: wmunstructuredapp.h:109
virtual ~WmUnstructuredApp()
T readVal(const WxCryptSet &wxc, const std::string &name, const T &defaultValue) const
Definition: wmunstructuredapp.h:72
static void outdent(std::string &indentation)
Definition: wmunstructuredapp.h:89
Definition: wmunstructuredequationset.h:19
Definition: wmvariableparser.h:77
bool has(const std::string &name) const
Returns true if the 'name' exists in the crypt.
std::vector< VALUETYPE > getVec(const std::string &name) const
Retrieve list of values associated with name.
Definition: wxcrypt.h:162
VALUETYPE get(const std::string &name) const
Retrieve the value associated with name.
Definition: wxcrypt.h:80
WxCryptSet extends WxCrypt by providing, in addition to name-value pairs, an set of named WxCryptSets...
Definition: wxcryptset.h:35
@ WMCALLTYPE_INVALID
Definition: wmunstructuredapp.h:21
@ WMCALLTYPE_EXTERNAL
Definition: wmunstructuredapp.h:25
@ WMCALLTYPE_PRIVATE
Definition: wmunstructuredapp.h:22
@ WMCALLTYPE_FLUX
Definition: wmunstructuredapp.h:23
@ WMCALLTYPE_SOURCE
Definition: wmunstructuredapp.h:24