47
47
48
48
// C++ Headers
49
49
#include < cmath>
50
+ #include < iterator>
50
51
#include < vector>
51
52
52
53
// ObjexxFCL Headers
@@ -487,12 +488,10 @@ GLHEResponseFactors::GLHEResponseFactors(EnergyPlusData &state, std::string cons
487
488
}
488
489
489
490
this ->numGFuncPairs = static_cast <int >(tmpLntts.size ());
490
- this ->LNTTS .dimension (this ->numGFuncPairs , 0.0 );
491
- this ->GFNC .dimension (this ->numGFuncPairs , 0.0 );
492
491
493
492
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 ]) ;
496
495
}
497
496
}
498
497
@@ -649,7 +648,7 @@ BuildAndGetResponseFactorsObjectFromSingleBHs(EnergyPlusData &state, std::vector
649
648
// Make new props object which has the mean values of the other props objects referenced by the individual BH objects
650
649
std::shared_ptr<GLHEVertProps> thisProps (new GLHEVertProps);
651
650
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 ) {
653
652
thisProps->bhDiameter += thisBH->props ->bhDiameter ;
654
653
thisProps->bhLength += thisBH->props ->bhLength ;
655
654
thisProps->bhTopDepth += thisBH->props ->bhTopDepth ;
@@ -962,18 +961,12 @@ void GLHEVert::calcUniformBHWallTempGFunctions(EnergyPlusData &state)
962
961
boreholes.emplace_back (bh->props ->bhLength , bh->props ->bhTopDepth , bh->props ->bhDiameter / 2.0 , bh->xLoc , bh->yLoc );
963
962
}
964
963
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
-
971
964
// Obtain number of segments by adaptive discretization
972
965
gt::segments::adaptive adptDisc;
973
966
int nSegments = adptDisc.discretize (this ->bhLength , this ->totalTubeLength );
974
967
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 );
977
970
}
978
971
979
972
// ******************************************************************************
@@ -989,8 +982,8 @@ void GLHEVert::calcGFunctions(EnergyPlusData &state)
989
982
990
983
// save data for later
991
984
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 );
994
987
myCacheData[" Response Factors" ][" GFNC" ] = std::vector<Real64>(this ->myRespFactors ->GFNC .begin (), this ->myRespFactors ->GFNC .end ());
995
988
writeGLHECacheToFile (state);
996
989
}
@@ -1025,17 +1018,12 @@ void GLHEVert::setupTimeVectors()
1025
1018
}
1026
1019
}
1027
1020
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 );
1039
1027
}
1040
1028
1041
1029
// ******************************************************************************
@@ -1045,15 +1033,15 @@ void GLHEVert::calcUniformHeatFluxGFunctions(EnergyPlusData &state)
1045
1033
DisplayString (state, " Initializing GroundHeatExchanger:System: " + this ->name );
1046
1034
1047
1035
// 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) {
1049
1037
for (auto const &bh_i : this ->myRespFactors ->myBorholes ) {
1050
1038
Real64 sum_T_ji = 0 ;
1051
1039
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] );
1053
1041
}
1054
- this ->myRespFactors ->GFNC ( lntts_index) += sum_T_ji;
1042
+ this ->myRespFactors ->GFNC [ lntts_index] += sum_T_ji;
1055
1043
}
1056
- this ->myRespFactors ->GFNC ( lntts_index) /= (2 * this ->totalTubeLength );
1044
+ this ->myRespFactors ->GFNC [ lntts_index] /= (2 * this ->totalTubeLength );
1057
1045
1058
1046
std::stringstream ss;
1059
1047
ss << std::fixed << std::setprecision (1 ) << float (lntts_index) / this ->myRespFactors ->LNTTS .size () * 100 ;
@@ -1375,25 +1363,18 @@ void GLHEVert::combineShortAndLongTimestepGFunctions()
1375
1363
}
1376
1364
1377
1365
// 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] );
1381
1369
}
1382
1370
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
+ } );
1387
1375
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;
1397
1378
}
1398
1379
1399
1380
void GLHEBase::makeThisGLHECacheAndCompareWithFileCache (EnergyPlusData &state)
@@ -1460,13 +1441,13 @@ void GLHEVert::readCacheFileAndCompareWithThisGLHECache(EnergyPlusData &state)
1460
1441
1461
1442
if (gFunctionsExist ) {
1462
1443
// 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>>());
1464
1445
1465
1446
// 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>>());
1467
1448
1468
1449
// 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>>());
1470
1451
}
1471
1452
}
1472
1453
@@ -1522,18 +1503,13 @@ void GLHESlinky::calcGFunctions(EnergyPlusData &state)
1522
1503
int NPairs = static_cast <int >((tLg_max - tLg_min) / (tLg_grid) + 1 );
1523
1504
1524
1505
// 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 );
1527
1508
this ->QnMonthlyAgg .allocate (static_cast <int >(this ->maxSimYears * 12 ));
1528
1509
this ->QnHr .allocate (730 + this ->AGG + this ->SubAGG );
1529
1510
this ->QnSubHr .allocate (static_cast <int >((this ->SubAGG + 1 ) * maxTSinHr + 1 ));
1530
1511
this ->LastHourN .allocate (this ->SubAGG + 1 );
1531
1512
1532
- for (int i = 1 ; i <= NPairs; ++i) {
1533
- this ->myRespFactors ->GFNC (i) = 0.0 ;
1534
- this ->myRespFactors ->LNTTS (i) = 0.0 ;
1535
- }
1536
-
1537
1513
// Calculate the number of loops (per trench) and number of trenches to be involved
1538
1514
// Due to the symmetry of a slinky GHX field, we need only calculate about
1539
1515
// on quarter of the rings' tube wall temperature perturbation to get the
@@ -1652,8 +1628,8 @@ void GLHESlinky::calcGFunctions(EnergyPlusData &state)
1652
1628
} // n1
1653
1629
} // m1
1654
1630
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;
1657
1633
1658
1634
} // NT time
1659
1635
}
@@ -1834,7 +1810,7 @@ inline bool GLHEBase::isEven(int const val)
1834
1810
1835
1811
// ******************************************************************************
1836
1812
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)
1838
1814
{
1839
1815
// SUBROUTINE INFORMATION:
1840
1816
// AUTHOR: Matt Mitchell
@@ -1848,33 +1824,28 @@ Real64 GLHESlinky::integral(int const m, int const n, int const m1, int const n1
1848
1824
// Simpson's 1/3 rule of integration
1849
1825
1850
1826
// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
1851
- Real64 sumIntF = 0.0 ;
1852
1827
Real64 theta = 0.0 ;
1853
1828
constexpr Real64 theta1 = 0.0 ;
1854
1829
constexpr Real64 theta2 = 2 * Constant::Pi;
1855
- Array1D <Real64> f (J0, 0.0 ) ;
1830
+ std::vector <Real64> f;
1856
1831
1857
1832
Real64 h = (theta2 - theta1) / (J0 - 1 );
1858
1833
1859
1834
// 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
+ }
1865
1839
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];
1870
1843
} else {
1871
- f (j) = 2 * f (j) ;
1844
+ f[j] = 2 * f[j] ;
1872
1845
}
1873
-
1874
- sumIntF += f (j);
1875
1846
}
1876
1847
1877
- return (h / 3 ) * sumIntF ;
1848
+ return (h / 3 ) * std::reduce (f. begin (), f. end ()) ;
1878
1849
}
1879
1850
1880
1851
// ******************************************************************************
@@ -1896,29 +1867,25 @@ Real64 GLHESlinky::doubleIntegral(int const m, int const n, int const m1, int co
1896
1867
constexpr Real64 eta1 = 0.0 ;
1897
1868
constexpr Real64 eta2 = 2 * Constant::Pi;
1898
1869
1899
- Real64 sumIntF = 0.0 ;
1900
- Array1D<Real64> g (I0, 0.0 );
1870
+ std::vector<Real64> g;
1901
1871
1902
1872
Real64 h = (eta2 - eta1) / (I0 - 1 );
1903
1873
1904
1874
// 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
+ }
1909
1879
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];
1914
1883
} else {
1915
- g (i) = 2 * g (i) ;
1884
+ g[i] = 2 * g[i] ;
1916
1885
}
1917
-
1918
- sumIntF += g (i);
1919
1886
}
1920
1887
1921
- return (h / 3 ) * sumIntF ;
1888
+ return (h / 3 ) * std::reduce (g. begin (), g. end ()) ;
1922
1889
}
1923
1890
1924
1891
// ******************************************************************************
0 commit comments