0

A bit of background: I am working on a project for university. Right now, I need to create shear force diagram. This is done by integrating the loads that are acting along the beam of interest. This is all well and good, and it is pretty straight forward I think. I am using the integrate.quad function, see also my code below.

def ShearIntegral(z):
    result = np.zeros_like(z)
    for i, val in enumerate(z):
        q,error = integrate.quad(Loading, 0, val)
        y = -q + 22028.2 + 68351.55 - L/2 #numerical terms take into account the reaction force at the root
        result[i] = y
    return result

In this code, z is an array of the form np.arange(0,18,0.25) (e.g. the beam I'm interested in extends from 0 meters to 18 meters). The loading is a combination of a few functions, but I don't think it is of much importance here, as the time needed to compute the value of each iteration is negligible.

My main "issue", if you will, is the time needed to compute the the result. In total, it takes 71 iterations to find the result. Of these iterations, the first 30 or so only take 30 seconds total. However, the remaining 41 iterations start taking ever longer, giving me a total program runtime of 4 minutes and 30 seconds.

Are there any computational enhancements that are available to speed up this process?

tdelaney
  • 73,364
  • 6
  • 83
  • 116
  • 1
    Whether or not `Loading` is written as a numpy function could make quite some difference in calculation time. Also, couldn't you just calculate the integral of the regions `z[i-1]` to `z[i]` and sum those partial integrals instead of always restarting from `0`? Further, you could experiment with the tolerance parameters, as the defaults might not be suitable for your situation. – JohanC Nov 17 '20 at 06:57
  • Check the `loading` function. Something's not right if we're talking minutes here. Is it singular? Why is integration at larger values of z takes this this long? – ev-br Nov 18 '20 at 04:31

0 Answers0