opensurgsim
FemElement.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_H
17 #define SURGSIM_PHYSICS_FEMELEMENT_H
18 
19 #include <vector>
20 
21 #include "SurgSim/Framework/ObjectFactory.h"
22 #include "SurgSim/Math/Matrix.h"
24 #include "SurgSim/Math/Vector.h"
25 #include "SurgSim/Physics/Fem.h"
26 
27 namespace SurgSim
28 {
29 
30 namespace Math
31 {
32 class OdeState;
33 };
34 
35 namespace Physics
36 {
37 
46 {
47 public:
49  FemElement();
50 
52  virtual ~FemElement();
53 
56  virtual void initialize(const SurgSim::Math::OdeState& state);
57 
60 
61  static FactoryType& getFactory();
62 
65  size_t getNumDofPerNode() const;
66 
69  size_t getNumNodes() const;
70 
73  size_t getNodeId(size_t elementNodeId) const;
74 
77  const std::vector<size_t>& getNodeIds() const;
78 
81  void setYoungModulus(double E);
84  double getYoungModulus() const;
85 
88  void setPoissonRatio(double nu);
91  double getPoissonRatio() const;
92 
95  void setMassDensity(double rho);
98  double getMassDensity() const;
99 
103  double getMass(const SurgSim::Math::OdeState& state) const;
104 
108  virtual double getVolume(const SurgSim::Math::OdeState& state) const = 0;
109 
116  virtual void addForce(SurgSim::Math::Vector* F, double scale) const;
117  virtual void addForce(SurgSim::Math::Vector* F) const;
118 
125  virtual void addMass(SurgSim::Math::SparseMatrix* M, double scale) const;
126  virtual void addMass(SurgSim::Math::SparseMatrix* M) const;
127 
135  virtual void addDamping(SurgSim::Math::SparseMatrix* D, double scale) const;
136  virtual void addDamping(SurgSim::Math::SparseMatrix* D) const;
137 
145  virtual void addStiffness(SurgSim::Math::SparseMatrix* K, double scale) const;
146  virtual void addStiffness(SurgSim::Math::SparseMatrix* K) const;
147 
156  virtual void addFMDK(SurgSim::Math::Vector* F,
159  SurgSim::Math::SparseMatrix* K) const;
160 
172  virtual void addMatVec(double alphaM, double alphaD, double alphaK,
174  SurgSim::Math::Vector* extractedX, SurgSim::Math::Vector* acumulator) const;
175 
179  bool isValidCoordinate(const SurgSim::Math::Vector& naturalCoordinate) const;
180 
185  virtual SurgSim::Math::Vector computeCartesianCoordinate(
186  const SurgSim::Math::OdeState& state,
187  const SurgSim::Math::Vector& naturalCoordinate) const = 0;
188 
193  virtual SurgSim::Math::Vector computeNaturalCoordinate(
194  const SurgSim::Math::OdeState& state,
195  const SurgSim::Math::Vector& cartesianCoordinate) const = 0;
196 
203  template <typename T, int Opt, typename StorageIndex>
204  void assembleMatrixBlocks(const Eigen::Ref<const Math::Matrix>& subMatrix,
205  const std::vector<size_t>& blockIds, size_t blockSize, Eigen::SparseMatrix<T, Opt, StorageIndex>* matrix) const;
206 
213  template <typename T, int Opt, typename StorageIndex>
214  void assembleMatrixBlocksNoInitialize(const Eigen::Ref<const Math::Matrix>& subMatrix,
215  const std::vector<size_t>& blockIds, size_t blockSize, Eigen::SparseMatrix<T, Opt, StorageIndex>* matrix) const;
216 
220  void updateFMDK(const Math::OdeState& state, int options);
221 
222 protected:
227  void setNumDofPerNode(size_t numDofPerNode);
228 
232  virtual void doUpdateFMDK(const Math::OdeState& state, int options) = 0;
233 
235  void initializeFMDK();
236 
238  virtual void doInitializeFMDK();
239 
242 
244  std::vector<size_t> m_nodeIds;
245 
248 
251 
254 
257 
260 
262  double m_rho;
263 
265  double m_E;
266 
268  double m_nu;
269 
270 };
271 
272 } // namespace Physics
273 
274 } // namespace SurgSim
275 
276 #include "SurgSim/Physics/FemElement-inl.h"
277 
278 #endif // SURGSIM_PHYSICS_FEMELEMENT_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
size_t m_numDofPerNode
Number of degree of freedom per node for this element.
Definition: FemElement.h:241
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
double m_nu
Poisson ratio (unitless)
Definition: FemElement.h:268
SurgSim::Math::Matrix m_D
The damping matrix.
Definition: FemElement.h:256
SurgSim::Math::Matrix m_K
The stiffness matrix.
Definition: FemElement.h:250
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
Base class for all Fem Element (1D, 2D, 3D) It handles the node ids to which it is connected and requ...
Definition: FemElement.h:45
Definitions of useful sparse matrix functions.
double m_rho
Mass density (in Kg.m-3)
Definition: FemElement.h:262
SurgSim::Math::Vector m_f
The force vector.
Definition: FemElement.h:247
double m_E
Young modulus (in N.m-2)
Definition: FemElement.h:265
SurgSim::Math::Matrix m_M
The mass matrix.
Definition: FemElement.h:253
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
Definitions of small fixed-size square matrix types.
Definitions of small fixed-size vector types.
std::vector< size_t > m_nodeIds
Node ids connected by this element.
Definition: FemElement.h:244
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
bool m_useDamping
Flag to specify of the damping is used.
Definition: FemElement.h:259
An object factory, once a class is registered with the factory it can be used to create instances of ...
Definition: ObjectFactory.h:83