45template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
49 if (registerWithNodes)
55template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
64template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
67 for (
unsigned i=0; i<this->mNodes.size(); i++)
69 this->mNodes[i]->AddElement(this->mIndex);
73template <
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);
84template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
87 assert(rIndex < this->mNodes.size());
90 this->mNodes[rIndex]->RemoveElement(this->mIndex);
93 this->mNodes[rIndex] = pNode;
96 this->mNodes[rIndex]->
AddElement(this->mIndex);
99template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
103 for (
unsigned i=0; i<this->GetNumNodes(); i++)
106 this->mNodes[i]->RemoveElement(this->mIndex);
113template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
125 assert(ELEMENT_DIM == SPACE_DIM);
126 c_vector<double, ELEMENT_DIM> rhs;
128 for (
unsigned j=0; j<ELEMENT_DIM; j++)
130 double squared_location=0.0;
131 for (
unsigned i=0; i<SPACE_DIM; i++)
134 squared_location += rJacobian(i,j)*rJacobian(i,j);
136 rhs[j]=squared_location/2.0;
139 c_vector<double, SPACE_DIM> centre = zero_vector<double>(SPACE_DIM);
140 centre = prod(rhs, rInverseJacobian);
141 c_vector<double, SPACE_DIM+1> circum = zero_vector<double>(SPACE_DIM+1);
142 double squared_radius = 0.0;
143 for (
unsigned i=0; i<SPACE_DIM; i++)
145 circum[i] = centre[i] + this->GetNodeLocation(0,i);
146 squared_radius += centre[i]*centre[i];
148 circum[SPACE_DIM] = squared_radius;
158template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
161 assert(SPACE_DIM == ELEMENT_DIM);
167 c_matrix<double, SPACE_DIM, ELEMENT_DIM> jacobian;
168 c_matrix<double, ELEMENT_DIM, SPACE_DIM> jacobian_inverse;
169 double jacobian_determinant;
171 this->CalculateInverseJacobian(jacobian, jacobian_determinant, jacobian_inverse);
173 c_vector<double, SPACE_DIM+1> circum=CalculateCircumsphere(jacobian, jacobian_inverse);
183 return 2.0*jacobian_determinant/(3.0*sqrt(3.0)*circum[SPACE_DIM]);
185 assert(SPACE_DIM == 3);
194 return (3.0*sqrt(3.0)*jacobian_determinant)
195 /(16.0*circum[SPACE_DIM]*sqrt(circum[SPACE_DIM]));
198template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
201 c_vector <double, 2> min_max;
202 min_max[0] = DBL_MAX;
204 for (
unsigned i=0; i<=ELEMENT_DIM; i++)
206 c_vector<double, SPACE_DIM> loc_i = this->GetNodeLocation(i);
207 for (
unsigned j=i+1; j<=ELEMENT_DIM; j++)
209 double length = norm_2(this->GetNodeLocation(j) - loc_i);
210 if (length < min_max[0])
214 if (length > min_max[1])
223template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
227 assert(ELEMENT_DIM == SPACE_DIM);
229 c_vector<double, SPACE_DIM+1> weights;
231 c_vector<double, SPACE_DIM> xi = CalculateXi(rTestPoint);
235 for (
unsigned i=1; i<=SPACE_DIM; i++)
237 weights[0] -= xi[i-1];
238 weights[i] = xi[i-1];
243template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
247 assert(ELEMENT_DIM == SPACE_DIM);
249 c_vector<double, SPACE_DIM+1> weights = CalculateInterpolationWeights(rTestPoint);
252 bool negative_weight =
false;
254 for (
unsigned i=0; i<=SPACE_DIM; i++)
256 if (weights[i] < 0.0)
260 negative_weight =
true;
264 if (negative_weight ==
false)
273 double sum = norm_1 (weights);
277 assert( sum + DBL_EPSILON >= 1.0);
280 weights = weights/sum;
285template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
289 assert(ELEMENT_DIM == SPACE_DIM);
294 c_vector<double, SPACE_DIM> test_location = zero_vector<double>(SPACE_DIM);
295 test_location = rTestPoint.
rGetLocation()-this->GetNodeLocation(0);
298 c_matrix<double, SPACE_DIM, ELEMENT_DIM> jacobian = zero_matrix<double>(SPACE_DIM, ELEMENT_DIM);
299 c_matrix<double, ELEMENT_DIM, SPACE_DIM> inverse_jacobian = zero_matrix<double>(ELEMENT_DIM, SPACE_DIM);
300 double jacobian_determinant;
303 this->CalculateInverseJacobian(jacobian, jacobian_determinant, inverse_jacobian);
305 return prod(inverse_jacobian, test_location);
309template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
313 assert(ELEMENT_DIM == SPACE_DIM);
315 c_vector<double, SPACE_DIM+1> weights=CalculateInterpolationWeights(rTestPoint);
319 for (
unsigned i=0; i<=SPACE_DIM; i++)
324 if (weights[i] <= 2*DBL_EPSILON)
332 if (weights[i] < -2*DBL_EPSILON)
c_vector< double, DIM > & rGetLocation()
c_vector< double, 2 > CalculateMinMaxEdgeLengths()
c_vector< double, SPACE_DIM+1 > CalculateInterpolationWeights(const ChastePoint< SPACE_DIM > &rTestPoint)
bool IncludesPoint(const ChastePoint< SPACE_DIM > &rTestPoint, bool strict=false)
void UpdateNode(const unsigned &rIndex, Node< SPACE_DIM > *pNode)
c_vector< double, SPACE_DIM > CalculateXi(const ChastePoint< SPACE_DIM > &rTestPoint)
void ResetIndex(unsigned index)
double CalculateQuality()
c_vector< double, SPACE_DIM+1 > CalculateCircumsphere(c_matrix< double, SPACE_DIM, ELEMENT_DIM > &rJacobian, c_matrix< double, ELEMENT_DIM, SPACE_DIM > &rInverseJacobian)
Element(unsigned index, const std::vector< Node< SPACE_DIM > * > &rNodes, bool registerWithNodes=true)
c_vector< double, SPACE_DIM+1 > CalculateInterpolationWeightsWithProjection(const ChastePoint< SPACE_DIM > &rTestPoint)
void AddElement(unsigned index)