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

Optimize the calculation of integrals and similarities #78

Closed
MassimoCimmino opened this issue Mar 9, 2021 · 7 comments · Fixed by #90
Closed

Optimize the calculation of integrals and similarities #78

MassimoCimmino opened this issue Mar 9, 2021 · 7 comments · Fixed by #90
Assignees

Comments

@MassimoCimmino
Copy link
Owner

Consider using quadpy or other specialized integration packages to speed up the calculation of integrals. quadpy supports vectorization for the integral bounds and has many options for integration schemes (some of which might be better adapted to the evaluation of the FLS).

I just checked and scipy seems to have support vectorization of the integrand. It could be used to vectorize over distances, whereas quadpy can vectorize over time.

@MassimoCimmino

This comment has been minimized.

@MassimoCimmino
Copy link
Owner Author

I may have misunderstood the capabilities of quadpy. I am unsure if will provide any increase in computational speed.

@MassimoCimmino MassimoCimmino changed the title Optimize the calculation of integrals Optimize the calculation of integrals and similarities Apr 10, 2021
@MassimoCimmino
Copy link
Owner Author

Using quad_vec requires changes to gFunction.thermal_reponse_factors() class methods. At the moment, the segment-to-segment response factors are calculated with parallel calls to finite_line_source using the time vector, one pair of segments at a time.

quad_vec needs constant bounds for integration. The two options are (1) to call finite_line_source for all pairs of segments at a given distance or (2) to call finite_line_source for similar pairs of segments at all distances. Option (1) is more natural since it amounts to considering pairs of boreholes at each call.

It would therefore be relevant to revisit the similarities method and adapt it to the new structure. Some elements of the method can be optimized. Right now, the method loops over segments to find similar distances and segments. A loop over boreholes first makes more sense: similar pairs of boreholes will have similar pairs of segments. This additional step should greatly reduce the time required to find similarities.

@MassimoCimmino
Copy link
Owner Author

MassimoCimmino commented Apr 14, 2021

A draft implementation is introduced in f7e6574, see #90.
2021-05-19 : Results are updated to 841e011.

The new algorithm almost eliminates the time required for the identification of similarities. The calculation time is also reduced by using quad_vec instead of quad. The new algorithm does not split the real and image parts of the FLS solution. It seems the image part is too difficult for quad_vec to solve efficiently. quad_vec is then used to solve the full FLS solution between all segments of similar pairs of boreholes at all distances at once (but one time step at a time).

Here a 3 test cases for the speed and accuracy of the new method (comparing the New algorithm with the Old):

  1. Using nSegments=12 and Nt=25 time steps : Evaluate the g-function for all rectangular fields from 1 by 1 to 12 by 12 boreholes.
  2. For a rectangular field of 5 by 5 boreholes and Nt=25 time steps : Evaluate the g-function for increasing nSegments = 1, 2, 4, ..., 32.
  3. For a special field of 100 boreholes with 2 different borehole lengths : Evaluate the g-function using nSegments=12 and Nt=25 time steps.

All results are shown below. The new method performs better in all tested cases, especially for the special field. Some differences are seen in the comparisons for rectangular fields. The new method finds distances for similarities differently than the old method. In the new method, the distance for a group of similar pairs is the average distance, whereas in the old method the distance is the first one found. This could be verified by decreasing the tolerance disTol.


Case 1 : Rectangular fields up to 12 by 12

Figure_1-Rectangular-Time
Figure_1-Rectangular-Error


Case 2 : Number of segments for a 5 by 5 bore field

Figure_2-Segments-Time
Figure_2-Segments-Error


Case 3 : Field of 100 boreholes with 2 different lengths

Figure_3-Special-Field
Figure_3-Special-gFunc
Figure_3-Special-Error

@MassimoCimmino
Copy link
Owner Author

MassimoCimmino commented Apr 14, 2021

(From an earlier commit)

Case 1 with disTol = 0.001 (decreased from disTol = 0.01)

Figure_4-Rectangular-Time-disTol
Figure_4-Rectangular-Error-disTol

@MassimoCimmino
Copy link
Owner Author

MassimoCimmino commented May 19, 2021

2021-05-19 : Results are from 841e011.

Additional test cases for the detailed solver, which now also uses quad_vec:

  1. Using nSegments=12 and Nt=25 time steps : Evaluate the g-function for all rectangular fields from 1 by 1 to 5 by 5 boreholes. We stop there since it is much slower than the similarities solver.
  2. For a rectangular field of 5 by 5 boreholes and Nt=25 time steps : Evaluate the g-function for increasing nSegments = 1, 3, 6, 12.
  3. Too slow with the old detailed solver.
  4. For a field of 5 boreholes of uneven lengths unevenly space on a line : Evaluate the g-function using nSegments=12 and Nt=25 time steps.

Case 1' : Rectangular fields up to 5 by 5

Figure_5-Rectangular-Time-Detailed
Figure_5-Rectangular-Error-Detailed


Case 2' : Number of segments for a 5 by 5 bore field

The differences are caused by the use of quad (old implementation) and quad_vec (new implementation). In the old implementation, segment-to-segment response factors are solved one pair at a time but all time steps are calculated in parallel using Pool. In the new implementation, segment-to-segment response factors are solved one time step at a time but multiple pairs at a time using quad_vec. The former is faster if there are only a few segments per borehole.

Figure_6-Segments-Time-Detailed
Figure_6-Segments-Error-Detailed


Case 4' : Field of 5 uneven boreholes

Figure_7-Uneven-Field
Figure_7-Uneven-gFunc-Detailed
Figure_7-Uneven-Error-Detailed

@MassimoCimmino
Copy link
Owner Author

2021-05-20 : Results are from 841e011.

Here we compare the new similarities solver with the new detailed solver :

  1. Using nSegments=12 and Nt=25 time steps : Evaluate the g-function for all rectangular fields from 1 by 1 to 12 by 12 boreholes.
  2. For a rectangular field of 5 by 5 boreholes and Nt=25 time steps : Evaluate the g-function for increasing nSegments = 1, 2, 4, 8, 16, 32.
  3. For a special field of 100 boreholes with 2 different borehole lengths : Evaluate the g-function using nSegments=12 and Nt=25 time steps.
  4. For a field of 5 boreholes of uneven lengths unevenly space on a line : Evaluate the g-function using nSegments=12 and Nt=25 time steps.

Case 1'' : Rectangular fields up to 12 by 12

The new similarities solver is closer to the detailed solver than to the old similarities solver. This seems to indicate that the new similarities solver provides better accuracy (thanks to using the average distance between similar pairs).

Figure_8-Rectangular-Time-Validation
Figure_8-Rectangular-Error-Validation


Case 2'' : Number of segments for a 5 by 5 bore field

Figure_9-Segments-Time-Validation
Figure_9-Segments-Error-Validation


Case 3'' : Field of 100 boreholes with 2 different lengths

Figure_3-Special-Field
Figure_10-Special-gFunc-Validation
Figure_10-Special-Error-Validation


Case 4'' : Field of 5 uneven boreholes

Figure_7-Uneven-Field
Figure_11-Uneven-gFunc-Validation
Figure_11-Uneven-Error-Validation

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

Successfully merging a pull request may close this issue.

1 participant