-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Three Rod-examples #456
base: update-0.3.3
Are you sure you want to change the base?
Three Rod-examples #456
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Andrew-Tao Thank you! Could you add some documentation on each case, such as link to the reference paper and where you got the theoretical data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work. I only went through one of the cases in detail, but I think the same comments apply to the other cases.
- Look into python naming convention (e.g. PEP 8). For example, look at when to use
CapWords
orlower_case_with_underscores
. Then go through these files and check if everything adheres to these conventions - Don't repeat yourself. If a function already exists and can be reused without much modification, look for ways to call them instead of copying them in every case.
- If possible, it may be cleaner to load large hard-coded data arrays from a separate data file.
- Remove comments unless they are related to simulation parameters (e.g. total steps) or final outputs
) | ||
|
||
# Add call backs | ||
class AxialStretchingCallBack(ea.CallBackBaseClass): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the class name to the case name accordingly
ea.OneEndFixedBC, constrained_position_idx=(0,), constrained_director_idx=(0,) | ||
) | ||
|
||
Conservative_Load = np.array([0.0, -end_force_x, 0.0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lower case
PLOT_FIGURE = True | ||
SAVE_FIGURE = False | ||
SAVE_RESULTS = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seem to be unused? Remove them if that is the case
# timestepper = PEFRL() | ||
|
||
total_steps = int(final_time / dt) | ||
print(stretch_sim) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think printing this out is useful.
x_tip_paper = [ | ||
0.9912, | ||
0.9309, | ||
0.8455, | ||
0.7613, | ||
0.6874, | ||
0.6249, | ||
0.5724, | ||
0.5281, | ||
0.4906, | ||
0.4584, | ||
0.4306, | ||
0.4064, | ||
0.3851, | ||
] | ||
y_tip_paper = [ | ||
0.1241, | ||
0.3411, | ||
0.4976, | ||
0.6031, | ||
0.6745, | ||
0.7243, | ||
0.7603, | ||
0.7871, | ||
0.8077, | ||
0.8239, | ||
0.8370, | ||
0.8478, | ||
0.8568, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to load this from a data file
return x_tip, y_tip, z_tip | ||
|
||
|
||
def adjust_square_cross_section( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems to have a lot in common with elastica/rod/factory_function
. Considering you are only modifying a few properties, is it possible to just do a function like
def adjust_square_cross_section(rod: RodType):
'''Take the rod as argument and modify its properties in-place'''
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had tried lots of ways to simplify this process, but I found it hardly possible. Because I need to change all three second moment of mass (I0_1,I0_2,I0_3) according to the shape of the cross-section, and all other key parameters including bend_matrix and shear_matrix, needed to be recalculated based on the new second moment of mass. So it's basically the same as the factory_function. However, I do can take the rod as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. A few things you can do:
- Like you said, take the rod as an argument, and the function need not return anything since rod is passed in as reference
- Many of the initial parts of this function is already done in
factory_function
, which is called when you first initialize the rods. Since you are only modifying moi, bend and shear matrices, there is no need for things like position/director initializations and all those assertions/validity checks as they are readily done infactory_function
. Only keep the most essential parts in this function. - You might consider merging the two cantilever cases into one directory. The post-processing files of these two are almost identical as far as i can tell.
- I see you hard-coded
side_length
andpoisson_ratio
into this function. Consider passing them in as arguments so the function is generic and not tied to this particular case
) | ||
|
||
|
||
def plot_video_with_surface( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is repeated in all of these examples. Consider only have one of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these functionalities are used repeatedly. Try condensing them based on 'DRY' (don't repeat yourself)
n_elem, base_length, base_radius, youngs_modulus, -15, True, False | ||
) | ||
|
||
x_tip_paper = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other file. Maybe load data from a file, and do not run the same simulation more than once.
print(relative_tip_position) | ||
return relative_tip_position | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good practice to structure a file like
import ... | |
def run_simulation(...): | |
"""" function definition """ | |
if __name__ == "__main__": | |
# actual code to run in this script |
3D_Tumbling_Unconstrained_Rod.mp4
Conservative-Case.mp4
3D_muscular_snake.mp4
3D_muscular_snake2.mp4