Skip to content

Conversation

bjhowie
Copy link
Contributor

@bjhowie bjhowie commented Aug 26, 2024

The Member3D array results methods were just generating the results in a list comprehension then converting to a numpy array, which is quite slow. I have updated the methods to use vectorised numpy methods instead, unless a P-delta analysis has been conducted.

From the tests i've done, results extraction is approximately 10x faster for a member with 100 result stations.

@bjhowie
Copy link
Contributor Author

bjhowie commented Aug 26, 2024

I suggest we update the tests to use Numpy < 2.0. Seems to be all that is failing.

@connorferster
Copy link
Collaborator

@bjhowie Thanks for doing that. I did the original implementation of the results arrays methods so I am glad that you took the time to vectorize them...for a whopping 10X speed increase!!! That is awesome and will make such a difference.

@connorferster
Copy link
Collaborator

@JWock82 I will leave this PR for you to do a final review on in case there is something in the code that I missed during my review but I think it looks good.

"""
Returns the torsional moment in the segment.
"""

# The torsional moment is constant across the segment
# This can be updated in the future for distributed torsional forces
return self.T1

if isinstance(x, (int, float)):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this change is doing. Can you provide some comments to clarify?

Copy link
Contributor Author

@bjhowie bjhowie Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for checking whether 'x' is a number or not is that these segment result functions can now be given an 'x' value that is actually an array of x values. The calling function expects the returned value to be an array of length equal to the input array of x values. For most functions, the returned value is calculated as a function of the input 'x' value which means the result is automatically equal in length to to 'x'. As the torsion is not calculated as a function of 'x', we need to manually check if 'x' is an array, and if so, return an array of equal length.

I am going to update these functions with type annotations, as a reminder in future that the function can accept either a number or an array of numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually scratch that last point. I'm not familiar with type annotations prior to python 3.10, which we would need to support. There is a broader conversation to be had there.

"""

# Segment the member into segments with mathematically continuous loads if not already done
Copy link
Owner

@JWock82 JWock82 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep some documentation stating why segmenting is necessary - to produce mathematically continuous beam segments (no point loads within a segment). This allows us to use direct integration to obtain changes in moment, shear, slope and deflection inside the member. That may not be obvious to others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. If i'm honest, I can't remember why this was changed. I'll revert.

Copy link
Owner

@JWock82 JWock82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears these changes only affect the member results arrays. These methods were originally written by @connorferster and I don't use them myself, so if he approves of them I'm OK with them. I've briefly skimmed the code and believe it to be correct. I recommend setting up some unit tests for these methods to help prevent bugs from being introduced into them going forward.

@JWock82 JWock82 merged commit d87b05f into JWock82:main Sep 11, 2024
4 checks passed
@bjhowie bjhowie deleted the better-results-extraction branch January 19, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants