pygfunction icon indicating copy to clipboard operation
pygfunction copied to clipboard

New `Borefield` class

Open MassimoCimmino opened this issue 3 years ago • 2 comments

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):

  • borefield[i] should return the i-th borehole
  • borefield[i0:i1] should return an instance of the Borefield class formed by boreholes i0 through i1-1.

To simplify the code, the Borefield class will:

  • Implement class methods similar to the Borehole class to evaluate, e.g., distance vectors and arrays. An additional parameter outer can be included to evaluate distance vectors (outer=False) and arrays (outer=True).
  • Return arrays of parameters, e.g. borefield.H returns an array of borehole lengths.

MassimoCimmino avatar Jun 21 '22 21:06 MassimoCimmino

  • 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()

j-c-cook avatar Jan 09 '23 23:01 j-c-cook

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.

MassimoCimmino avatar Jan 10 '23 13:01 MassimoCimmino