Skip to content
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

Open
wants to merge 5 commits into
base: update-0.3.3
Choose a base branch
from

Conversation

Andrew-Tao
Copy link

Conservative_Load

3D_Tumbling_Unconstrained_Rod.mp4

Conservative_Load

Conservative-Case.mp4

Convergence Study

3D_muscular_snake.mp4
3D_muscular_snake2.mp4

Copy link
Collaborator

@skim0119 skim0119 left a 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?

@Andrew-Tao
Copy link
Author

Andrew-Tao commented Dec 20, 2024 via email

Copy link
Contributor

@sy-cui sy-cui left a 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.

  1. Look into python naming convention (e.g. PEP 8). For example, look at when to use CapWords or lower_case_with_underscores. Then go through these files and check if everything adheres to these conventions
  2. 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.
  3. If possible, it may be cleaner to load large hard-coded data arrays from a separate data file.
  4. Remove comments unless they are related to simulation parameters (e.g. total steps) or final outputs

)

# Add call backs
class AxialStretchingCallBack(ea.CallBackBaseClass):
Copy link
Contributor

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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lower case

Comment on lines 22 to 24
PLOT_FIGURE = True
SAVE_FIGURE = False
SAVE_RESULTS = False
Copy link
Contributor

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)
Copy link
Contributor

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.

n_elem, base_length, base_radius, youngs_modulus, -15, True, False
)

x_tip_paper = [
Copy link
Contributor

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


Copy link
Contributor

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

Suggested change
import ...
def run_simulation(...):
"""" function definition """
if __name__ == "__main__":
# actual code to run in this script

Copy link
Contributor

@sy-cui sy-cui left a 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
Copy link
Contributor

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):
Copy link
Contributor

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(
Copy link
Contributor

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.


plot_video_with_surface(
[recorded_history],
video_name="cantilever_subjected_to_a_transversal_load.mp4",
Copy link
Contributor

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.

Comment on lines +1 to +17
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,
)
Copy link
Contributor

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)
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants