FemElement-inl.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_PHYSICS_FEMELEMENT_INL_H
17 #define SURGSIM_PHYSICS_FEMELEMENT_INL_H
18 
19 #include <vector>
20 
21 #include "SurgSim/Math/Matrix.h"
23 
24 namespace SurgSim
25 {
26 
27 namespace Physics
28 {
29 
30 template <typename DerivedSub, typename T, int Opt, typename Index>
31 void FemElement::assembleMatrixBlocks(const DerivedSub& subMatrix, const std::vector<size_t> blockIds,
32  size_t blockSize, Eigen::SparseMatrix<T, Opt, Index>* matrix,
33  bool initialize) const
34 {
36 
37  const Index numBlocks = static_cast<Index>(blockIds.size());
38  for (Index block0 = 0; block0 < numBlocks; block0++)
39  {
40  Index subRow = static_cast<Index>(blockSize * block0);
41  for (Index block1 = 0; block1 < numBlocks; block1++)
42  {
43  Index subCol = static_cast<Index>(blockSize * block1);
44  addSubMatrix(subMatrix.block(subRow, subCol, blockSize, blockSize),
45  static_cast<Index>(blockIds[block0]),
46  static_cast<Index>(blockIds[block1]),
47  matrix, initialize);
48  }
49  }
50 }
51 
52 } // namespace Physics
53 
54 } // namespace SurgSim
55 
56 #endif // SURGSIM_PHYSICS_FEMELEMENT_INL_H
Definition: CompoundShapeToGraphics.cpp:29
Definitions of useful sparse matrix functions.
void addSubMatrix(const SubMatrix &subMatrix, size_t blockIdRow, size_t blockIdCol, size_t blockSizeRow, size_t blockSizeCol, Matrix *matrix)
Helper method to add a sub-matrix into a matrix, for the sake of clarity.
Definition: Matrix.h:157
virtual void initialize(const SurgSim::Math::OdeState &state)
Initialize the FemElement once everything has been set.
Definition: FemElement.cpp:34
void assembleMatrixBlocks(const DerivedSub &subMatrix, const std::vector< size_t > blockIds, size_t blockSize, Eigen::SparseMatrix< T, Opt, Index > *matrix, bool initialize=true) const
Helper method to add a sub-matrix made of squared-blocks into a matrix, for the sake of clarity...
Definition: FemElement-inl.h:31
Definitions of small fixed-size square matrix types.