LCOV - code coverage report
Current view: top level - EnergyPlus - DataSystemVariables.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 98 109 89.9 %
Date: 2023-01-17 19:17:23 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2023, 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             : // C++ Headers
      49             : #include <utility>
      50             : 
      51             : // ObjexxFCL Headers
      52             : #include <ObjexxFCL/environment.hh>
      53             : #include <ObjexxFCL/string.functions.hh>
      54             : 
      55             : // EnergyPlus Headers
      56             : #include <EnergyPlus/Data/EnergyPlusData.hh>
      57             : #include <EnergyPlus/DataEnvironment.hh>
      58             : #include <EnergyPlus/DataGlobals.hh>
      59             : #include <EnergyPlus/DataStringGlobals.hh>
      60             : #include <EnergyPlus/DataSystemVariables.hh>
      61             : #include <EnergyPlus/FileSystem.hh>
      62             : #include <EnergyPlus/UtilityRoutines.hh>
      63             : 
      64             : namespace EnergyPlus {
      65             : 
      66             : namespace DataSystemVariables {
      67             : 
      68             :     // MODULE INFORMATION:
      69             :     //       AUTHOR         Linda K. Lawrie
      70             :     //       DATE WRITTEN   May 2006
      71             :     //       MODIFIED       na
      72             :     //       RE-ENGINEERED  na
      73             : 
      74             :     // PURPOSE OF THIS MODULE:
      75             :     // This data-only module is a repository for system (such as environment) variables that are set
      76             :     // before a run or set of runs.
      77             : 
      78             :     constexpr const char *DDOnlyEnvVar("DDONLY");       // Only run design days
      79             :     constexpr const char *ReverseDDEnvVar("REVERSEDD"); // Reverse DD during run
      80             :     constexpr const char *DisableGLHECachingEnvVar("DISABLEGLHECACHING");
      81             :     constexpr const char *FullAnnualSimulation("FULLANNUALRUN"); // Generate annual run
      82             :     constexpr const char *cDeveloperFlag("DeveloperFlag");
      83             :     constexpr const char *cDisplayAllWarnings("DisplayAllWarnings");
      84             :     constexpr const char *cDisplayExtraWarnings("DisplayExtraWarnings");
      85             :     constexpr const char *cDisplayAdvancedReportVariables("DisplayAdvancedReportVariables");
      86             :     constexpr const char *cDisplayUnusedObjects("DisplayUnusedObjects");
      87             :     constexpr const char *cDisplayUnusedSchedules("DisplayUnusedSchedules");
      88             :     constexpr const char *cDisplayZoneAirHeatBalanceOffBalance("DisplayZoneAirHeatBalanceOffBalance");
      89             :     constexpr const char *cSortIDD("SortIDD");
      90             :     constexpr const char *cReportDuringWarmup("ReportDuringWarmup");
      91             :     constexpr const char *cReportDuringHVACSizingSimulation("REPORTDURINGHVACSIZINGSIMULATION");
      92             :     constexpr const char *cIgnoreSolarRadiation("IgnoreSolarRadiation");
      93             :     constexpr const char *cIgnoreBeamRadiation("IgnoreBeamRadiation");
      94             :     constexpr const char *cIgnoreDiffuseRadiation("IgnoreDiffuseRadiation");
      95             :     constexpr const char *cSutherlandHodgman("SutherlandHodgman");
      96             :     constexpr const char *cSlaterBarsky("SlaterBarsky");
      97             :     constexpr const char *cMinimalSurfaceVariables("CreateMinimalSurfaceVariables");
      98             :     constexpr const char *cMinimalShadowing("MinimalShadowing");
      99             :     constexpr const char *cInputPath1("epin");       // EP-Launch setting.  Full path + project name
     100             :     constexpr const char *cInputPath2("input_path"); // RunEplus.bat setting.  Full path
     101             :     constexpr const char *cProgramPath("program_path");
     102             :     constexpr const char *cTimingFlag("TimingFlag");
     103             :     constexpr const char *TrackAirLoopEnvVar("TRACK_AIRLOOP"); // To generate a file with runtime statistics
     104             :     // for each controller on each air loop
     105             :     constexpr const char *TraceAirLoopEnvVar("TRACE_AIRLOOP"); // To generate a trace file with the converged
     106             :     // solutions of all controllers on each air loop at each call to SimAirLoop()
     107             :     constexpr const char *TraceHVACControllerEnvVar("TRACE_HVACCONTROLLER"); // To generate a trace file for
     108             :     //  each individual HVAC controller with all controller iterations
     109             : 
     110             :     constexpr const char *MinReportFrequencyEnvVar("MINREPORTFREQUENCY"); // environment var for reporting frequency.
     111             :     constexpr const char *
     112             :         cDisplayInputInAuditEnvVar("DISPLAYINPUTINAUDIT"); // environmental variable that enables the echoing of the input file into the audit file
     113             : 
     114             :     // DERIVED TYPE DEFINITIONS
     115             :     // na
     116             : 
     117             :     // INTERFACE BLOCK SPECIFICATIONS
     118             :     // na
     119             : 
     120             :     // MODULE VARIABLE DECLARATIONS:
     121             : 
     122             :     // Shading methods
     123             : 
     124             :     // Functions
     125             : 
     126         148 :     fs::path CheckForActualFilePath(EnergyPlusData &state,
     127             :                                     fs::path const &originalInputFilePath, // path (or filename only) as input for object
     128             :                                     const std::string &contextString       //
     129             :     )
     130             :     {
     131             : 
     132             :         // SUBROUTINE INFORMATION:
     133             :         //       AUTHOR         Linda Lawrie
     134             :         //       DATE WRITTEN   October 2011
     135             :         //       MODIFIED       na
     136             :         //       RE-ENGINEERED  na
     137             : 
     138             :         // PURPOSE OF THIS SUBROUTINE:
     139             :         // With the Windows version, there are subfolders set and the input file names may not
     140             :         // be accurate. This searches a few folders (CurrentWorkingFolder, Program folder) to see
     141             :         // if the file can be found. (It may have been input with full path so that is checked first.)
     142             : 
     143             :         // Locals
     144             :         // SUBROUTINE ARGUMENT DEFINITIONS:
     145             : 
     146             :         // SUBROUTINE PARAMETER DEFINITIONS:
     147             : 
     148             :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     149         148 :         fs::path foundFilePath;
     150             : 
     151         148 :         if (state.dataSysVars->firstTime) {
     152          21 :             state.files.audit.ensure_open(state, "CheckForActualFilePath", state.files.outputControl.audit);
     153          42 :             std::string tmp;
     154             : 
     155             :             // epin is passed from Epl-run.bat as the path to the IDF file minus its extension, so take the parent directory
     156          21 :             get_environment_variable(cInputPath1, tmp);
     157          21 :             state.dataSysVars->envinputpath1 = FileSystem::getParentDirectoryPath(fs::path(tmp));
     158             : 
     159          21 :             get_environment_variable(cInputPath2, tmp);
     160          21 :             state.dataSysVars->envinputpath2 = fs::path(tmp);
     161             : 
     162          21 :             get_environment_variable(cProgramPath, tmp);
     163          21 :             state.dataStrGlobals->ProgramPath = fs::path(tmp);
     164          21 :             state.dataSysVars->firstTime = false;
     165             :         }
     166             : 
     167         296 :         fs::path InputFilePath = FileSystem::makeNativePath(originalInputFilePath); // save for changing out path characters
     168             : 
     169         296 :         std::vector<std::pair<fs::path, std::string>> pathsChecked;
     170             : 
     171             :         const std::array<std::pair<fs::path, std::string>, 7> pathsToCheck = {
     172             :             {{InputFilePath, "Current Working Directory"},
     173         296 :              {state.dataStrGlobals->inputDirPath / InputFilePath, "IDF Directory"},
     174         296 :              {state.dataStrGlobals->exeDirectoryPath / InputFilePath, "EnergyPlus Executable Directory"},
     175         296 :              {state.dataSysVars->envinputpath1 / InputFilePath, R"("epin" Environment Variable)"},
     176         296 :              {state.dataSysVars->envinputpath2 / InputFilePath, R"("input_path" Environment Variable)"},
     177             :              // These two only tested if `TestAllPaths` is true
     178         296 :              {state.dataStrGlobals->CurrentWorkingFolder / InputFilePath, "INI File Directory"},
     179        1776 :              {state.dataStrGlobals->ProgramPath / InputFilePath, R"("program", "dir" from INI File)"}}};
     180             : 
     181         148 :         std::size_t numPathsToTest = (state.dataSysVars->TestAllPaths) ? pathsToCheck.size() : pathsToCheck.size() - 2;
     182             : 
     183         296 :         for (std::size_t i = 0; i < numPathsToTest; ++i) {
     184         296 :             if (FileSystem::fileExists(pathsToCheck[i].first)) {
     185         148 :                 foundFilePath = pathsToCheck[i].first;
     186         148 :                 print(state.files.audit, "found ({})={}\n", pathsToCheck[i].second, FileSystem::getAbsolutePath(foundFilePath).string());
     187             : 
     188         148 :                 return foundFilePath;
     189             :             } else {
     190         296 :                 std::pair<fs::path, std::string> currentPath(FileSystem::getParentDirectoryPath(FileSystem::getAbsolutePath(pathsToCheck[i].first)),
     191         444 :                                                              pathsToCheck[i].second);
     192         148 :                 bool found = false;
     193         148 :                 for (auto &path : pathsChecked) {
     194           0 :                     if (path.first == currentPath.first) {
     195           0 :                         found = true;
     196             :                     }
     197             :                 }
     198         148 :                 if (!found) {
     199         148 :                     pathsChecked.push_back(currentPath);
     200             :                 }
     201         148 :                 print(state.files.audit, "not found ({})={}\n", pathsToCheck[i].second, FileSystem::getAbsolutePath(pathsToCheck[i].first).string());
     202             :             }
     203             :         }
     204             : 
     205             :         // If we get here, we didn't find the file
     206           0 :         ShowSevereError(state, contextString + "\"" + originalInputFilePath.string() + "\" not found.");
     207           0 :         ShowContinueError(state, "  Paths searched:");
     208           0 :         for (auto &path : pathsChecked) {
     209           0 :             ShowContinueError(state, "    " + path.second + ": \"" + path.first.string() + "\"");
     210             :         }
     211             : 
     212           0 :         return foundFilePath;
     213             :     }
     214             : 
     215         771 :     void processEnvironmentVariables(EnergyPlusData &state)
     216             :     {
     217             : 
     218        1542 :         std::string cEnvValue;
     219             : 
     220         771 :         get_environment_variable(DDOnlyEnvVar, cEnvValue);
     221         771 :         state.dataSysVars->DDOnly = env_var_on(cEnvValue); // Yes or True
     222         771 :         if (state.dataGlobal->DDOnlySimulation) state.dataSysVars->DDOnly = true;
     223             : 
     224         771 :         get_environment_variable(ReverseDDEnvVar, cEnvValue);
     225         771 :         state.dataSysVars->ReverseDD = env_var_on(cEnvValue); // Yes or True
     226             : 
     227         771 :         get_environment_variable(DisableGLHECachingEnvVar, cEnvValue);
     228         771 :         state.dataSysVars->DisableGLHECaching = env_var_on(cEnvValue); // Yes or True
     229             : 
     230         771 :         get_environment_variable(FullAnnualSimulation, cEnvValue);
     231         771 :         state.dataSysVars->FullAnnualRun = env_var_on(cEnvValue); // Yes or True
     232         771 :         if (state.dataGlobal->AnnualSimulation) state.dataSysVars->FullAnnualRun = true;
     233             : 
     234         771 :         get_environment_variable(cDisplayAllWarnings, cEnvValue);
     235         771 :         state.dataGlobal->DisplayAllWarnings = env_var_on(cEnvValue); // Yes or True
     236         771 :         if (state.dataGlobal->DisplayAllWarnings) {
     237           0 :             state.dataGlobal->DisplayAllWarnings = true;
     238           0 :             state.dataGlobal->DisplayExtraWarnings = true;
     239           0 :             state.dataGlobal->DisplayUnusedSchedules = true;
     240           0 :             state.dataGlobal->DisplayUnusedObjects = true;
     241             :         }
     242             : 
     243         771 :         get_environment_variable(cDisplayExtraWarnings, cEnvValue);
     244         771 :         if (!cEnvValue.empty()) state.dataGlobal->DisplayExtraWarnings = env_var_on(cEnvValue); // Yes or True
     245             : 
     246         771 :         get_environment_variable(cDisplayUnusedObjects, cEnvValue);
     247         771 :         if (!cEnvValue.empty()) state.dataGlobal->DisplayUnusedObjects = env_var_on(cEnvValue); // Yes or True
     248             : 
     249         771 :         get_environment_variable(cDisplayUnusedSchedules, cEnvValue);
     250         771 :         if (!cEnvValue.empty()) state.dataGlobal->DisplayUnusedSchedules = env_var_on(cEnvValue); // Yes or True
     251             : 
     252         771 :         get_environment_variable(cDisplayZoneAirHeatBalanceOffBalance, cEnvValue);
     253         771 :         if (!cEnvValue.empty()) state.dataGlobal->DisplayZoneAirHeatBalanceOffBalance = env_var_on(cEnvValue); // Yes or True
     254             : 
     255         771 :         get_environment_variable(cDisplayAdvancedReportVariables, cEnvValue);
     256         771 :         if (!cEnvValue.empty()) state.dataGlobal->DisplayAdvancedReportVariables = env_var_on(cEnvValue); // Yes or True
     257             : 
     258         771 :         get_environment_variable(cReportDuringWarmup, cEnvValue);
     259         771 :         if (!cEnvValue.empty()) state.dataSysVars->ReportDuringWarmup = env_var_on(cEnvValue); // Yes or True
     260         771 :         if (state.dataSysVars->ReverseDD) state.dataSysVars->ReportDuringWarmup = false;       // force to false for ReverseDD runs
     261             : 
     262         771 :         get_environment_variable(cReportDuringWarmup, cEnvValue);
     263         771 :         if (!cEnvValue.empty()) state.dataSysVars->ReportDuringWarmup = env_var_on(cEnvValue);   // Yes or True
     264         771 :         if (state.dataSysVars->DisableGLHECaching) state.dataSysVars->ReportDuringWarmup = true; // force to true for standard runs runs
     265             : 
     266         771 :         get_environment_variable(cReportDuringHVACSizingSimulation, cEnvValue);
     267         771 :         if (!cEnvValue.empty()) state.dataSysVars->ReportDuringHVACSizingSimulation = env_var_on(cEnvValue); // Yes or True
     268             : 
     269         771 :         get_environment_variable(cIgnoreSolarRadiation, cEnvValue);
     270         771 :         if (!cEnvValue.empty()) state.dataEnvrn->IgnoreSolarRadiation = env_var_on(cEnvValue); // Yes or True
     271             : 
     272         771 :         get_environment_variable(cMinimalSurfaceVariables, cEnvValue);
     273         771 :         if (!cEnvValue.empty()) state.dataGlobal->CreateMinimalSurfaceVariables = env_var_on(cEnvValue); // Yes or True
     274             : 
     275         771 :         get_environment_variable(cSortIDD, cEnvValue);
     276         771 :         if (!cEnvValue.empty()) state.dataSysVars->SortedIDD = env_var_on(cEnvValue); // Yes or True
     277             : 
     278         771 :         get_environment_variable(MinReportFrequencyEnvVar, cEnvValue);
     279         771 :         if (!cEnvValue.empty()) state.dataSysVars->MinReportFrequency = cEnvValue; // turned into value later
     280             : 
     281         771 :         get_environment_variable(cDeveloperFlag, cEnvValue);
     282         771 :         if (!cEnvValue.empty()) state.dataSysVars->DeveloperFlag = env_var_on(cEnvValue); // Yes or True
     283             : 
     284         771 :         get_environment_variable(cIgnoreBeamRadiation, cEnvValue);
     285         771 :         if (!cEnvValue.empty()) state.dataEnvrn->IgnoreBeamRadiation = env_var_on(cEnvValue); // Yes or True
     286             : 
     287         771 :         get_environment_variable(cIgnoreDiffuseRadiation, cEnvValue);
     288         771 :         if (!cEnvValue.empty()) state.dataEnvrn->IgnoreDiffuseRadiation = env_var_on(cEnvValue); // Yes or True
     289             : 
     290         771 :         get_environment_variable(cSutherlandHodgman, cEnvValue);
     291         771 :         if (!cEnvValue.empty()) state.dataSysVars->SutherlandHodgman = env_var_on(cEnvValue); // Yes or True
     292             : 
     293         771 :         get_environment_variable(cSlaterBarsky, cEnvValue);
     294         771 :         if (!cEnvValue.empty()) state.dataSysVars->SlaterBarsky = env_var_on(cEnvValue); // Yes or True
     295             : 
     296         771 :         get_environment_variable(cMinimalShadowing, cEnvValue);
     297         771 :         if (!cEnvValue.empty()) state.dataSysVars->lMinimalShadowing = env_var_on(cEnvValue); // Yes or True
     298             : 
     299         771 :         get_environment_variable(cTimingFlag, cEnvValue);
     300         771 :         if (!cEnvValue.empty()) state.dataSysVars->TimingFlag = env_var_on(cEnvValue); // Yes or True
     301             : 
     302             :         // Initialize env flags for air loop simulation debugging
     303         771 :         get_environment_variable(TrackAirLoopEnvVar, cEnvValue);
     304         771 :         if (!cEnvValue.empty()) state.dataSysVars->TrackAirLoopEnvFlag = env_var_on(cEnvValue); // Yes or True
     305             : 
     306         771 :         get_environment_variable(TraceAirLoopEnvVar, cEnvValue);
     307         771 :         if (!cEnvValue.empty()) state.dataSysVars->TraceAirLoopEnvFlag = env_var_on(cEnvValue); // Yes or True
     308             : 
     309         771 :         get_environment_variable(TraceHVACControllerEnvVar, cEnvValue);
     310         771 :         if (!cEnvValue.empty()) state.dataSysVars->TraceHVACControllerEnvFlag = env_var_on(cEnvValue); // Yes or True
     311             : 
     312         771 :         get_environment_variable(cDisplayInputInAuditEnvVar, cEnvValue);
     313         771 :         if (!cEnvValue.empty()) state.dataGlobal->DisplayInputInAudit = env_var_on(cEnvValue); // Yes or True
     314         771 :     }
     315             : 
     316             : } // namespace DataSystemVariables
     317             : 
     318        2313 : } // namespace EnergyPlus

Generated by: LCOV version 1.13