LinearBasisFunction.cpp
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
00030
00031
00032
00033
00034
00035
00036 #include "UblasCustomFunctions.hpp"
00037 #include "LinearBasisFunction.hpp"
00038 #include "ChastePoint.hpp"
00039 #include <cassert>
00040
00050 template <>
00051 double LinearBasisFunction<3>::ComputeBasisFunction(
00052 const ChastePoint<3>& rPoint,
00053 unsigned basisIndex)
00054 {
00055 assert(basisIndex <= 3);
00056
00057 switch (basisIndex)
00058 {
00059 case 0:
00060 return 1.0 - rPoint[0] - rPoint[1] - rPoint[2];
00061 break;
00062 case 1:
00063 return rPoint[0];
00064 break;
00065 case 2:
00066 return rPoint[1];
00067 break;
00068 case 3:
00069 return rPoint[2];
00070 break;
00071 default:
00072 ;
00073 }
00074 return 0.0;
00075 }
00076
00086 template <>
00087 double LinearBasisFunction<2>::ComputeBasisFunction(
00088 const ChastePoint<2>& rPoint,
00089 unsigned basisIndex)
00090 {
00091 assert(basisIndex <= 2);
00092
00093 switch (basisIndex)
00094 {
00095 case 0:
00096 return 1.0 - rPoint[0] - rPoint[1];
00097 break;
00098 case 1:
00099 return rPoint[0];
00100 break;
00101 case 2:
00102 return rPoint[1];
00103 break;
00104 default:
00105 ;
00106 }
00107 return 0.0;
00108 }
00109
00119 template <>
00120 double LinearBasisFunction<1>::ComputeBasisFunction(
00121 const ChastePoint<1>& rPoint,
00122 unsigned basisIndex)
00123 {
00124 assert(basisIndex <= 1);
00125
00126 switch (basisIndex)
00127 {
00128 case 0:
00129 return 1.0 - rPoint[0];
00130 break;
00131 case 1:
00132 return rPoint[0];
00133 break;
00134 default:
00135 ;
00136 }
00137 return 0.0;
00138 }
00139
00149 double LinearBasisFunction<0>::ComputeBasisFunction(const ChastePoint<0>& rPoint, unsigned basisIndex)
00150 {
00151 assert(basisIndex == 0);
00152 return 1.0;
00153 }
00154
00167 template <>
00168 c_vector<double, 3> LinearBasisFunction<3>::ComputeBasisFunctionDerivative(
00169 const ChastePoint<3>& rPoint,
00170 unsigned basisIndex)
00171 {
00172 assert(basisIndex <= 3);
00173
00174 c_vector<double, 3> gradN;
00175 switch (basisIndex)
00176 {
00177 case 0:
00178 gradN(0) = -1;
00179 gradN(1) = -1;
00180 gradN(2) = -1;
00181 break;
00182 case 1:
00183 gradN(0) = 1;
00184 gradN(1) = 0;
00185 gradN(2) = 0;
00186 break;
00187 case 2:
00188 gradN(0) = 0;
00189 gradN(1) = 1;
00190 gradN(2) = 0;
00191 break;
00192 case 3:
00193 gradN(0) = 0;
00194 gradN(1) = 0;
00195 gradN(2) = 1;
00196 break;
00197 default:
00198 ;
00199 }
00200 return gradN;
00201 }
00202
00215 template <>
00216 c_vector<double, 2> LinearBasisFunction<2>::ComputeBasisFunctionDerivative(
00217 const ChastePoint<2>& rPoint,
00218 unsigned basisIndex)
00219 {
00220 assert(basisIndex <= 2);
00221
00222 c_vector<double, 2> gradN;
00223 switch (basisIndex)
00224 {
00225 case 0:
00226 gradN(0) = -1;
00227 gradN(1) = -1;
00228 break;
00229 case 1:
00230 gradN(0) = 1;
00231 gradN(1) = 0;
00232 break;
00233 case 2:
00234 gradN(0) = 0;
00235 gradN(1) = 1;
00236 break;
00237 default:
00238 ;
00239 }
00240 return gradN;
00241 }
00242
00255 template <>
00256 c_vector<double,1> LinearBasisFunction<1>::ComputeBasisFunctionDerivative(
00257 const ChastePoint<1>& rPoint,
00258 unsigned basisIndex)
00259 {
00260 assert(basisIndex <= 1);
00261
00262 c_vector<double,1> gradN;
00263 switch (basisIndex)
00264 {
00265 case 0:
00266 gradN(0) = -1;
00267 break;
00268 case 1:
00269 gradN(0) = 1;
00270 break;
00271 default:
00272 ;
00273 }
00274 return gradN;
00275 }
00276
00277
00285 template <unsigned ELEMENT_DIM>
00286 void LinearBasisFunction<ELEMENT_DIM>::ComputeBasisFunctions(const ChastePoint<ELEMENT_DIM>& rPoint,
00287 c_vector<double, ELEMENT_DIM+1>& rReturnValue)
00288 {
00289 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
00290 for (unsigned i=0; i<ELEMENT_DIM+1; i++)
00291 {
00292 rReturnValue(i) = ComputeBasisFunction(rPoint, i);
00293 }
00294 }
00295
00304 void LinearBasisFunction<0>::ComputeBasisFunctions(const ChastePoint<0>& rPoint,
00305 c_vector<double,1>& rReturnValue)
00306 {
00307 rReturnValue(0) = ComputeBasisFunction(rPoint, 0);
00308 }
00309
00319 template <unsigned ELEMENT_DIM>
00320 void LinearBasisFunction<ELEMENT_DIM>::ComputeBasisFunctionDerivatives(const ChastePoint<ELEMENT_DIM>& rPoint,
00321 c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
00322 {
00323 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
00324
00325 for (unsigned j=0; j<ELEMENT_DIM+1; j++)
00326 {
00327 matrix_column<c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1> > column(rReturnValue, j);
00328 column = ComputeBasisFunctionDerivative(rPoint, j);
00329 }
00330 }
00331
00346 template <unsigned ELEMENT_DIM>
00347 void LinearBasisFunction<ELEMENT_DIM>::ComputeTransformedBasisFunctionDerivatives(const ChastePoint<ELEMENT_DIM>& rPoint,
00348 const c_matrix<double, ELEMENT_DIM, ELEMENT_DIM>& rInverseJacobian,
00349 c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
00350 {
00351 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
00352
00353 ComputeBasisFunctionDerivatives(rPoint, rReturnValue);
00354 rReturnValue = prod(trans(rInverseJacobian), rReturnValue);
00355 }
00356
00358
00360
00361 template class LinearBasisFunction<1>;
00362 template class LinearBasisFunction<2>;
00363 template class LinearBasisFunction<3>;