Replies: 3 comments 1 reply
-
|
Python is a indentation based language. I think we have to keep the naming convention as small as possible. Common symbols will increase the readibility of the code. For example lets assume that we are trying to write method for signed von mises. long form |
Beta Was this translation helpful? Give feedback.
-
Naming suggestion:Calculation functionsShould utilize import numpy as np
from numpy.typing import NDArray
def calc_stress_von_mises[T: NDArray[np.floating]](stress_vector: T) -> T:
""" Calculate the von Mises stress from the stress vector.
Args:
stress_vector (T): Stress vector of shape (n, 6) where n is the number of points.
"""
svm = np.sqrt(
0.5 * ((stress_vector[:, 0] - stress_vector[:, 1]) ** 2
+ (stress_vector[:, 1] - stress_vector[:, 2]) ** 2
+ (stress_vector[:, 2] - stress_vector[:, 0]) ** 2
+ 6 * (stress_vector[:, 3] ** 2 + stress_vector[:, 4] ** 2 + stress_vector[:, 5] ** 2))
)
return svmFunctions input - Voigt notation vs componentsStress vector in voigt notation is prefered over multiple components vectors / stress tensor def correct_function[T: NDArray[np.floating]](stress_vector: T) -> T:
""" Description of function
Args:
stress_vector (T): Stress vector of shape (n, 6) where n is the number of points.
"""
pass
def incorrect_function[T: NDArray[np.floating]](s11: T, s22: T, s33: T, s12: T, s23: T, s13: T) -> T:
""" Description of function
Args:
s11 (T): Normal stress ($S_{11}$) vector (n,) where n is the number of points.
...
s13 (T): Shear stress ($S_{13}$) vector (n,) where n is the number of points.
"""
passStressesMaterial parameters: |
Beta Was this translation helpful? Give feedback.
-
|
I would like to additionally correct myself, as Generic type annotation from python 3.12 will not be initially implemented as this is not required currently. Maybe in future if there will be such requirement, we could implement something of that sort. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
Edit: changed naming for first, second principal stress, mean, amp stress
It's crucial to decide on consistent naming conventions. Establishing this early, in line with the spirit of Python's PEP 8 for readable code, will make the library easier to understand, use, and contribute to.
Fatigue analysis uses many specific terms and symbols (e.g., σ_a, R, S_e). While symbols are common in literature, clear, descriptive names are generally better for code clarity and maintainability. Therefore, the initial suggestion is to prioritize descriptive, verbose names over brevity or abbreviations, even if they are slightly longer. We should, of course, use standard Python
snake_case.Applying this principle, let's consider some examples:
calculate_von_mises_stressorcalculate_stress_amplituderather thanvon_misesorstress_amp. Thoughts?stress_amplitude,mean_stressor potentionallysg_mean,sg_ampoversg_a,sg_morsa,sm. Does this seem right?stress_ratiovs.R?youngs_modulusvs.E?poissons_ratiovs.nu?ultimate_strengthvs.R_m?first_principal,second_principalseems most descriptive. Agree?Goal: To establish naming conventions that prioritize clarity and readability for all users, making the code self-explanatory where possible.
What are your thoughts on this "clarity first" approach? Do you agree with leaning towards verbosity? What are your preferences on the specific examples, especially regarding common symbols?
Beta Was this translation helpful? Give feedback.
All reactions