-
Notifications
You must be signed in to change notification settings - Fork 4
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
Balance energy #184
Merged
Merged
Balance energy #184
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 tasks
nealkruis
requested changes
Dec 7, 2023
src/HPWH.hh
Outdated
@@ -1299,18 +1319,20 @@ private: | |||
|
|||
}; // end of HeatSource class | |||
|
|||
// a few extra functions for unit converesion | |||
#define BTUperKWH 3412.14163312794 // https://www.rapidtables.com/convert/energy/kWh_to_BTU.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use constexpr instead of a preprocessor definition.
src/HPWH.cc
Outdated
Comment on lines
2684
to
2715
// maximum heat deliverable in this timestep | ||
double targetT_C; | ||
while((qAdd_kJ > 0.) && (setPointNodeNum < getNumNodes())) { | ||
// if the whole tank is at the same temp, the target temp is the setpoint | ||
if(setPointNodeNum == (getNumNodes() - 1)) { | ||
targetT_C = tankTemps_C[setPointNodeNum] + qAdd_kJ / nodeCp_kJperC / (setPointNodeNum + 1 - nodeNum); | ||
} | ||
//otherwise the target temp is the first non-equal-temp node | ||
else { | ||
targetT_C = tankTemps_C[setPointNodeNum + 1]; | ||
} | ||
|
||
double deltaT_C = targetT_C - tankTemps_C[setPointNodeNum]; | ||
|
||
//heat needed to bring all equal temp. nodes up to the temp of the next node. kJ | ||
double qInc_kJ = nodeCp_kJperC * (setPointNodeNum + 1 - nodeNum) * deltaT_C; | ||
|
||
//Running the rest of the time won't recover | ||
if(qInc_kJ > qAdd_kJ) { | ||
for(int j = nodeNum; j <= setPointNodeNum; j++) { | ||
tankTemps_C[j] += qAdd_kJ / nodeCp_kJperC / (setPointNodeNum + 1 - nodeNum); | ||
} | ||
qAdd_kJ = 0.; | ||
} | ||
else if(qInc_kJ > 0.) | ||
{ // temp will recover by/before end of timestep | ||
for(int j = nodeNum; j <= setPointNodeNum; j++) | ||
tankTemps_C[j] = targetT_C; | ||
qAdd_kJ -= qInc_kJ; | ||
} | ||
setPointNodeNum++; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update comments here to better explain what's happening in the loop.
nealkruis
approved these changes
Dec 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
isEnergyBalanced
to test whether the net change in tank energy over one simulation step is equal to the sum of all available contributions. The code was mostly copied directly from main.cc, which had run this test, but didn't require success or report the results when running the full test suite. The extant code failed this test by 10's of J/min. Sources of energy imbalance were then sought out. Five errors in energy accounting were found:doConduction
section of updateTankTemps was missing a factor of 2 in the node-to-node heat transfer calculation. There also appeared to be an error in updating via nextTankTemps_C, though this was hard to localize. The coefficientbc
had incorrect units, and inspection of the same function shows that it was not actually needed (only the UA is needed). The section was significantly rearranged.addExtaHeatAboveNode
is added to handle these cases.Author Progress Checklist:
Reviewer Checklist: