00001
00030 #ifndef P1NDELEMENT_H_
00031 #define P1NDELEMENT_H_
00032
00033 #include <vector>
00034 #include <cassert>
00035
00036 #include "AuxDefs.h"
00037 #include "Element.h"
00038 #include "ElementBoundaryTrace.h"
00039 #include "ElementGeometry.h"
00040
00041 template <size_t NF>
00042 class P1nDElement: public Element_ {
00043 private:
00044 const ElementGeometry& elemGeom;
00045
00046 public:
00049 P1nDElement (const ElementGeometry& _elemGeom) : Element_(), elemGeom(_elemGeom) {
00050
00051 }
00052
00055 P1nDElement (const P1nDElement& that) : Element_(that), elemGeom (that.elemGeom) {
00056
00057 }
00058
00060 virtual const size_t getNumFields () const {
00061 return NF;
00062 }
00063
00065 virtual const ElementGeometry& getGeometry () const {
00066 return elemGeom;
00067 }
00068
00069 protected:
00071 size_t getFieldShapes (size_t field) const {
00072 return 0;
00073 }
00074 };
00075
00079 template <size_t NF>
00080 class P1nDTrace: public P1nDElement<NF> {
00081 public:
00085 enum FaceLabel {
00086 FaceOne, FaceTwo, FaceThree, FaceFour
00087 };
00088
00093 enum ShapeType {
00094 TwoDofs, ThreeDofs, FourDofs
00095 };
00096
00097 P1nDTrace (const P1nDElement<NF>& baseElem):
00098 P1nDElement<NF>(baseElem) {
00099
00100 }
00101
00102 P1nDTrace (const P1nDTrace<NF>& that):
00103 P1nDElement<NF> (that) {
00104
00105 }
00106
00107
00108 };
00109
00110
00116 template <size_t NF>
00117 class P1nDBoundaryTraces: public ElementBoundaryTraces_ {
00118 private:
00119 MatDouble normals;
00120
00121 public:
00122 typedef typename P1nDTrace<NF>::FaceLabel FaceLabel;
00123 typedef typename P1nDTrace<NF>::ShapeType ShapeType;
00124
00125 P1nDBoundaryTraces (const P1nDElement<NF>& baseElem,
00126 const std::vector<FaceLabel>& faceLabels, const ShapeType& shapeType) :
00127 ElementBoundaryTraces_ () {
00128
00129 assert (faceLabels.size() == baseElem.getGeometry().getNumFaces ());
00130
00131 for (size_t i = 0; i < faceLabels.size (); ++i) {
00132 const P1nDTrace<NF>* fTrace = makeTrace (baseElem, faceLabels[i], shapeType);
00133 addFace (fTrace, i);
00134 }
00135
00136 normals.resize (getNumTraceFaces ());
00137
00138 for (size_t i = 0; i < getNumTraceFaces (); ++i) {
00139 baseElem.getGeometry ().computeNormal (getTraceFaceIds ()[i], normals[i]);
00140 }
00141
00142 }
00143
00144 P1nDBoundaryTraces (const P1nDBoundaryTraces<NF>& that) :
00145 ElementBoundaryTraces_ (that), normals (that.normals) {
00146
00147 }
00148
00149 const std::vector<double> & getNormal (size_t FaceIndex) const {
00150 return normals[FaceIndex];
00151 }
00152
00153 protected:
00154 virtual const P1nDTrace<NF>* makeTrace (const P1nDElement<NF>& baseElem,
00155 const FaceLabel& flabel, const ShapeType& shType) const = 0;
00156
00157 };
00158
00159
00175 class StandardP1nDMap: public LocalToGlobalMap {
00176 private:
00177 const std::vector<Element*>& elementArray;
00178
00179 public:
00180 StandardP1nDMap (const std::vector<Element*>& _elementArray)
00181 : LocalToGlobalMap (), elementArray (_elementArray) {
00182
00183 }
00184
00185 StandardP1nDMap (const StandardP1nDMap& that) :
00186 LocalToGlobalMap (that), elementArray (that.elementArray) {
00187
00188 }
00189
00190 virtual StandardP1nDMap* clone () const {
00191 return new StandardP1nDMap (*this);
00192 }
00193
00194 inline const GlobalDofIndex map (size_t field, size_t dof, const GlobalElementIndex& ElementMapped) const {
00195 const Element* elem = elementArray[ElementMapped];
00196
00197
00198
00199 return elem->getNumFields () * (elem-> getGeometry ().getConnectivity ()[dof]) + field;
00200 }
00201
00202
00203 inline const size_t getNumElements () const {
00204 return elementArray.size ();
00205 }
00206
00207 inline const size_t getNumFields (const GlobalElementIndex & ElementMapped) const {
00208 return elementArray[ElementMapped]->getNumFields ();
00209 }
00210 inline const size_t getNumDof (const GlobalElementIndex & ElementMapped, size_t field) const {
00211 return elementArray[ElementMapped]->getDof (field);
00212 }
00213
00214 const size_t getTotalNumDof () const {
00215 GlobalNodalIndex MaxNodeNumber = 0;
00216
00217 for (size_t e = 0; e < elementArray.size (); e++) {
00218 const std::vector<GlobalNodalIndex>& conn = elementArray[e]->getGeometry ().getConnectivity ();
00219
00220 for (size_t a = 0; a < conn.size (); ++a) {
00221 if (conn[a] > MaxNodeNumber) {
00222 MaxNodeNumber = conn[a];
00223 }
00224 }
00225 }
00226
00227
00228
00229 return static_cast<size_t> (MaxNodeNumber + 1) * elementArray[0]->getNumFields ();
00230 }
00231
00232 protected:
00234 const std::vector<Element *> & getElementArray () const {
00235 return elementArray;
00236 }
00237
00238 };
00239
00240 #endif