Skip to content

Introduce ReadDataContext and WriteDataContext.#1159

Merged
BenjaminRodenberg merged 26 commits intoprecice:developfrom
BenjaminRodenberg:read-write-data-context
Jan 31, 2022
Merged

Introduce ReadDataContext and WriteDataContext.#1159
BenjaminRodenberg merged 26 commits intoprecice:developfrom
BenjaminRodenberg:read-write-data-context

Conversation

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

@BenjaminRodenberg BenjaminRodenberg commented Dec 29, 2021

Main changes of this PR

Introduces ReadDataContext and WriteDataContext which are used for reading/writing data. Both classes are derived from DataContext.

Motivation and additional information

Introducing the two classes reduces direct access to Mesh::Data and allows for a clearer separation of both use cases. In #1029 this new design is used to add additional data depending on the context. A Waveform, for example, is only used in the ReadDataContext and is not used in the WriteDataContext.

Author's checklist

  • I added a changelog file with make changelog if there are user-observable changes since the last release. (only visible to developers)
  • I ran make format to ensure everything is formatted correctly.
  • I sticked to C++14 features.
  • I sticked to CMake version 3.10.
  • 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 Dec 29, 2021
@BenjaminRodenberg BenjaminRodenberg self-assigned this Dec 29, 2021
@BenjaminRodenberg BenjaminRodenberg marked this pull request as ready for review January 4, 2022 12:38
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.

Good refactoring. I think this was needed. Only a few real concerns below.

I am not sure if it is good practice to automatically add a PRECICE_TRACE() call to every function. Makes the code and the debug output harder to read. I always only enable tracing if I could imagine a debug use case.

Comment thread src/precice/impl/DataContext.hpp Outdated
Comment thread src/precice/impl/ReadDataContext.hpp Outdated
Comment thread src/precice/impl/WriteDataContext.hpp Outdated
Comment thread src/precice/impl/WriteDataContext.hpp Outdated
Comment thread src/precice/impl/ReadDataContext.hpp Outdated
Comment thread src/precice/impl/SolverInterfaceImpl.cpp Outdated
Comment thread src/precice/impl/SolverInterfaceImpl.cpp
Comment thread src/precice/impl/Participant.hpp Outdated
Comment on lines +133 to +135
const utils::ptr_vector<DataContext> &writeDataContexts() const;
const std::vector<WriteDataContext *> &writeDataContexts() const;
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 am not sure about this change. I agree the old one is ugly, but why not a vector of references?
@fsimonis typically has a good opinion on such things.

More similar occasions below.

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.

IIRC the main reasons for moving from utils::ptr_vector<T> to std::vector<T> were:

  1. some standard functionality that I needed for the implementation was missing and I did not want to implement it in utils::ptr_vector, if std::vector can also do the job.
  2. I do not understand why utils::ptr_vector<T> actually exists. It looks to me just like std::vector without a real benefit.

I can also try to get a vector of references working 👍

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.

Also done in ce0eb84. I will keep this one open until @fsimonis has reviewed.

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 am not sure about this change. I agree the old one is ugly, but why not a vector of references?

References are immutable. Imagine what push_back means if the new element cannot be assigned. So, this doesn't work.
Raw pointers are not a problem as long as they are just used to access the pointees. Raw owning pointers are the real problem.

I do not understand why utils::ptr_vector actually exists.

The utils::ptr_vector<T> is a possibly owning vector of pointers to objects.
I already replaced quite some occurrences with normal vectors.

It looks to me just like std::vector without a real benefit.

It allows to delete all contained elements. That's about it.

@BenjaminRodenberg Maybe we can implement this as std::vector<WriteDataContext> instead? Who owns these Contexts?

Comment thread src/precice/impl/Participant.cpp Outdated
Comment thread src/precice/impl/Participant.cpp Outdated
@uekerman uekerman requested a review from fsimonis January 17, 2022 16:00
Copy link
Copy Markdown
Member

@fsimonis fsimonis left a comment

Choose a reason for hiding this comment

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

This makes many things clearer and some loops uglier.

Can you explain the difference between a MappingContext, a DataContext, and a MeshContext and how they are related?

Comment thread src/precice/impl/Participant.cpp Outdated
Comment thread src/precice/impl/Participant.cpp Outdated
Comment thread src/precice/impl/Participant.cpp Outdated
Comment thread src/precice/impl/Participant.hpp Outdated
Comment thread src/precice/impl/ReadDataContext.hpp Outdated
Comment thread src/precice/config/ParticipantConfiguration.cpp Outdated
Comment thread src/precice/impl/WriteDataContext.cpp Outdated
Comment thread src/precice/impl/ReadDataContext.hpp Outdated
Comment thread src/precice/impl/WriteDataContext.hpp Outdated
Comment thread src/precice/impl/WriteDataContext.hpp Outdated
@BenjaminRodenberg
Copy link
Copy Markdown
Contributor Author

@fsimonis can you take another look? Generally I tried fix all the points. Some points are still not 100% clear and I would need some input/help.

Comment thread src/precice/impl/Participant.hpp Outdated
Comment thread src/precice/impl/Participant.cpp Outdated
Comment thread src/precice/impl/Participant.cpp Outdated
Comment thread src/precice/impl/Participant.hpp Outdated
Comment thread src/precice/impl/SolverInterfaceImpl.cpp Outdated
Comment thread src/precice/impl/SolverInterfaceImpl.cpp Outdated
Comment thread src/precice/impl/SolverInterfaceImpl.cpp Outdated
@BenjaminRodenberg
Copy link
Copy Markdown
Contributor Author

I removed most of the PRECICE_TRACE statements in 9de1067, because I don't really use them for debugging and don't see a real need. Moreover, it makes the diff shorter and easier to read. @uekerman can you take a final look?

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.

Only looked at my comments again.

@fsimonis fsimonis self-requested a review January 31, 2022 12:31
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.

3 participants