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

Address #148 by adding ConfigurableFixedConstraint boundary condition class #143

Merged

Conversation

mstoelzle
Copy link
Contributor

@mstoelzle mstoelzle commented Jul 18, 2022

Motivation

Currently, there exists only the option to either have a) no boundary conditions or b) fully fixed boundary conditions. The only functionality in between is that for example translations are allowed, but rotations are constrained and vice-versa. However in practice, there are many situations where we would like to allow certain translations (for example along a plane) or rotations (for example allow yawing of the end of the rod), but constrain all other DoF. The user of the library would have to implement this functionality all themselves inheriting from the FreeBC class. In many cases, such an implementation is not straight-forward. Thus, the library should provide the user the option to configure the BC themselves in a simple fashion. Although it obviously will never cover all the edge-cases a specific project might require, it will give the user an idea / hint / guidance on how to implement a similar solution.

Provided functionality

This PR add the following functionality through the ConfigurableFixedConstraint class:

  • Using boolean arrays translational_constraint_selector and rotational_constraint_selector, the user can specify which Degrees of Freedom to allow / constrain at the specified nodes.
  • These boolean arrays have to be specified in the inertial frame.
  • The ConfigurableFixedConstraint will now only re-set the positions, velocities, directors and omegas to the saved, fixed values for the constrained dimensions. The other DoF are allowed to freely move / rotate.
  • We can simplify the codebase by now having FixedConstraint be a child class of ConfigurableFixedConstraint. FixedConstraint will still constrain all dimension, e.g. translational_constraint_selector=np.array([True, True, True]) and rotational_constraint_selector=np.array([True, True, True])

Examples for usage

Below examples motivate the usage of this new class.

# How to fix all translational and rotational DoF except allowing twisting around z-axis in inertial frame:

simulator.constrain(rod).using(
    ConfigurableFixedConstraint,
    constrained_position_idx=(0,),
    constrained_director_idx=(0,),
    translational_constraint_selector=np.array([True, True, True]),
    rotational_constraint_selector=np.array([True, True, False]),
)

# How to allow the end of the rod to move in the x-y plane and allow all rotational DoF:

simulator.constrain(rod).using(
    ConfigurableFixedConstraint,
    constrained_position_idx=(-1,),
    translational_constraint_selector=np.array([True, True, False]),
)

I also added an example in examples/BoundaryConditionCases/configurable_fixed_constraint.py, which applies torsion to end tip of a rod. With a fully FixedConstraint the resulting orientation of the first node of the rod would look like this:

Fully Fixed BC:
configurable_bc_fully_fixed

When we now use rotational_constraint_selector=np.array([True, True, False]) (e.g. allow for yawing / rotation around the z-axis), the orientation of the first node of the rod looks like this:

Free Yawing:
configurable_bc_free_yaw

TODO's

  • Tests for ConfigurableFixedConstraint class
  • Numba-compatible implementation of nb_constraint_rotational_values
  • Rotate omega_collection into the inertial frame before applying zero-speed constraints

Request for ideas / feedback

I would like to ask the maintainers specifically for feedback on the current prototype of nb_constraint_rotational_values. Obviously, this is currently not numba-compatible. But more importantly, I would like to ask for your thoughts if constraining the Euler angles is a suitable way to go and if you have other ideas to allow the rotation around certain axis and constrain the rotation around other axis?

@mstoelzle
Copy link
Contributor Author

The velocity_collection (of each node) is given in the inertial frame and the omega_collection (of each element) in the local frame, right?

@armantekinalp
Copy link
Contributor

The velocity_collection (of each node) is given in the inertial frame and the omega_collection (of each element) in the local frame, right?

Yes @mstoelzle that is correct.

@mstoelzle
Copy link
Contributor Author

The velocity_collection (of each node) is given in the inertial frame and the omega_collection (of each element) in the local frame, right?

Yes @mstoelzle that is correct.

@armantekinalp Thanks for confirming this so quickly!

@armantekinalp @bhosale2 @skim0119 Could you guys have a look at the nb_constraint_rotational_values function and the related questions / requests for feedback in the first post of this PR? Are you happy with the current implemented method and / or do you have ideas for alternative approaches to achieve this functionality?

@bhosale2 bhosale2 added enhancement New feature or request discussion Topic that needs to be discussed. labels Jul 19, 2022
@bhosale2 bhosale2 added this to the Version 0.3 milestone Jul 19, 2022
@bhosale2
Copy link
Collaborator

bhosale2 commented Jul 19, 2022

@mstoelzle a couple of comments to start with from my side:

  1. Please usually open an issue first for the problem/feature request where we can discuss things, and then after discussion open a PR accordingly.
  2. Instead of ConfigurableFixedConstraint maybe a CustomConstraintBC would be a shorter to-the-point name? (if I understand correctly what you are trying to do)
  3. I agree that this can be a useful feature to have, but based on my experience of working with pyelastica (and @armantekinalp can concur) enforcing hard boundary conditions (pinning velocities or omegas dynamically), is usually a bit "hard" on the numerical stability of the solver compared to soft ones (say adding a spring-damper force between a constrained node and a point BC moving in space and time). If it works for your problem maybe that could be a useful feature to have in pyelastica forcing? This point is open for discussion.
  4. I would recommend splitting the discussion you have above first into an issue describing the problem (as mentioned in 1.) and then the suggested solution workings here in the PR.

@mstoelzle mstoelzle changed the title [WIP] Add ConfigurableFixedConstraint boundary condition class [WIP] Address #148 by adding ConfigurableFixedConstraint boundary condition class Jul 19, 2022
@bhosale2 bhosale2 linked an issue Jul 19, 2022 that may be closed by this pull request
Copy link
Collaborator

@bhosale2 bhosale2 left a comment

Choose a reason for hiding this comment

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

Nice addition @mstoelzle, can you also add tests for the class you add here in tests?

elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jul 21, 2022

Codecov Report

Merging #143 (4682601) into update-0.3.0 (011a0fe) will increase coverage by 0.03%.
The diff coverage is 90.47%.

@@               Coverage Diff                @@
##           update-0.3.0     #143      +/-   ##
================================================
+ Coverage         87.58%   87.62%   +0.03%     
================================================
  Files                43       43              
  Lines              2780     2820      +40     
  Branches            361      368       +7     
================================================
+ Hits               2435     2471      +36     
- Misses              326      328       +2     
- Partials             19       21       +2     
Impacted Files Coverage Δ
elastica/boundary_conditions.py 95.00% <90.47%> (-1.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 011a0fe...4682601. Read the comment docs.

- Application of end-forces to test fixed translational constraint and fixed x- and y- rotations
- Application of torsional torque to test free yawing of BC
Copy link
Collaborator

@bhosale2 bhosale2 left a comment

Choose a reason for hiding this comment

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

LGTM, @mstoelzle one last thing–can you restore back the .lock file from the update-0.3.0 branch? since no new dependencies were added (no change to .toml)

@mstoelzle
Copy link
Contributor Author

LGTM, @mstoelzle one last thing–can you restore back the .lock file from the update-0.3.0 branch? since no new dependencies were added (no change to .toml)

Thanks! Yes, sorry - I just reverted the poetry.lock file. Didn't mean to commit it to the branch...

Copy link
Contributor

@armantekinalp armantekinalp left a comment

Choose a reason for hiding this comment

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

@mstoelzle I asked some minor changes. One thing is could you please also update example ReadMe and add boundary condition examples.

elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
tests/test_boundary_conditions.py Outdated Show resolved Hide resolved
tests/test_boundary_conditions.py Outdated Show resolved Hide resolved
tests/test_boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
@mstoelzle
Copy link
Contributor Author

@mstoelzle I asked some minor changes. One thing is could you please also update example ReadMe and add boundary condition examples.

I updated the README in bdec395

Copy link
Contributor

@armantekinalp armantekinalp left a comment

Choose a reason for hiding this comment

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

LGTM, nice work!

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.

Please add GeneralConstraint in docs/api/constraints.rst

elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Outdated Show resolved Hide resolved
elastica/boundary_conditions.py Show resolved Hide resolved
mstoelzle and others added 5 commits July 24, 2022 22:09
…ational_constraint_selector`

- Declare `translational_constraint_selector` and `rotational_constraint_selector` as optional in docstring
- Add `translational_constraint_selector` and `rotational_constraint_selector` as params to `__init__` instead of using `kwargs`
@mstoelzle
Copy link
Contributor Author

Please add GeneralConstraint in docs/api/constraints.rst

I added the GeneralConstraint to the constraints.rst in 2cdc2f9

@skim0119
Copy link
Collaborator

Please add GeneralConstraint in docs/api/constraints.rst

I added the GeneralConstraint to the constraints.rst in 2cdc2f9

Please add them on the table above as well.

https://github.com/GazzolaLab/PyElastica/blob/master/docs/api/constraints.rst#description
https://github.com/GazzolaLab/PyElastica/blob/master/docs/api/constraints.rst#compatibility

@mstoelzle
Copy link
Contributor Author

Please add GeneralConstraint in docs/api/constraints.rst

I added the GeneralConstraint to the constraints.rst in 2cdc2f9

Please add them on the table above as well.

https://github.com/GazzolaLab/PyElastica/blob/master/docs/api/constraints.rst#description https://github.com/GazzolaLab/PyElastica/blob/master/docs/api/constraints.rst#compatibility

Sorry - didn't see that. Done in 4682601

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.

LGTM. Good Work!

@skim0119 skim0119 merged commit 129c35e into GazzolaLab:update-0.3.0 Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Topic that needs to be discussed. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ConfigurableFixedConstraint boundary condition class
5 participants