35 #include "PottsElement.hpp"
36 #include "RandomNumberGenerator.hpp"
41 #include "petscblaslapack.h"
44 template<
unsigned DIM>
51 template<
unsigned DIM>
56 template<
unsigned DIM>
63 this->mNodes.push_back(pNode);
66 template<
unsigned DIM>
71 assert(this->GetNumNodes() != 0);
73 if (this->GetNumNodes() <= 2)
90 for (
unsigned i=0; i<this->GetNumNodes(); i++)
92 mean_x += this->mNodes[i]->rGetLocation()[0];
93 mean_y += this->mNodes[i]->rGetLocation()[1];
95 mean_x /= this->GetNumNodes();
96 mean_y /= this->GetNumNodes();
98 double variance_x = 0;
99 double variance_y = 0;
100 double covariance_xy = 0;
102 for (
unsigned i=0; i<this->GetNumNodes(); i++)
104 variance_x += pow((this->mNodes[i]->rGetLocation()[0]-mean_x),2);
105 variance_y += pow((this->mNodes[i]->rGetLocation()[1]-mean_y),2);
106 covariance_xy += (this->mNodes[i]->rGetLocation()[0]-mean_x)*(this->mNodes[i]->rGetLocation()[1]-mean_y);
108 variance_x /= this->GetNumNodes();
109 variance_y /= this->GetNumNodes();
110 covariance_xy /= this->GetNumNodes();
113 double trace = variance_x+variance_y;
114 double det = variance_x*variance_y - covariance_xy*covariance_xy;
116 eig_max = 0.5*(trace+sqrt(trace*trace - 4*det));
117 eig_min = 0.5*(trace-sqrt(trace*trace - 4*det));
201 assert(eig_min >= 0);
202 assert(eig_max >= 0);
206 EXCEPTION(
"All nodes in an element lie in the same line/plane (2D/3D) so aspect ratio is infinite. This interferes with calculation of the Hamiltonian.");
209 return eig_max/eig_min;
void AddNode(Node< DIM > *pNode, const unsigned &rIndex=UINT_MAX)
#define EXCEPTION(message)
PottsElement(unsigned index, const std::vector< Node< DIM > * > &rNodes)
void AddElement(unsigned index)