opensurgsim
Fem3DElementTetrahedron.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_FEM3DELEMENTTETRAHEDRON_H
17 #define SURGSIM_PHYSICS_FEM3DELEMENTTETRAHEDRON_H
18 
19 #include <array>
20 
21 #include "SurgSim/Math/Matrix.h"
22 #include "SurgSim/Math/Vector.h"
23 #include "SurgSim/Physics/Fem.h"
24 #include "SurgSim/Physics/FemElement.h"
25 
26 namespace SurgSim
27 {
28 
29 namespace Physics
30 {
31 SURGSIM_STATIC_REGISTRATION(Fem3DElementTetrahedron);
32 
42 {
43 public:
46 
53  explicit Fem3DElementTetrahedron(std::array<size_t, 4> nodeIds);
54 
62  explicit Fem3DElementTetrahedron(std::shared_ptr<FemElementStructs::FemElementParameter> elementData);
63 
65 
66  void initialize(const SurgSim::Math::OdeState& state) override;
67 
68  double getVolume(const SurgSim::Math::OdeState& state) const override;
69 
71  const SurgSim::Math::Vector& naturalCoordinate) const override;
72 
74  const SurgSim::Math::Vector& cartesianCoordinate) const override;
75 
76 protected:
78  void initializeMembers();
79 
80  void doUpdateFMDK(const Math::OdeState& state, int options) override;
81 
90  double* volume,
91  std::array<double, 4>* ai,
92  std::array<double, 4>* bi,
93  std::array<double, 4>* ci,
94  std::array<double, 4>* di) const;
95 
99  void computeStiffness(const SurgSim::Math::OdeState& state,
101 
105  void computeMass(const SurgSim::Math::OdeState& state,
107 
109  Eigen::Matrix<double, 12, 1> m_x0;
110 
111 };
112 
113 namespace Tetrahedron {
114  template <class Vector, class SubVector>
115  void getSubVector(const Vector& vector, const std::vector<size_t>& blockIds, SubVector* subVector)
116  {
117  static const int blockSize = 3;
118  subVector->segment(blockSize * 0, blockSize) = vector.segment(blockSize * blockIds[0], blockSize);
119  subVector->segment(blockSize * 1, blockSize) = vector.segment(blockSize * blockIds[1], blockSize);
120  subVector->segment(blockSize * 2, blockSize) = vector.segment(blockSize * blockIds[2], blockSize);
121  subVector->segment(blockSize * 3, blockSize) = vector.segment(blockSize * blockIds[3], blockSize);
122  }
123 }
124 
125 } // namespace Physics
126 
127 } // namespace SurgSim
128 
129 #endif // SURGSIM_PHYSICS_FEM3DELEMENTTETRAHEDRON_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Class for Fem Element 3D based on a tetrahedron volume discretization.
Definition: Fem3DElementTetrahedron.h:41
Eigen::Matrix< double, 12, 1 > m_x0
The tetrahedon rest state.
Definition: Fem3DElementTetrahedron.h:109
void computeShapeFunctions(const SurgSim::Math::OdeState &state, double *volume, std::array< double, 4 > *ai, std::array< double, 4 > *bi, std::array< double, 4 > *ci, std::array< double, 4 > *di) const
Computes the tetrahedron shape functions.
Definition: Fem3DElementTetrahedron.cpp:237
void initializeMembers()
Initializes variables needed before Initialize() is called.
Definition: Fem3DElementTetrahedron.cpp:72
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
void computeStiffness(const SurgSim::Math::OdeState &state, SurgSim::Math::Matrix *k)
Computes the tetrahedron stiffness matrix.
Definition: Fem3DElementTetrahedron.cpp:168
SurgSim::Math::Vector computeCartesianCoordinate(const SurgSim::Math::OdeState &state, const SurgSim::Math::Vector &naturalCoordinate) const override
Computes a given natural coordinate in cartesian coordinates.
Definition: Fem3DElementTetrahedron.cpp:361
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
void computeMass(const SurgSim::Math::OdeState &state, SurgSim::Math::Matrix *m)
Computes the tetrahedron mass matrix.
Definition: Fem3DElementTetrahedron.cpp:123
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.
SurgSim::Math::Vector computeNaturalCoordinate(const SurgSim::Math::OdeState &state, const SurgSim::Math::Vector &cartesianCoordinate) const override
Computes a natural coordinate given a global coordinate.
Definition: Fem3DElementTetrahedron.cpp:374
void doUpdateFMDK(const Math::OdeState &state, int options) override
Update the FemElement based on the given state.
Definition: Fem3DElementTetrahedron.cpp:77
void initialize(const SurgSim::Math::OdeState &state) override
Initialize the FemElement once everything has been set.
Definition: Fem3DElementTetrahedron.cpp:92
double getVolume(const SurgSim::Math::OdeState &state) const override
Gets the element volume based on the input state (in m-3)
Definition: Fem3DElementTetrahedron.cpp:218
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
Fem3DElementTetrahedron()
Constructor.
Definition: Fem3DElementTetrahedron.cpp:49