preCICE v3.2.0
Loading...
Searching...
No Matches
la.hpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include "utils/assertion.hpp"
3
4namespace precice::math {
5
7/* Assumes vector has size k*size(result), i.e. the components of
8 * vector are a sequence of smaller vectors with length of result.
9 * @param[in] vector Vector that is summed up
10 * @param[in, out] result Vector which holds the sum and also defines the block sizes.
11 */
12template <typename DerivedA, typename DerivedB>
13void sumSubvectors(const Eigen::MatrixBase<DerivedA> &vector,
14 Eigen::MatrixBase<DerivedB> &result)
15{
16 int vectorSize = vector.size();
17 int subvectorSize = result.size();
18 PRECICE_ASSERT(vectorSize > 0);
19 PRECICE_ASSERT(subvectorSize > 0);
20 PRECICE_ASSERT(vectorSize % subvectorSize == 0, vectorSize, subvectorSize);
21
22 result.setZero();
23
24 // Sum up subvectors
25 for (int i = 0; i < vectorSize; i += subvectorSize) {
26 result += vector.block(i, 0, subvectorSize, 1);
27 }
28}
29
30} // namespace precice::math
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
STL class.
provides general mathematical constants and functions.
Definition barycenter.cpp:9
void sumSubvectors(const Eigen::MatrixBase< DerivedA > &vector, Eigen::MatrixBase< DerivedB > &result)
Sums up the components of subvectors in vector into result.
Definition la.hpp:13
T size(T... args)