00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkFEMElementBase_h
00019 #define __itkFEMElementBase_h
00020
00021 #include "itkFEMLightObject.h"
00022 #include "itkFEMPArray.h"
00023 #include "itkFEMMaterialBase.h"
00024 #include "itkFEMSolution.h"
00025 #include "itkVisitorDispatcher.h"
00026 #include "vnl/vnl_matrix.h"
00027 #include "vnl/vnl_vector.h"
00028 #include <set>
00029 #include <vector>
00030
00031 namespace itk {
00032 namespace fem {
00033
00034
00035
00036
00069 #define HANDLE_ELEMENT_LOADS() \
00070 \
00071 typedef void (*LoadImplementationFunctionPointer)(ConstPointer,Element::LoadPointer, Element::VectorType& ); \
00072 virtual void GetLoadVector( Element::LoadPointer l, Element::VectorType& Fe ) const \
00073 { VisitorDispatcher<Self,Element::LoadType, LoadImplementationFunctionPointer>::Visit(l)(this,l,Fe); }
00074
00075 class Element : public FEMLightObject
00076 {
00077 FEM_ABSTRACT_CLASS(Element,FEMLightObject)
00078 public:
00079
00083 typedef double Float;
00084
00088 typedef FEMPArray<Element> ArrayType;
00089
00093 typedef vnl_matrix<Float> MatrixType;
00094
00098 typedef vnl_vector<Float> VectorType;
00099
00111 typedef FEMLightObject LoadType;
00112 typedef LoadType::Pointer LoadPointer;
00113
00117 typedef unsigned int DegreeOfFreedomIDType;
00118
00124 enum{ InvalidDegreeOfFreedomID = 0xffffffff };
00125
00134 class Node : public FEMLightObject
00135 {
00136 FEM_CLASS(Node,FEMLightObject)
00137 public:
00138
00142 typedef double Float;
00143
00147 typedef FEMPArray<Self> ArrayType;
00148
00149
00150
00151 #ifdef FEM_BUILD_VISUALIZATION
00152
00153 void Draw(CDC* pDC, Solution::ConstPointer sol) const;
00155 static double& DC_Scale;
00156 #endif
00157
00161 Node() {}
00162
00166 Node(Float x, Float y) : m_coordinates(VectorType(2))
00167 { m_coordinates[0]=x; m_coordinates[1]=y; }
00168
00172 Node(Float x, Float y, Float z) : m_coordinates(VectorType(3))
00173 { m_coordinates[0]=x; m_coordinates[1]=y; m_coordinates[2]=z;}
00178 const VectorType& GetCoordinates( void ) const
00179 { return m_coordinates; }
00180
00184 void SetCoordinates( const VectorType& coords )
00185 { m_coordinates=coords; }
00186
00190 DegreeOfFreedomIDType GetDegreeOfFreedom(unsigned int i) const
00191 {
00192 if( i>=m_dof.size() ) { return InvalidDegreeOfFreedomID; }
00193 return m_dof[i];
00194 }
00195
00199 void SetDegreeOfFreedom(unsigned int i, DegreeOfFreedomIDType dof) const
00200 {
00201 if( i>=m_dof.size() ) { m_dof.resize(i+1, InvalidDegreeOfFreedomID); }
00202 m_dof[i]=dof;
00203 }
00204
00205 virtual void ClearDegreesOfFreedom( void ) const
00206 {
00207 m_dof.clear();
00208 }
00209
00210 virtual void Read( std::istream& f, void* info );
00211 virtual void Write( std::ostream& f ) const;
00212
00213 public:
00218 typedef std::set<Element*> SetOfElements;
00219 mutable SetOfElements m_elements;
00220
00221 private:
00225 VectorType m_coordinates;
00226
00231 mutable std::vector<DegreeOfFreedomIDType> m_dof;
00232
00233 };
00234
00235
00236
00237
00239
00240
00241
00242
00243 virtual VectorType GetStrainsAtPoint(const VectorType& pt, const Solution& sol, unsigned int index) const;
00244
00245 virtual VectorType GetStressesAtPoint(const VectorType& pt, const VectorType& e, const Solution& sol, unsigned int index) const;
00246
00267 virtual void GetStiffnessMatrix( MatrixType& Ke ) const;
00268
00278 virtual Float GetElementDeformationEnergy( MatrixType& LocalSolution ) const;
00279
00291 virtual void GetMassMatrix( MatrixType& Me ) const;
00292
00304 virtual void GetLandmarkContributionMatrix(float eta, MatrixType& Le) const;
00305
00335 virtual void GetLoadVector( LoadPointer l, VectorType& Fe ) const = 0;
00336
00344 virtual void GetStrainDisplacementMatrix( MatrixType& B, const MatrixType& shapeDgl ) const = 0;
00345
00351 virtual void GetMaterialMatrix( MatrixType& D ) const = 0;
00352
00364 virtual VectorType InterpolateSolution( const VectorType& pt, const Solution& sol , unsigned int solutionIndex=0 ) const;
00365
00379 virtual Float InterpolateSolutionN( const VectorType& pt, const Solution& sol, unsigned int f , unsigned int solutionIndex=0 ) const;
00380
00387 DegreeOfFreedomIDType GetDegreeOfFreedom( unsigned int local_dof ) const
00388 {
00389 if(local_dof>this->GetNumberOfDegreesOfFreedom()) { return InvalidDegreeOfFreedomID; }
00390 return this->GetNode(local_dof/this->GetNumberOfDegreesOfFreedomPerNode())->GetDegreeOfFreedom(local_dof%this->GetNumberOfDegreesOfFreedomPerNode());
00391 }
00392
00409 virtual Material::ConstPointer GetMaterial(void) const { return 0; }
00410
00419 virtual void SetMaterial(Material::ConstPointer) {}
00420
00421
00422
00423
00425
00426
00427
00428
00451 virtual void GetIntegrationPointAndWeight( unsigned int i, VectorType& pt, Float& w, unsigned int order=0 ) const = 0;
00452
00463 virtual unsigned int GetNumberOfIntegrationPoints( unsigned int order=0 ) const = 0;
00464
00473 enum { gaussMaxOrder=10 };
00474
00486 static const Float gaussPoint[gaussMaxOrder+1][gaussMaxOrder];
00487
00493 static const Float gaussWeight[gaussMaxOrder+1][gaussMaxOrder];
00494
00495
00497
00498
00499
00500
00505 typedef Node::ConstPointer NodeIDType;
00506
00510 virtual unsigned int GetNumberOfNodes( void ) const = 0;
00511
00515 virtual NodeIDType GetNode(unsigned int n) const = 0;
00516
00520 virtual void SetNode(unsigned int n, NodeIDType node) = 0;
00521
00527 virtual const VectorType& GetNodeCoordinates( unsigned int n ) const = 0;
00528
00534 virtual VectorType GetGlobalFromLocalCoordinates( const VectorType& pt ) const;
00535
00542 virtual bool GetLocalFromGlobalCoordinates( const VectorType& globalPt , VectorType& localPt ) const = 0;
00543
00549 virtual unsigned int GetNumberOfSpatialDimensions() const = 0;
00550
00558 virtual VectorType ShapeFunctions( const VectorType& pt ) const = 0;
00559
00575 virtual void ShapeFunctionDerivatives( const VectorType& pt, MatrixType& shapeD ) const = 0;
00576
00596 virtual void ShapeFunctionGlobalDerivatives( const VectorType& pt, MatrixType& shapeDgl, const MatrixType* pJ=0, const MatrixType* pshapeD=0 ) const;
00597
00619 virtual void Jacobian( const VectorType& pt, MatrixType& J, const MatrixType* pshapeD = 0 ) const;
00620
00630 virtual Float JacobianDeterminant( const VectorType& pt, const MatrixType* pJ = 0 ) const;
00631
00643 virtual void JacobianInverse( const VectorType& pt, MatrixType& invJ, const MatrixType* pJ = 0 ) const;
00644
00650 virtual unsigned int GetNumberOfDegreesOfFreedom( void ) const
00651 {
00652 return this->GetNumberOfNodes() * this->GetNumberOfDegreesOfFreedomPerNode();
00653 }
00654
00662 virtual unsigned int GetNumberOfDegreesOfFreedomPerNode( void ) const = 0;
00663
00664
00665
00666
00668
00669
00670
00671
00672 #ifdef FEM_BUILD_VISUALIZATION
00673
00676 virtual void Draw(CDC* pDC, Solution::ConstPointer sol) const {}
00678 static double DC_Scale;
00679 #endif
00680
00681 };
00682
00683
00684 static INITClass Initializer_ElementNode(Element::Node::CLID());
00685
00686
00687 typedef Element::Node Node;
00688
00689
00690
00691
00703 class ReadInfoType
00704 {
00705 public:
00706
00707 typedef Node::ArrayType::ConstPointer NodeArrayPointer;
00708 typedef Element::ArrayType::ConstPointer ElementArrayPointer;
00709 typedef Material::ArrayType::ConstPointer MaterialArrayPointer;
00710
00712 NodeArrayPointer m_node;
00713
00715 ElementArrayPointer m_el;
00716
00718 MaterialArrayPointer m_mat;
00719
00721 ReadInfoType( NodeArrayPointer node_, ElementArrayPointer el_, MaterialArrayPointer mat_) :
00722 m_node(node_), m_el(el_), m_mat(mat_) {}
00723 };
00724
00725
00726
00727
00728 }}
00729
00730 #endif // #ifndef __itkFEMElementBase_h