MassimoCimmino / pygfunction

An open-source toolbox for the evaluation of thermal response factors (g-functions) of geothermal borehole fields.
BSD 3-Clause "New" or "Revised" License
48 stars 21 forks source link

New `Borefield` class #210

Open MassimoCimmino opened 2 years ago

MassimoCimmino commented 2 years ago

Many functions in the heat_transfer and gfunction modules necessitate to generate arrays of borehole parameters (i.e. H, D, r_b, x, y, tilt, orientation) from lists of boreholes. This generates multiple instances of duplicate and not very readable code.

The new Borefield class will replace lists of boreholes within the modules. Anytime a user provides a list of boreholes, this list will be used to generate a Borefield object. Alternatively, Borefield objects can be provided as input.

To preserve current behavior, the following should be considered (for an instance borefield of the Borefield class):

To simplify the code, the Borefield class will:

j-c-cook commented 1 year ago
  • Return arrays of parameters, e.g. borefield.H returns an array of borehole lengths.

I'm currently not sure how to make an instance a callable method like above. If self.H = self.H(), then when calling borefield.H, the method is bound and still needs the () on the end. Given that Borefield inherits from list, I think all of the methods would need overridden to update the instances any time an item was added or removed.

import pygfunction as gt
borefield = gt.boreholes.rectangle_field(2, 2, 5, 5, 100, 5, 0.075)
H = borefield.H()
MassimoCimmino commented 1 year ago

I had started the development a while ago on my branch. I also have uncommitted changes.

I had the Borefield class implemented similar to the Borehole class but with parameters stored as arrays: https://github.com/MassimoCimmino/pygfunction/blob/0beb558de5f921be22a45fc42a12cb45aa9b6533/pygfunction/boreholes.py#L240-L252

The main objective of implementing a Borefield class is to simplify the code for g-function calculation, since we have multiple instances of converting lists of boreholes into arrays of parameters (there are other operations that are encountered a couple times). I put this on hold since my initial implementation had non-negligible impact on the computational efficiency.