36 #include "Element.hpp"
45 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
49 if (registerWithNodes)
55 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
64 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
67 for (
unsigned i=0; i<this->mNodes.size(); i++)
69 this->mNodes[i]->AddElement(this->mIndex);
73 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
76 this->mIsDeleted =
true;
78 for (
unsigned i=0; i<this->GetNumNodes(); i++)
80 this->mNodes[i]->RemoveElement(this->mIndex);
88 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
91 assert(rIndex < this->mNodes.size());
94 this->mNodes[rIndex]->RemoveElement(this->mIndex);
97 this->mNodes[rIndex] = pNode;
100 this->mNodes[rIndex]->
AddElement(this->mIndex);
103 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
107 for (
unsigned i=0; i<this->GetNumNodes(); i++)
110 this->mNodes[i]->RemoveElement(this->mIndex);
117 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
129 assert(ELEMENT_DIM == SPACE_DIM);
130 c_vector<double, ELEMENT_DIM> rhs;
132 for (
unsigned j=0; j<ELEMENT_DIM; j++)
134 double squared_location=0.0;
135 for (
unsigned i=0; i<SPACE_DIM; i++)
138 squared_location += rJacobian(i,j)*rJacobian(i,j);
140 rhs[j]=squared_location/2.0;
143 c_vector<double, SPACE_DIM> centre;
144 centre = prod(rhs, rInverseJacobian);
145 c_vector<double, SPACE_DIM+1> circum;
146 double squared_radius = 0.0;
147 for (
unsigned i=0; i<SPACE_DIM; i++)
149 circum[i] = centre[i] + this->GetNodeLocation(0,i);
150 squared_radius += centre[i]*centre[i];
152 circum[SPACE_DIM] = squared_radius;
162 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
165 assert(SPACE_DIM == ELEMENT_DIM);
171 c_matrix<double, SPACE_DIM, ELEMENT_DIM> jacobian;
172 c_matrix<double, ELEMENT_DIM, SPACE_DIM> jacobian_inverse;
173 double jacobian_determinant;
175 this->CalculateInverseJacobian(jacobian, jacobian_determinant, jacobian_inverse);
177 c_vector<double, SPACE_DIM+1> circum=CalculateCircumsphere(jacobian, jacobian_inverse);
187 return 2.0*jacobian_determinant/(3.0*sqrt(3.0)*circum[SPACE_DIM]);
189 assert(SPACE_DIM == 3);
198 return (3.0*sqrt(3.0)*jacobian_determinant)
199 /(16.0*circum[SPACE_DIM]*sqrt(circum[SPACE_DIM]));
202 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
205 c_vector <double, 2> min_max;
206 min_max[0] = DBL_MAX;
208 for (
unsigned i=0; i<=ELEMENT_DIM; i++)
210 c_vector<double, SPACE_DIM> loc_i = this->GetNodeLocation(i);
211 for (
unsigned j=i+1; j<=ELEMENT_DIM; j++)
213 double length = norm_2(this->GetNodeLocation(j) - loc_i);
214 if (length < min_max[0])
218 if (length > min_max[1])
227 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
231 assert(ELEMENT_DIM == SPACE_DIM);
233 c_vector<double, SPACE_DIM+1> weights;
235 c_vector<double, SPACE_DIM> xi=CalculateXi(rTestPoint);
239 for (
unsigned i=1; i<=SPACE_DIM; i++)
241 weights[0] -= xi[i-1];
242 weights[i] = xi[i-1];
247 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
251 assert(ELEMENT_DIM == SPACE_DIM);
253 c_vector<double, SPACE_DIM+1> weights = CalculateInterpolationWeights(rTestPoint);
256 bool negative_weight =
false;
258 for (
unsigned i=0; i<=SPACE_DIM; i++)
260 if (weights[i] < 0.0)
264 negative_weight =
true;
268 if (negative_weight ==
false)
277 double sum = norm_1 (weights);
281 assert( sum + DBL_EPSILON >= 1.0);
284 weights = weights/sum;
289 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
293 assert(ELEMENT_DIM == SPACE_DIM);
298 c_vector<double, SPACE_DIM> test_location=rTestPoint.
rGetLocation()-this->GetNodeLocation(0);
301 c_matrix<double, SPACE_DIM, ELEMENT_DIM> jacobian;
302 c_matrix<double, ELEMENT_DIM, SPACE_DIM> inverse_jacobian;
303 double jacobian_determinant;
306 this->CalculateInverseJacobian(jacobian, jacobian_determinant, inverse_jacobian);
308 return prod(inverse_jacobian, test_location);
312 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
316 assert(ELEMENT_DIM == SPACE_DIM);
318 c_vector<double, SPACE_DIM+1> weights=CalculateInterpolationWeights(rTestPoint);
322 for (
unsigned i=0; i<=SPACE_DIM; i++)
327 if (weights[i] <= 2*DBL_EPSILON)
335 if (weights[i] < -2*DBL_EPSILON)
c_vector< double, SPACE_DIM+1 > CalculateCircumsphere(c_matrix< double, SPACE_DIM, ELEMENT_DIM > &rJacobian, c_matrix< double, ELEMENT_DIM, SPACE_DIM > &rInverseJacobian)
c_vector< double, DIM > & rGetLocation()
double CalculateQuality()
void UpdateNode(const unsigned &rIndex, Node< SPACE_DIM > *pNode)
void ResetIndex(unsigned index)
c_vector< double, SPACE_DIM > CalculateXi(const ChastePoint< SPACE_DIM > &rTestPoint)
void AddElement(unsigned index)
Element(unsigned index, const std::vector< Node< SPACE_DIM > * > &rNodes, bool registerWithNodes=true)
bool IncludesPoint(const ChastePoint< SPACE_DIM > &rTestPoint, bool strict=false)
c_vector< double, SPACE_DIM+1 > CalculateInterpolationWeights(const ChastePoint< SPACE_DIM > &rTestPoint)
c_vector< double, SPACE_DIM+1 > CalculateInterpolationWeightsWithProjection(const ChastePoint< SPACE_DIM > &rTestPoint)
c_vector< double, 2 > CalculateMinMaxEdgeLengths()