00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef ABSTRACTELEMENT_HPP_
00030 #define ABSTRACTELEMENT_HPP_
00031 #include "Node.hpp"
00032 #include "ChastePoint.hpp"
00033 #include "UblasCustomFunctions.hpp"
00034
00035 #include "Exception.hpp"
00036
00037 #include <vector>
00038 #include <cmath>
00039
00040
00041
00042
00043 const unsigned INDEX_IS_NOT_USED=0;
00044
00048 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00049 class AbstractElement
00050 {
00051 protected:
00053 std::vector<Node<SPACE_DIM>*> mNodes;
00055 unsigned mIndex;
00057 unsigned mRegion;
00058
00063 bool mIsDeleted;
00065 bool mOwnership;
00067 bool mFlag;
00068
00069 public:
00070 AbstractElement(unsigned index, const std::vector<Node<SPACE_DIM>*>& rNodes)
00071 : mNodes(rNodes), mIndex(index)
00072 {
00073
00074 assert(ELEMENT_DIM <= SPACE_DIM);
00075
00076
00077
00078 mIsDeleted = false;
00079 mFlag = false;
00080 mOwnership = true;
00081
00082 mRegion = 0;
00083 }
00084
00088 AbstractElement(unsigned index=INDEX_IS_NOT_USED)
00089 : mIndex(index),
00090 mRegion(0),
00091 mIsDeleted(false),
00092 mOwnership(true),
00093 mFlag(false)
00094 {}
00095
00100 virtual ~AbstractElement()
00101 {}
00102
00103
00109 virtual void UpdateNode(const unsigned& rIndex, Node<SPACE_DIM>* pNode)=0;
00110
00117 void ReplaceNode(Node<SPACE_DIM>* pOldNode, Node<SPACE_DIM>* pNewNode)
00118 {
00119
00120 for (unsigned i=0; i<this->mNodes.size(); i++)
00121 {
00122 if (this->mNodes[i]==pOldNode)
00123 {
00124 UpdateNode(i,pNewNode);
00125 return;
00126 }
00127 }
00128 EXCEPTION("You didn't have that node to start with.");
00129 }
00130
00135 virtual void MarkAsDeleted()=0;
00136
00137
00141 virtual void RegisterWithNodes()=0;
00142
00151 double GetNodeLocation(unsigned localIndex, unsigned dimension) const
00152 {
00153 assert(dimension < SPACE_DIM);
00154 assert((unsigned)localIndex < mNodes.size());
00155 return mNodes[localIndex]->rGetLocation()[dimension];
00156 }
00157
00168 c_vector<double, SPACE_DIM> GetNodeLocation(unsigned localIndex) const
00169 {
00170 assert((unsigned)localIndex < mNodes.size());
00171 return mNodes[localIndex]->rGetLocation();
00172 }
00173
00174 unsigned GetNodeGlobalIndex(unsigned localIndex) const
00175 {
00176 assert((unsigned)localIndex < mNodes.size());
00177 return mNodes[localIndex]->GetIndex();
00178 }
00179
00180 Node<SPACE_DIM>* GetNode(unsigned localIndex) const
00181 {
00182 assert((unsigned)localIndex < mNodes.size());
00183 return mNodes[localIndex];
00184 }
00185
00186 unsigned GetNumNodes() const
00187 {
00188 return mNodes.size();
00189 }
00190
00191
00192 void AddNode(Node<SPACE_DIM>* node)
00193 {
00194 mNodes.push_back(node);
00195 }
00196
00197 bool IsDeleted() const
00198 {
00199 return mIsDeleted;
00200 }
00201
00205 unsigned GetIndex(void) const
00206 {
00207 return mIndex;
00208 }
00209
00210 void SetIndex(unsigned index)
00211 {
00212 mIndex=index;
00213 }
00214
00215 bool GetOwnership() const
00216 {
00217 return mOwnership;
00218 }
00219
00220 void SetOwnership(bool ownership)
00221 {
00222 mOwnership=ownership;
00223 }
00224
00225 void Flag()
00226 {
00227 mFlag = true;
00228 }
00229
00230 void Unflag()
00231 {
00232 mFlag = false;
00233 }
00234
00235 bool IsFlagged() const
00236 {
00237 return mFlag;
00238 }
00239
00240 void SetRegion(unsigned region)
00241 {
00242 mRegion = region;
00243 }
00244
00245 unsigned GetRegion()
00246 {
00247 return mRegion;
00248 }
00249
00250
00251 };
00252
00253 #endif