Skip to content

Adds storeIteration for initial write data#1036

Merged
fsimonis merged 18 commits intodevelopfrom
storeWriteInitialData
Sep 13, 2021
Merged

Adds storeIteration for initial write data#1036
fsimonis merged 18 commits intodevelopfrom
storeWriteInitialData

Conversation

@KyleDavisSA
Copy link
Copy Markdown
Contributor

@KyleDavisSA KyleDavisSA commented Jun 23, 2021

Main changes of this PR

stores the previousIteration after calling writeInitialData.

Motivation and additional information

This PR closes #1034 and #1032

Author's checklist

  • I added a changelog file with this PR number in docs/changelog/ if there are noteworthy changes. -> Fixes a bug, but the buggy version was never released, so no need to add anything to the changelog.
  • I ran tools/formatting/check-format and everything is formatted correctly.
  • I sticked to C++14 features.
  • I sticked to CMake version 3.10.

Reviewers' checklist

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

@MakisH
Copy link
Copy Markdown
Member

MakisH commented Jun 23, 2021

This does fix #1032 for me. I do not understand the change, though.

@KyleDavisSA
Copy link
Copy Markdown
Contributor Author

For the quasi-Newton scheme, the x^0 variable is always zero unless the initial write data is specified. In PR #1004, the initial write data is read in, but is not stored in the variable cplData->previousIteration for the QN method. That means in the concatenateCouplingData function in BaseQNAcceleration, x^0 is always zero and never updated with the initial write data.

const auto &oldValues = cplData[id]->previousIteration();

The 1D elastic tube test case is sensitive to this initial write data. The function storeIteration() updates the previousIteration values in:

void CouplingData::storeIteration()
{
_previousIteration = this->values();
}

Adding this during exchangeInitialData solved this problem.

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

Good find and thanks for the explanation! This is something I oversaw in #1004.

Any idea why some of the tests are failing now? Do you think we should write a specific test to avoid this kind of bug in the future? I'll look into it more closely tomorrow.

@KyleDavisSA
Copy link
Copy Markdown
Contributor Author

I think a test is necessary. I will look into a test, that writes initial data and checks that value against x^0 values.

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

I think a test is necessary. I will look into a test, that writes initial data and checks that value against x^0 values.

Then I will wait until you trigger me again or something pops up here. Right?

Copy link
Copy Markdown
Contributor

@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 guess we also have to add storeIteration at the right places in MultiCouplingScheme:

void MultiCouplingScheme::exchangeInitialData()
{
PRECICE_ASSERT(isImplicitCouplingScheme(), "MultiCouplingScheme is always Implicit.");
if (receivesInitializedData()) {
for (size_t i = 0; i < _m2ns.size(); i++) {
receiveData(_m2ns[i], _receiveDataVector[i]);
}
checkDataHasBeenReceived();
}
if (sendsInitializedData()) {
for (size_t i = 0; i < _m2ns.size(); i++) {
sendData(_m2ns[i], _sendDataVector[i]);
}
}
}

@KyleDavisSA
Copy link
Copy Markdown
Contributor Author

Is there a potential bug in the SerialTests? Below is an output from the test:

/__w/precice/precice/src/precice/tests/SerialTests.cpp(401): error: in "PreciceTests/Serial/testExplicitWithDataInitialization": check 2.0 == valueDataB has failed [2 != 0]. Absolute value exceeds tolerance [|2| > 1e-09]

SolverB writes the initial data of 2

cplInterface.writeScalarData(dataBID, 0, 2.0);
//sagen dass daten jetzt geschrieben
cplInterface.markActionFulfilled(precice::constants::actionWriteInitialData());
cplInterface.initializeData();

and SolverA reads in the initial data

double valueDataB = 0.0;
cplInterface.initializeData();
cplInterface.readScalarData(dataBID, 0, valueDataB);
BOOST_TEST(2.0 == valueDataB);

However the test still says the the solverB data is zero. SolverA should not be reading the values before SolverB sets them?

@fsimonis fsimonis added this to the Version 2.3.0 milestone Jun 30, 2021
@uekerman
Copy link
Copy Markdown
Member

uekerman commented Jul 2, 2021

However the test still says the the solverB data is zero. SolverA should not be reading the values before SolverB sets them?

Not sure I understand what you mean, but the test looks correct. Not the test is buggy, preCICE is buggy.

@fsimonis
Copy link
Copy Markdown
Member

fsimonis commented Jul 26, 2021

Shouldn't the receiving serial solver skip the call to initializeData?

Sender / Second:

  • initialize
  • is initializeData required?
  • write Data(2)
  • initializeData
  • mark as done

Receiver / First:

  • initialize (receives here)
  • read data = 2

Actually, initializeData should throw an error if it is called without being required to.

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

I did another quick test comparing 3ff0899 (pre #1004) and 54707b3 (current state of this PR): I ran the 1d-elastic-tube cpp version precice/tutorials@46ce8ab and compared the precice-{Fluid,Solid}-iterations.log. Here nothing suspicous shows up. I interpret this as a good sign and will dig deeper.

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

BenjaminRodenberg commented Jul 29, 2021

With this version the tests work and also the elastic-tube is ok. However, I would like to add a test that catches the underlying problem. I'm also not yet sure whether actually all additions to the code are necessary.

Todos

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

This PR is from my perspective ready. I would still suggest to merge #1050 first.

@BenjaminRodenberg BenjaminRodenberg self-assigned this Jul 29, 2021
@KyleDavisSA
Copy link
Copy Markdown
Contributor Author

This PR closes #1034 and #1032, but does it also work in the expected manner for the newly constructed tests in PR #1050 ?

All tests pass now with this PR.

@BenjaminRodenberg
Copy link
Copy Markdown
Contributor

This PR closes #1034 and #1032, but does it also work in the expected manner for the newly constructed tests in PR #1050 ?

All tests pass now with this PR.

When I tried this out a while ago: yes. You can locally merge this branch into i_1032_test (#1050) an run the tests. Then all tests (especially the previously failing ones) should succeed.

@uekerman uekerman removed their request for review September 13, 2021 08:42
@fsimonis
Copy link
Copy Markdown
Member

Can we merge the tests into this PR, see if all is well and finally merge the fix?

@fsimonis fsimonis merged commit 8f67136 into develop Sep 13, 2021
@BenjaminRodenberg BenjaminRodenberg deleted the storeWriteInitialData branch November 18, 2021 14:30
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.

Write initial data does not set initial data

5 participants