LCOV - code coverage report
Current view: top level - EnergyPlus - MatrixDataManager.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 51 62 82.3 %
Date: 2023-01-17 19:17:23 Functions: 6 6 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 <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         876 :             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 :             UtilityRoutines::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, "GetMatrixInput: for " + cCurrentModuleObject + ": " + state.dataIPShortCut->cAlphaArgs(1));
     166           0 :                 ShowContinueError(state,
     167           0 :                                   "Check " + state.dataIPShortCut->cNumericFieldNames(1) + " and " + state.dataIPShortCut->cNumericFieldNames(2) +
     168             :                                       " total number of elements in matrix must be 1 or more");
     169           0 :                 ErrorsFound = true;
     170             :             }
     171         146 :             if ((NumNumbers - 2) < NumElements) {
     172           0 :                 ShowSevereError(state, "GetMatrixInput: for " + cCurrentModuleObject + ": " + state.dataIPShortCut->cAlphaArgs(1));
     173           0 :                 ShowContinueError(state,
     174           0 :                                   "Check input, total number of elements does not agree with " + state.dataIPShortCut->cNumericFieldNames(1) +
     175           0 :                                       " and " + state.dataIPShortCut->cNumericFieldNames(2));
     176           0 :                 ErrorsFound = true;
     177             :             }
     178         146 :             state.dataMatrixDataManager->MatData(MatNum).MatrixType = TwoDimensional;
     179             :             // Note With change to row-major arrays the "row" and "col" usage here is transposed
     180         146 :             auto &matrix(state.dataMatrixDataManager->MatData(MatNum).Mat2D);
     181         146 :             matrix.allocate(NumCols, NumRows); // This is standard order for a NumRows X NumCols matrix
     182         146 :             Array2<Real64>::size_type l(0);
     183      799402 :             for (int ElementNum = 1; ElementNum <= NumElements; ++ElementNum, l += matrix.size()) {
     184      799256 :                 int const RowIndex = (ElementNum - 1) / NumCols + 1;
     185      799256 :                 int const ColIndex = mod((ElementNum - 1), NumCols) + 1;
     186      799256 :                 matrix(ColIndex, RowIndex) = state.dataIPShortCut->rNumericArgs(ElementNum + 2); // Matrix is read in row-by-row
     187             :             }
     188             :         }
     189             : 
     190          10 :         if (ErrorsFound) {
     191           0 :             ShowFatalError(state, "GetMatrixInput: Errors found in Matrix objects. Preceding condition(s) cause termination.");
     192             :         }
     193          10 :     }
     194             : #pragma warning(pop)
     195             : 
     196         146 :     int MatrixIndex(EnergyPlusData &state, std::string const &MatrixName)
     197             :     {
     198             : 
     199             :         // FUNCTION INFORMATION:
     200             :         //       AUTHOR         B. Griffith
     201             :         //       DATE WRITTEN   June 2010
     202             :         //       MODIFIED       na
     203             :         //       RE-ENGINEERED  na
     204             : 
     205             :         // PURPOSE OF THIS FUNCTION:
     206             :         // Return integer index or pointer to MatData structure array
     207             : 
     208             :         // METHODOLOGY EMPLOYED:
     209             :         // inputs name of matrix and returns integer index
     210             :         // currently uses UtilityRoutines::FindItemInList( which is case sensitive
     211             : 
     212             :         // Return value
     213             :         int MatrixIndexPtr; // Function result
     214             : 
     215             :         // FUNCTION LOCAL VARIABLE DECLARATIONS:
     216         146 :         auto &GetMatrixInputFlag = state.dataUtilityRoutines->GetMatrixInputFlag;
     217             : 
     218         146 :         if (GetMatrixInputFlag) {
     219          10 :             GetMatrixInput(state);
     220          10 :             GetMatrixInputFlag = false;
     221             :         }
     222             : 
     223         146 :         if (state.dataMatrixDataManager->NumMats > 0) {
     224         146 :             MatrixIndexPtr = UtilityRoutines::FindItemInList(MatrixName, state.dataMatrixDataManager->MatData);
     225             :         } else {
     226           0 :             MatrixIndexPtr = 0;
     227             :         }
     228             : 
     229         146 :         return MatrixIndexPtr;
     230             :     }
     231             : 
     232         146 :     void Get2DMatrix(EnergyPlusData &state,
     233             :                      int const Idx, // pointer index to location in MatData
     234             :                      Array2S<Real64> Mat2D)
     235             :     {
     236             : 
     237             :         // SUBROUTINE INFORMATION:
     238             :         //       AUTHOR         B. Griffith
     239             :         //       DATE WRITTEN   June 2010
     240             :         //       MODIFIED       na
     241             :         //       RE-ENGINEERED  na
     242             : 
     243             :         // PURPOSE OF THIS SUBROUTINE:
     244             :         // pass matrix to calling routine
     245             : 
     246         146 :         if (Idx > 0) { // protect hard crash
     247         146 :             Mat2D = state.dataMatrixDataManager->MatData(Idx).Mat2D;
     248             :         } else {
     249             :             // do nothing (?) throw dev error
     250             :         }
     251         146 :     }
     252             : 
     253         146 :     void Get2DMatrixDimensions(EnergyPlusData &state,
     254             :                                int const Idx, // pointer index to location in MatData
     255             :                                int &NumRows,
     256             :                                int &NumCols)
     257             :     {
     258             : 
     259             :         // SUBROUTINE INFORMATION:
     260             :         //       AUTHOR         B. Griffith
     261             :         //       DATE WRITTEN   June 2010
     262             :         //       MODIFIED       na
     263             :         //       RE-ENGINEERED  na
     264             : 
     265             :         // PURPOSE OF THIS SUBROUTINE:
     266             :         // <description>
     267             : 
     268         146 :         if (Idx > 0) {
     269         146 :             NumRows = state.dataMatrixDataManager->MatData(Idx).Mat2D.isize(2);
     270         146 :             NumCols = state.dataMatrixDataManager->MatData(Idx).Mat2D.isize(1);
     271             :         } else {
     272             :             // do nothing (?) throw dev error?
     273             :         }
     274         146 :     }
     275             : 
     276             : } // namespace MatrixDataManager
     277             : 
     278        2313 : } // namespace EnergyPlus

Generated by: LCOV version 1.13