1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
// disable debug warnings in MS compiler
#ifdef _MSC_VER
# pragma warning(disable : 4786)
#endif
#include <cmath>
#include "itkFEMElement3DC0LinearTriangularLaplaceBeltrami.h"
namespace itk
{
namespace fem
{
Element3DC0LinearTriangularLaplaceBeltrami ::Element3DC0LinearTriangularLaplaceBeltrami()
: Superclass()
{}
Element3DC0LinearTriangularLaplaceBeltrami ::Element3DC0LinearTriangularLaplaceBeltrami(NodeIDType n1_,
NodeIDType n2_,
NodeIDType n3_,
Material::ConstPointer m_)
: Superclass()
{
// Set the geometrical points
this->SetNode(0, n1_);
this->SetNode(1, n2_);
this->SetNode(2, n3_);
/*
* Initialize the pointer to material object and check that
* we were given the pointer to the right class.
* If the material class was incorrect an exception is thrown.
*/
if ((m_mat = dynamic_cast<const MaterialLinearElasticity *>(&*m_)) == 0)
{
throw FEMExceptionWrongClass(
__FILE__, __LINE__, "Element3DC0LinearTriangularLaplaceBeltrami::Element3DC0LinearTriangularLaplaceBeltrami()");
}
}
void
Element3DC0LinearTriangularLaplaceBeltrami::GetStiffnessMatrix(MatrixType & Ke) const
{
MatrixType cot, D, BB;
this->GetMaterialMatrix(D);
//
// ::std::cout<< " Nip " << Nip << " w " << w << std::endl;
this->GetMaterialMatrix(D);
cot.set_size(3, 3);
cot.fill(0.);
int na = 0;
int nb = 1;
int nc = 2;
VectorType A = this->GetNode(na)->GetCoordinates();
VectorType B = this->GetNode(nb)->GetCoordinates();
VectorType C = this->GetNode(nc)->GetCoordinates();
VectorType BA = B - A;
VectorType CA = C - A;
VectorType CB = C - B;
float L1 = CB.magnitude();
float L2 = CA.magnitude();
float L3 = BA.magnitude();
float s = (L1 + L2 + L3) * .5;
Float Area = sqrt(s * (s - L1) * (s - L2) * (s - L3));
cot[0][0] = (2.0 * L1 * L1) * D[0][0];
cot[1][1] = (2.0 * L2 * L2) * D[0][0];
cot[2][2] = (2.0 * L3 * L3) * D[0][0];
cot[0][1] = (L3 * L3 - L1 * L1 - L2 * L2) * D[0][0];
cot[0][2] = (L2 * L2 - L1 * L1 - L3 * L3) * D[0][0];
cot[1][2] = (L1 * L1 - L3 * L3 - L2 * L2) * D[0][0];
cot[1][0] = (L3 * L3 - L1 * L1 - L2 * L2) * D[0][0];
cot[2][0] = (L2 * L2 - L1 * L1 - L3 * L3) * D[0][0];
cot[2][1] = (L1 * L1 - L3 * L3 - L2 * L2) * D[0][0];
cot = cot * 1.0 / (8.0 * Area);
/* if ( this->GetNode(0)->GetDegreeOfFreedom(0)==53 ||
this->GetNode(1)->GetDegreeOfFreedom(0)==53 ||
this->GetNode(2)->GetDegreeOfFreedom(0)==53 )
{
::std::cout << " cot " << this->GetNode(0)->GetDegreeOfFreedom(0) << " " <<this->GetNode(1)->GetDegreeOfFreedom(0)
<< " " <<this->GetNode(2)->GetDegreeOfFreedom(0) <<std::endl;
::std::cout << cot <<std::endl;
}
*/
if (GetNumberOfDegreesOfFreedomPerNode() == 3)
{
Ke.set_size(9, 9);
Ke.fill(0.0);
for (int dd = 0; dd < 3; dd++)
{
Ke[0][dd * 3] = cot[0][dd];
}
for (int dd = 0; dd < 3; dd++)
{
Ke[1][dd * 3 + 1] = cot[0][dd];
}
for (int dd = 0; dd < 3; dd++)
{
Ke[2][dd * 3 + 2] = cot[0][dd];
}
for (int dd = 0; dd < 3; dd++)
{
Ke[3][dd * 3] = cot[1][dd];
}
for (int dd = 0; dd < 3; dd++)
{
Ke[4][dd * 3 + 1] = cot[1][dd];
}
for (int dd = 0; dd < 3; dd++)
{
Ke[5][dd * 3 + 2] = cot[1][dd];
}
for (int dd = 0; dd < 3; dd++)
{
Ke[6][dd * 3] = cot[2][dd];
}
for (int dd = 0; dd < 3; dd++)
{
Ke[7][dd * 3 + 1] = cot[2][dd];
}
for (int dd = 0; dd < 3; dd++)
{
Ke[8][dd * 3 + 2] = cot[2][dd];
}
}
else
{
Ke = cot;
}
// ::std::cout << " Ke in elt " <<std::endl;
// ::std::cout << Ke <<std::endl;
}
/*
void Element3DC0LinearTriangularLaplaceBeltrami::GetStiffnessMatrix(MatrixType& Ke) const
{
MatrixType cot,D,BB;
this->GetMaterialMatrix( D );
VectorType ip;
Float w;
MatrixType J;
MatrixType shapeDgl;
MatrixType shapeD;
//
//::std::cout<< " Nip " << Nip << " w " << w << std::endl;
this->GetMaterialMatrix(D);
cot.set_size(3,3);
cot.fill(0.);
int na=0;
int nb=1;
int nc=2;
{
VectorType A=this->GetNode(na)->GetCoordinates();
VectorType B=this->GetNode(nb)->GetCoordinates();
VectorType C=this->GetNode(nc)->GetCoordinates();
VectorType BA =B-A;
VectorType AC =A-C;
VectorType CB =C-B;
float bamag=BA.magnitude();
float cbmag=CB.magnitude();
float acmag=AC.magnitude();
if (bamag > cbmag && bamag > acmag) { na=0; nb=1; nc=2; }
if (cbmag > bamag && cbmag > acmag) { na=1; nb=2; nc=0; }
if (acmag > bamag && acmag > cbmag) { na=2; nb=0; nc=1; }
}
VectorType A=this->GetNode(na)->GetCoordinates();
VectorType B=this->GetNode(nb)->GetCoordinates();
VectorType C=this->GetNode(nc)->GetCoordinates();
VectorType BA =B-A;
VectorType CA =C-A;
VectorType CB =C-B;
float bamag=BA.magnitude();
float cbmag=CB.magnitude();
float acmag=CA.magnitude();
float t=(CA[0]*BA[0]+CA[1]*BA[1]+CA[2]*BA[2])/bamag*bamag;
VectorType E = A+BA*t;
VectorType CE =C-E;
VectorType BE =B-E;
VectorType AE =A-E;
float cemag=CE.magnitude();
float bemag=CE.magnitude();
float aemag=AE.magnitude();
float h1;
if (acmag > aemag) h1=acmag; else h1=aemag;
float theta1=asin(cemag/h1);
float h2;
if (cbmag > bemag) h2=cbmag; else h2=bemag;
float theta2=asin(cemag/h2);
float theta3=acos(-1.0)-theta1-theta2;
float cottheta1=cemag/aemag;
// if (aemag == 0) cottheta1=1.0/tan(3.14159/2.0);
float cottheta2=cemag/bemag;
float cottheta3=1.0/tan(theta3);
// if (fabs(cottheta1-1) < 1.e-6 && fabs(cottheta2-1) < 1.e-6) cottheta3=1.0;
// ::std::cout <<" ct0 " << cottheta1 <<" ct1 " << cottheta2 <<" ct2 " << cottheta3 << std::endl;
cot[na][na]=(cottheta3+cottheta2)*D[0][0];
cot[nb][nb]=(cottheta3+cottheta1)*D[0][0];
cot[nc][nc]=(cottheta1+cottheta2)*D[0][0];
cot[na][na]=-cottheta3*D[0][0];
cot[na][nc]=-cottheta2*D[0][0];
cot[nb][nc]=-cottheta1*D[0][0];
cot[nc][nb]=cot[nb][nc]*D[0][0];
cot[nc][na]=cot[na][nc]*D[0][0];
cot[nb][na]=cot[na][nb]*D[0][0];
cot=cot*0.5;
Ke=cot;
if ( this->GetNode(0)->GetDegreeOfFreedom(0)==909 ||
this->GetNode(1)->GetDegreeOfFreedom(0)==909 ||
this->GetNode(2)->GetDegreeOfFreedom(0)==909 )
{
::std::cout << " cot " << std::endl;
::std::cout << cot <<std::endl;
}
Ke.set_size(9,9);
Ke.fill(0.0);
for(int dd=0; dd<3; dd++) Ke[0][dd*3]=cot[0][dd];
for(int dd=0; dd<3; dd++) Ke[1][dd*3+1]=cot[0][dd];
for(int dd=0; dd<3; dd++) Ke[2][dd*3+2]=cot[0][dd];
for(int dd=0; dd<3; dd++) Ke[3][dd*3]=cot[1][dd];
for(int dd=0; dd<3; dd++) Ke[4][dd*3+1]=cot[1][dd];
for(int dd=0; dd<3; dd++) Ke[5][dd*3+2]=cot[1][dd];
for(int dd=0; dd<3; dd++) Ke[6][dd*3]=cot[2][dd];
for(int dd=0; dd<3; dd++) Ke[7][dd*3+1]=cot[2][dd];
for(int dd=0; dd<3; dd++) Ke[8][dd*3+2]=cot[2][dd];
// ::std::cout << " Ke in elt " <<std::endl;
// ::std::cout << Ke <<std::endl;
}
*/
FEM_CLASS_REGISTER(Element3DC0LinearTriangularLaplaceBeltrami)
} // namespace fem
} // namespace itk
|