JWock82 / PyNite

A 3D structural engineering finite element library for Python.
MIT License
421 stars 86 forks source link

Add methods to Member for returning result arrays #144

Closed connorferster closed 1 year ago

connorferster commented 1 year ago

Is your feature request related to a problem? Please describe. In order to generate a factored load envelope, I need access to the results arrays of various load cases/combinations. I can generate these on my own but thought that it would be a welcome addition and possibly a stepping stone for future features in #101.

I am happy to create the PR for this!

Describe the solution you'd like The suggestion is to create the following methods onto Member:

They could be implemented similar to the hard-coded approach you have in .plot_shear, etc.

def shear_array(dir: str, n: int, combo_name: str) -> np.ndarray:
    """
    Returns an array describing the shear result...
    ...
    """
    L = self.L
    x_arr = np.linspace(0, L, n)
    y_arr = np.array(
        [self.shear(dir, combo_name) for x in x_arr]
    )
    return np.array([x_arr, y_arr])

These methods could then replace those sections of code in the .plot_... methods and would allow for the .plot_... methods to have a user-specified n indicating the number of points they would like to discretize the plot with, which would be good because sometimes 20 points is just not enough and the plots end up looking distorted and confusing.

Describe alternatives you've considered Generating the arrays myself

Additional context Having access to results arrays allows for plots to be generated in any plotting software, not just matplotlib. By generating the resulting arrays conveniently, it allows for a little bit extra extensibility both for plotting and post-processing.

JWock82 commented 1 year ago

I like this idea. I think there's a way to do it with minimal extra lines of code. What if we had a boolean argument in the plot_shear method named 'to_array' (defaults to False) that changed the output of the method to an array instead of a matplotlib plot? I agree that 20 points is often just not enough too. I've been meaning to add an 'n' argument to plot_shear as well.

JWock82 commented 1 year ago

It seems like all it would take is an if statement placed conveniently to ignore the plotting commands and return the array directly.