preCICE v3.1.2
Loading...
Searching...
No Matches
SerializedStamples.cpp
Go to the documentation of this file.
4
6
8{
10
11 result._timeSteps = data->timeStepsStorage().nTimes(); // @todo use all available time steps for subcycling
12 result.allocate(data);
13 result.serializeValues(data);
14 if (data->hasGradient()) {
15 result.serializeGradients(data);
16 }
17 return result;
18}
19
21{
22 SerializedStamples result;
23
24 result._timeSteps = timeStamps.size();
25
26 result.allocate(data);
27
28 return result;
29}
30
31void SerializedStamples::deserializeInto(const Eigen::VectorXd &timeStamps, const cplscheme::PtrCouplingData data)
32{
33 PRECICE_ASSERT(_timeSteps == timeStamps.size());
34
35 deserialize(timeStamps, data);
36}
37
39{
40 _values = Eigen::VectorXd(_timeSteps * data->getSize());
41
42 if (data->hasGradient()) {
43 _gradients = Eigen::VectorXd(_timeSteps * data->getSize() * data->meshDimensions() * data->getDimensions());
44 }
45}
46
48{
49 const int nValues = data->sample().values.size();
50 int timeId = 0;
51 for (const auto &stample : data->stamples()) {
52 const Eigen::VectorXd &slice = stample.sample.values;
53 for (int valueId = 0; valueId < nValues; valueId++) {
54 _values(valueId * _timeSteps + timeId) = slice(valueId);
55 }
56 timeId++;
57 }
58}
59
61{
62 const int nValues = data->sample().gradients.size();
63 int timeId = 0;
64 for (const auto &stample : data->stamples()) {
65 const Eigen::VectorXd &slice = Eigen::VectorXd::Map(stample.sample.gradients.data(), stample.sample.gradients.rows() * stample.sample.gradients.cols());
66 PRECICE_ASSERT(nValues == slice.size());
67 for (int valueId = 0; valueId < slice.size(); valueId++) {
68 _gradients(valueId * _timeSteps + timeId) = slice(valueId);
69 }
70 timeId++;
71 }
72}
73
74void SerializedStamples::deserialize(const Eigen::VectorXd timeStamps, cplscheme::PtrCouplingData data) const
75{
76 PRECICE_ASSERT(timeStamps.size() * data->getSize() == _values.size(), timeStamps.size() * data->getSize(), _values.size());
77
78 data->timeStepsStorage().clear(); // @todo needs optimization. Don't need to communicate and serialize / deserialize data at beginning of window, because it is already there.
79
80 const auto dataDims = data->getDimensions();
81
82 for (int timeId = 0; timeId < timeStamps.size(); timeId++) {
83 const double time = timeStamps(timeId);
84
85 Eigen::VectorXd slice(data->getSize());
86 for (int valueId = 0; valueId < slice.size(); valueId++) {
87 slice(valueId) = _values(valueId * timeStamps.size() + timeId);
88 }
89
90 if (!data->hasGradient()) {
91 data->setSampleAtTime(time, time::Sample{dataDims, std::move(slice)});
92 continue;
93 }
94
95 Eigen::MatrixXd gradientSlice(data->sample().gradients.rows(), data->sample().gradients.cols());
96 auto gradientView = Eigen::VectorXd::Map(gradientSlice.data(), gradientSlice.rows() * gradientSlice.cols());
97 for (int gradientId = 0; gradientId < gradientView.size(); gradientId++) {
98 gradientView(gradientId) = _gradients(gradientId * timeStamps.size() + timeId);
99 }
100 data->setSampleAtTime(time, time::Sample{dataDims, std::move(slice), std::move(gradientSlice)});
101 }
102}
103
104const Eigen::VectorXd &SerializedStamples::values() const
105{
106 return _values;
107}
108
110{
111 return _values;
112}
113
114const Eigen::VectorXd &SerializedStamples::gradients() const
115{
116 return _gradients;
117}
118
120{
121 return _gradients;
122}
123
125{
126 return _timeSteps;
127}
128
129} // namespace precice::com::serialize
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
serialized representation of CouplingData
Eigen::VectorXd _gradients
Buffer for serialized gradients of stamples.
void deserializeInto(const Eigen::VectorXd &timeStamps, const cplscheme::PtrCouplingData data)
Deserialize data from this SerializedStamples into provided CouplingData.
int _timeSteps
number of timesteps stored in SerializedStamples
void deserialize(const Eigen::VectorXd timeStamps, cplscheme::PtrCouplingData data) const
Deserialize _values and (if required by data) _gradients into timeStepsStorage of data....
void serializeValues(const cplscheme::PtrCouplingData data)
Serialize values from timeStepsStorage of data into _values.
const Eigen::VectorXd & gradients() const
const reference to serialized gradients. Used for sending serialized gradients.
void allocate(const cplscheme::PtrCouplingData data)
static SerializedStamples empty(Eigen::VectorXd timeStamps, const cplscheme::PtrCouplingData data)
Create SerializedStamples with allocated buffers according to size of CouplingData.
Eigen::VectorXd _values
Buffer for serialized values of stamples.
void serializeGradients(const cplscheme::PtrCouplingData data)
Serialize gradients from timeStepsStorage of data into _gradients.
int nTimeSteps() const
Returns number of timeSteps.
static SerializedStamples serialize(const cplscheme::PtrCouplingData data)
Serializes a given CouplingData into SerializedStamples.
const Eigen::VectorXd & values() const
const reference to serialized values. Used for sending serialized values.
contains serialization logic