-
Notifications
You must be signed in to change notification settings - Fork 113
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.
examples/CantileverDistributedLoad/cantilever_conservative_distributed_load.py
Outdated
Show resolved
Hide resolved
examples/CantileverDistributedLoad/cantilever_distrubuted_load_postprecessing.py
Show resolved
Hide resolved
examples/CantileverDistributedLoad/cantilever_distrubuted_load_postprecessing.py
Show resolved
Hide resolved
examples/CantileverDistributedLoad/cantilever_distrubuted_load_postprecessing.py
Show resolved
Hide resolved
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 |
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. Just a few small conventional things like renaming variables. I did not exhaustively comment at every occurrence that should be changed, so when you make a change (e.g. changing stretch_sim
to more appropriate names), check the other files and see if they can be improved in the same way. Again, make sure that after changing things your code still runs.
@@ -0,0 +1,240 @@ | |||
# from charset_normalizer.legacy import ResultDict |
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.
Remove
) | ||
|
||
|
||
def conservative_force_simulator(load, Animation=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.
Change animation
to lower case. Make sure you change every occurrence in the function as well. (Use refactor / batch replace)
|
||
|
||
def conservative_force_simulator(load, Animation=False): | ||
class StretchingBeamSimulator( |
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.
For all StretchingBeam
/ stretch_sim
/ stretchable_rod
and any other ones that are appropriate, change to something more coherent to this case, e.g. square_rod
.
examples/CantileverDistributedLoad/cantilever_conservative_distributed_load.py
Show resolved
Hide resolved
examples/CantileverDistributedLoad/cantilever_distrubuted_load_postprecessing.py
Outdated
Show resolved
Hide resolved
|
||
plot_video_with_surface( | ||
[recorded_history], | ||
video_name="cantilever_subjected_to_a_transversal_load.mp4", |
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 before. if __name__
block here.
import numpy as np | ||
from matplotlib import pyplot as plt | ||
from matplotlib import cm | ||
from tqdm import tqdm | ||
from typing import Dict, Sequence | ||
|
||
pass | ||
import logging | ||
from numpy.testing import assert_allclose | ||
from elastica.utils import MaxDimension, Tolerance | ||
from elastica._linalg import _batch_cross, _batch_norm, _batch_dot | ||
from elastica.rod.factory_function import ( | ||
_assert_dim, | ||
_position_validity_checker, | ||
_directors_validity_checker, | ||
_position_validity_checker_ring_rod, | ||
) |
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.
Make sure all of these imports are necessary. You can see which ones are unused in your IDE.
tmp[0, :] = -radius * np.cos(t) + 1 | ||
tmp[1, :] = radius * np.sin(t) | ||
tmp[2, :] *= 0.0 | ||
dir = np.zeros((3, 3, n_elem), dtype=np.float64) |
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.
dir
shadows a built-in python function. Change it to something else
3D_Tumbling_Unconstrained_Rod.mp4
Conservative-Case.mp4
3D_muscular_snake.mp4
3D_muscular_snake2.mp4