-
Notifications
You must be signed in to change notification settings - Fork 145
/
data_structures.h
315 lines (243 loc) · 10.4 KB
/
data_structures.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
BSD 3-Clause License
Copyright (c) Alliance for Sustainable Energy, LLC. See also https://github.com/NREL/SAM/blob/develop/LICENSE
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SYSTEM_ADVISOR_MODEL_EXPORTED_MAPS_H
#define SYSTEM_ADVISOR_MODEL_EXPORTED_MAPS_H
#include <string>
#include <unordered_map>
#include <map>
#include <set>
#include <iostream>
#include "equations.h"
#include "variables.h"
#include "variable_graph.h"
/* List of all intermediate and exported data structures with descriptions */
/**
* Each input page consists of a page_info with the sidebar title in the SAM GUI, ui forms which are common
* to the page no matter what selection of variables is active, an exclusive variable which determines what
* subset of ui forms should be shown, and those exclusive ui forms, of which only one is shown at a time.
*/
struct page_info{
std::string sidebar_title;
std::vector<std::string> common_uiforms;
std::string exclusive_var = "";
std::vector<std::string> exclusive_uiforms;
};
/**
* Maps each technology-financial configuration to the ui forms in each SAM page
* e.g. 'MSLF-None': { 'Location and Resource': {'common': Solar Resource Data } ...
*/
extern std::unordered_map<std::string, std::vector<page_info>> SAM_config_to_input_pages;
/**
* Maps each technology-financial configuration to the primary compute_modules required
* e.g. 'Biopower-LCOE Calculator': ('biomass', 'lcoefcr')
*/
extern std::map<std::string, std::vector<std::string>> SAM_config_to_primary_modules;
/**
* Maps each compute_module variable to its index in the info table for each config
*/
extern std::unordered_map<std::string, std::unordered_map<std::string, size_t>> SAM_cmod_to_ssc_index;
/**
* All inputs to primary and secondary compute_modules: includes SSC_INPUT and SSC_INOUT
*/
extern std::unordered_map<std::string, std::vector<std::string>> SAM_cmod_to_inputs;
/**
* All secondary compute_modules: SSC_OUT
*/
extern std::unordered_map<std::string, std::unordered_map<std::string, VarValue>> SAM_cmod_to_outputs;
/**
* Maps each ui form to the config-independent default values found in included input pages
*/
extern std::unordered_map<std::string, std::unordered_map<std::string, VarValue>> SAM_ui_form_to_defaults;
/**
* Maps each configuration to its specific defaults found in defaults text files
*/
extern std::unordered_map<std::string, VarTable> SAM_config_to_defaults;
/**
* Maps each financial or technology option to its long name and description
*/
extern std::map<std::string, std::pair<std::string, std::string>> SAM_option_to_description;
/**
* Manages mapping and memory for ui_form_extractors
*/
class ui_form_extractor_database;
extern ui_form_extractor_database SAM_ui_extracted_db;
/**
* Maps each ui form with the ui input/outputs of each equation. Required for tracking if ui variables
* are changed via equations (becoming ui_outputs) before becoming primary ssc inputs.
*/
struct equation_info{
std::vector<std::string> all_inputs;
std::vector<std::string> all_outputs;
std::vector<std::string> ssc_only_inputs;
std::vector<std::string> ui_only_inputs;
std::string ui_source;
EqnData* eqn_data;
};
extern std::unordered_map<std::string, std::vector<equation_info>> SAM_ui_form_to_eqn_info;
/**
* Mapping how ui variables are transformed by equations and callbacks before being assigned to primary ssc inputs
* across
*/
extern std::unordered_map<std::string, digraph*> SAM_config_to_variable_graph;
/**
* Maps each ui form with its callbacks. ui variables may be ssc
* or only found in the ui. Creating using information from digraph
*/
struct callback_info{
std::vector<std::string> ssc_only_inputs;
std::vector<std::string> ui_only_inputs;
std::vector<std::string> all_outputs;
std::string method_name;
std::string function_name;
std::string ui_source;
};
/// Bookmarks active ui form during UI script parsing
extern std::string active_ui;
extern std::string active_object;
extern std::string active_subobject;
extern std::unordered_map<std::string, std::vector<std::string>> SAM_ui_obj_to_enabled_variables;
static std::unordered_map<std::string, std::string> config_to_cmod_name = {
{"6parsolve", "SixParsolve"},
{"AllEquityPartnershipFlip", "Equpartflip"},
{"Battery", "Battery"},
{"Belpe", "Belpe"},
{"Biopower", "Biomass"},
{"Commercial", "Commercial"},
{"CommunitySolar", "Communitysolar"},
{"CspSubcomponent", "CspSubcomponent"},
{"CustomGenerationProfile", "CustomGenerationProfile"},
{"CustomGenerationBattery", "CustomGenerationBattery"},
{"CustomGenerationPVWattsWindFuelCellBatteryHybrid", "CustomGenerationProfile,Pvwattsv8,Windpower,Fuelcell,Battery"},
{"DishStirling", "Tcsdish"},
{"DSGLIPH", "LinearFresnelDsgIph"},
{"DSLF", "TcslinearFresnel"},
{"EmpiricalTrough", "TcstroughEmpirical"},
{"ETES", "EtesElectricResistance"},
{"FlatPlatePV", "Pvsamv1"},
{"FuelCell", "Fuelcell"},
{"GenericCSPSystem", "TcsgenericSolar"},
{"GeothermalPower", "Geothermal"},
{"HighXConcentratingPV", "Hcpv"},
{"HostDeveloper", "HostDeveloper"},
{"LCOECalculator", "Lcoefcr"},
{"LCOHCalculator", "IphToLcoefcr"},
{"LeveragedPartnershipFlip", "Levpartflip"},
{"MerchantPlant", "MerchantPlant"},
{"MEtidal", "MHKTidal"},
{"MEwave", "MHKWave"},
{"MEwaveBattery", "MHKWave,Battery"},
{"MSLF", "FresnelPhysical"},
{"MSLFIPH", "FresnelPhysicalIph"},
{"MSPT", "TcsmoltenSalt"},
{"MSPTIPH", "MsptIph"},
{"None", "None"},
{"PhotovoltaicWindBatteryHybrid", "Pvsamv1,Windpower,Battery"},
{"PhysicalTrough", "TroughPhysical"},
{"PhysicalTroughIPH", "TroughPhysicalProcessHeat"},
{"PVBattery", "Pvsamv1"},
{"PVWatts", "Pvwattsv8"},
{"PVWattsBattery", "BattWatts"},
{"PVWattsWindBatteryHybrid", "Pvwattsv8,Windpower,Battery"},
{"PVWattsWindFuelCellBatteryHybrid", "Pvwattsv8,Windpower,Fuelcell,Battery"},
{"PTES", "EtesPtes"},
{"Residential", "Residential"},
{"SaleLeaseback", "Saleleaseback"},
{"SCO2", "SCO2"},
{"SingleOwner", "Singleowner"},
{"SolarWaterHeating", "Swh"},
{"StandaloneBattery", "Battery"},
{"ThirdParty", "Thirdpartyownership"},
{"Utilityrate5", "Utilityrate5"},
{"Utilityrateforecast", "Utilityrateforecast"},
{"WindPower", "Windpower"}
};
/**
* Maps each config to the secondary cmod outputs that are used as inputs to the primary cmod
* e.g. 'Wind Power-Residential': {'wind_obos': wind_turbine_rotor_diameter, rotorD)
*/
std::vector<std::string> get_cmod_var_info(std::string cmod_name, std::string which_type);
void load_primary_cmod_inputs();
void load_secondary_cmod_outputs(std::string cmod_name);
page_info& find_page_info_of_variable(std::string name, std::string config);
/// Find which ui form a variable is defined inside for a given config
std::string find_ui_of_variable(std::string name, std::string config);
class ui_form_extractor;
ui_form_extractor* find_ui_of_object(std::string obj, std::string config);
/// Find the config-independent default VarValue for a variable for a given config
VarValue* find_default_from_ui(std::string name, std::string config);
/// Determine if a variable is a primary ssc input by returning cmod name
std::string which_cmod_as_input(std::string name, std::string config);
// SAM config utils
void get_tech_fin_of_config(const std::string& config, std::string& tech, std::string& fin);
// LK parsing utils
std::vector<std::string> split_identity_string(std::string str, size_t n);
static void clear_arg_string(lk::invoke_t& cxt){
size_t pos = cxt.error().find("args");
if (pos == std::string::npos)
return;
else if (pos == 0){
cxt.clear_error();
}
else{
cxt.error(cxt.error().substr(0, pos));
}
}
std::string unescape(const std::string& s);
static bool argument_of_special(std::string& s){
if (s.find("${") == std::string::npos)
return false;
size_t pos1 = s.find("${");
size_t pos2 = s.find("}");
s = s.substr(pos1 + 2, pos2);
s = unescape(s);
return true;
}
static bool argument_of_value(std::string& s){
if (s.find("value(") == std::string::npos)
return false;
s = unescape(s);
size_t pos1 = s.find("value()(");
s = s.substr(pos1 + 8);
pos1 = s.find(")");
s = s.substr(0, pos1);
return true;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
{
os << "(";
for (int i = 0; i < v.size(); ++i) {
os << "'" <<v[i] << "'";
if (i != v.size() - 1)
os << ", ";
}
os << ")";
return os;
}
std::vector<std::string> find_ui_forms_for_config(std::string config_name);
void print_ui_form_to_eqn_variable();
equation_info& find_equation_info_from_edge(edge *edge, std::string config);
#endif //SYSTEM_ADVISOR_MODEL_EXPORTED_MAPS_H