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

Add convergence check for co2 and contaminant #10500

Merged
merged 12 commits into from
May 29, 2024

Conversation

lgu1234
Copy link
Contributor

@lgu1234 lgu1234 commented May 9, 2024

Pull request overview

The convergence check for CO2 and generic contaminant was added based on decision in the issue.

The differences are found in the test file, located in EnergyPlusDevSupport.

NOTE: ENHANCEMENTS MUST FOLLOW A SUBMISSION PROCESS INCLUDING A FEATURE PROPOSAL AND DESIGN DOCUMENT PRIOR TO SUBMITTING CODE

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • [ X] Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • [X ] Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • [X ] Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • [ X] Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • [X ] If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies

Reviewer

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@lgu1234 lgu1234 added the Defect Includes code to repair a defect in EnergyPlus label May 9, 2024
std::array<bool, 3> HVACGenContamNotConverged = {false}; // Flag to show mass flow convergence
std::array<Real64, ConvergLogStackDepth> HVACGenContamDemandToSupplyTolValue = {0.0}; // Queue of convergence "results"
std::array<Real64, ConvergLogStackDepth> HVACGenContamSupplyDeck1ToDemandTolValue = {0.0}; // Queue of convergence "results"
std::array<Real64, ConvergLogStackDepth> HVACGenContamSupplyDeck2ToDemandTolValue = {0.0}; // Queue of convergence "results"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more variables for CO2 and contaminant convergence check

}
if (state.dataContaminantBalance->Contaminant.GenericContamSimulation) {
airLoopConv.HVACGenContamNotConverged[0] = false;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize bool variables with false

OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convergence check for AirSystemDemandSide

airLoopConv.HVACGenContamNotConverged[1] = true;
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convergence check for AirSystemSupplySideDeck1

airLoopConv.HVACGenContamNotConverged[2] = true;
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convergence check for AirSystemSupplySideDeck2

HistoryTrace));
}
} // Generic contaminant not converged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide error messages if convergence is not met.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could all this repeated stuff be put into a single function and called with an array reference or two passed in?

Copy link
Member

@Myoldmopar Myoldmopar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to hold off on marking approve/reject right now. I would love to get a response about the array index comments. Honestly, when there is a check on a contam tolerance value at array index [0], and then assigning not converged[2] to a value, I cannot tell if that's right or a typo. It would be great to know how big of an effort it would be to "at least" give those zeroes, ones, and twos meaningful names through constexpr int variables. Or an enum. Or something else. If it's enormous, I won't hold this fix up for that.

}
if (state.dataContaminantBalance->Contaminant.GenericContamSimulation) {
airLoopConv.HVACGenContamNotConverged[1] = false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, I really don't like further propagating these numbers. As far as I can tell, the index in this array is based on where we are calling from? Is that actually how it works? I'm not saying we need to go in and gut things for this fix, but it's just something that I think should be cleaned up. At a minimum, shouldn't we at least have a constexpr variable for "0", "1", and "2"? And more importantly, does it make sense for these to be arrays at all? Feels more like we should have a little struct and just create 3 different variable instances of that struct. Rant over.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Myoldmopar Your understanding is correct. The index in the array represents a call-from type as DataConvergParams::CalledFrom. I also agree to have a constexpr variable for "0", "1", and "2" with clear representation. Since constexpr variable change is beyond the current issue scope, I would like to suggest to create a new issue to handle a new constexpr variable.

if (airLoopConv.HVACGenContamSupplyDeck2ToDemandTolValue[0] > DataConvergParams::HVACGenContamToler) {
airLoopConv.HVACGenContamNotConverged[2] = true;
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, checking the value of variable [0] and then saying converged[2] = true. This is not easy to read and understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Myoldmopar a new constexpr variable suggested by you may address your concern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this DemandTolValue[0] is not related to the same indexing that the converged[2] was referencing? It doesn't have to be changed now, and using CalledFrom is helpful indeed.

HistoryTrace));
}
} // Generic contaminant not converged

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could all this repeated stuff be put into a single function and called with an array reference or two passed in?

@lgu1234
Copy link
Contributor Author

lgu1234 commented May 13, 2024

@Myoldmopar The convergence check for CO2 and generic contaminant mimics the convergence check for temperature and others. That is why I adopt index of the array of NotConverged as (0, 1, 2). I agree the index can be replaced by a new constexpr variable or enum. Since the change is beyond the current issue scope, it is better to have a new issue to handle the change.

@lgu1234
Copy link
Contributor Author

lgu1234 commented May 13, 2024

@Myoldmopar Since the index of the array represents calledFrom type, here is my suggestion for the index. It should be noted that CalledFrom is defined as enum already.
from
airLoopConv.HVACMassFlowNotConverged[0] = false;
Revide
airLoopConv.HVACMassFlowNotConverged[(int)CalledFrom] = false;

Please let me know what you think.

@lgu1234
Copy link
Contributor Author

lgu1234 commented May 20, 2024

@Myoldmopar A function was created to handle not convergence errors in different categories, mass flow rate, humidity ratio, temperature, energy, CO2 and generic contaminant.

@lgu1234
Copy link
Contributor Author

lgu1234 commented May 20, 2024

A new test file was uploaded to test no convergence errors.

@lgu1234
Copy link
Contributor Author

lgu1234 commented May 20, 2024

@Myoldmopar The Win64-Windows-10-VisualStudio-16 — Build Failed

I recompiled E+ on my local computer using Visual Studio. It is OK to generate exe files for both release and debug. Is ti possible to let me know how fix this failure? Thanks.

@lgu1234
Copy link
Contributor Author

lgu1234 commented May 21, 2024

@Myoldmopar It is ready for review again.

Copy link
Member

@Myoldmopar Myoldmopar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm requesting changes, but I'm going to make them myself. I'll get them pushed up and wait for one more round of CI and then get this merged. Thanks @lgu1234

airLoopConv.HVACHumRatNotConverged[0] = false;
airLoopConv.HVACTempNotConverged[0] = false;
airLoopConv.HVACEnergyNotConverged[0] = false;
airLoopConv.HVACMassFlowNotConverged[(int)CalledFrom] = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be changed here, but you are welcome to do this cast one time and create a new int from it. That way the array lookup is a bit cleaner. It won't affect performance or anything, but could help readability:

    int iCall = (int)calledFromEnum;
    airLoopConv.HVACMassFlowNotConverged[iCall] = false;
    // ...lots more uses of iCall without having (int) everywhere...

if (airLoopConv.HVACGenContamSupplyDeck2ToDemandTolValue[0] > DataConvergParams::HVACGenContamToler) {
airLoopConv.HVACGenContamNotConverged[2] = true;
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this DemandTolValue[0] is not related to the same indexing that the converged[2] was referencing? It doesn't have to be changed now, and using CalledFrom is helpful indeed.

}
} // energy not converged

// mass flow rate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future work: create a reference to reuse to avoid these lookups and collapse all these long lines:

auto & thisSys = state.dataConvergeParams->AirLoopConvergence(AirSysNum);
ConvergenceErrors(state,
                  thisSys.HVACMassFlowNotConverged,
                  thisSys.HVACFlowDemandToSupplyTolValue,
                  thisSys.HVACFlowSupplyDeck1ToDemandTolValue,
                  thisSys.HVACFlowSupplyDeck2ToDemandTolValue,
                  AirSysNum,
                  1);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Myoldmopar I tried to use references for all arrays and was unable to pass compile.

if (index == 3) CaseName = "temperature";
if (index == 4) CaseName = "energy";
if (index == 5) CaseName = "CO2";
if (index == 6) CaseName = "generic contaminant";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh this should be a constexpr array of strings. I'm going to stop short of requiring it here, but this should just be a lookup.

std::array<bool, 3> HVACNotConverged,
std::array<Real64, 10> DemandToSupply,
std::array<Real64, 10> SupplyDeck1ToDemand,
std::array<Real64, 10> SupplyDeck2ToDemand,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm... are these going to be copied? This is something that might actually have to be changed. @lgu1234 I will likely make a pass at cleaning this up and maybe touch some of the other random notes I've made here.

@Myoldmopar
Copy link
Member

Alright, I addressed my own comments and it should be ready. I'll let CI confirm things, but then this should be ready for merge.

@lgu1234
Copy link
Contributor Author

lgu1234 commented May 22, 2024

@Myoldmopar Your changes are better. Thanks.

@Myoldmopar
Copy link
Member

I ran a quick local test with develop, still happy, let's merge. Thanks @lgu1234

@Myoldmopar Myoldmopar merged commit 1b333b5 into develop May 29, 2024
15 checks passed
@Myoldmopar Myoldmopar deleted the Add-more-convergence-check-for-CO2-and-Cont branch May 29, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Includes code to repair a defect in EnergyPlus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error with Zone Air Contaminant Balance
7 participants