There is a segmentation fault that is occurring inside of the Eigen
library upon the API call to cpgfunctionEP
via the UBHWTCalc
input on the Linux CI machines and inside of CLion on my local. This segmentation fault has been around and unnoticed for quite some time. The segmentation fault does not exist if I build energyplus from source, and then pass a weather file and the GSHP-GLHE-CalcGFunctions-cpg.idf
test file. The segmentation fault does not exist when I build cpgfunctionEP
in my own repository as a standalone.
mkdir build && cd build && cmake .. && make energyplus -j 16
cp ../testfiles/GSHP-GLHE-CalcGFunctions-cpg.idf Products/ && cp ../weather/USA_OK_Oklahoma.City-Will.Rogers.World.AP.723530_TMY3.epw Products/
cd Products/
./energyplus -w USA_OK_Oklahoma.City-Will.Rogers.World.AP.723530_TMY3.epw GSHP-GLHE-CalcGFunctions-cpg.idf
The resulting long time-step g-function located in the eplusout.glhe
file:
2.5227814172726757,
2.7705529489647103,
3.0181546610457,
3.2655977297246355,
3.516846551928096,
3.7912271892255647,
4.127136395615098,
4.56335062650864,
5.116250608380114,
5.774475535544771,
6.509681059546577
I have gone to the j-c-cook/cpgfunctionEP
repository and created a test file that performs the same function call to the uniform_borehole_wall_temperature()
function. That example is below (Note: I have modified the number of segmnents in the EnergyPlus call to be 1 to reduce the total number of sources so the matrices are more palpable):
//
// Created by jackcook on 8/16/21.
//
#include <cpgfunction/coordinates.h>
#include <cpgfunction/boreholes.h>
#include <cpgfunction/utilities.h>
#include <cpgfunction/gfunction.h>
int main() {
// -- Definitions --
// Coordinate geometry
int Nx = 2;
int Ny = 2;
double Bx = 5.;
double By = 5;
// -- Configurations --
// Get x,y coordinates for a rectangle
std::string shape = "Rectangle";
std::vector<std::tuple<double, double>> coordinates =
gt::coordinates::configuration(shape, Nx, Ny, Bx, By);
// -- Borehole geometry --
double H = 100; // height of the borehole (in meters)
double D = 1; // burial depth (in meters)
double r_b = 0.057; // borehole radius (in meters)
// -- boreField --
std::vector<gt::boreholes::Borehole> boreField =
gt::boreholes::boreField(coordinates, r_b, H, D);
// Thermal properties
double alpha = 1.0e-6; // Ground thermal diffusivity (m2/s)
// Number of segments per borehole
int nSegments = 1;
double duration = 1;
std::string units = "year";
double const expansion = 0.5;
vector<double> time = gt::utilities::time_vector_constant_expansion(
H, alpha, duration, units, expansion);
std::vector<double> gFunction =
gt::gfunction::uniform_borehole_wall_temperature(boreField,
time,
alpha,
nSegments,
true);
for (size_t i=0; i<gFunction.size(); i++) {
std::cout << gFunction[i] << std::endl;
}
}
Outputs (Note the exact match out to 16 decimal places to the ./energyplus UBHWT g-function above):
2.522781417272676
2.77055294896471
3.0181546610457
3.265597729724635
3.516846551928096
3.791227189225565
4.127136395615098
4.56335062650864
5.116250608380114
5.774475535544771
6.509681059546577
The segmentation fault in EnergyPlus occurs upon the first partial pivot LU decomposition API call. The A and B matrix are shown below:
A (EnergyPlus -> cpgfunctionEP)
2.52278 1.71313e-14 1.71313e-14 8.60119e-27 -1
1.71313e-14 2.52278 8.60119e-27 1.71313e-14 -1
1.71313e-14 8.60119e-27 2.52278 1.71313e-14 -1
8.60119e-27 1.71313e-14 1.71313e-14 2.52278 -1
100 100 100 100 0
B (EnergyPlus -> cpgfunctionEP)
A (cpgfunctionEP)
2.52278 1.71313e-14 1.71313e-14 8.60119e-27 -1
1.71313e-14 2.52278 8.60119e-27 1.71313e-14 -1
1.71313e-14 8.60119e-27 2.52278 1.71313e-14 -1
8.60119e-27 1.71313e-14 1.71313e-14 2.52278 -1
100 100 100 100 0
B (cpgfunctionEP)
The A and B matrices appear identical. The g-function results of the energyplus
executable are identical to cpgfunctionEP
. The reasoning for the segmentation fault in Linux on the CI machines when running tests, when running tests (ctest) on my local and when running the input file on CLion are unknown.
Given that this is a timely manner due to the deadline for API changes for the next release to be finalized by this Friday, I am considering replacing the Eigen LU partial pivot decomposition call with a hand written one or finding a standalone.