-
-
Notifications
You must be signed in to change notification settings - Fork 278
Reduce number of references to Data::values() #1645
Description
Currently all packages of preCICE reference Data::values() to read or write data. Mapping, acceleration, communication and actions operate on the data in Data::values(). For time interpolation we recently introduced a write data buffer and a storage (#1612) in Data. In #1612 data has to be moved from the storage to Data::values() and vice-versa when mapping, acceleration, communication or actions are executed to not interfere with the currently existing implementation. In the future, we should, however avoid using Data::values() and instead use the data from the storage (see example below).
The following packages need a review:
- mapping (see Samplize mapping #1660, Refactor mapping to work on Storages, not on Data::values #1651)
- communication (see Directly perform extrapolation in time::Storage, only allow CouplingScheme to moveToNextWindow #1639)
- acceleration
- actions
- exporter / io
Note that this issue is mainly meant as an overview.
Example for mapping
Current state (#1612)
precice/src/precice/impl/DataContext.cpp
Lines 88 to 102 in f272d0a
| for (auto &stample : context.fromData->getStamples()) { | |
| // Put data from storage into mapping buffer | |
| context.fromData->sample() = stample.sample; | |
| // Reset the toData before executing the mapping | |
| context.toData->toZero(); | |
| const DataID fromDataID = context.fromData->getID(); | |
| const DataID toDataID = context.toData->getID(); | |
| context.mapping->map(fromDataID, toDataID); | |
| // Store data from mapping buffer in storage | |
| context.toData->setSampleAtTime(stample.timestamp, context.toData->sample()); | |
| PRECICE_DEBUG("Mapped values = {}", utils::previewRange(3, context.toData->values())); | |
| } |
map accesses Data::values() using fromDataID and toDataID.
Proposed implementation:
for (auto &stample : context.fromData->getStamples()) {
const Eigen::VectorXd fromData = stample.sample.values;
const Eigen::VectorXd toData = context.mapping->map(fromData);
// Store data from mapping buffer in storage
context.toData->setSampleAtTime(stample.timestamp, toData);
} map does not need to access Data::values(), because it would just operate on Eigen::VectorXd.
Benefits:
- No need for moving data back and forth
- Better encapsulation of packages