Skip to content

Commit

Permalink
Add scaleVector fnc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Ahrenkiel authored and Phil Ahrenkiel committed Feb 5, 2024
1 parent c02652f commit 9062a80
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
34 changes: 18 additions & 16 deletions src/HPWH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ void calcThermalDist(std::vector<double>& thermalDist,
}
}

//-----------------------------------------------------------------------------
/// @brief Scales all values of a std::vector<double> by a common factor.
/// @param[in/out] coeffs values to be scaled
/// @param[in] scaleFactor scaling factor
//-----------------------------------------------------------------------------
void scaleVector(std::vector<double>& coeffs, const double scaleFactor)
{
if (scaleFactor != 1.)
{
std::transform(coeffs.begin(),
coeffs.end(),
coeffs.begin(),
std::bind(std::multiplies<double>(), std::placeholders::_1, scaleFactor));
}
}

void HPWH::setMinutesPerStep(const double minutesPerStep_in)
{
minutesPerStep = minutesPerStep_in;
Expand Down Expand Up @@ -3109,21 +3125,8 @@ int HPWH::setScaleCapacityCOP(double scaleCapacity /*=1.0*/, double scaleCOP /*=

for (auto& perfP : heatSources[compressorIndex].perfMap)
{
if (scaleCapacity != 1.)
{
std::transform(
perfP.inputPower_coeffs.begin(),
perfP.inputPower_coeffs.end(),
perfP.inputPower_coeffs.begin(),
std::bind(std::multiplies<double>(), std::placeholders::_1, scaleCapacity));
}
if (scaleCOP != 1.)
{
std::transform(perfP.COP_coeffs.begin(),
perfP.COP_coeffs.end(),
perfP.COP_coeffs.begin(),
std::bind(std::multiplies<double>(), std::placeholders::_1, scaleCOP));
}
scaleVector(perfP.inputPower_coeffs, scaleCapacity);
scaleVector(perfP.COP_coeffs, scaleCOP);
}

return 0;
Expand Down Expand Up @@ -4127,7 +4130,6 @@ bool compressorIsRunning(HPWH& hpwh)

/* static */ bool HPWH::mapNameToPreset(const std::string& modelName, HPWH::MODELS& model)
{

if (modelName == "Voltex60" || modelName == "AOSmithPHPT60")
{
model = HPWH::MODELS_AOSmithPHPT60;
Expand Down
5 changes: 3 additions & 2 deletions src/HPWH.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,9 @@ class HPWH
/**< caller context pointer for external message processing */

MODELS model;
/**< The model enum id */
/**< The model id */

// a std::vector containing the HeatSources, in order of priority
/// a std::vector containing the HeatSources, in order of priority
std::vector<HeatSource> heatSources;

int compressorIndex;
Expand Down Expand Up @@ -1586,5 +1586,6 @@ void calcThermalDist(std::vector<double>& thermalDist,
const int lowestNode,
const std::vector<double>& nodeTemp_C,
const double setpointT_C);
void scaleVector(std::vector<double>& coeffs, const double scaleFactor);

#endif
18 changes: 6 additions & 12 deletions src/HPWHpresets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4357,25 +4357,19 @@ int HPWH::initPreset(MODELS presetNum)
0.0000392,
-3.52E-07};

// Set model scale
double scale = 1.;
// Set model scale factor
double scaleFactor = 1.;
if (presetNum == MODELS_TamScalable_SP_2X)
{
scale = 2.;
scaleFactor = 2.;
}
else if (presetNum == MODELS_TamScalable_SP_Half)
{
scale = 0.5;
scaleFactor = 0.5;
}

// Scale the compressor capacity
if (scale != 1.)
{
std::transform(inputPower_coeffs.begin(),
inputPower_coeffs.end(),
inputPower_coeffs.begin(),
std::bind(std::multiplies<double>(), std::placeholders::_1, scale));
}
scaleVector(inputPower_coeffs, scaleFactor);

compressor.perfMap.push_back({
105, // Temperature (T_F)
Expand All @@ -4400,7 +4394,7 @@ int HPWH::initPreset(MODELS presetNum)
compressor.depressesTemperature = false; // no temp depression

// Scale the resistance-element power
double elementPower_W = scale * 30000.;
double elementPower_W = scaleFactor * 30000.;
resistiveElementBottom.setupAsResistiveElement(0, elementPower_W);
resistiveElementTop.setupAsResistiveElement(9, elementPower_W);

Expand Down

0 comments on commit 9062a80

Please sign in to comment.