preCICE v3.1.2
Loading...
Searching...
No Matches
SummationAction.cpp
Go to the documentation of this file.
1#include "SummationAction.hpp"
2#include <Eigen/Core>
3#include <algorithm>
4#include <memory>
5#include "action/Action.hpp"
7#include "mapping/Mapping.hpp"
8#include "mesh/Data.hpp"
9#include "mesh/Mesh.hpp"
10
11namespace precice::action {
12
14 Timing timing,
15 const std::vector<int> &sourceDataIDs,
16 int targetDataID,
17 const mesh::PtrMesh & mesh)
18 : Action(timing, mesh, mapping::Mapping::MeshRequirement::VERTEX), _targetData(mesh->data(targetDataID))
19{
20
21 for (int sourceID : sourceDataIDs) {
22 _sourceDataVector.push_back(mesh->data(sourceID));
23 }
24
25 for (const auto &source : _sourceDataVector) {
26 PRECICE_CHECK(source->getDimensions() == _targetData->getDimensions(), "Source and target data dimensions (scalar or vector) of summation action need to be identical.");
27 }
28}
29
31{
33
34 const auto &referenceData = _sourceDataVector.front(); // serves as reference
35 const int nStamples = referenceData->stamples().size();
36 for (int stampleId = 0; stampleId < nStamples; stampleId++) { // simultaneously loop over stamples in all sourceData of _sourceDataVector
37 auto &targetValues = _targetData->values();
38 targetValues.setZero();
39 const double currentTimestamp = referenceData->stamples()[stampleId].timestamp;
40 for (const auto &sourceData : _sourceDataVector) {
41 auto sourceStample = sourceData->stamples()[stampleId];
42 PRECICE_CHECK(math::equals(sourceStample.timestamp, currentTimestamp), "Trying to perform summation action on samples with different timestamps: expected timestamp {}, but got source data with timestamp {}. Time meshes of all source data must agree. Actions do not fully support subcycling yet.", currentTimestamp, sourceStample.timestamp);
43 auto sourceDataValues = sourceStample.sample.values;
44 targetValues += sourceDataValues;
45 }
46 _targetData->setSampleAtTime(currentTimestamp, _targetData->sample());
47 }
48}
49
50} // namespace precice::action
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:95
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:35
Abstract base class for configurable actions on data and/or meshes.
Definition Action.hpp:14
Timing
Defines the time and place of application of the action.
Definition Action.hpp:17
std::vector< mesh::PtrData > _sourceDataVector
SummationAction(Timing timing, const std::vector< int > &sourceDataIDs, int targetDataID, const mesh::PtrMesh &mesh)
Constructor.
void performAction() final override
Adding data and applying them to target.
contains actions to modify exchanged data.
Definition Action.hpp:6
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.