NuTo
Numerics Tool
DofVectorConvertEigen.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 namespace NuTo
6 {
7 template <typename T>
8 inline int TotalRows(const DofVector<T>& v, const std::vector<DofType>& dofs)
9 {
10  int totalRows = 0;
11  for (auto dof : dofs)
12  totalRows += v[dof].rows();
13  return totalRows;
14 }
15 
21 template <typename T>
22 inline Eigen::Matrix<T, Eigen::Dynamic, 1> ToEigen(const DofVector<T>& v, std::vector<DofType> dofs)
23 {
25 
26  int currentStartRow = 0;
27  for (auto dof : dofs)
28  {
29  const int rows = v[dof].rows();
30  combined.segment(currentStartRow, rows) = v[dof];
31  currentStartRow += rows;
32  }
33  return combined;
34 }
35 
40 template <typename T>
41 inline void FromEigen(const Eigen::Matrix<T, Eigen::Dynamic, 1>& source, std::vector<DofType> dofs,
42  DofVector<T>* rDestination)
43 {
44  assert(rDestination != nullptr);
45  assert(TotalRows(*rDestination, dofs) == source.rows());
46  int currentStartRow = 0;
47  for (auto dof : dofs)
48  {
49  const int rows = (*rDestination)[dof].rows();
50  (*rDestination)[dof] = source.segment(currentStartRow, rows);
51  currentStartRow += rows;
52  }
53 }
54 } /* NuTo */
int TotalRows(const DofMatrixSparse< T > &v, std::vector< DofType > dofs)
Definition: DofMatrixSparseConvertEigen.h:8
Eigen::SparseMatrix< T > ToEigen(const DofMatrixSparse< T > &v, std::vector< DofType > dofs)
export the dofs entries of a DofMatrixSparse to a Eigen::SparseMatrix
Definition: DofMatrixSparseConvertEigen.h:41
int v
Definition: Quad2DPatchTest.py:9
Definition: Exception.h:6
Definition: SerializeStreamOut.h:9
void FromEigen(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &source, std::vector< DofType > dofs, DofVector< T > *rDestination)
imports a values into a properly sized DofVector
Definition: DofVectorConvertEigen.h:41
Definition: DofVector.h:12