LCOV - code coverage report
Current view: top level - EnergyPlus - GlobalNames.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 51 87 58.6 %
Date: 2024-08-24 18:31:18 Functions: 8 8 100.0 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2024, The Board of Trustees of the University of Illinois,
       2             : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
       3             : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
       4             : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
       5             : // contributors. All rights reserved.
       6             : //
       7             : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
       8             : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
       9             : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
      10             : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
      11             : // derivative works, and perform publicly and display publicly, and to permit others to do so.
      12             : //
      13             : // Redistribution and use in source and binary forms, with or without modification, are permitted
      14             : // provided that the following conditions are met:
      15             : //
      16             : // (1) Redistributions of source code must retain the above copyright notice, this list of
      17             : //     conditions and the following disclaimer.
      18             : //
      19             : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
      20             : //     conditions and the following disclaimer in the documentation and/or other materials
      21             : //     provided with the distribution.
      22             : //
      23             : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
      24             : //     the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
      25             : //     used to endorse or promote products derived from this software without specific prior
      26             : //     written permission.
      27             : //
      28             : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
      29             : //     without changes from the version obtained under this License, or (ii) Licensee makes a
      30             : //     reference solely to the software portion of its product, Licensee must refer to the
      31             : //     software as "EnergyPlus version X" software, where "X" is the version number Licensee
      32             : //     obtained under this License and may not use a different name for the software. Except as
      33             : //     specifically required in this Section (4), Licensee shall not use in a company name, a
      34             : //     product name, in advertising, publicity, or other promotional activities any name, trade
      35             : //     name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
      36             : //     similar designation, without the U.S. Department of Energy's prior written consent.
      37             : //
      38             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
      39             : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      40             : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      41             : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      42             : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      43             : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      44             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      45             : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      46             : // POSSIBILITY OF SUCH DAMAGE.
      47             : 
      48             : // EnergyPlus Headers
      49             : #include <EnergyPlus/Data/EnergyPlusData.hh>
      50             : #include <EnergyPlus/GlobalNames.hh>
      51             : #include <EnergyPlus/UtilityRoutines.hh>
      52             : 
      53             : namespace EnergyPlus::GlobalNames {
      54             : 
      55             : // Module containing the routines dealing with matching and assuring that
      56             : // various component types are unique by name (e.g. Chillers).
      57             : 
      58             : // MODULE INFORMATION:
      59             : //       AUTHOR         Linda Lawrie
      60             : //       DATE WRITTEN   October 2005
      61             : //       MODIFIED       na
      62             : //       RE-ENGINEERED  na
      63             : 
      64             : // PURPOSE OF THIS MODULE:
      65             : // This module allows for verification of uniqueness (by name) across
      66             : // certain component names (esp. Chillers, Boilers)
      67             : 
      68        6026 : void IntraObjUniquenessCheck(EnergyPlusData &state,
      69             :                              std::string const &NameToVerify,
      70             :                              std::string_view const CurrentModuleObject,
      71             :                              std::string_view FieldName,
      72             :                              std::unordered_set<std::string> &UniqueStrings,
      73             :                              bool &ErrorsFound)
      74             : {
      75        6026 :     if (NameToVerify.empty()) {
      76           0 :         ShowSevereError(state, format("E+ object type {} cannot have a blank {} field", CurrentModuleObject, FieldName));
      77           0 :         ErrorsFound = true;
      78             :         // NameToVerify = "xxxxx";
      79           0 :         return;
      80             :     }
      81             : 
      82        6026 :     auto const find_string = UniqueStrings.find(NameToVerify);
      83        6026 :     if (find_string == UniqueStrings.end()) {
      84        6026 :         UniqueStrings.emplace(NameToVerify);
      85             :     } else {
      86           0 :         ErrorsFound = true;
      87           0 :         ShowSevereError(state, format("{} has a duplicate field {}", CurrentModuleObject, NameToVerify));
      88             :     }
      89        6026 : }
      90             : 
      91       96887 : bool VerifyUniqueInterObjectName(EnergyPlusData &state,
      92             :                                  std::unordered_map<std::string, std::string> &names,
      93             :                                  std::string const &object_name,
      94             :                                  std::string_view object_type,
      95             :                                  std::string_view field_name,
      96             :                                  bool &ErrorsFound)
      97             : {
      98       96887 :     if (object_name.empty()) {
      99           0 :         ShowSevereError(state, format("E+ object type {} cannot have blank {} field", object_name, field_name));
     100           0 :         ErrorsFound = true;
     101             :         // object_name = "xxxxx";
     102           0 :         return true;
     103             :     }
     104       96887 :     auto const names_iter = names.find(object_name);
     105       96887 :     if (names_iter == names.end()) {
     106       96887 :         names.emplace(object_name, object_type);
     107             :     } else {
     108           0 :         ErrorsFound = true;
     109           0 :         ShowSevereError(state, format("{} with object type {} duplicates a name in object type {}", object_name, object_type, names_iter->second));
     110           0 :         return true;
     111             :     }
     112       96887 :     return false;
     113       96887 : }
     114             : 
     115        8281 : bool VerifyUniqueInterObjectName(EnergyPlusData &state,
     116             :                                  std::unordered_map<std::string, std::string> &names,
     117             :                                  std::string const &object_name,
     118             :                                  std::string const &object_type,
     119             :                                  bool &ErrorsFound)
     120             : {
     121        8281 :     if (object_name.empty()) {
     122           0 :         ShowSevereError(state, format("E+ object type {} has a blank field", object_name));
     123           0 :         ErrorsFound = true;
     124             :         // object_name = "xxxxx";
     125           0 :         return true;
     126             :     }
     127        8281 :     auto const names_iter = names.find(object_name);
     128        8281 :     if (names_iter == names.end()) {
     129        8281 :         names.emplace(object_name, object_type);
     130             :     } else {
     131           0 :         ErrorsFound = true;
     132           0 :         ShowSevereError(state, format("{} with object type {} duplicates a name in object type {}", object_name, object_type, names_iter->second));
     133           0 :         return true;
     134             :     }
     135        8281 :     return false;
     136        8281 : }
     137             : 
     138         427 : void VerifyUniqueChillerName(
     139             :     EnergyPlusData &state, std::string_view TypeToVerify, std::string const &NameToVerify, bool &ErrorsFound, std::string const &StringToDisplay)
     140             : {
     141             : 
     142             :     // SUBROUTINE INFORMATION:
     143             :     //       AUTHOR         Linda Lawrie
     144             :     //       DATE WRITTEN   October 2005
     145             :     //       MODIFIED       na
     146             :     //       RE-ENGINEERED  na
     147             : 
     148             :     // PURPOSE OF THIS SUBROUTINE:
     149             :     // This subroutine verifies that a new name will be unique in the list of
     150             :     // chillers.  If not found in the list, it is added before returning.
     151             : 
     152         427 :     auto const iter = state.dataGlobalNames->ChillerNames.find(NameToVerify);
     153         427 :     if (iter != state.dataGlobalNames->ChillerNames.end()) {
     154           0 :         ShowSevereError(state, format("{}, duplicate name={}, Chiller Type=\"{}\".", StringToDisplay, NameToVerify, iter->second));
     155           0 :         ShowContinueError(state, format("...Current entry is Chiller Type=\"{}\".", TypeToVerify));
     156           0 :         ErrorsFound = true;
     157             :     } else {
     158         427 :         state.dataGlobalNames->ChillerNames.emplace(NameToVerify, Util::makeUPPER(TypeToVerify));
     159         427 :         state.dataGlobalNames->NumChillers = static_cast<int>(state.dataGlobalNames->ChillerNames.size());
     160             :     }
     161         427 : }
     162             : 
     163         124 : void VerifyUniqueBaseboardName(EnergyPlusData &state,
     164             :                                std::string_view const &TypeToVerify,
     165             :                                std::string const &NameToVerify,
     166             :                                bool &ErrorsFound,
     167             :                                std::string const &StringToDisplay)
     168             : {
     169             : 
     170             :     // SUBROUTINE INFORMATION:
     171             :     //       AUTHOR         Linda Lawrie
     172             :     //       DATE WRITTEN   July 2008
     173             :     //       MODIFIED       na
     174             :     //       RE-ENGINEERED  na
     175             : 
     176             :     // PURPOSE OF THIS SUBROUTINE:
     177             :     // This subroutine verifies that a new name will be unique in the list of
     178             :     // Baseboards.  If not found in the list, it is added before returning.
     179             : 
     180         124 :     auto const iter = state.dataGlobalNames->BaseboardNames.find(NameToVerify);
     181         124 :     if (iter != state.dataGlobalNames->BaseboardNames.end()) {
     182           0 :         ShowSevereError(state, format("{}, duplicate name={}, Baseboard Type=\"{}\".", StringToDisplay, NameToVerify, iter->second));
     183           0 :         ShowContinueError(state, format("...Current entry is Baseboard Type=\"{}\".", TypeToVerify));
     184           0 :         ErrorsFound = true;
     185             :     } else {
     186         124 :         state.dataGlobalNames->BaseboardNames.emplace(NameToVerify, Util::makeUPPER(TypeToVerify));
     187         124 :         state.dataGlobalNames->NumBaseboards = static_cast<int>(state.dataGlobalNames->BaseboardNames.size());
     188             :     }
     189         124 : }
     190             : 
     191         216 : void VerifyUniqueBoilerName(
     192             :     EnergyPlusData &state, std::string const &TypeToVerify, std::string const &NameToVerify, bool &ErrorsFound, std::string const &StringToDisplay)
     193             : {
     194             : 
     195             :     // SUBROUTINE INFORMATION:
     196             :     //       AUTHOR         Linda Lawrie
     197             :     //       DATE WRITTEN   October 2005
     198             :     //       MODIFIED       na
     199             :     //       RE-ENGINEERED  na
     200             : 
     201             :     // PURPOSE OF THIS SUBROUTINE:
     202             :     // This subroutine verifies that a new name will be unique in the list of
     203             :     // Boilers.  If not found in the list, it is added before returning.
     204             : 
     205         216 :     auto const iter = state.dataGlobalNames->BoilerNames.find(NameToVerify);
     206         216 :     if (iter != state.dataGlobalNames->BoilerNames.end()) {
     207           0 :         ShowSevereError(state, format("{}, duplicate name={}, Boiler Type=\"{}\".", StringToDisplay, NameToVerify, iter->second));
     208           0 :         ShowContinueError(state, format("...Current entry is Boiler Type=\"{}\".", TypeToVerify));
     209           0 :         ErrorsFound = true;
     210             :     } else {
     211         216 :         state.dataGlobalNames->BoilerNames.emplace(NameToVerify, Util::makeUPPER(TypeToVerify));
     212         216 :         state.dataGlobalNames->NumBoilers = static_cast<int>(state.dataGlobalNames->BoilerNames.size());
     213             :     }
     214         216 : }
     215             : 
     216        6153 : void VerifyUniqueCoilName(
     217             :     EnergyPlusData &state, std::string const &TypeToVerify, std::string &NameToVerify, bool &ErrorsFound, std::string const &StringToDisplay)
     218             : {
     219             : 
     220             :     // SUBROUTINE INFORMATION:
     221             :     //       AUTHOR         Linda Lawrie
     222             :     //       DATE WRITTEN   October 2005
     223             :     //       MODIFIED       na
     224             :     //       RE-ENGINEERED  na
     225             : 
     226             :     // PURPOSE OF THIS SUBROUTINE:
     227             :     // This subroutine verifies that a new name will be unique in the list of
     228             :     // Coils.  If not found in the list, it is added before returning.
     229             : 
     230        6153 :     if (NameToVerify.empty()) {
     231           0 :         ShowSevereError(state, format("\"{}\" cannot have a blank field", TypeToVerify));
     232           0 :         ErrorsFound = true;
     233           0 :         NameToVerify = "xxxxx";
     234           0 :         return;
     235             :     }
     236             : 
     237        6153 :     auto const iter = state.dataGlobalNames->CoilNames.find(NameToVerify);
     238        6153 :     if (iter != state.dataGlobalNames->CoilNames.end()) {
     239           0 :         ShowSevereError(state, format("{}, duplicate name={}, Coil Type=\"{}\".", StringToDisplay, NameToVerify, iter->second));
     240           0 :         ShowContinueError(state, format("...Current entry is Coil Type=\"{}\".", TypeToVerify));
     241           0 :         ErrorsFound = true;
     242             :     } else {
     243        6153 :         state.dataGlobalNames->CoilNames.emplace(NameToVerify, Util::makeUPPER(TypeToVerify));
     244        6153 :         state.dataGlobalNames->NumCoils = static_cast<int>(state.dataGlobalNames->CoilNames.size());
     245             :     }
     246        6153 : }
     247             : 
     248          30 : void VerifyUniqueADUName(
     249             :     EnergyPlusData &state, std::string const &TypeToVerify, std::string const &NameToVerify, bool &ErrorsFound, std::string const &StringToDisplay)
     250             : {
     251          30 :     auto const iter = state.dataGlobalNames->aDUNames.find(NameToVerify);
     252          30 :     if (iter != state.dataGlobalNames->aDUNames.end()) {
     253           0 :         ShowSevereError(state, format("{}, duplicate name={}, ADU Type=\"{}\".", StringToDisplay, NameToVerify, iter->second));
     254           0 :         ShowContinueError(state, format("...Current entry is Air Distribution Unit Type=\"{}\".", TypeToVerify));
     255           0 :         ErrorsFound = true;
     256             :     } else {
     257          30 :         state.dataGlobalNames->aDUNames.emplace(NameToVerify, Util::makeUPPER(TypeToVerify));
     258          30 :         state.dataGlobalNames->numAirDistUnits = static_cast<int>(state.dataGlobalNames->aDUNames.size());
     259             :     }
     260          30 : }
     261             : 
     262             : } // namespace EnergyPlus::GlobalNames

Generated by: LCOV version 1.14