Skip to content

Directly perform extrapolation in time::Storage, only allow CouplingScheme to moveToNextWindow#1639

Merged
BenjaminRodenberg merged 151 commits intoprecice:developfrom
BenjaminRodenberg:use-storage-in-coupling-data-v2
May 20, 2023
Merged

Directly perform extrapolation in time::Storage, only allow CouplingScheme to moveToNextWindow#1639
BenjaminRodenberg merged 151 commits intoprecice:developfrom
BenjaminRodenberg:use-storage-in-coupling-data-v2

Conversation

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

@BenjaminRodenberg BenjaminRodenberg commented May 4, 2023

Main changes of this PR

Replaces #1520 and #1504. Extrapolation now happens directly inside Storage and Storage is directly maintained in CouplingData.

Motivation and additional information

  • Allows to remove dedicated Extrapolation class
  • Allows to remove receiveResultOfFirstAdvance from ParticipantImpl
  • Simplifies maintainment of storage from CouplingScheme via CouplingData
  • Only CouplingScheme takes care of moveToNextWindow (previously also partially done by ParticipantImpl)

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, basically refactoring)
  • I added a test to cover the proposed changes in our test suite.
  • For breaking changes: I documented the changes in the appropriate porting guide.
  • 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.
  • Merge Add write data buffer #1612

Reviewers' checklist

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

* use DataMap<PtrWriteDataContext> and DataMap<PtrReadDataContext>
* Remove performReceiveOfFirstAdvance.
* Implement specific exchangeInitialData in SerialCouplingScheme and
ParallelCouplingScheme.
Copy link
Copy Markdown
Contributor Author

@BenjaminRodenberg BenjaminRodenberg left a comment

Choose a reason for hiding this comment

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

I added a few comments on how we dealt with extrapolation previously and what we do now. Hopefully this clarifies the open point about UNDEFINED_EXTRAPOLATION_ORDER.

One important part that I did not touch in this PR, but that is relevant: An explicit coupling scheme must use UNDEFINED_EXTRAPOLATION_ORDER, while an implicit coupling scheme must use (_extrapolationOrder == 0) || (_extrapolationOrder == 1). See in BaseCouplingScheme.cpp:

  if (isExplicitCouplingScheme()) {
    PRECICE_ASSERT(_extrapolationOrder == UNDEFINED_EXTRAPOLATION_ORDER, "Extrapolation is not allowed for explicit coupling");
  } else {
    PRECICE_ASSERT(isImplicitCouplingScheme());
    PRECICE_CHECK((_extrapolationOrder == 0) || (_extrapolationOrder == 1),
                  "Extrapolation order has to be 0 or 1.");
  }

Comment on lines 324 to 309
PRECICE_TRACE(_timeWindows);
for (auto &data : getAccelerationData() | boost::adaptors::map_values) {
for (auto &data : _allData | boost::adaptors::map_values) {
data->moveToNextWindow();
}
}
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.

Regarding extrapolation this is one important bit I changed: Before, we only called moveToNextWindow for the accelerated data. This applied the extrapolation. Now, we move _allData.

Especially for explicit coupling schemes this part changed a lot: Previously this function was never called for explicit coupling schemes, because extrapolation is not reasonable for explicit coupling schemes:

  if (isImplicitCouplingScheme()) {
    if (not doesFirstStep()) {
      storeExtrapolationData();
      moveToNextWindow();
    }
  }

Now, we always call it for all coupling schemes, because all coupling schemes have to move the storage and extrapolation is just an optional feature of moving.

Comment on lines -411 to -409
if (_couplingScheme->isTimeWindowComplete()) {
for (auto &context : _accessor->readDataContexts()) {
context.moveToNextWindow();
}
}
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 important regarding extrapolation: Previously we called moveToNextWindow for the storage of the ReadDataContext here. I moved this inside the coupling scheme, because then we don't have to worry about convergence etc. in ParticipantImpl anymore.

Comment on lines 132 to 140
void CouplingData::moveToNextWindow()
{
_extrapolation.moveToNextWindow();
values() = _extrapolation.getInitialGuess();

this->setSampleAtTime(time::Storage::WINDOW_END, sample());
}

void CouplingData::storeExtrapolationData()
{
const auto stamples = this->stamples();
PRECICE_ASSERT(stamples.size() > 0);
this->values() = stamples.back().sample.values;
_extrapolation.store(values());
if (this->timeStepsStorage().stamples().size() > 0) {
this->timeStepsStorage().move();
auto atEnd = this->timeStepsStorage().stamples().back();
PRECICE_ASSERT(math::equals(atEnd.timestamp, time::Storage::WINDOW_END));
_data->sample() = atEnd.sample;
}
}
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.

Previously, this did not move the Storage of the coupling data, but computed the extrapolation (remember: for acceleration data) and stored it at the WINDOW_END of the Storage. Technically this is the same like moving, but the implementation is different.

@BenjaminRodenberg BenjaminRodenberg changed the title Directly perform extrapolation in time::Storage Directly perform extrapolation in time::Storage, only allow CouplingScheme to moveToNextWindow May 19, 2023
@BenjaminRodenberg
Copy link
Copy Markdown
Contributor Author

1c676d6 is interesting: I think I found a fix, but at the moment this test also fails on develop. Meaning: There is probably a bug with respect to this combination of features on develop. I will try to understand this better on develop by using this test there tomorrow.

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor Author

As directly discussed with @uekerman: This PR is ready to go and I will merge as soon as the tests have completed. There are still some details that we did not 100% finalize yet, but this will change and we will reiterate on these details soon again when subcycling + higher interpolation is implemented.

@BenjaminRodenberg BenjaminRodenberg merged commit d3485cd into precice:develop May 20, 2023
@BenjaminRodenberg BenjaminRodenberg deleted the use-storage-in-coupling-data-v2 branch May 20, 2023 12:42
kanishkbh added a commit to kanishkbh/precice that referenced this pull request Jun 1, 2023
kanishkbh added a commit to kanishkbh/precice that referenced this pull request Jul 6, 2023
kanishkbh added a commit to kanishkbh/precice that referenced this pull request Jul 12, 2023
BenjaminRodenberg added a commit to BenjaminRodenberg/precice that referenced this pull request Jul 12, 2023
BenjaminRodenberg added a commit that referenced this pull request Jul 24, 2023
* Add tests to reproduce faulty behavior.
* Use initialCommunication as it has already been introduced in #1639.
uekerman added a commit that referenced this pull request Oct 11, 2023
* Add tests to reproduce faulty behavior.

* Dirty fix. Needs refactoring.

* Refactoring.

* Cleanup comments.

* Reduce diff.

* Naming: Use initialCommunication as introduced in #1639.

* Make substeps=false default.

* Use substeps=true only in tests where it is necessary
* Mark buggy tests for substeps=false (Compositional Coupling Scheme)

* Remove unnecessary exception for compositional coupling scheme. Works now. Not sure why.

* Use substeps=true.

* Update changelog.

* Update docs/changelog/1664.md

---------

Co-authored-by: Benjamin Uekermann <[email protected]>
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.

2 participants