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

Implement Lees-Edwards boundary conditions #4457

Merged
merged 1 commit into from
Feb 28, 2022

Conversation

jngrad
Copy link
Member

@jngrad jngrad commented Feb 25, 2022

Fixes #2051
Fixes #2083

@jngrad jngrad added this to the Espresso 4.2 milestone Feb 25, 2022
Co-authored-by: Sebastian Bindgen <info@bindgen.net>
Co-authored-by: Jean-Noël Grad <jgrad@icp.uni-stuttgart.de>
@jngrad jngrad marked this pull request as ready for review February 28, 2022 14:10
@jngrad jngrad requested a review from reinaual February 28, 2022 14:10
@jngrad
Copy link
Member Author

jngrad commented Feb 28, 2022

Note: this PR blocks the Particle interface rollout, the HybridDecomposition PR and the walberla branch.

public:
LinearShear()
: m_protocol{
new ::LeesEdwards::ActiveProtocol{::LeesEdwards::LinearShear()}} {
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 the shear-cases, is there a reason to use new instead of std::make_shared for the construction of the core object? Intuitively i would expect it to work out of the box and to be more explicit than this solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

This new construction is actually quite common in the script interface. Unfortunately, the reasons for this design decision were not documented, as far as I know. The resulting shared_ptr is much smaller since it only contains a pointer instead of the pointee, and the rules for deallocation are slightly different (I think the pointee is deallocated immediately when the reference counter is zero, regardless of the value of the weak pointer counter).

Copy link
Contributor

Choose a reason for hiding this comment

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

To me it is not clear where this difference comes from, especially because we just construct a shared-pointer from it. I would have expected that std::make_shared does exactly that, but I never bothered to check what std::make_shared actually does internally. I always had the impression that it is designed to replace new with a shared-ownership, which does not seem to be the whole story.

Copy link
Member Author

Choose a reason for hiding this comment

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

The std::shared_ptr constructor takes a raw pointer as argument, and takes ownership of it, i.e. we are no longer allowed to call free() or delete on the original raw pointer. The resulting shared pointer is lightweight, since it only wraps a raw pointer. Whether the pointee is allocated with new or malloc is not really relevant, but the new syntax is a bit more readable. This strategy has some overhead due to the double dereference, but then we can have a lightweight std::vector<std::shared_ptr<T>> that is easy to resize and resort.

The std::shared_ptr copy constructor is designed to work with std::make_shared, which embeds the pointee. For our use case in the script interface, I think it's safe to replace the new syntax with the std::make_shared everywhere. It also bugged me a few weeks ago when I realized we were using the new syntax in the script interface.

@jngrad jngrad added the automerge Merge with kodiak label Feb 28, 2022
@kodiakhq kodiakhq bot merged commit 9c40d78 into espressomd:python Feb 28, 2022
@jngrad jngrad deleted the lees_edwards branch February 28, 2022 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge with kodiak New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify get_mi_vector to support Lees-Edwards Lees Edwards Rewrite tracking ticket
3 participants