Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes SAM issue 994 #1041

Merged
merged 19 commits into from May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d7865b8
Start on saving analysis period with DataMatrixLifetime mData member
sjanzou May 12, 2022
b9e8f4c
Merge remote-tracking branch 'origin/patch' into SAM_994
sjanzou May 13, 2022
4e2784a
fix broken export config on Windows
sjanzou May 13, 2022
9b2e6e4
Updated test results for branch SAM_994 for Github Actions
sjanzou May 14, 2022
93a3f66
Update to handle analysis period in widgets in DataExchange
sjanzou May 14, 2022
5a67e56
Fix saving and loading issue 994
sjanzou May 15, 2022
71f2e04
Update SAM to handle analysis period dependent widget updating
sjanzou May 16, 2022
c05c395
Fix issue 994 and reset when analysis periods changes
sjanzou May 16, 2022
806c4c3
Merge branch 'patch' into SAM_994
sjanzou May 20, 2022
7c1f585
Fix merge conflicts after Github merge
sjanzou May 20, 2022
acc7f2c
Remove all 'AnalysisPeriod' property settings from callbacks
sjanzou May 20, 2022
56b9912
Update DataLifetimeMatrix widget for changed analysis period
sjanzou May 20, 2022
34fbb1d
Message box for merchant plant analysis period change
cpaulgilman May 20, 2022
96fc59b
Merge branch 'patch' into SAM_994
sjanzou May 21, 2022
123f467
Work on handling multiple analysis period changes per 1041
sjanzou May 21, 2022
b75deeb
Rewrite analysis period changing to handle at variable level
sjanzou May 22, 2022
5244c24
Add analysis period old value for case dependent updates of analysis …
sjanzou May 23, 2022
39a1b22
Merge remote-tracking branch 'origin/patch' into SAM_994
sjanzou May 24, 2022
747a4ab
Updates to go with ssc pull request 822
sjanzou May 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions api/include/SAM_Communitysolar.h
Expand Up @@ -4447,8 +4447,6 @@ extern "C"

SAM_EXPORT double SAM_Communitysolar_Outputs_npv_uti_pbi_income_nget(SAM_table ptr, SAM_error *err);

SAM_EXPORT double SAM_Communitysolar_Outputs_ppa_price_nget(SAM_table ptr, SAM_error *err);

SAM_EXPORT double SAM_Communitysolar_Outputs_present_value_fuel_nget(SAM_table ptr, SAM_error *err);

SAM_EXPORT double SAM_Communitysolar_Outputs_present_value_insandproptax_nget(SAM_table ptr, SAM_error *err);
Expand Down
12 changes: 12 additions & 0 deletions api/include/SAM_Merchantplant.h
Expand Up @@ -2236,6 +2236,14 @@ extern "C"
*/
SAM_EXPORT void SAM_Merchantplant_SystemOutput_gen_purchases_aset(SAM_table ptr, double* arr, int length, SAM_error *err);

/**
* Set gen_without_battery: Electricity to or from the renewable system, without the battery [kW]
* options: None
* constraints: None
* required if: None
*/
SAM_EXPORT void SAM_Merchantplant_SystemOutput_gen_without_battery_aset(SAM_table ptr, double* arr, int length, SAM_error *err);

/**
* Set system_capacity: System nameplate capacity [kW]
* options: None
Expand Down Expand Up @@ -3149,6 +3157,8 @@ extern "C"

SAM_EXPORT double* SAM_Merchantplant_SystemOutput_gen_purchases_aget(SAM_table ptr, int* length, SAM_error *err);

SAM_EXPORT double* SAM_Merchantplant_SystemOutput_gen_without_battery_aget(SAM_table ptr, int* length, SAM_error *err);

SAM_EXPORT double SAM_Merchantplant_SystemOutput_system_capacity_nget(SAM_table ptr, SAM_error *err);

SAM_EXPORT double* SAM_Merchantplant_SystemOutput_system_pre_curtailment_kwac_aget(SAM_table ptr, int* length, SAM_error *err);
Expand Down Expand Up @@ -3347,6 +3357,8 @@ extern "C"

SAM_EXPORT double* SAM_Merchantplant_Outputs_cf_energy_sales_aget(SAM_table ptr, int* length, SAM_error *err);

SAM_EXPORT double* SAM_Merchantplant_Outputs_cf_energy_without_battery_aget(SAM_table ptr, int* length, SAM_error *err);

SAM_EXPORT double* SAM_Merchantplant_Outputs_cf_feddepr_custom_aget(SAM_table ptr, int* length, SAM_error *err);

SAM_EXPORT double* SAM_Merchantplant_Outputs_cf_feddepr_macrs_15_aget(SAM_table ptr, int* length, SAM_error *err);
Expand Down
11 changes: 0 additions & 11 deletions api/modules/SAM_Communitysolar.cpp
Expand Up @@ -11445,17 +11445,6 @@ SAM_EXPORT double SAM_Communitysolar_Outputs_npv_uti_pbi_income_nget(SAM_table p



SAM_EXPORT double SAM_Communitysolar_Outputs_ppa_price_nget(SAM_table ptr, SAM_error *err){
double result;
translateExceptions(err, [&]{
if (!ssc_data_get_number(ptr, "ppa_price", &result))
make_access_error("SAM_Communitysolar", "ppa_price");
});
return result;
}



SAM_EXPORT double SAM_Communitysolar_Outputs_present_value_fuel_nget(SAM_table ptr, SAM_error *err){
double result;
translateExceptions(err, [&]{
Expand Down
30 changes: 30 additions & 0 deletions api/modules/SAM_Merchantplant.cpp
Expand Up @@ -1634,6 +1634,12 @@ SAM_EXPORT void SAM_Merchantplant_SystemOutput_gen_purchases_aset(SAM_table ptr,
});
}

SAM_EXPORT void SAM_Merchantplant_SystemOutput_gen_without_battery_aset(SAM_table ptr, double* arr, int length, SAM_error *err){
translateExceptions(err, [&]{
ssc_data_set_array(ptr, "gen_without_battery", arr, length);
});
}

SAM_EXPORT void SAM_Merchantplant_SystemOutput_system_capacity_nset(SAM_table ptr, double number, SAM_error *err){
translateExceptions(err, [&]{
ssc_data_set_number(ptr, "system_capacity", number);
Expand Down Expand Up @@ -4865,6 +4871,18 @@ SAM_EXPORT double* SAM_Merchantplant_SystemOutput_gen_purchases_aget(SAM_table p



SAM_EXPORT double* SAM_Merchantplant_SystemOutput_gen_without_battery_aget(SAM_table ptr, int* length, SAM_error *err){
double* result = nullptr;
translateExceptions(err, [&]{
result = ssc_data_get_array(ptr, "gen_without_battery", length);
if (!result)
make_access_error("SAM_Merchantplant", "gen_without_battery");
});
return result;
}



SAM_EXPORT double SAM_Merchantplant_SystemOutput_system_capacity_nget(SAM_table ptr, SAM_error *err){
double result;
translateExceptions(err, [&]{
Expand Down Expand Up @@ -5790,6 +5808,18 @@ SAM_EXPORT double* SAM_Merchantplant_Outputs_cf_energy_sales_aget(SAM_table ptr,



SAM_EXPORT double* SAM_Merchantplant_Outputs_cf_energy_without_battery_aget(SAM_table ptr, int* length, SAM_error *err){
double* result = nullptr;
translateExceptions(err, [&]{
result = ssc_data_get_array(ptr, "cf_energy_without_battery", length);
if (!result)
make_access_error("SAM_Merchantplant", "cf_energy_without_battery");
});
return result;
}



SAM_EXPORT double* SAM_Merchantplant_Outputs_cf_feddepr_custom_aget(SAM_table ptr, int* length, SAM_error *err){
double* result = nullptr;
translateExceptions(err, [&]{
Expand Down
9 changes: 5 additions & 4 deletions deploy/runtime/ui/Financial Analysis Parameters.txt
Expand Up @@ -404,9 +404,8 @@ equations{ 'nominal_discount_rate' } = define() {
};


2003
2205
on_load{'Financial Analysis Parameters'} = define() {
on_change{'analysis_period'}();
txt = analysis_period_message();
property('analysis_period_warning','caption',txt);
};
Expand Down Expand Up @@ -446,7 +445,9 @@ function analysis_period_message() {
}

on_change{'analysis_period'} = define() {
txt = analysis_period_message();
if ( financing() == 'Merchant Plant') {
msgbox('Analysis period changed!\nThe merchant plant price data may not match the analysis period. Go to the Revenue page to update the Energy Market or Ancillary Service price data as appropriate.');
}
txt = analysis_period_message();
property('analysis_period_warning','caption',txt);
refresh();
};
Expand Up @@ -347,10 +347,8 @@ Time series cleared capacity and price|Fixed cleared capacity and time series pr
RadioChoice

0
896
737
on_load{'Financial Merchant Plant Ancillary Service 1'} = define() {
property('mp_ancserv1_revenue','AnalysisPeriod',value('analysis_period'));
property('mp_ancserv1_revenue_single','AnalysisPeriod',value('analysis_period'));
update_ancillary_service1_inputs();
};

Expand Down
Expand Up @@ -347,10 +347,8 @@ Time series cleared capacity and price|Fixed cleared capacity and time series pr
RadioChoice

0
896
737
on_load{'Financial Merchant Plant Ancillary Service 2'} = define() {
property('mp_ancserv2_revenue','AnalysisPeriod',value('analysis_period'));
property('mp_ancserv2_revenue_single','AnalysisPeriod',value('analysis_period'));
update_ancillary_service2_inputs();
};

Expand Down
Expand Up @@ -347,10 +347,8 @@ Time series cleared capacity and price|Fixed cleared capacity and time series pr
RadioChoice

0
896
737
on_load{'Financial Merchant Plant Ancillary Service 3'} = define() {
property('mp_ancserv3_revenue','AnalysisPeriod',value('analysis_period'));
property('mp_ancserv3_revenue_single','AnalysisPeriod',value('analysis_period'));
update_ancillary_service3_inputs();
};

Expand Down
Expand Up @@ -347,10 +347,8 @@ Time series cleared capacity and price|Fixed cleared capacity and time series pr
RadioChoice

0
896
737
on_load{'Financial Merchant Plant Ancillary Service 4'} = define() {
property('mp_ancserv4_revenue','AnalysisPeriod',value('analysis_period'));
property('mp_ancserv4_revenue_single','AnalysisPeriod',value('analysis_period'));
update_ancillary_service4_inputs();
};

Expand Down
Expand Up @@ -412,7 +412,7 @@ equations{ '$MIMO$ mp_check_cleared_capacity' } = define() {
return 0;
};

906
737
function update_merchant_plant_inputs()
{
market_enable = value('mp_enable_energy_market_revenue');
Expand All @@ -423,8 +423,6 @@ function update_merchant_plant_inputs()
}

on_load{'Financial Merchant Plant Energy Market Revenue'} = define() {
property('mp_energy_market_revenue','AnalysisPeriod',value('analysis_period'));
property('mp_energy_market_revenue_single','AnalysisPeriod',value('analysis_period'));
update_merchant_plant_inputs();
};

Expand Down
3 changes: 1 addition & 2 deletions deploy/runtime/ui/Grid Outage.txt
Expand Up @@ -847,12 +847,11 @@ Meet critical load during outage time steps (grid outage data required)|Calculat
RadioChoice

0
4593
4528
on_load{'Grid Outage'} = define() {
on_change{'normalize_to_utility_bill'}();
on_change{'crit_load_type'}();
property('crit_load_escalation','FixedLength',${analysis_period});
property( 'grid_outage','AnalysisPeriod', ${analysis_period} );
check_outage_soc();
fuel_cell_check();
critical_load_message();
Expand Down
3 changes: 2 additions & 1 deletion src/case.cpp
Expand Up @@ -273,6 +273,7 @@ bool CaseEvaluator::UpdateLibrary( const wxString &trigger, wxArrayString &chang
Case::Case()
: m_config(0), m_baseCase( this, wxEmptyString ), m_parametric( this )
{
m_oldAnalysisPeriod = 0;
}

Case::~Case()
Expand Down Expand Up @@ -302,7 +303,7 @@ bool Case::Copy( Object *obj )
m_parametric.Copy(rhs->m_parametric);
m_excelExch.Copy(rhs->m_excelExch);
m_stochastic.Copy(rhs->m_stochastic);

m_oldAnalysisPeriod = rhs->m_oldAnalysisPeriod;
m_graphs.clear();
for( size_t i=0;i<rhs->m_graphs.size();i++ )
m_graphs.push_back( rhs->m_graphs[i] );
Expand Down
4 changes: 4 additions & 0 deletions src/case.h
Expand Up @@ -175,6 +175,9 @@ class Case : public Object

wxString GetLastError() { return m_lastError; };

// testing analysis period changes
size_t m_oldAnalysisPeriod;

private:
wxString m_lastError;
std::vector<CaseEventListener*> m_listeners;
Expand All @@ -199,6 +202,7 @@ class Case : public Object
std::vector<Graph> m_graphs;
std::vector<Uncertainties> m_uncertainties;
StringHash m_perspective;

};

class CaseEvaluator : public EqnEvaluator
Expand Down
42 changes: 41 additions & 1 deletion src/casewin.cpp
Expand Up @@ -698,16 +698,56 @@ void CaseWindow::OnCaseEvent( Case *, CaseEvent &evt )
{
if ( evt.GetType() == CaseEvent::VARS_CHANGED )
{
// "fix" for controls dependent on analysis period
size_t analysis_period = 0;
VarValue* vv_ap = m_case->Values().Get("analysis_period");
if (vv_ap) analysis_period = vv_ap->Integer();

// update UI objects for the ones that changed
wxArrayString &list = evt.GetVars();

/* Recursion error
// test to update objects and then variables when generating code without reopening objects
// if analysis period has changed then update analysis dependent ui objects and variables
if (m_case->m_oldAnalysisPeriod > 0 && m_case->m_oldAnalysisPeriod != analysis_period) {
//FindObjectsOfType("DataLifetimeMatrix");


for (size_t i = 0; i < m_pageGroups.size(); i++) {
m_currentGroup = m_pageGroups[i];
for (size_t i = 0; i < m_currentGroup->Pages.size(); i++)
for (size_t j = 0; j < m_currentGroup->Pages[i].size(); j++)
if (wxUIFormData* form = m_forms.Lookup(m_currentGroup->Pages[i][j].Name)) {
auto vpobj = form->GetObjects();
for (auto pobj : vpobj) {
if (pobj->GetTypeName() == "DataLifetimeMatrix") {
// list.Add(pobj->GetName());
VarValue* vv = m_case->Values().Get(pobj->GetName());
if (pobj && vv) {
if (SwitchToInputPage(m_currentGroup->SideBarLabel)) {

//ActiveInputPage::DataExchange(pobj, *vv, ActiveInputPage::VAR_TO_OBJ, analysis_period, m_case->m_oldAnalysisPeriod);
ActiveInputPage* ipage = 0;
wxUIObject* obj = FindActiveObject(pobj->GetName(), &ipage); // sets object value in initialize
if (ipage && obj && vv)
ipage->DataExchange(obj, *vv, ActiveInputPage::OBJ_TO_VAR, analysis_period, m_case->m_oldAnalysisPeriod);
}
}
}
}
}
}
}
*/

for( size_t i=0;i<list.size();i++ )
{
ActiveInputPage *ipage = 0;
wxUIObject *obj = FindActiveObject( list[i], &ipage );
VarValue *vv = m_case->Values().Get( list[i] );
if ( ipage && obj && vv )
{
ipage->DataExchange( obj, *vv, ActiveInputPage::VAR_TO_OBJ );
ipage->DataExchange( obj, *vv, ActiveInputPage::VAR_TO_OBJ, analysis_period, m_case->m_oldAnalysisPeriod );

// lookup and run any callback functions.
if ( lk::node_t *root = m_case->QueryCallback( "on_change", obj->GetName() ) )
Expand Down
19 changes: 15 additions & 4 deletions src/inputpage.cpp
Expand Up @@ -188,6 +188,12 @@ void ActiveInputPage::Initialize()
VarInfoLookup &vdb = GetVariables();
VarTable &vals = GetValues();

// "fix" for controls dependent on analysis period
size_t analysis_period = 0;
VarValue* vv_ap = m_case->Values().Get("analysis_period");
if (vv_ap) analysis_period = vv_ap->Integer();


std::vector<wxUIObject*> objs = m_formData->GetObjects();
for( size_t i=0;i<objs.size();i++ )
{
Expand Down Expand Up @@ -255,7 +261,7 @@ void ActiveInputPage::Initialize()
}

if ( VarValue *vval = vals.Get( name ) )
DataExchange( objs[i], *vval, VAR_TO_OBJ );
DataExchange( objs[i], *vval, VAR_TO_OBJ, analysis_period, m_case->m_oldAnalysisPeriod );
}
}

Expand Down Expand Up @@ -392,6 +398,9 @@ void ActiveInputPage::OnNativeEvent( wxCommandEvent &evt )
// other UI objects (calculated ones) need to be updated
if( VarValue *vval = GetValues().Get( obj->GetName() ) )
{
// tracking analysis period changes to update analysis period dependent widgets
if (obj->GetName() == "analysis_period")
m_case->m_oldAnalysisPeriod = vval->Integer();
if ( DataExchange( obj, *vval, OBJ_TO_VAR ) )
{
wxLogStatus( "Variable " + obj->GetName() + " changed by user interaction, case notified." );
Expand All @@ -417,7 +426,7 @@ void ActiveInputPage::OnNativeEvent( wxCommandEvent &evt )
}
}

bool ActiveInputPage::DataExchange( wxUIObject *obj, VarValue &val, DdxDir dir )
bool ActiveInputPage::DataExchange( wxUIObject *obj, VarValue &val, DdxDir dir, size_t AnalysisPeriod, size_t AnalysisPeriodOld)
{
if ( wxNumericCtrl *num = obj->GetNative<wxNumericCtrl>() )
{
Expand Down Expand Up @@ -530,8 +539,10 @@ bool ActiveInputPage::DataExchange( wxUIObject *obj, VarValue &val, DdxDir dir )
}
else if (AFDataLifetimeMatrixButton *dl = obj->GetNative<AFDataLifetimeMatrixButton>())
{
if (dir == VAR_TO_OBJ) dl->Set(val.Matrix());
else val.Set(dl->Get());
if (dir == VAR_TO_OBJ) {
dl->Set(val.Matrix(), AnalysisPeriod, AnalysisPeriodOld);
}
else val.Set(dl->Get());
}
else if (AFStringArrayButton *sa = obj->GetNative<AFStringArrayButton>())
{
Expand Down
2 changes: 1 addition & 1 deletion src/inputpage.h
Expand Up @@ -91,7 +91,7 @@ class ActiveInputPage : public wxPanel

// data exchange from UI object to data value and vice versa
enum DdxDir { OBJ_TO_VAR, VAR_TO_OBJ };
static bool DataExchange( wxUIObject *obj, VarValue &val, DdxDir dir );
static bool DataExchange( wxUIObject *obj, VarValue &val, DdxDir dir, size_t AnalysisPeriod = 0, size_t AnalysisPeriodOld = 0);

protected:

Expand Down