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 2 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.

Comment on lines +193 to +222
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,
]
Copy link
Contributor

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

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'''

Copy link
Author

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.

Copy link
Contributor

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:

  1. Like you said, take the rod as an argument, and the function need not return anything since rod is passed in as reference
  2. 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 in factory_function. Only keep the most essential parts in this function.
  3. 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.
  4. I see you hard-coded side_length and poisson_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(
Copy link
Contributor

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?

Copy link
Contributor

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 = [
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

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