opensurgsim
FemElement-inl.h
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 T, int Opt, typename StorageIndex>
31 void FemElement::assembleMatrixBlocks(const Eigen::Ref<const Math::Matrix>& subMatrix,
32  const std::vector<size_t>& blockIds, size_t blockSize, Eigen::SparseMatrix<T, Opt, StorageIndex>* matrix) const
33 {
34  using SurgSim::Math::addSubMatrix;
35  using Eigen::Index;
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]), static_cast<Index>(blockIds[block1]), matrix);
46  }
47  }
48 }
49 
50 template <typename T, int Opt, typename StorageIndex>
51 void FemElement::assembleMatrixBlocksNoInitialize(const Eigen::Ref<const Math::Matrix>& subMatrix,
52  const std::vector<size_t>& blockIds, size_t blockSize, Eigen::SparseMatrix<T, Opt, StorageIndex>* matrix) const
53 {
54  using SurgSim::Math::addSubMatrixNoInitialize;
55  using Eigen::Index;
56 
57  const Index numBlocks = static_cast<Index>(blockIds.size());
58  for (Index block0 = 0; block0 < numBlocks; block0++)
59  {
60  Index subRow = static_cast<Index>(blockSize * block0);
61  for (Index block1 = 0; block1 < numBlocks; block1++)
62  {
63  Index subCol = static_cast<Index>(blockSize * block1);
64  addSubMatrixNoInitialize(subMatrix.block(subRow, subCol, blockSize, blockSize),
65  static_cast<Index>(blockIds[block0]), static_cast<Index>(blockIds[block1]), matrix);
66  }
67  }
68 }
69 
70 } // namespace Physics
71 
72 } // namespace SurgSim
73 
74 #endif // SURGSIM_PHYSICS_FEMELEMENT_INL_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
void assembleMatrixBlocksNoInitialize(const Eigen::Ref< const Math::Matrix > &subMatrix, const std::vector< size_t > &blockIds, size_t blockSize, Eigen::SparseMatrix< T, Opt, StorageIndex > *matrix) const
Add a sub-matrix made of squared-blocks into a matrix that is already initialized.
Definition: FemElement-inl.h:51
Definitions of useful sparse matrix functions.
void assembleMatrixBlocks(const Eigen::Ref< const Math::Matrix > &subMatrix, const std::vector< size_t > &blockIds, size_t blockSize, Eigen::SparseMatrix< T, Opt, StorageIndex > *matrix) const
Add a sub-matrix made of squared-blocks into a matrix that could be un-initialized.
Definition: FemElement-inl.h:31
Definitions of small fixed-size square matrix types.