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 #include "UblasCustomFunctions.hpp"
00030 #include "LinearBasisFunction.hpp"
00031 #include "ChastePoint.hpp"
00032 #include <cassert>
00033
00043 template <>
00044 double LinearBasisFunction<3>::ComputeBasisFunction(
00045 const ChastePoint<3>& rPoint,
00046 unsigned basisIndex)
00047 {
00048 assert(basisIndex <= 3);
00049
00050 switch (basisIndex)
00051 {
00052 case 0:
00053 return 1.0 - rPoint[0] - rPoint[1] - rPoint[2];
00054 break;
00055 case 1:
00056 return rPoint[0];
00057 break;
00058 case 2:
00059 return rPoint[1];
00060 break;
00061 case 3:
00062 return rPoint[2];
00063 break;
00064 default:
00065 ;
00066 }
00067 return 0.0;
00068 }
00069
00079 template <>
00080 double LinearBasisFunction<2>::ComputeBasisFunction(
00081 const ChastePoint<2>& rPoint,
00082 unsigned basisIndex)
00083 {
00084 assert(basisIndex <= 2);
00085
00086 switch (basisIndex)
00087 {
00088 case 0:
00089 return 1.0 - rPoint[0] - rPoint[1];
00090 break;
00091 case 1:
00092 return rPoint[0];
00093 break;
00094 case 2:
00095 return rPoint[1];
00096 break;
00097 default:
00098 ;
00099 }
00100 return 0.0;
00101 }
00102
00112 template <>
00113 double LinearBasisFunction<1>::ComputeBasisFunction(
00114 const ChastePoint<1>& rPoint,
00115 unsigned basisIndex)
00116 {
00117 assert(basisIndex <= 1);
00118
00119 switch (basisIndex)
00120 {
00121 case 0:
00122 return 1.0 - rPoint[0];
00123 break;
00124 case 1:
00125 return rPoint[0];
00126 break;
00127 default:
00128 ;
00129 }
00130 return 0.0;
00131 }
00132
00142 double LinearBasisFunction<0>::ComputeBasisFunction(const ChastePoint<0>& rPoint, unsigned basisIndex)
00143 {
00144 assert(basisIndex == 0);
00145 return 1.0;
00146 }
00147
00160 template <>
00161 c_vector<double, 3> LinearBasisFunction<3>::ComputeBasisFunctionDerivative(
00162 const ChastePoint<3>& rPoint,
00163 unsigned basisIndex)
00164 {
00165 assert(basisIndex <= 3);
00166
00167 c_vector<double, 3> gradN;
00168 switch (basisIndex)
00169 {
00170 case 0:
00171 gradN(0) = -1;
00172 gradN(1) = -1;
00173 gradN(2) = -1;
00174 break;
00175 case 1:
00176 gradN(0) = 1;
00177 gradN(1) = 0;
00178 gradN(2) = 0;
00179 break;
00180 case 2:
00181 gradN(0) = 0;
00182 gradN(1) = 1;
00183 gradN(2) = 0;
00184 break;
00185 case 3:
00186 gradN(0) = 0;
00187 gradN(1) = 0;
00188 gradN(2) = 1;
00189 break;
00190 default:
00191 ;
00192 }
00193 return gradN;
00194 }
00195
00208 template <>
00209 c_vector<double, 2> LinearBasisFunction<2>::ComputeBasisFunctionDerivative(
00210 const ChastePoint<2>& rPoint,
00211 unsigned basisIndex)
00212 {
00213 assert(basisIndex <= 2);
00214
00215 c_vector<double, 2> gradN;
00216 switch (basisIndex)
00217 {
00218 case 0:
00219 gradN(0) = -1;
00220 gradN(1) = -1;
00221 break;
00222 case 1:
00223 gradN(0) = 1;
00224 gradN(1) = 0;
00225 break;
00226 case 2:
00227 gradN(0) = 0;
00228 gradN(1) = 1;
00229 break;
00230 default:
00231 ;
00232 }
00233 return gradN;
00234 }
00235
00248 template <>
00249 c_vector<double,1> LinearBasisFunction<1>::ComputeBasisFunctionDerivative(
00250 const ChastePoint<1>& rPoint,
00251 unsigned basisIndex)
00252 {
00253 assert(basisIndex <= 1);
00254
00255 c_vector<double,1> gradN;
00256 switch (basisIndex)
00257 {
00258 case 0:
00259 gradN(0) = -1;
00260 break;
00261 case 1:
00262 gradN(0) = 1;
00263 break;
00264 default:
00265 ;
00266 }
00267 return gradN;
00268 }
00269
00270
00278 template <unsigned ELEM_DIM>
00279 void LinearBasisFunction<ELEM_DIM>::ComputeBasisFunctions(const ChastePoint<ELEM_DIM>& rPoint,
00280 c_vector<double, ELEM_DIM+1>& rReturnValue)
00281 {
00282 assert(ELEM_DIM < 4 && ELEM_DIM > 0);
00283 for (unsigned i=0; i<ELEM_DIM+1; i++)
00284 {
00285 rReturnValue(i) = ComputeBasisFunction(rPoint, i);
00286 }
00287 }
00288
00297 void LinearBasisFunction<0>::ComputeBasisFunctions(const ChastePoint<0>& rPoint,
00298 c_vector<double,1>& rReturnValue)
00299 {
00300 rReturnValue(0) = ComputeBasisFunction(rPoint, 0);
00301 }
00302
00312 template <unsigned ELEM_DIM>
00313 void LinearBasisFunction<ELEM_DIM>::ComputeBasisFunctionDerivatives(const ChastePoint<ELEM_DIM>& rPoint,
00314 c_matrix<double, ELEM_DIM, ELEM_DIM+1>& rReturnValue)
00315 {
00316 assert(ELEM_DIM < 4 && ELEM_DIM > 0);
00317
00318 for (unsigned j=0; j<ELEM_DIM+1; j++)
00319 {
00320 matrix_column<c_matrix<double, ELEM_DIM, ELEM_DIM+1> > column(rReturnValue, j);
00321 column = ComputeBasisFunctionDerivative(rPoint, j);
00322 }
00323 }
00324
00339 template <unsigned ELEM_DIM>
00340 void LinearBasisFunction<ELEM_DIM>::ComputeTransformedBasisFunctionDerivatives(const ChastePoint<ELEM_DIM>& rPoint,
00341 const c_matrix<double, ELEM_DIM, ELEM_DIM>& rInverseJacobian,
00342 c_matrix<double, ELEM_DIM, ELEM_DIM+1>& rReturnValue)
00343 {
00344 assert(ELEM_DIM < 4 && ELEM_DIM > 0);
00345
00346 ComputeBasisFunctionDerivatives(rPoint, rReturnValue);
00347 rReturnValue = prod(trans(rInverseJacobian), rReturnValue);
00348 }
00349
00351
00353
00354 template class LinearBasisFunction<1>;
00355 template class LinearBasisFunction<2>;
00356 template class LinearBasisFunction<3>;