From d3160dced9112596c41ed1d6ac21b95605e5e8a4 Mon Sep 17 00:00:00 2001 From: Chris McComb Date: Sun, 17 Dec 2023 10:24:25 -0500 Subject: [PATCH] Added summary table in report and more conistent typehinting --- trussme/evaluate.py | 22 +++++++++---------- trussme/report.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/trussme/evaluate.py b/trussme/evaluate.py index ca90211..95aaed8 100644 --- a/trussme/evaluate.py +++ b/trussme/evaluate.py @@ -6,12 +6,12 @@ TrussInfo = TypedDict( "TrussInfo", { - "coordinates": numpy.ndarray, - "connections": numpy.ndarray, - "loads": numpy.ndarray, - "reactions": numpy.ndarray, - "area": numpy.ndarray, - "elastic_modulus": numpy.ndarray, + "coordinates": NDArray[float], + "connections": NDArray[float], + "loads": NDArray[float], + "reactions": NDArray[float], + "area": NDArray[float], + "elastic_modulus": NDArray[float], }, ) @@ -19,19 +19,19 @@ def the_forces( truss_info: TrussInfo, ) -> tuple[NDArray[float], NDArray[float], NDArray[float], float]: - tj: numpy.ndarray = numpy.zeros([3, numpy.size(truss_info["connections"], axis=1)]) - w: numpy.ndarray = numpy.array( + tj: NDArray[float] = numpy.zeros([3, numpy.size(truss_info["connections"], axis=1)]) + w: NDArray[float] = numpy.array( [ numpy.size(truss_info["reactions"], axis=0), numpy.size(truss_info["reactions"], axis=1), ] ) - dof: numpy.ndarray = numpy.zeros([3 * w[1], 3 * w[1]]) - deflections: numpy.ndarray = numpy.ones(w) + dof: NDArray[float] = numpy.zeros([3 * w[1], 3 * w[1]]) + deflections: NDArray[float] = numpy.ones(w) deflections -= truss_info["reactions"] # This identifies joints that can be loaded - ff: numpy.ndarray = numpy.where(deflections.T.flat == 1)[0] + ff: NDArray[float] = numpy.where(deflections.T.flat == 1)[0] # Build the global stiffness matrix for i in range(numpy.size(truss_info["connections"], axis=1)): diff --git a/trussme/report.py b/trussme/report.py index 8a68c0d..97d0b76 100644 --- a/trussme/report.py +++ b/trussme/report.py @@ -82,6 +82,59 @@ def generate_summary(the_truss) -> str: summary += st + "," summary += "and " + str(failure_string[-1]) + " were not satisfied.\n" + data = [] + rows = [ + "Minimum Total FOS", + "Minimum FOS for Buckling", + "Minimum FOS for Yielding", + "Maximum Mass", + "Maximum Deflection", + ] + data.append( + [ + the_truss.minimum_fos_total, + the_truss.fos_total, + "Yes" if the_truss.fos_total > the_truss.minimum_fos_total else "No", + ] + ) + data.append( + [ + the_truss.minimum_fos_buckling, + the_truss.fos_buckling, + "Yes" if the_truss.fos_buckling > the_truss.minimum_fos_buckling else "No", + ] + ) + data.append( + [ + the_truss.minimum_fos_yielding, + the_truss.fos_yielding, + "Yes" if the_truss.fos_yielding > the_truss.minimum_fos_yielding else "No", + ] + ) + data.append( + [ + the_truss.maximum_mass, + the_truss.mass, + "Yes" if the_truss.mass < the_truss.maximum_mass else "No", + ] + ) + data.append( + [ + the_truss.maximum_deflection, + the_truss.deflection, + "Yes" if the_truss.deflection < the_truss.maximum_deflection else "No", + ] + ) + + summary += ( + "\n" + + pandas.DataFrame( + data, + index=rows, + columns=["Target", "Actual", "Ok?"], + ).to_markdown() + ) + return summary