preCICE v3.2.0
Loading...
Searching...
No Matches
Acceleration.cpp
Go to the documentation of this file.
3#include "utils/Helpers.hpp"
4
6
7void Acceleration::checkDataIDs(const DataMap &cplData) const
8{
9#ifndef NDEBUG
10 for (int id : getPrimaryDataIDs()) {
11 bool valid = utils::contained(id, cplData);
12 PRECICE_ASSERT(valid, "Data with ID {} unknown.", id);
13 }
14#endif
15}
16
17void Acceleration::applyRelaxation(double omega, DataMap &cplData, double windowStart)
18{
19 for (auto &pair : cplData) {
20 auto &couplingData = *(pair.second);
21
22 if (couplingData.timeStepsStorage().empty()) {
23 continue;
24 }
25 // @todo: This will apply the scaling to the sample at t=0 and t=1 when
26 // calling performAcceleration the first time. Computations at the
27 // previousValuesAtTime/oldValues don't change anything and are unneeded
28 for (auto &stample : couplingData.timeStepsStorage().stamples()) {
29 if (!math::greater(stample.timestamp, windowStart)) {
30 // skip stamples at beginning of this window or earlier since this is either initial data or already converged data from previous windows
31 continue;
32 }
33
34 auto &values = stample.sample.values;
35 auto old = couplingData.getPreviousValuesAtTime(stample.timestamp); // IMPORTANT DETAIL: The interpolation that we use for resampling does not necessarily have to be the same interpolation as the interpolation the user accesses via read-data. (But probably it is easier to just use the same)
36 values = values * omega + old.values() * (1.0 - omega);
37
38 if (couplingData.hasGradient()) {
39 auto &gradients = stample.sample.gradients;
40 auto oldGradients = couplingData.getPreviousGradientsAtTime(stample.timestamp); // IMPORTANT DETAIL: The interpolation that we use for resampling does not necessarily have to be the same interpolation as the interpolation the user accesses via read-data. (But probably it is easier to just use the same)
41 gradients = gradients * omega + oldGradients * (1.0 - omega);
42 }
43 couplingData.setGlobalSample(stample.sample); // @todo try to remove, currently we have to set CouplingData::_data::_sample to the final stample in the storage. Should not be needed anymore when https://github.com/precice/precice/issues/1645 is resolved.
44 }
45 }
46}
47} // namespace precice::acceleration
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
virtual std::vector< int > getPrimaryDataIDs() const =0
static void applyRelaxation(double omega, DataMap &cplData, double windowStart)
performs a relaxation given a relaxation factor omega
void checkDataIDs(const DataMap &cplData) const
Checks if all dataIDs are contained in cplData.
std::map< int, cplscheme::PtrCouplingData > DataMap
Map from data ID to data values.
contains implementations of acceleration schemes.
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type greater(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool contained(const ELEMENT_T &element, const std::vector< ELEMENT_T > &vec)
Returns true, if given element is in vector, otherwise false.
Definition Helpers.hpp:38