preCICE v3.1.1
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 {
5namespace math {
6
8/* Assumes vector has size k*size(result), i.e. the components of
9 * vector are a sequence of smaller vectors with length of result.
10 * @param[in] vector Vector that is summed up
11 * @param[in, out] result Vector which holds the sum and also defines the block sizes.
12 */
13template <typename DerivedA, typename DerivedB>
14void sumSubvectors(const Eigen::MatrixBase<DerivedA> &vector,
15 Eigen::MatrixBase<DerivedB> & result)
16{
17 int vectorSize = vector.size();
18 int subvectorSize = result.size();
19 PRECICE_ASSERT(vectorSize > 0);
20 PRECICE_ASSERT(subvectorSize > 0);
21 PRECICE_ASSERT(vectorSize % subvectorSize == 0, vectorSize, subvectorSize);
22
23 result.setZero();
24
25 // Sum up subvectors
26 for (int i = 0; i < vectorSize; i += subvectorSize) {
27 result += vector.block(i, 0, subvectorSize, 1);
28 }
29}
30
31} // namespace math
32} // namespace precice
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
void sumSubvectors(const Eigen::MatrixBase< DerivedA > &vector, Eigen::MatrixBase< DerivedB > &result)
Sums up the components of subvectors in vector into result.
Definition la.hpp:14
Main namespace of the precice library.