Skip to content

Commit

Permalink
calc and report timestep solution duration
Browse files Browse the repository at this point in the history
  • Loading branch information
tyneises committed Jan 13, 2025
1 parent cb9fc58 commit ffc7c9e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ssc/cmod_trough_physical_iph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ static var_info _cm_vtab_trough_physical_iph[] = {

// Simulation Kernel
{ SSC_OUTPUT, SSC_ARRAY, "time_hr", "Time at end of timestep", "hr", "", "solver", "sim_type=1", "", "" },

{ SSC_OUTPUT, SSC_ARRAY, "timestep_sim_duration", "Simulation duration of timestep", "s", "", "solver", "sim_type=1", "", "" },

// Weather Reader
{ SSC_OUTPUT, SSC_ARRAY, "month", "Resource Month", "", "", "weather", "sim_type=1", "", "" },
{ SSC_OUTPUT, SSC_ARRAY, "hour_day", "Resource Hour of Day", "", "", "weather", "sim_type=1", "", "" },
Expand Down Expand Up @@ -1747,6 +1748,7 @@ class cm_trough_physical_iph : public compute_module
{
// Simulation Kernel
csp_solver.mc_reported_outputs.assign(C_csp_solver::C_solver_outputs::TIME_FINAL, allocate("time_hr", n_steps_fixed), n_steps_fixed);
csp_solver.mc_reported_outputs.assign(C_csp_solver::C_solver_outputs::SIM_DURATION, allocate("timestep_sim_duration", n_steps_fixed), n_steps_fixed);
// Weather reader
csp_solver.mc_reported_outputs.assign(C_csp_solver::C_solver_outputs::MONTH, allocate("month", n_steps_fixed), n_steps_fixed);
csp_solver.mc_reported_outputs.assign(C_csp_solver::C_solver_outputs::HOUR_DAY, allocate("hour_day", n_steps_fixed), n_steps_fixed);
Expand Down
8 changes: 8 additions & 0 deletions tcs/csp_solver_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ static C_csp_reported_outputs::S_output_info S_solver_output_info[] =
// Ouputs that are NOT reported as weighted averages
// Simulation
{C_csp_solver::C_solver_outputs::TIME_FINAL, C_csp_reported_outputs::TS_LAST}, //[hr]
{C_csp_solver::C_solver_outputs::SIM_DURATION, C_csp_reported_outputs::SUMMED}, //[s]
// Weather Reader
{ C_csp_solver::C_solver_outputs::MONTH, C_csp_reported_outputs::TS_1ST}, //[-] Month of year
{ C_csp_solver::C_solver_outputs::HOUR_DAY, C_csp_reported_outputs::TS_1ST}, //[hr] hour of day
Expand Down Expand Up @@ -597,6 +598,8 @@ void C_csp_solver::Ssimulate(C_csp_solver::S_sim_setup & sim_setup)

while( mc_kernel.mc_sim_info.ms_ts.m_time <= mc_kernel.get_sim_setup()->m_sim_time_end )
{
std::clock_t clock_start = std::clock();

// Report simulation progress
double calc_frac_current = (mc_kernel.mc_sim_info.ms_ts.m_time - mc_kernel.get_sim_setup()->m_sim_time_start) / (mc_kernel.get_sim_setup()->m_sim_time_end - mc_kernel.get_sim_setup()->m_sim_time_start);
if( calc_frac_current > progress_msg_frac_current )
Expand Down Expand Up @@ -1126,6 +1129,11 @@ void C_csp_solver::Ssimulate(C_csp_solver::S_sim_setup & sim_setup)
mc_pc_out_solver.m_q_dot_htf -
mc_tes_outputs.m_q_dot_ch_from_htf) / m_cycle_q_dot_des; //[-]

std::clock_t clock_end = std::clock();
double timestep_cpu_run_time = (clock_end - clock_start) / (double)CLOCKS_PER_SEC; //[s]

mc_reported_outputs.value(C_solver_outputs::SIM_DURATION, timestep_cpu_run_time);

mc_reported_outputs.value(C_solver_outputs::ERR_M_DOT, m_dot_bal_max);
mc_reported_outputs.value(C_solver_outputs::ERR_Q_DOT, q_dot_bal);

Expand Down
1 change: 1 addition & 0 deletions tcs/csp_solver_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ class C_csp_solver
// Ouputs that are NOT reported as weighted averages
// Simulation
TIME_FINAL, //[hr] Simulation timestep
SIM_DURATION, //[s] Timestep simulation duration
// Weather Reader
MONTH, //[-] Month of year
HOUR_DAY, //[hr] hour of day
Expand Down
16 changes: 14 additions & 2 deletions tcs/csp_solver_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void C_csp_reported_outputs::C_output::set_m_is_ts_weighted(int subts_weight_typ
m_subts_weight_type == TS_1ST ||
m_subts_weight_type == TS_LAST ||
m_subts_weight_type == TS_MAX ||
m_subts_weight_type == DEPENDENT ))
m_subts_weight_type == DEPENDENT ||
m_subts_weight_type == SUMMED))
{
throw(C_csp_exception("C_csp_reported_outputs::C_output::send_to_reporting_ts_array did not recognize subtimestep weighting type"));
}
Expand Down Expand Up @@ -166,7 +167,18 @@ void C_csp_reported_outputs::C_output::send_to_reporting_ts_array(double report_
// if multiple csp-timesteps for one reporting timestep
// ************************************************************
mp_reporting_ts_array[m_counter_reporting_ts_array] =(float)(*std::max_element(mv_temp_outputs.begin(), mv_temp_outputs.end()));
}
}
else if (m_subts_weight_type == SUMMED){
// *******************************************************
// If multiple csp-timesteps for one reporting timestep, sum them
// --- original use case is timestep simulation duration
// *************************************************************
double sum_val = 0;
for (size_t i = 0; i < n_report; i++) {
sum_val += (float)mv_temp_outputs[i];
}
mp_reporting_ts_array[m_counter_reporting_ts_array] = sum_val;
}
else
{
throw(C_csp_exception("C_csp_reported_outputs::C_output::send_to_reporting_ts_array did not recognize subtimestep weighting type"));
Expand Down
3 changes: 2 additions & 1 deletion tcs/csp_solver_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class C_csp_reported_outputs
TS_1ST,
TS_LAST,
TS_MAX,
DEPENDENT
DEPENDENT,
SUMMED
};

enum E_AB_relationship
Expand Down

0 comments on commit ffc7c9e

Please sign in to comment.