FemElement.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_H
17 #define SURGSIM_PHYSICS_FEMELEMENT_H
18 
19 #include <vector>
20 
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 = 1.0) const;
117 
124  virtual void addMass(SurgSim::Math::SparseMatrix* M, double scale = 1.0) const;
125 
133  virtual void addDamping(SurgSim::Math::SparseMatrix* D, double scale = 1.0) const;
134 
142  virtual void addStiffness(SurgSim::Math::SparseMatrix* K, double scale = 1.0) const;
143 
152  virtual void addFMDK(SurgSim::Math::Vector* F,
155  SurgSim::Math::SparseMatrix* K) const;
156 
166  virtual void addMatVec(double alphaM, double alphaD, double alphaK,
167  const SurgSim::Math::Vector& x, SurgSim::Math::Vector* F) const;
168 
172  bool isValidCoordinate(const SurgSim::Math::Vector& naturalCoordinate) const;
173 
178  virtual SurgSim::Math::Vector computeCartesianCoordinate(
179  const SurgSim::Math::OdeState& state,
180  const SurgSim::Math::Vector& naturalCoordinate) const = 0;
181 
186  virtual SurgSim::Math::Vector computeNaturalCoordinate(
187  const SurgSim::Math::OdeState& state,
188  const SurgSim::Math::Vector& cartesianCoordinate) const = 0;
189 
202  template <typename DerivedSub, typename T, int Opt, typename Index>
203  void assembleMatrixBlocks(const DerivedSub& subMatrix, const std::vector<size_t> blockIds,
204  size_t blockSize, Eigen::SparseMatrix<T, Opt, Index>* matrix,
205  bool initialize = true) const;
206 
210  void updateFMDK(const Math::OdeState& state, int options);
211 
212 protected:
217  void setNumDofPerNode(size_t numDofPerNode);
218 
222  virtual void doUpdateFMDK(const Math::OdeState& state, int options) = 0;
223 
225  void initializeFMDK();
226 
228  virtual void doInitializeFMDK();
229 
232 
234  std::vector<size_t> m_nodeIds;
235 
237  double m_rho;
238 
240  double m_E;
241 
243  double m_nu;
244 
247 
250 
253 
256 
259 
260 private:
263 };
264 
265 } // namespace Physics
266 
267 } // namespace SurgSim
268 
270 
271 #endif // SURGSIM_PHYSICS_FEMELEMENT_H
Definition: CompoundShapeToGraphics.cpp:29
size_t m_numDofPerNode
Number of degree of freedom per node for this element.
Definition: FemElement.h:231
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
double m_nu
Poisson ratio (unitless)
Definition: FemElement.h:243
SurgSim::Framework::ObjectFactory1< FemElement, std::shared_ptr< FemElementStructs::FemElementParameter > > FactoryType
Definition: FemElement.h:59
SurgSim::Math::Matrix m_D
The damping matrix.
Definition: FemElement.h:252
SurgSim::Math::Matrix m_K
The stiffness matrix.
Definition: FemElement.h:258
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:237
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
SurgSim::Math::Vector m_f
The force vector.
Definition: FemElement.h:246
double m_E
Young modulus (in N.m-2)
Definition: FemElement.h:240
SurgSim::Math::Matrix m_M
The mass matrix.
Definition: FemElement.h:249
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:234
bool m_initializedFMDK
Flag to check in the f, M, D, K variables have been initialized.
Definition: FemElement.h:262
bool m_useDamping
Flag to specify of the damping is used.
Definition: FemElement.h:255
An object factory, once a class is registered with the factory it can be used to create instances of ...
Definition: ObjectFactory.h:83