/Users/jack/Code/basso_dev/inc/Element.h

Go to the documentation of this file.
00001 
00012 #ifndef _ELEMENT_BASSO_H_
00013 #define _ELEMENT_BASSO_H_
00014 
00015 // std includes
00016 
00017 // Basso includes
00018 #include "basso.h"
00019 #include "Basis.h"
00020 #include "basic_fem_operations.h"
00021 
00022 // Basis types
00023 #include "basis_includes.h"
00024 
00025 namespace basso {
00026 
00027 
00028 
00034 class Element  {
00035 
00036 public:
00037         
00038         // PUBLIC DEFS
00039         typedef iArray::const_iterator  const_iterator;
00040         typedef iArray::iterator                iterator;
00041         
00042         // CONSTRUCTORS 
00043         
00049         Element( int id=0, int part=0, BasisType bt=kNONE ) : fConn( basis_type_numnodes(bt) )
00050                 { fBasisLocal=false; SetBasis(bt); eid=id; pid=part; }
00051         
00058         Element( int id, int part, BasisType bt, const iArray &nids ) 
00059                 : fConn(nids) { eid=id; pid=part; fBasisLocal=false; SetBasis(bt); }
00060         
00069         Element( int id, int part, Basis *bt, const iArray &nids ) : fConn( nids )
00070                 { eid=id; pid=part; fBasis=bt; fBasisLocal=false; }
00071 
00073         Element( const Element &be ) { fBasisLocal=false; CopyElement(be); }
00074         
00076         ~Element() { if ( fBasisLocal ) delete fBasis; }
00077         
00078         // ACCESSORS
00079         Element::const_iterator begin() const { return fConn.begin(); }
00080         Element::iterator begin()  { return fConn.begin(); }
00081         
00082         Element::const_iterator end() const { return fConn.end(); }
00083         Element::iterator end()  { return fConn.end(); }
00084         
00086         int operator[] ( int i ) const { return NodeId(i); }
00087         
00088         // MEMBER FUNCTIONS
00089         
00091         int NodeId( int i ) const
00092         {
00093 #ifdef EXPLICIT_BOUNDS_CHECK
00094                 if ( i<0 || i>fConn.size()-1 )
00095                         ErrorMessage("Element::NodeId","index i out of range for element");
00096 #endif          
00097                 return fConn[i];
00098         }
00099 
00100 
00102         BasisType Type() const { return fBasis->Type(); }
00103                 
00105         BasisShape Shape() const { return fBasis->Shape(); }
00106 
00108         int     NumNodes() const { return fBasis->NumNodes(); }
00109 
00111         int     NumEdges() const { return fBasis->NumEdges(); }
00112 
00114         int     NumFaces() const { return fBasis->NumFaces(); }
00115 
00117         int     Dimension() const { return fBasis->Dimension(); }
00118 
00120         int     Order() const { return fBasis->Order(); }
00121 
00123         void ParentCoord( Array< Point > &pts ) const { fBasis->ParentCoord(pts); }
00124 
00126         Point Centroid() const { return fBasis->Centroid(); }
00127 
00129         void NumNodesOnFaces( iArray &nn_face ) const { fBasis->NumNodesOnFaces(nn_face); }
00130 
00133         void NumNodesOnEdges( iArray &nn_edge ) const { fBasis->NumNodesOnEdges(nn_edge); }
00134 
00138         void NodesOnFace ( int f, iArray &face_nodeids ) const { fBasis->NodesOnFace(f,face_nodeids); }
00139 
00141         void NodesOnEdge ( int e, iArray &edge_nodeids ) const { fBasis->NodesOnEdge(e,edge_nodeids); }
00142 
00144         void FaceBasisType( Array<BasisType> &face_basis ) const { fBasis->FaceBasisType(face_basis); }
00145 
00147         void EdgeBasisType( Array< BasisType > &edge_basis ) const { fBasis->EdgeBasisType(edge_basis); }
00148 
00150         void Quadrature( int p, QuadratureRule &quad ) const { fBasis->Quadrature(p,quad); }
00151                 
00155         void Na( const Point &p, Array<Numeric> &shapefunct ) const { fBasis->Na(p,shapefunct); }
00156 
00158         void Na( Array<Numeric> &shapefunct ) const { fBasis->Na(shapefunct); }
00159 
00164         void DNa( const Point &p, dense_matrix<Numeric> &shapefunct ) const { fBasis->DNa(p,shapefunct); }
00165 
00167         void DNa( dense_matrix<Numeric> &shapefunct ) const { fBasis->DNa(shapefunct); }
00168         
00170         int Id() const { return eid; }
00171         
00173         int PartId() const { return pid; }
00174         
00176         const iArray &Connectivity() const { return fConn; }
00177         
00179         const Basis *BasisPtr() const { return fBasis; }
00180         
00182         Element &CopyElement( const Element &elem ) 
00183         {
00184                 // check element size
00185                 fConn = elem.fConn;
00186                 eid = elem.eid;
00187                 pid = elem.pid;
00188                 if ( elem.fBasisLocal )
00189                         if ( fBasisLocal )
00190                                 *fBasis = *(elem.fBasis);
00191                         else
00192                                 SetBasis( elem.fBasis->Type() );
00193                 else
00194                         fBasis = elem.fBasis; 
00195                 return *this; 
00196         }
00197         
00199         Element &operator = ( const Element &conn1 ) { return CopyElement(conn1); }
00200 
00201 protected:
00203         void SetBasis( BasisType bt );
00204 
00205 protected:
00206         int eid;
00207         int pid;
00208         iArray fConn;
00209         Basis *fBasis;
00210         bool fBasisLocal;
00211         
00212 };
00213 
00214 void Element::SetBasis( BasisType bt )
00215 {
00216         if ( fBasisLocal ) delete fBasis;
00217         
00218         switch ( bt )  {
00219                 
00220                 case kLINE2:
00221                 fBasis = new Line2Basis();
00222                 break;
00223 
00224                 case kLINE3:
00225                 fBasis = new Line3Basis();
00226                 break;
00227                                                 
00228                 case kTRIA3:
00229                 fBasis = new Tria3Basis();
00230                 break;
00231 
00232 /*
00233                 case kTRIA4:
00234                 fBasis = new Tria4Basis();
00235                 break;
00236 */
00237                 
00238                 case kTRIA6:
00239                 fBasis = new Tria6Basis();
00240                 break;
00241                 
00242                 case kQUAD4:
00243                 fBasis = new Quad4Basis();
00244                 break;
00245                 
00246                 case kQUAD8:
00247                 fBasis = new Quad8Basis();
00248                 break;
00249                 
00250                 case kTETRA4:
00251                 fBasis = new Tetra4Basis();
00252                 break;
00253                 
00254                 case kTETRA10:
00255                 fBasis = new Tetra10Basis();
00256                 break;
00257                 
00258                 case kHEXA8:
00259                 fBasis = new Hexa8Basis();
00260                 break;  
00261 
00262 /*              
00263                 case kHEXA20:
00264                 fBasis = new Hexa20Basis();
00265                 break;
00266                 
00267                 
00268 */                                                                                                                      
00269                 default:
00270                 WarningMessage("Element::SetBasis( BasisType )","BasisType not yet implemented in this function");
00271                 return;
00272                 
00273         } 
00274         fBasisLocal=true;
00275         
00276 }
00277 
00278 std::ostream &operator << ( std::ostream &out, const Element &elem )
00279 {
00280         out << "Element " << elem.Id()  << " Part " << elem.PartId() << " " << elem.Type();
00281         out << " { ";
00282         if ( elem.NumNodes()>0 ) {
00283                 for ( int i=0; i<elem.NumNodes()-1; ++i ) {     
00284                         out << elem[i] << ", ";
00285                 }
00286                 out << elem[elem.NumNodes()-1]; 
00287         }
00288         out << " }";
00289         
00290         return out;
00291 }
00292 
00293 } // end namespace
00294 
00295 #endif
00296 
00297 

Generated on Sat Jan 19 09:03:57 2008 for Basso by  doxygen 1.5.2