Skip to content

Simplify implementation of DataContext.#1435

Merged
BenjaminRodenberg merged 2 commits intoprecice:develop-v3.0.0from
BenjaminRodenberg:store-data-ptr-in-mapping-context
Sep 19, 2022
Merged

Simplify implementation of DataContext.#1435
BenjaminRodenberg merged 2 commits intoprecice:develop-v3.0.0from
BenjaminRodenberg:store-data-ptr-in-mapping-context

Conversation

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

@BenjaminRodenberg BenjaminRodenberg commented Sep 17, 2022

Main changes of this PR

  • Move DataPtr inside MappingContext.
  • Use range-based for loops in DataContext.
  • Simplify access of data properties vie context (does not require detour over std::vector in DataContext anymore)

Motivation and additional information

Helpful in scope of #1414

Author's checklist

  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I added a changelog file with make changelog if there are user-observable changes since the last release. (not needed?)
  • I added a test to cover the proposed changes in our test suite. (not needed?)
  • I sticked to C++17 features.
  • I sticked to CMake version 3.16.3.
  • I squashed / am about to squash all commits that should be seen as one.

Reviewers' checklist

  • Does the changelog entry make sense? Is it formatted correctly?
  • Do you understand the code changes?

@BenjaminRodenberg BenjaminRodenberg added the maintainability Working on this will make our lives easier in the long run as preCICE gets easier to maintain. label Sep 17, 2022
@BenjaminRodenberg BenjaminRodenberg self-assigned this Sep 17, 2022
@BenjaminRodenberg BenjaminRodenberg added this to the Version 3.0.0 milestone Sep 17, 2022
Copy link
Copy Markdown
Member

@uekerman uekerman left a comment

Choose a reason for hiding this comment

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

Makes things easier, yes.
Only one doubt below, otherwise good to go.

Comment on lines -37 to +30
std::for_each(_toData.begin(), _toData.end(), [](auto &data) { data->toZero(); });
// PRECICE_ASSERT(!hasReadMapping()); // we also need this assertion, because currently we also reset toData from read mappings, if a data context has a read and write mapping! Is this what we want?
std::for_each(_mappingContexts.begin(), _mappingContexts.end(), [](auto &context) { context.toData->toZero(); });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I don't understand the comment here. Can a data context have a read and a write mapping? I would guess no.
And where do we reset toData?

Sth different: maybe it's cleaner if we move the resetting to a MappingContext::resetData?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I don't understand the comment here. Can a data context have a read and a write mapping? I would guess no. And where do we reset toData?

I tried out what happens, if I activate the assertion and it does not get triggered. I thought this was the reason for originally commenting it out, but everything looks fine now: A DataContext either has a read or write mapping, not both at the same time (at least, if we reset data).

I added the assertion in 5a0ff28 and I think we can merge it this way (if the tests run though).

Sth different: maybe it's cleaner if we move the resetting to a MappingContext::resetData?

Yes. But MappingContext is a struct, so moving something inside MappingContext will cause a bigger refactoring and this is from my perspective out of scope for this PR. Opening an isssue would be useful and I guess it would also be a low-hanging fruit, if somebody wants to get his or her hands dirty with C++ and preCICE.

@BenjaminRodenberg BenjaminRodenberg merged commit 9222bc8 into precice:develop-v3.0.0 Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainability Working on this will make our lives easier in the long run as preCICE gets easier to maintain.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants