Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1s gfunction evaluation: numpy.linalg.LinAlgError: Singular matrix #231

Closed
wouterpeere opened this issue Oct 11, 2022 · 7 comments · Fixed by #240
Closed

1s gfunction evaluation: numpy.linalg.LinAlgError: Singular matrix #231

wouterpeere opened this issue Oct 11, 2022 · 7 comments · Fixed by #240
Labels
Milestone

Comments

@wouterpeere
Copy link
Contributor

When I tried to evaluate a gfunction at 1 second, I got an 'numpy.linalg.LinAlgError: Singular matrix' error.
The problem is, I think, caused by getting a all-zero matrix when calculating the thermal response factors, leading to a singular matrix. Whenever I try to run the code with an evaluation at 2 seconds, the thermal response factors are small (10^-200) but non-zero ...

The code I used was

import pygfunction as gt

borefield = gt.boreholes.rectangle_field(10, 12, 6, 6, 100, 4, 0.075)
gt.gfunction.gFunction(borefield, 1.25*10**-6, 1.).gFunc
@wouterpeere
Copy link
Contributor Author

I can create a function to check if the gfunction evaluation is at too small a timestep and make a PR, if you want to.

@MassimoCimmino
Copy link
Owner

This is an issue I had during the implementation of g-functions into modelica-ibpsa.

The solution should still return values for all requested times, even if the result is zero. One option is to evaluate a threshold time value (e.g. min(r_b)^2/(25*alpha)). Only times above the threshold have their g-function calculated. For the times below, the g-function is linearized between 0 (at t=0.) and the g-function at the threshold time.

I am of course open to other ideas.

@wouterpeere
Copy link
Contributor Author

That can be an elegant solution, although linearisation will not solve the problem in and of itself I think. One can evaluate at 0.00001s so it will be 0 even with linearisation.

Shouldn't there be a threshold below which the concept of gfunctions doesn't make sence anymore due to the fact that we are totally in the range of short-term effect?

@jeffreyspitler
Copy link

jeffreyspitler commented Oct 12, 2022 via email

@wouterpeere
Copy link
Contributor Author

@jeffreyspitler The paper you referenced was an interesting read. I think your comment is somewhat related to issues #149 and #44 (about the implementation of short-term g-functions). That would be indeed the most elegant solution in my opinion ...

@MassimoCimmino
Copy link
Owner

Thank you @jeffreyspitler. I also missed the (Mitchell and Spitler 2020) paper.

There are 3 issues discussed here. The first one being the bug (this issue) and the other 2 related to short time steps.

When considering short time steps, there are two classes of g-function definitions :

(1) The "wall-to-ground" g-function

This one relates the effective borehole wall temperature variation (T_b) to the heat extracted at the borehole wall (Q_b), with T_b(t) = T_g - Q_b / (2*pi*k_s) * g(t). This can be coupled to a short time step model during a simulation to relate the heat extracted from the fluid (Q_f) to the heat extracted at the borehole wall (`Q_b) and consider effects such as variable (and intermittent) fluid mass flow rates. This is the approach currently implemented in modelica-ibpsa.

(2) The "fluid-to-ground" g-function (sometimes called the g*-function)

This one relates the effective borehole wall temperature variation (T_b) (or sometimes the mean or inlet fluid temperature) to the heat extracted from the fluid (Q_f), with T_b(t) = T_g - Q_f / (2*pi*k_s) * g*(t). As @jeffreyspitler pointed out, T_b can be an "effective" temperature derived from the steady-state thermal resistance.

When using a steady-state thermal resistance to model the boreholes, the two approaches are equivalent : Q_b = Q_f.

Ideally, both will eventually be available in pygfunction. For (1), only the cylindrical correction to the borehole geometry is missing (#44). For (2), we probably need the development of a new module into pygfunction (#149).

@MassimoCimmino MassimoCimmino added this to the v2.2.2 milestone Oct 30, 2022
@MassimoCimmino
Copy link
Owner

@wouterpeere I fixed the error on the issue231_singularMatrix branch. Let me know if that fixes your issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants