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
00030
00031
00032
00033
00034
00035
00036 #include "AbstractElement.hpp"
00037
00038 #include "MathsCustomFunctions.hpp"
00039 #include "Exception.hpp"
00040
00041 #include <cassert>
00042
00044
00046
00047 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00048 AbstractElement<ELEMENT_DIM, SPACE_DIM>::AbstractElement(unsigned index, const std::vector<Node<SPACE_DIM>*>& rNodes)
00049 : mNodes(rNodes),
00050 mIndex(index),
00051 mAttribute(0.0),
00052 mIsDeleted(false),
00053 mOwnership(true),
00054 mFlag(false)
00055 {
00056
00057 assert(ELEMENT_DIM <= SPACE_DIM);
00058
00059
00060 }
00061
00062 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00063 AbstractElement<ELEMENT_DIM, SPACE_DIM>::AbstractElement(unsigned index)
00064 : mIndex(index),
00065 mAttribute(0.0),
00066 mIsDeleted(false),
00067 mOwnership(true),
00068 mFlag(false)
00069 {}
00070
00071 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00072 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::ReplaceNode(Node<SPACE_DIM>* pOldNode, Node<SPACE_DIM>* pNewNode)
00073 {
00074 assert(pOldNode != pNewNode);
00075 for (unsigned i=0; i<this->mNodes.size(); i++)
00076 {
00077 if (this->mNodes[i] == pOldNode)
00078 {
00079 UpdateNode(i, pNewNode);
00080 return;
00081 }
00082 }
00083 EXCEPTION("You didn't have that node to start with.");
00084 }
00085
00086 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00087 double AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNodeLocation(unsigned localIndex, unsigned dimension) const
00088 {
00089 assert(dimension < SPACE_DIM);
00090 assert((unsigned)localIndex < mNodes.size());
00091 return mNodes[localIndex]->rGetLocation()[dimension];
00092 }
00093
00094
00095
00096
00097
00098
00099 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00100 c_vector<double, SPACE_DIM> AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNodeLocation(unsigned localIndex) const
00101 {
00102 assert((unsigned)localIndex < mNodes.size());
00103 return mNodes[localIndex]->rGetLocation();
00104 }
00105
00106 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00107 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNodeGlobalIndex(unsigned localIndex) const
00108 {
00109 assert((unsigned)localIndex < mNodes.size());
00110 return mNodes[localIndex]->GetIndex();
00111 }
00112
00113 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00114 Node<SPACE_DIM>* AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNode(unsigned localIndex) const
00115 {
00116 assert((unsigned)localIndex < mNodes.size());
00117 return mNodes[localIndex];
00118 }
00119
00120 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00121 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNumNodes() const
00122 {
00123 return mNodes.size();
00124 }
00125
00126 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00127 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::AddNode(Node<SPACE_DIM>* pNode)
00128 {
00129 mNodes.push_back(pNode);
00130 }
00131
00132 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00133 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::IsDeleted() const
00134 {
00135 return mIsDeleted;
00136 }
00137
00138 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00139 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetIndex() const
00140 {
00141 return mIndex;
00142 }
00143
00144 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00145 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetIndex(unsigned index)
00146 {
00147 mIndex = index;
00148 }
00149
00150 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00151 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetOwnership() const
00152 {
00153 return mOwnership;
00154 }
00155
00156 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00157 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetOwnership(bool ownership)
00158 {
00159 mOwnership = ownership;
00160 }
00161
00162 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00163 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::Flag()
00164 {
00165 mFlag = true;
00166 }
00167
00168 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00169 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::Unflag()
00170 {
00171 mFlag = false;
00172 }
00173
00174 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00175 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::IsFlagged() const
00176 {
00177 return mFlag;
00178 }
00179
00180 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00181 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetAttribute(double attribute)
00182 {
00183 mAttribute = attribute;
00184 }
00185
00186 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00187 double AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetAttribute()
00188 {
00189 return mAttribute;
00190 }
00191
00192 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00193 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetUnsignedAttribute()
00194 {
00195 double double_attr = GetAttribute();
00196 unsigned unsigned_attr = (unsigned) (double_attr + 0.5);
00197
00198 if( CompareDoubles::WithinAnyTolerance(double_attr, unsigned_attr) == false )
00199 {
00200 EXCEPTION("Element attribute '"<< double_attr <<"' cannot be converted to an unsigned.");
00201 }
00202 return unsigned_attr;
00203 }
00204
00205
00207
00209
00210 template class AbstractElement<0,1>;
00211 template class AbstractElement<1,1>;
00212 template class AbstractElement<0,2>;
00213 template class AbstractElement<1,2>;
00214 template class AbstractElement<2,2>;
00215 template class AbstractElement<0,3>;
00216 template class AbstractElement<1,3>;
00217 template class AbstractElement<2,3>;
00218 template class AbstractElement<3,3>;