Skip to content

Commit

Permalink
Merge branch 'develop' into mspt_no_finance
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanzou committed May 2, 2023
2 parents 3fa2278 + c2c1d28 commit ef9b670
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
27 changes: 16 additions & 11 deletions ssc/cmod_swh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ class cm_swh : public compute_module
V_hot = V_hot_prev + ts_sec*mdot_total/rho_water;
V_cold = V_tank - V_hot;
T_hot = (T_hot_prev*V_hot_prev + ts_sec*(mdot_total/rho_water)*(T_cold_prev + dT_collector))/V_hot;
T_cold = (V_tank/V_cold)*T_tank - (V_hot/V_cold)*T_hot;
T_cold = (V_tank/V_cold)*T_tank - (V_hot/V_cold)*T_hot; // weighted average to enforce T_tank based on T_hot
if (T_cold < std::min(T_mains_use, T_room)) T_cold = std::min(T_mains_use, T_room); // above relation breaks-down at small V_cold causing unphysical T_cold
T_top = T_hot;
T_bot = T_cold;
T_deliv = T_top;
Expand Down Expand Up @@ -722,9 +723,11 @@ class cm_swh : public compute_module
V_hot = 0;
}

double T_hot_drained = std::numeric_limits<double>::quiet_NaN();
if (V_hot == 0) // cold water drawn into the bottom of the tank in previous timesteps has completely flushed hot water from the tank
{
T_hot = T_hot_prev;
double time_to_drain_sec = V_hot_prev * rho_water / mdot_mix;
T_hot_drained = (T_hot_prev * time_to_drain_sec + T_cold * (ts_sec - time_to_drain_sec)) / ts_sec;
}
else
{
Expand All @@ -733,7 +736,6 @@ class cm_swh : public compute_module
double m_hot = V_hot_prev*rho_water;
T_hot = ((T_hot_prev * Cp_water * m_hot) + (ts_sec*U_tank*A_hot * T_room))/((m_hot*Cp_water) + (ts_sec*U_tank*A_hot)); // IMPLICIT NON-STEADY (Euler)
}
hotLoss = U_tank * A_hot * (T_hot - T_room);

// Cold node calculations
V_cold = V_tank-V_hot;
Expand All @@ -749,20 +751,23 @@ class cm_swh : public compute_module
T_cold = ((T_cold_prev*m_cold*Cp_water) + (ts_sec*U_tank*A_cold*T_room) + (ts_sec*mdot_mix*Cp_water*T_mains_use))
/((m_cold*Cp_water) + (ts_sec*A_cold*U_tank) + (mdot_mix*ts_sec*Cp_water) ); // IMPLICIT NON-STEADY
}
coldLoss = U_tank*A_cold*(T_cold - T_room);

Q_tankloss = hotLoss + coldLoss;
T_tank = (V_hot / V_tank) * T_hot + (V_cold / V_tank) * T_cold;
T_top = T_tank + 0.33*dT_collector;
T_bot = T_tank - 0.67*dT_collector;
// T_top = T_hot
// T_bot = T_cold
if (V_hot > 0) {
T_deliv = T_hot;
}
else {
T_deliv = T_cold;
T_deliv = T_hot_drained;
T_hot = T_cold; // hot water completely flushed from tank
}
T_tank = (V_hot / V_tank) * T_hot + (V_cold / V_tank) * T_cold;
T_top = T_tank + 0.33*dT_collector;
T_bot = T_tank - 0.67*dT_collector;
// T_top = T_hot
// T_bot = T_cold

hotLoss = U_tank * A_hot * (T_hot - T_room);
coldLoss = U_tank*A_cold*(T_cold - T_room);
Q_tankloss = hotLoss + coldLoss;
}

// calculate pumping losses (pump size is user entered) -
Expand Down
14 changes: 11 additions & 3 deletions tcs/csp_solver_mono_eq_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,26 @@ int C_csp_solver::solve_operating_mode(C_csp_collector_receiver::E_csp_cr_modes
C_monotonic_eq_solver::S_xy_pair xy2;
double m_dot_bal2 = std::numeric_limits<double>::quiet_NaN();
double x1 = xy1.x;
size_t iter_count = 0;
do
{
xy2.x = x1 * (1.0 / (1.0 + m_dot_bal));
xy2.x = x1 * (1.0 / (1.0 + std::max(0.02,m_dot_bal)));

m_dot_bal_code = c_mdot_solver.test_member_function(xy2.x, &m_dot_bal2);
if (m_dot_bal_code != 0)
if (std::abs(m_dot_bal2 - m_dot_bal) >= 0.02) {
break;
}

iter_count++;
// 23-04-18 tn: If defocus is < 10% get out
// If changing defocus isn't changing mass balance, get out (e.g. trough at its minimum flow rate)
if (m_dot_bal_code != 0 || xy2.x < 0.1 || (iter_count > 2 && m_dot_bal2 == m_dot_bal) )
{
reset_time(t_ts_initial);
return -2;
}
x1 = xy2.x;
} while (std::abs(m_dot_bal2 - m_dot_bal) < 0.02);
} while (true);

xy2.y = m_dot_bal2;

Expand Down
7 changes: 7 additions & 0 deletions tcs/htf_props.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ void HTFProperties::set_temp_enth_lookup()
double T_low = this->min_temp();
double T_high = this->max_temp();

if (!std::isfinite(T_low)) {
T_low = 270.0 + 273.15;
}
if (!std::isfinite(T_high)) {
T_high = 720.0 + 273.15;
}

double delta_T_target = 1.0;

int n_rows = (int)(ceil((T_high - T_low)/delta_T_target) + 1.0);
Expand Down
2 changes: 1 addition & 1 deletion test/ssc_test/cmod_swh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TEST_F(CM_SWH, ResidentialDefault_cmod_swh) {

ssc_number_t annual_energy;
ssc_data_get_number(data, "annual_energy", &annual_energy);
EXPECT_NEAR(annual_energy, 2362.2, 0.1);
EXPECT_NEAR(annual_energy, 2362.5, 0.1);

}

Expand Down

0 comments on commit ef9b670

Please sign in to comment.