@@ -1662,6 +1662,8 @@ void GetChildrenData(EnergyPlusData &state,
16621662 Array1D_string ChildOutNodeName;
16631663 Array1D_int ChildInNodeNum;
16641664 Array1D_int ChildOutNodeNum;
1665+ Array1D_bool ChildMatched;
1666+
16651667 bool ErrInObject;
16661668
16671669 std::fill (ChildrenCType.begin (), ChildrenCType.end (), DataLoopNode::ConnectionObjectType::Invalid);
@@ -1672,86 +1674,134 @@ void GetChildrenData(EnergyPlusData &state,
16721674 OutletNodeNum = 0 ;
16731675 ErrInObject = false ;
16741676
1675- if (IsParentObject (state, ComponentType, ComponentName)) {
1676- NumChildren = GetNumChildren (state, ComponentType, ComponentName);
1677- if (NumChildren == 0 ) {
1678- ShowWarningError (state,
1679- format (" GetChildrenData: Parent Node has no children, node={}:{}." ,
1680- ConnectionObjectTypeNames[static_cast <int >(ComponentType)],
1681- ComponentName));
1677+ if (!IsParentObject (state, ComponentType, ComponentName)) {
1678+ ShowWarningError (state,
1679+ format (" GetChildrenData: Requested Children Data for non Parent Node={}:{}." ,
1680+ ConnectionObjectTypeNames[static_cast <int >(ComponentType)],
1681+ ComponentName));
1682+ ErrorsFound = true ;
1683+
1684+ } else if ((NumChildren = GetNumChildren (state, ComponentType, ComponentName)) == 0 ) {
1685+ ShowWarningError (state,
1686+ format (" GetChildrenData: Parent Node has no children, node={}:{}." ,
1687+ ConnectionObjectTypeNames[static_cast <int >(ComponentType)],
1688+ ComponentName));
1689+
1690+ } else {
1691+ int ParentInletNodeNum;
1692+ int ParentOutletNodeNum;
1693+ std::string ParentInletNodeName;
1694+ std::string ParentOutletNodeName;
1695+ GetParentData (
1696+ state, ComponentType, ComponentName, ParentInletNodeName, ParentInletNodeNum, ParentOutletNodeName, ParentOutletNodeNum, ErrInObject);
1697+ ChildCType.allocate (NumChildren);
1698+ ChildCName.allocate (NumChildren);
1699+ ChildInNodeName.allocate (NumChildren);
1700+ ChildOutNodeName.allocate (NumChildren);
1701+ ChildInNodeNum.allocate (NumChildren);
1702+ ChildOutNodeNum.allocate (NumChildren);
1703+ ChildMatched.allocate (NumChildren);
1704+
1705+ std::fill (ChildCType.begin (), ChildCType.end (), DataLoopNode::ConnectionObjectType::Invalid);
1706+ ChildCName = std::string ();
1707+ ChildInNodeName = std::string ();
1708+ ChildOutNodeName = std::string ();
1709+ ChildInNodeNum = 0 ;
1710+ ChildOutNodeNum = 0 ;
1711+ ChildMatched = false ;
1712+
1713+ int CountNum = 0 ;
1714+ for (int Loop = 1 ; Loop <= state.dataBranchNodeConnections ->NumCompSets ; ++Loop) {
1715+ auto const &compSet = state.dataBranchNodeConnections ->CompSets (Loop);
1716+ if (compSet.ParentObjectType == ComponentType && compSet.ParentCName == ComponentName) {
1717+ ++CountNum;
1718+ ChildCType (CountNum) = compSet.ComponentObjectType ;
1719+ ChildCName (CountNum) = compSet.CName ;
1720+ ChildInNodeName (CountNum) = compSet.InletNodeName ;
1721+ ChildOutNodeName (CountNum) = compSet.OutletNodeName ;
1722+ // Get Node Numbers
1723+ ChildInNodeNum (CountNum) = Util::FindItemInList (ChildInNodeName (CountNum), state.dataLoopNodes ->NodeID );
1724+ ChildOutNodeNum (CountNum) = Util::FindItemInList (ChildOutNodeName (CountNum), state.dataLoopNodes ->NodeID );
1725+ }
1726+ }
1727+
1728+ if (CountNum != NumChildren) {
1729+ ShowSevereError (state, " GetChildrenData: Counted nodes not equal to GetNumChildren count" );
1730+ ErrorsFound = true ;
1731+
16821732 } else {
1683- int ParentInletNodeNum;
1684- int ParentOutletNodeNum;
1685- std::string ParentInletNodeName;
1686- std::string ParentOutletNodeName;
1687- GetParentData (
1688- state, ComponentType, ComponentName, ParentInletNodeName, ParentInletNodeNum, ParentOutletNodeName, ParentOutletNodeNum, ErrInObject);
1689- ChildCType.clear ();
1690- ChildCType.allocate (NumChildren);
1691- ChildCName.allocate (NumChildren);
1692- ChildInNodeName.allocate (NumChildren);
1693- ChildOutNodeName.allocate (NumChildren);
1694- ChildInNodeNum.allocate (NumChildren);
1695- ChildOutNodeNum.allocate (NumChildren);
1696- ChildCName = std::string ();
1697- ChildInNodeName = std::string ();
1698- ChildOutNodeName = std::string ();
1699- ChildInNodeNum = 0 ;
1700- ChildOutNodeNum = 0 ;
1701- int CountNum = 0 ;
1702- for (int Loop = 1 ; Loop <= state.dataBranchNodeConnections ->NumCompSets ; ++Loop) {
1703- if (state.dataBranchNodeConnections ->CompSets (Loop).ParentObjectType == ComponentType &&
1704- state.dataBranchNodeConnections ->CompSets (Loop).ParentCName == ComponentName) {
1733+ // Children arrays built. Now "sort" for flow connection order(?)
1734+ // FindIntInList is 0-based and FindItemInList is 1-based .. great!
1735+ int ParentInletNodeIndex = 0 ;
1736+ for (int Loop = 1 ; Loop <= NumChildren; ++Loop)
1737+ if (ChildInNodeNum (Loop) == ParentInletNodeNum) { ParentInletNodeIndex = Loop; break ; }
1738+
1739+ int ParentOutletNodeIndex = 0 ;
1740+ for (int Loop = 1 ; Loop <= NumChildren; ++Loop)
1741+ if (ChildOutNodeNum (Loop) == ParentOutletNodeNum) { ParentOutletNodeIndex = Loop; break ; }
1742+
1743+ // Parent inlet node matches one of the inlet-nodes of the sub-components
1744+ if (ParentInletNodeIndex > 0 ) {
1745+ int MatchInNodeNum = ParentInletNodeNum;
1746+ CountNum = 0 ;
1747+
1748+ while (CountNum < NumChildren) {
1749+ int MatchInNodeIndex = 0 ;
1750+ for (int Loop = 1 ; Loop <= NumChildren; ++Loop)
1751+ if (ChildInNodeNum (Loop) == MatchInNodeNum && !ChildMatched (Loop)) { MatchInNodeIndex = Loop; break ; }
1752+
1753+ if (MatchInNodeIndex == 0 ) // The chain is broken
1754+ break ;
1755+
17051756 ++CountNum;
1706- ChildCType (CountNum) = state.dataBranchNodeConnections ->CompSets (Loop).ComponentObjectType ;
1707- ChildCName (CountNum) = state.dataBranchNodeConnections ->CompSets (Loop).CName ;
1708- ChildInNodeName (CountNum) = state.dataBranchNodeConnections ->CompSets (Loop).InletNodeName ;
1709- ChildOutNodeName (CountNum) = state.dataBranchNodeConnections ->CompSets (Loop).OutletNodeName ;
1710- // Get Node Numbers
1711- ChildInNodeNum (CountNum) = Util::FindItemInList (ChildInNodeName (CountNum),
1712- state.dataLoopNodes ->NodeID ({1 , state.dataLoopNodes ->NumOfNodes }),
1713- state.dataLoopNodes ->NumOfNodes );
1714- ChildOutNodeNum (CountNum) = Util::FindItemInList (ChildOutNodeName (CountNum),
1715- state.dataLoopNodes ->NodeID ({1 , state.dataLoopNodes ->NumOfNodes }),
1716- state.dataLoopNodes ->NumOfNodes );
1757+ ChildrenCType (CountNum) = ChildCType (MatchInNodeIndex);
1758+ ChildrenCName (CountNum) = ChildCName (MatchInNodeIndex);
1759+ InletNodeName (CountNum) = ChildInNodeName (MatchInNodeIndex);
1760+ InletNodeNum (CountNum) = ChildInNodeNum (MatchInNodeIndex);
1761+ OutletNodeName (CountNum) = ChildOutNodeName (MatchInNodeIndex);
1762+ OutletNodeNum (CountNum) = ChildOutNodeNum (MatchInNodeIndex);
1763+ ChildMatched (MatchInNodeIndex) = true ;
1764+ MatchInNodeNum = ChildOutNodeNum (MatchInNodeIndex);
17171765 }
1718- }
1719- if (CountNum != NumChildren) {
1720- ShowSevereError (state, " GetChildrenData: Counted nodes not equal to GetNumChildren count" );
1721- ErrInObject = true ;
1722- } else {
1723- // Children arrays built. Now "sort" for flow connection order(?)
1724- std::string MatchNodeName = ParentInletNodeName;
1725- CountNum = 0 ;
1726- int CountMatchLoop = 0 ;
1727- while (CountMatchLoop < NumChildren) {
1728- ++CountMatchLoop;
1729- // Matched=.FALSE.
1730- for (int Loop = 1 ; Loop <= NumChildren; ++Loop) {
1731- if (ChildInNodeName (Loop) == MatchNodeName) {
1732- ++CountNum;
1733- ChildrenCType (CountNum) = ChildCType (Loop);
1734- ChildrenCName (CountNum) = ChildCName (Loop);
1735- InletNodeName (CountNum) = ChildInNodeName (Loop);
1736- InletNodeNum (CountNum) = ChildInNodeNum (Loop);
1737- OutletNodeName (CountNum) = ChildOutNodeName (Loop);
1738- OutletNodeNum (CountNum) = ChildOutNodeNum (Loop);
1739- ChildInNodeName (Loop).clear (); // So it won't match anymore
1740- // Matched=.TRUE.
1741- MatchNodeName = ChildOutNodeName (Loop);
1742- break ;
1743- }
1744- }
1766+
1767+ for (int Loop = 1 ; Loop <= NumChildren; ++Loop) {
1768+ if (ChildMatched (Loop)) continue ;
1769+ ++CountNum;
1770+ ChildrenCType (CountNum) = ChildCType (Loop);
1771+ ChildrenCName (CountNum) = ChildCName (Loop);
1772+ InletNodeName (CountNum) = ChildInNodeName (Loop);
1773+ InletNodeNum (CountNum) = ChildInNodeNum (Loop);
1774+ OutletNodeName (CountNum) = ChildOutNodeName (Loop);
1775+ OutletNodeNum (CountNum) = ChildOutNodeNum (Loop);
17451776 }
1746- if (MatchNodeName != ParentOutletNodeName) {
1747- for (int Loop = 1 ; Loop <= NumChildren; ++Loop) {
1748- if (ChildInNodeName (Loop).empty ()) continue ;
1749- if (ChildOutNodeName (Loop) == ParentOutletNodeName) break ;
1777+
1778+ // Parent outlet node matches one of the outlet-nodes of the sub-components
1779+ } else if (ParentOutletNodeIndex > 0 ) {
1780+ int MatchOutNodeNum = ParentOutletNodeNum;
1781+ CountNum = NumChildren + 1 ;
1782+
1783+ while (CountNum > 1 ) {
1784+ int MatchOutNodeIndex = 0 ;
1785+ for (int Loop = 1 ; Loop <= NumChildren; ++Loop)
1786+ if (ChildOutNodeNum (Loop) == MatchOutNodeNum && !ChildMatched (Loop)) { MatchOutNodeIndex = Loop; break ; }
1787+
1788+ if (MatchOutNodeIndex == 0 ) // The chain is broken
17501789 break ;
1751- }
1790+
1791+ --CountNum;
1792+ ChildrenCType (CountNum) = ChildCType (MatchOutNodeIndex);
1793+ ChildrenCName (CountNum) = ChildCName (MatchOutNodeIndex);
1794+ InletNodeName (CountNum) = ChildInNodeName (MatchOutNodeIndex);
1795+ InletNodeNum (CountNum) = ChildInNodeNum (MatchOutNodeIndex);
1796+ OutletNodeName (CountNum) = ChildOutNodeName (MatchOutNodeIndex);
1797+ OutletNodeNum (CountNum) = ChildOutNodeNum (MatchOutNodeIndex);
1798+ ChildMatched (MatchOutNodeIndex) = true ;
1799+ MatchOutNodeNum = ChildInNodeNum (MatchOutNodeIndex);
17521800 }
1801+
1802+ CountNum = 0 ;
17531803 for (int Loop = 1 ; Loop <= NumChildren; ++Loop) {
1754- if (ChildInNodeName (Loop). empty ( )) continue ;
1804+ if (ChildMatched (Loop)) continue ;
17551805 ++CountNum;
17561806 ChildrenCType (CountNum) = ChildCType (Loop);
17571807 ChildrenCName (CountNum) = ChildCName (Loop);
@@ -1760,21 +1810,32 @@ void GetChildrenData(EnergyPlusData &state,
17601810 OutletNodeName (CountNum) = ChildOutNodeName (Loop);
17611811 OutletNodeNum (CountNum) = ChildOutNodeNum (Loop);
17621812 }
1763- ChildCType.deallocate ();
1764- ChildCName.deallocate ();
1765- ChildInNodeName.deallocate ();
1766- ChildOutNodeName.deallocate ();
1767- ChildInNodeNum.deallocate ();
1768- ChildOutNodeNum.deallocate ();
1813+ } else {
1814+ // No sub-component is connected to either the parent
1815+ // component's inlet- or outlet- nodes? Just copy the
1816+ // sub-components in the order in which they appear in
1817+ // the CompSets
1818+
1819+ for (int Loop = 1 ; Loop <= NumChildren; ++Loop) {
1820+ if (ChildMatched (Loop)) continue ;
1821+ ChildrenCType (Loop) = ChildCType (Loop);
1822+ ChildrenCName (Loop) = ChildCName (Loop);
1823+ InletNodeName (Loop) = ChildInNodeName (Loop);
1824+ InletNodeNum (Loop) = ChildInNodeNum (Loop);
1825+ OutletNodeName (Loop) = ChildOutNodeName (Loop);
1826+ OutletNodeNum (Loop) = ChildOutNodeNum (Loop);
1827+ }
17691828 }
17701829 }
1771- } else {
1772- ShowWarningError (state,
1773- format (" GetChildrenData: Requested Children Data for non Parent Node={}:{}." ,
1774- ConnectionObjectTypeNames[static_cast <int >(ComponentType)],
1775- ComponentName));
1776- ErrInObject = true ;
1777- }
1830+
1831+ ChildCType.deallocate ();
1832+ ChildCName.deallocate ();
1833+ ChildInNodeName.deallocate ();
1834+ ChildOutNodeName.deallocate ();
1835+ ChildInNodeNum.deallocate ();
1836+ ChildOutNodeNum.deallocate ();
1837+ ChildMatched.deallocate ();
1838+ }
17781839
17791840 if (ErrInObject) ErrorsFound = true ;
17801841}
0 commit comments