LinearBasisFunction.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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            ; //not possible to get here because of assertions above
00066     }
00067     return 0.0; // Avoid compiler warning
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            ; //not possible to get here because of assertions above
00099     }
00100     return 0.0; // Avoid compiler warning
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            ; //not possible to get here because of assertions above
00129     }
00130     return 0.0; // Avoid compiler warning
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            ; //not possible to get here because of assertions above
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            ; //not possible to get here because of assertions above
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            ; //not possible to get here because of assertions above
00266     }
00267     return gradN;
00268 }
00269 
00270 
00278 template <unsigned ELEMENT_DIM>
00279 void LinearBasisFunction<ELEMENT_DIM>::ComputeBasisFunctions(const ChastePoint<ELEMENT_DIM>& rPoint,
00280                                                           c_vector<double, ELEMENT_DIM+1>& rReturnValue)
00281 {
00282     assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
00283     for (unsigned i=0; i<ELEMENT_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 ELEMENT_DIM>
00313 void LinearBasisFunction<ELEMENT_DIM>::ComputeBasisFunctionDerivatives(const ChastePoint<ELEMENT_DIM>& rPoint,
00314                                                                     c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
00315 {
00316     assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
00317 
00318     for (unsigned j=0; j<ELEMENT_DIM+1; j++)
00319     {
00320         matrix_column<c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1> > column(rReturnValue, j);
00321         column = ComputeBasisFunctionDerivative(rPoint, j);
00322     }
00323 }
00324 
00339 template <unsigned ELEMENT_DIM>
00340 void LinearBasisFunction<ELEMENT_DIM>::ComputeTransformedBasisFunctionDerivatives(const ChastePoint<ELEMENT_DIM>& rPoint,
00341                                                                                const c_matrix<double, ELEMENT_DIM, ELEMENT_DIM>& rInverseJacobian,
00342                                                                                c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
00343 {
00344     assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
00345 
00346     ComputeBasisFunctionDerivatives(rPoint, rReturnValue);
00347     rReturnValue = prod(trans(rInverseJacobian), rReturnValue);
00348 }
00349 
00351 // Explicit instantiation
00353 
00354 template class LinearBasisFunction<1>;
00355 template class LinearBasisFunction<2>;
00356 template class LinearBasisFunction<3>;
Generated on Thu Dec 22 13:00:17 2011 for Chaste by  doxygen 1.6.3