LCOV - code coverage report
Current view: top level - EnergyPlus - MatrixDataManager.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 49 63 77.8 %
Date: 2024-08-24 18:31:18 Functions: 4 4 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             : // C++ Headers
      49             : #include <cmath>
      50             : 
      51             : // ObjexxFCL Headers
      52             : #include <ObjexxFCL/Fmath.hh>
      53             : 
      54             : // EnergyPlus Headers
      55             : #include <EnergyPlus/Data/EnergyPlusData.hh>
      56             : #include <EnergyPlus/DataIPShortCuts.hh>
      57             : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      58             : #include <EnergyPlus/MatrixDataManager.hh>
      59             : #include <EnergyPlus/UtilityRoutines.hh>
      60             : 
      61             : namespace EnergyPlus {
      62             : 
      63             : namespace MatrixDataManager {
      64             : 
      65             :     // Module containing the routines dealing with Matrix input objects and services
      66             : 
      67             :     // MODULE INFORMATION:
      68             :     //       AUTHOR         B. Griffith
      69             :     //       DATE WRITTEN   June 2010
      70             :     //       MODIFIED       na
      71             :     //       RE-ENGINEERED  na
      72             : 
      73             :     // PURPOSE OF THIS MODULE:
      74             :     // Process user input for Matrix: input data objects
      75             :     // Provide central services for other routines to access
      76             :     // matrix input data.
      77             : 
      78             :     // METHODOLOGY EMPLOYED:
      79             :     // Basic calls to InputProcessor, series of simple get and set routines
      80             : 
      81             :     // REFERENCES:
      82             :     // none
      83             : 
      84             :     // OTHER NOTES:
      85             :     // first implemented for complex fenestration
      86             : 
      87             :     // Data
      88             :     // MODULE PARAMETER DEFINITIONS:
      89             : 
      90             :     // SUBROUTINE SPECIFICATIONS FOR MODULE <module_name>:
      91             : 
      92             :     // todo, flush out the following routines, see CurveManager for patterns
      93             :     // PUBLIC GetMatrixValue
      94             :     // PUBLIC GetMatrixCheck
      95             :     // PUBLIC GetMatrixType
      96             :     // PUBLIC GetMatrixMinMaxValues
      97             :     // PUBLIC SetMatrixOutputMinMaxValues
      98             :     // PUBLIC GetMatrixName
      99             : 
     100             :     // Object Data
     101             : 
     102             : // MSVC was complaining that it detected a divide by zero in the Row = (El - 1) / NumCols + 1 line, indicating it thought NumCols was zero
     103             : // the compiler should never have been able to identify that, as NumCols is based directly on rNumericArgs, which is based on input values
     104             : // Apparently, interaction between the high level optimizer that does flow-graph transformations and backend that emits warnings can cause
     105             : // false positives.  The warning simply needs to be muted.  Placing the pragma at the statement itself was not sufficient for muting, so I
     106             : // placed the pragma out here at this level and it worked.  Note that this warning was only showing up on release builds, not debug builds
     107             : #pragma warning(push)
     108             : #pragma warning(disable : 4723)
     109          10 :     void GetMatrixInput(EnergyPlusData &state)
     110             :     {
     111             : 
     112             :         // SUBROUTINE INFORMATION:
     113             :         //       AUTHOR         B. Griffith
     114             :         //       DATE WRITTEN   June 2010
     115             :         //       MODIFIED       na
     116             :         //       RE-ENGINEERED  na
     117             : 
     118             :         // PURPOSE OF THIS SUBROUTINE:
     119             :         // get input for Matrix objects
     120             : 
     121             :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     122             :         int NumTwoDimMatrix;     // count of Matrix:TwoDimension objects
     123             :         int MatIndex;            // do loop counter
     124             :         int MatNum;              // index management
     125             :         int NumAlphas;           // Number of Alphas for each GetObjectItem call
     126             :         int NumNumbers;          // Number of Numbers for each GetObjectItem call
     127             :         int IOStatus;            // Used in GetObjectItem
     128          10 :         bool ErrorsFound(false); // Set to true if errors in input, fatal at end of routine
     129             :         int NumRows;
     130             :         int NumCols;
     131             :         int NumElements;
     132          10 :         auto &cCurrentModuleObject = state.dataIPShortCut->cCurrentModuleObject;
     133             : 
     134          10 :         cCurrentModuleObject = "Matrix:TwoDimension";
     135          10 :         NumTwoDimMatrix = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
     136             : 
     137          10 :         state.dataMatrixDataManager->NumMats = NumTwoDimMatrix;
     138             : 
     139          10 :         state.dataMatrixDataManager->MatData.allocate(state.dataMatrixDataManager->NumMats);
     140             : 
     141          10 :         MatNum = 0;
     142         156 :         for (MatIndex = 1; MatIndex <= NumTwoDimMatrix; ++MatIndex) {
     143         438 :             state.dataInputProcessing->inputProcessor->getObjectItem(state,
     144             :                                                                      cCurrentModuleObject,
     145             :                                                                      MatIndex,
     146         146 :                                                                      state.dataIPShortCut->cAlphaArgs,
     147             :                                                                      NumAlphas,
     148         146 :                                                                      state.dataIPShortCut->rNumericArgs,
     149             :                                                                      NumNumbers,
     150             :                                                                      IOStatus,
     151         146 :                                                                      state.dataIPShortCut->lNumericFieldBlanks,
     152             :                                                                      _,
     153         146 :                                                                      state.dataIPShortCut->cAlphaFieldNames,
     154         146 :                                                                      state.dataIPShortCut->cNumericFieldNames);
     155         146 :             ++MatNum;
     156         146 :             Util::IsNameEmpty(state, state.dataIPShortCut->cAlphaArgs(1), cCurrentModuleObject, ErrorsFound);
     157             : 
     158         146 :             state.dataMatrixDataManager->MatData(MatNum).Name = state.dataIPShortCut->cAlphaArgs(1);
     159         146 :             NumRows = std::floor(state.dataIPShortCut->rNumericArgs(1));
     160         146 :             NumCols = std::floor(state.dataIPShortCut->rNumericArgs(2));
     161         146 :             NumElements = NumRows * NumCols;
     162             : 
     163             :             // test
     164         146 :             if (NumElements < 1) {
     165           0 :                 ShowSevereError(state, format("GetMatrixInput: for {}: {}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     166           0 :                 ShowContinueError(state,
     167           0 :                                   format("Check {} and {} total number of elements in matrix must be 1 or more",
     168           0 :                                          state.dataIPShortCut->cNumericFieldNames(1),
     169           0 :                                          state.dataIPShortCut->cNumericFieldNames(2)));
     170           0 :                 ErrorsFound = true;
     171             :             }
     172         146 :             if ((NumNumbers - 2) < NumElements) {
     173           0 :                 ShowSevereError(state, format("GetMatrixInput: for {}: {}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     174           0 :                 ShowContinueError(state,
     175           0 :                                   format("Check input, total number of elements does not agree with {} and {}",
     176           0 :                                          state.dataIPShortCut->cNumericFieldNames(1),
     177           0 :                                          state.dataIPShortCut->cNumericFieldNames(2)));
     178           0 :                 ErrorsFound = true;
     179             :             }
     180         146 :             state.dataMatrixDataManager->MatData(MatNum).MatrixType = TwoDimensional;
     181             :             // Note With change to row-major arrays the "row" and "col" usage here is transposed
     182         146 :             auto &matrix(state.dataMatrixDataManager->MatData(MatNum).Mat2D);
     183         146 :             matrix.allocate(NumCols, NumRows); // This is standard order for a NumRows X NumCols matrix
     184         146 :             Array2<Real64>::size_type l(0);
     185      799402 :             for (int ElementNum = 1; ElementNum <= NumElements; ++ElementNum, l += matrix.size()) {
     186      799256 :                 int const RowIndex = (ElementNum - 1) / NumCols + 1;
     187      799256 :                 int const ColIndex = mod((ElementNum - 1), NumCols) + 1;
     188      799256 :                 matrix(ColIndex, RowIndex) = state.dataIPShortCut->rNumericArgs(ElementNum + 2); // Matrix is read in row-by-row
     189             :             }
     190             :         }
     191             : 
     192          10 :         if (ErrorsFound) {
     193           0 :             ShowFatalError(state, "GetMatrixInput: Errors found in Matrix objects. Preceding condition(s) cause termination.");
     194             :         }
     195          10 :     }
     196             : #pragma warning(pop)
     197             : 
     198         146 :     int MatrixIndex(EnergyPlusData &state, std::string const &MatrixName)
     199             :     {
     200             : 
     201             :         // FUNCTION INFORMATION:
     202             :         //       AUTHOR         B. Griffith
     203             :         //       DATE WRITTEN   June 2010
     204             :         //       MODIFIED       na
     205             :         //       RE-ENGINEERED  na
     206             : 
     207             :         // PURPOSE OF THIS FUNCTION:
     208             :         // Return integer index or pointer to MatData structure array
     209             : 
     210             :         // METHODOLOGY EMPLOYED:
     211             :         // inputs name of matrix and returns integer index
     212             :         // currently uses Util::FindItemInList( which is case sensitive
     213             : 
     214             :         // Return value
     215             :         int MatrixIndexPtr; // Function result
     216             : 
     217             :         // FUNCTION LOCAL VARIABLE DECLARATIONS:
     218             : 
     219         146 :         if (state.dataUtilityRoutines->GetMatrixInputFlag) {
     220          10 :             GetMatrixInput(state);
     221          10 :             state.dataUtilityRoutines->GetMatrixInputFlag = false;
     222             :         }
     223             : 
     224         146 :         if (state.dataMatrixDataManager->NumMats > 0) {
     225         146 :             MatrixIndexPtr = Util::FindItemInList(MatrixName, state.dataMatrixDataManager->MatData);
     226             :         } else {
     227           0 :             MatrixIndexPtr = 0;
     228             :         }
     229             : 
     230         146 :         return MatrixIndexPtr;
     231             :     }
     232             : 
     233         146 :     void Get2DMatrix(EnergyPlusData &state,
     234             :                      int const Idx, // pointer index to location in MatData
     235             :                      Array2S<Real64> Mat2D)
     236             :     {
     237             : 
     238             :         // SUBROUTINE INFORMATION:
     239             :         //       AUTHOR         B. Griffith
     240             :         //       DATE WRITTEN   June 2010
     241             :         //       MODIFIED       na
     242             :         //       RE-ENGINEERED  na
     243             : 
     244             :         // PURPOSE OF THIS SUBROUTINE:
     245             :         // pass matrix to calling routine
     246             : 
     247         146 :         if (Idx > 0) { // protect hard crash
     248         146 :             Mat2D = state.dataMatrixDataManager->MatData(Idx).Mat2D;
     249             :         } else {
     250             :             // do nothing (?) throw dev error
     251             :         }
     252         146 :     }
     253             : 
     254         146 :     void Get2DMatrixDimensions(EnergyPlusData &state,
     255             :                                int const Idx, // pointer index to location in MatData
     256             :                                int &NumRows,
     257             :                                int &NumCols)
     258             :     {
     259             : 
     260             :         // SUBROUTINE INFORMATION:
     261             :         //       AUTHOR         B. Griffith
     262             :         //       DATE WRITTEN   June 2010
     263             :         //       MODIFIED       na
     264             :         //       RE-ENGINEERED  na
     265             : 
     266             :         // PURPOSE OF THIS SUBROUTINE:
     267             :         // <description>
     268             : 
     269         146 :         if (Idx > 0) {
     270         146 :             NumRows = state.dataMatrixDataManager->MatData(Idx).Mat2D.isize(2);
     271         146 :             NumCols = state.dataMatrixDataManager->MatData(Idx).Mat2D.isize(1);
     272             :         } else {
     273             :             // do nothing (?) throw dev error?
     274             :         }
     275         146 :     }
     276             : 
     277             : } // namespace MatrixDataManager
     278             : 
     279             : } // namespace EnergyPlus

Generated by: LCOV version 1.14