precice / dealii-adapter

A coupled structural solver written with the C++ finite element library deal.II
GNU Lesser General Public License v3.0
19 stars 12 forks source link

InitializeData skipped in case no WriteInitialData is required #46

Closed davidscn closed 3 years ago

davidscn commented 3 years ago

In our current implementation, the initializeData call is only reached in case WriteInitialData is required. However, in case another participants needs to initialize data and the dealii participant does not, the function call is skipped and preCICE complains:

---[precice] ERROR:  initializeData() needs to be called before advance if data has to be initialized.

This is probably a bug, but I would like to get some other opinions. https://github.com/precice/dealii-adapter/blob/1d148462224d0148ee77ebd6d7f93612c0adcd8e/adapter/adapter.h#L327-L341

EDIT: Maybe something like actionReadInitialData would be useful.

MakisH commented 3 years ago

What is the precice-config.xml that triggered this?

MakisH commented 3 years ago

Actually, the precice.initializeData() should be outside the action: https://www.precice.org/couple-your-code-initializing-coupling-data.html#undefined

It is a step similar to advance(). It does not really depend on what happened to the buffers, as long as the actions are fulfilled.

uekerman commented 3 years ago

EDIT: Maybe something like actionReadInitialData would be useful.

You normally read data as soon as you enter the isOngoing loop. Here you can ask isReadDataAvailable. This makes a actionReadInitialData unnecessary in my opinion. Do you agree?

davidscn commented 3 years ago

@MakisH the config (where I faced this issue) looked like this:

      <exchange data="Stress" mesh="second-part-mesh" from="second-participant" to="first-participant" initialize="true" />

where deal.II was the first participant.

Actually, the precice.initializeData() should be outside the action: https://www.precice.org/couple-your-code-initializing-coupling-data.html#undefined It is a step similar to advance(). It does not really depend on what happened to the buffers, as long as the actions are fulfilled.

Ok this makes sense. I will pull out the initializeData() and it will appear unconditional during the initialization flow. I'm just a bit confused that we haven't seen it earlier.

You normally read data as soon as you enter the isOngoing loop. Here you can ask isReadDataAvailable. This makes a actionReadInitialData unnecessary in my opinion. Do you agree?

No, not really. In the link Makis posted, the initializeData call is placed before isOngoing. Looking in the documentation of isReadDataAvailable(), however, it says @pre initialize() has been called successfully.. Hence, I guess the isOngoing call is not a prerequisite in order to use isReadDataAvailable (maybe I misunderstood your comment).

uekerman commented 3 years ago

No, not really. In the link Makis posted, the initializeData call is placed before isOngoing. Looking in the documentation of isReadDataAvailable(), however, it says @pre initialize() has been called successfully.. Hence, I guess the isOngoing call is not a prerequisite in order to use isReadDataAvailable (maybe I misunderstood your comment).

No, that's not what I meant. The thing is that you don't need to read data after initializeData. Normally the first read will only happen within the coupling loop. And there you already have the isReadDataAvailable. More understandable?

davidscn commented 3 years ago

More understandable. However, I don't ask for isReadDataAvailable (in my example case) since I don't copy the data 'into' the participant but rather make use of readVectorData where the data is actually required. So, this won't solve the problem, right? Also, the documentation of isReadDataAvailable says

   * It is allowed to read data even if this function returns false.
   * This is not recommended due to performance reasons.
   * Use this function to prevent unnecessary reads.

so that reading data would be allowed.

uekerman commented 3 years ago

The solution is

Actually, the precice.initializeData() should be outside the action: https://www.precice.org/couple-your-code-initializing-coupling-data.html#undefined

Or is there still another problem that I am overlooking?

davidscn commented 3 years ago

No.

davidscn commented 3 years ago

Done in #47