4747
4848// C++ Headers
4949#include < cmath>
50+ #include < iterator>
5051#include < vector>
5152
5253// ObjexxFCL Headers
@@ -487,12 +488,10 @@ GLHEResponseFactors::GLHEResponseFactors(EnergyPlusData &state, std::string cons
487488 }
488489
489490 this ->numGFuncPairs = static_cast <int >(tmpLntts.size ());
490- this ->LNTTS .dimension (this ->numGFuncPairs , 0.0 );
491- this ->GFNC .dimension (this ->numGFuncPairs , 0.0 );
492491
493492 for (int i = 1 ; i <= (int )tmpLntts.size (); ++i) {
494- this ->LNTTS (i) = tmpLntts[i - 1 ];
495- this ->GFNC (i) = tmpGvals[i - 1 ];
493+ this ->LNTTS . push_back ( tmpLntts[i - 1 ]) ;
494+ this ->GFNC . push_back ( tmpGvals[i - 1 ]) ;
496495 }
497496}
498497
@@ -649,7 +648,7 @@ BuildAndGetResponseFactorsObjectFromSingleBHs(EnergyPlusData &state, std::vector
649648 // Make new props object which has the mean values of the other props objects referenced by the individual BH objects
650649 std::shared_ptr<GLHEVertProps> thisProps (new GLHEVertProps);
651650 thisProps->name = format (" Response Factor Auto Generated Mean Props No: {}" , state.dataGroundHeatExchanger ->numAutoGeneratedResponseFactors + 1 );
652- for (auto &thisBH : state. dataGroundHeatExchanger -> singleBoreholesVector ) {
651+ for (auto &thisBH : singleBHsForRFVect ) {
653652 thisProps->bhDiameter += thisBH->props ->bhDiameter ;
654653 thisProps->bhLength += thisBH->props ->bhLength ;
655654 thisProps->bhTopDepth += thisBH->props ->bhTopDepth ;
@@ -962,18 +961,12 @@ void GLHEVert::calcUniformBHWallTempGFunctions(EnergyPlusData &state)
962961 boreholes.emplace_back (bh->props ->bhLength , bh->props ->bhTopDepth , bh->props ->bhDiameter / 2.0 , bh->xLoc , bh->yLoc );
963962 }
964963
965- // convert time to a std::vector from an Array1D
966- std::vector<double > time;
967- for (auto &v : this ->myRespFactors ->time ) {
968- time.push_back (v);
969- }
970-
971964 // Obtain number of segments by adaptive discretization
972965 gt::segments::adaptive adptDisc;
973966 int nSegments = adptDisc.discretize (this ->bhLength , this ->totalTubeLength );
974967
975- this ->myRespFactors ->GFNC =
976- gt::gfunction::uniform_borehole_wall_temperature ( boreholes, time, this ->soil .diffusivity , nSegments, true , state.dataGlobal ->numThread );
968+ this ->myRespFactors ->GFNC = gt::gfunction::uniform_borehole_wall_temperature (
969+ boreholes, this -> myRespFactors -> time , this ->soil .diffusivity , nSegments, true , state.dataGlobal ->numThread );
977970}
978971
979972// ******************************************************************************
@@ -989,8 +982,8 @@ void GLHEVert::calcGFunctions(EnergyPlusData &state)
989982
990983 // save data for later
991984 if (state.files .outputControl .glhe && !state.dataSysVars ->DisableGLHECaching ) {
992- myCacheData[" Response Factors" ][" time" ] = std::vector<Real64>(this ->myRespFactors ->time . begin (), this -> myRespFactors -> time . end () );
993- myCacheData[" Response Factors" ][" LNTTS" ] = std::vector<Real64>(this ->myRespFactors ->LNTTS . begin (), this -> myRespFactors -> LNTTS . end () );
985+ myCacheData[" Response Factors" ][" time" ] = std::vector<Real64>(this ->myRespFactors ->time );
986+ myCacheData[" Response Factors" ][" LNTTS" ] = std::vector<Real64>(this ->myRespFactors ->LNTTS );
994987 myCacheData[" Response Factors" ][" GFNC" ] = std::vector<Real64>(this ->myRespFactors ->GFNC .begin (), this ->myRespFactors ->GFNC .end ());
995988 writeGLHECacheToFile (state);
996989 }
@@ -1025,17 +1018,12 @@ void GLHEVert::setupTimeVectors()
10251018 }
10261019 }
10271020
1028- // Setup the arrays
1029- this ->myRespFactors ->time .dimension (tempLNTTS.size (), 0.0 );
1030- this ->myRespFactors ->LNTTS .dimension (tempLNTTS.size (), 0.0 );
1031- this ->myRespFactors ->GFNC .dimension (tempLNTTS.size (), 0.0 );
1032-
1033- int index = 1 ;
1034- for (auto const &thisLNTTS : tempLNTTS) {
1035- this ->myRespFactors ->time (index) = exp (thisLNTTS) * t_s;
1036- this ->myRespFactors ->LNTTS (index) = thisLNTTS;
1037- ++index;
1038- }
1021+ this ->myRespFactors ->LNTTS = tempLNTTS;
1022+ this ->myRespFactors ->time = tempLNTTS;
1023+ std::transform (this ->myRespFactors ->time .begin (), this ->myRespFactors ->time .end (), this ->myRespFactors ->time .begin (), [&t_s](auto &c) {
1024+ return exp (c) * t_s;
1025+ });
1026+ this ->myRespFactors ->GFNC = std::vector<Real64>(tempLNTTS.size (), 0.0 );
10391027}
10401028
10411029// ******************************************************************************
@@ -1045,15 +1033,15 @@ void GLHEVert::calcUniformHeatFluxGFunctions(EnergyPlusData &state)
10451033 DisplayString (state, " Initializing GroundHeatExchanger:System: " + this ->name );
10461034
10471035 // Calculate the g-functions
1048- for (size_t lntts_index = 1 ; lntts_index <= this ->myRespFactors ->LNTTS .size (); ++lntts_index) {
1036+ for (size_t lntts_index = 0 ; lntts_index < this ->myRespFactors ->LNTTS .size (); ++lntts_index) {
10491037 for (auto const &bh_i : this ->myRespFactors ->myBorholes ) {
10501038 Real64 sum_T_ji = 0 ;
10511039 for (auto const &bh_j : this ->myRespFactors ->myBorholes ) {
1052- sum_T_ji += doubleIntegral (bh_i, bh_j, this ->myRespFactors ->time ( lntts_index) );
1040+ sum_T_ji += doubleIntegral (bh_i, bh_j, this ->myRespFactors ->time [ lntts_index] );
10531041 }
1054- this ->myRespFactors ->GFNC ( lntts_index) += sum_T_ji;
1042+ this ->myRespFactors ->GFNC [ lntts_index] += sum_T_ji;
10551043 }
1056- this ->myRespFactors ->GFNC ( lntts_index) /= (2 * this ->totalTubeLength );
1044+ this ->myRespFactors ->GFNC [ lntts_index] /= (2 * this ->totalTubeLength );
10571045
10581046 std::stringstream ss;
10591047 ss << std::fixed << std::setprecision (1 ) << float (lntts_index) / this ->myRespFactors ->LNTTS .size () * 100 ;
@@ -1375,25 +1363,18 @@ void GLHEVert::combineShortAndLongTimestepGFunctions()
13751363 }
13761364
13771365 // Add the rest of the long time-step g-functions to the combined curve
1378- for (int index_longTS = this -> myRespFactors -> GFNC . l () ; index_longTS <= this ->myRespFactors ->GFNC .u (); ++index_longTS) {
1379- GFNC_combined.push_back (this ->myRespFactors ->GFNC ( index_longTS) );
1380- LNTTS_combined.push_back (this ->myRespFactors ->LNTTS ( index_longTS) );
1366+ for (int index_longTS = 0 ; index_longTS < this ->myRespFactors ->GFNC .size (); ++index_longTS) {
1367+ GFNC_combined.push_back (this ->myRespFactors ->GFNC [ index_longTS] );
1368+ LNTTS_combined.push_back (this ->myRespFactors ->LNTTS [ index_longTS] );
13811369 }
13821370
1383- // Move combined values into right data struct
1384- this ->myRespFactors ->time .deallocate ();
1385- this -> myRespFactors -> LNTTS . deallocate () ;
1386- this -> myRespFactors -> GFNC . deallocate ( );
1371+ this -> myRespFactors -> time = LNTTS_combined;
1372+ std::transform ( this ->myRespFactors ->time .begin (), this -> myRespFactors -> time . end (), this -> myRespFactors -> time . begin (), [&t_s]( auto &c) {
1373+ return exp (c) * t_s ;
1374+ } );
13871375
1388- this ->myRespFactors ->time .dimension (GFNC_combined.size (), 0.0 );
1389- this ->myRespFactors ->LNTTS .dimension (GFNC_combined.size (), 0.0 );
1390- this ->myRespFactors ->GFNC .dimension (GFNC_combined.size (), 0.0 );
1391-
1392- for (unsigned int index = 0 ; index < GFNC_combined.size (); ++index) {
1393- this ->myRespFactors ->time [index] = exp (LNTTS_combined[index]) * t_s;
1394- this ->myRespFactors ->LNTTS [index] = LNTTS_combined[index];
1395- this ->myRespFactors ->GFNC [index] = GFNC_combined[index];
1396- }
1376+ this ->myRespFactors ->LNTTS = LNTTS_combined;
1377+ this ->myRespFactors ->GFNC = GFNC_combined;
13971378}
13981379
13991380void GLHEBase::makeThisGLHECacheAndCompareWithFileCache (EnergyPlusData &state)
@@ -1460,13 +1441,13 @@ void GLHEVert::readCacheFileAndCompareWithThisGLHECache(EnergyPlusData &state)
14601441
14611442 if (gFunctionsExist ) {
14621443 // Populate the time array
1463- this ->myRespFactors ->time = Array1D <Real64>(myCacheData[" Response Factors" ][" time" ].get <std::vector<Real64>>());
1444+ this ->myRespFactors ->time = std::vector <Real64>(myCacheData[" Response Factors" ][" time" ].get <std::vector<Real64>>());
14641445
14651446 // Populate the lntts array
1466- this ->myRespFactors ->LNTTS = Array1D <Real64>(myCacheData[" Response Factors" ][" LNTTS" ].get <std::vector<Real64>>());
1447+ this ->myRespFactors ->LNTTS = std::vector <Real64>(myCacheData[" Response Factors" ][" LNTTS" ].get <std::vector<Real64>>());
14671448
14681449 // Populate the g-function array
1469- this ->myRespFactors ->GFNC = Array1D <Real64>(myCacheData[" Response Factors" ][" GFNC" ].get <std::vector<Real64>>());
1450+ this ->myRespFactors ->GFNC = std::vector <Real64>(myCacheData[" Response Factors" ][" GFNC" ].get <std::vector<Real64>>());
14701451 }
14711452}
14721453
@@ -1522,18 +1503,13 @@ void GLHESlinky::calcGFunctions(EnergyPlusData &state)
15221503 int NPairs = static_cast <int >((tLg_max - tLg_min) / (tLg_grid) + 1 );
15231504
15241505 // Allocate and setup g-function arrays
1525- this ->myRespFactors ->GFNC . allocate (NPairs);
1526- this ->myRespFactors ->LNTTS . allocate (NPairs);
1506+ this ->myRespFactors ->GFNC = std::vector<Real64> (NPairs, 0.0 );
1507+ this ->myRespFactors ->LNTTS = std::vector<Real64> (NPairs, 0.0 );
15271508 this ->QnMonthlyAgg .allocate (static_cast <int >(this ->maxSimYears * 12 ));
15281509 this ->QnHr .allocate (730 + this ->AGG + this ->SubAGG );
15291510 this ->QnSubHr .allocate (static_cast <int >((this ->SubAGG + 1 ) * maxTSinHr + 1 ));
15301511 this ->LastHourN .allocate (this ->SubAGG + 1 );
15311512
1532- for (int i = 1 ; i <= NPairs; ++i) {
1533- this ->myRespFactors ->GFNC (i) = 0.0 ;
1534- this ->myRespFactors ->LNTTS (i) = 0.0 ;
1535- }
1536-
15371513 // Calculate the number of loops (per trench) and number of trenches to be involved
15381514 // Due to the symmetry of a slinky GHX field, we need only calculate about
15391515 // on quarter of the rings' tube wall temperature perturbation to get the
@@ -1652,8 +1628,8 @@ void GLHESlinky::calcGFunctions(EnergyPlusData &state)
16521628 } // n1
16531629 } // m1
16541630
1655- this ->myRespFactors ->GFNC (NT) = (gFunc * (this ->coilDiameter / 2.0 )) / (4 * Constant::Pi * fraction * this ->numTrenches * this ->numCoils );
1656- this ->myRespFactors ->LNTTS (NT) = tLg;
1631+ this ->myRespFactors ->GFNC [NT - 1 ] = (gFunc * (this ->coilDiameter / 2.0 )) / (4 * Constant::Pi * fraction * this ->numTrenches * this ->numCoils );
1632+ this ->myRespFactors ->LNTTS [NT - 1 ] = tLg;
16571633
16581634 } // NT time
16591635}
@@ -1834,7 +1810,7 @@ inline bool GLHEBase::isEven(int const val)
18341810
18351811// ******************************************************************************
18361812
1837- Real64 GLHESlinky::integral (int const m, int const n, int const m1, int const n1, Real64 const t, Real64 const eta, Real64 const J0)
1813+ Real64 GLHESlinky::integral (int const m, int const n, int const m1, int const n1, Real64 const t, Real64 const eta, int const J0)
18381814{
18391815 // SUBROUTINE INFORMATION:
18401816 // AUTHOR: Matt Mitchell
@@ -1848,33 +1824,28 @@ Real64 GLHESlinky::integral(int const m, int const n, int const m1, int const n1
18481824 // Simpson's 1/3 rule of integration
18491825
18501826 // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
1851- Real64 sumIntF = 0.0 ;
18521827 Real64 theta = 0.0 ;
18531828 constexpr Real64 theta1 = 0.0 ;
18541829 constexpr Real64 theta2 = 2 * Constant::Pi;
1855- Array1D <Real64> f (J0, 0.0 ) ;
1830+ std::vector <Real64> f;
18561831
18571832 Real64 h = (theta2 - theta1) / (J0 - 1 );
18581833
18591834 // Calculate the function at various equally spaced x values
1860- for (int j = 1 ; j <= J0; ++j) {
1861-
1862- theta = theta1 + (j - 1 ) * h;
1863-
1864- f (j) = nearFieldResponseFunction (m, n, m1, n1, eta, theta, t);
1835+ for (int j = 0 ; j < J0; ++j) {
1836+ theta = theta1 + j * h;
1837+ f.push_back (nearFieldResponseFunction (m, n, m1, n1, eta, theta, t));
1838+ }
18651839
1866- if (j == 1 || j == J0) {
1867- f (j) = f (j);
1868- } else if (isEven (j)) {
1869- f (j) = 4 * f (j);
1840+ for (int j = 1 ; j < J0 - 1 ; ++j) {
1841+ if (!isEven (j)) {
1842+ f[j] = 4 * f[j];
18701843 } else {
1871- f (j) = 2 * f (j) ;
1844+ f[j] = 2 * f[j] ;
18721845 }
1873-
1874- sumIntF += f (j);
18751846 }
18761847
1877- return (h / 3 ) * sumIntF ;
1848+ return (h / 3 ) * std::reduce (f. begin (), f. end ()) ;
18781849}
18791850
18801851// ******************************************************************************
@@ -1896,29 +1867,25 @@ Real64 GLHESlinky::doubleIntegral(int const m, int const n, int const m1, int co
18961867 constexpr Real64 eta1 = 0.0 ;
18971868 constexpr Real64 eta2 = 2 * Constant::Pi;
18981869
1899- Real64 sumIntF = 0.0 ;
1900- Array1D<Real64> g (I0, 0.0 );
1870+ std::vector<Real64> g;
19011871
19021872 Real64 h = (eta2 - eta1) / (I0 - 1 );
19031873
19041874 // Calculates the value of the function at various equally spaced values
1905- for (int i = 1 ; i <= I0; ++i) {
1906-
1907- Real64 eta = eta1 + (i - 1 ) * h ;
1908- g (i) = integral (m, n, m1, n1, t, eta, J0);
1875+ for (int i = 0 ; i < I0; ++i) {
1876+ Real64 eta = eta1 + i * h;
1877+ g. push_back ( integral (m, n, m1, n1, t, eta, J0)) ;
1878+ }
19091879
1910- if (i == 1 || i == I0) {
1911- g (i) = g (i);
1912- } else if (isEven (i)) {
1913- g (i) = 4 * g (i);
1880+ for (int i = 1 ; i < g.size () - 1 ; ++i) {
1881+ if (!isEven (i)) {
1882+ g[i] = 4 * g[i];
19141883 } else {
1915- g (i) = 2 * g (i) ;
1884+ g[i] = 2 * g[i] ;
19161885 }
1917-
1918- sumIntF += g (i);
19191886 }
19201887
1921- return (h / 3 ) * sumIntF ;
1888+ return (h / 3 ) * std::reduce (g. begin (), g. end ()) ;
19221889}
19231890
19241891// ******************************************************************************
0 commit comments