Chaste Release::3.1
LinearBasisFunction.cpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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            ; //not possible to get here because of assertions above
00073     }
00074     return 0.0; // Avoid compiler warning
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            ; //not possible to get here because of assertions above
00106     }
00107     return 0.0; // Avoid compiler warning
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            ; //not possible to get here because of assertions above
00136     }
00137     return 0.0; // Avoid compiler warning
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            ; //not possible to get here because of assertions above
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            ; //not possible to get here because of assertions above
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            ; //not possible to get here because of assertions above
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 // Explicit instantiation
00360 
00361 template class LinearBasisFunction<1>;
00362 template class LinearBasisFunction<2>;
00363 template class LinearBasisFunction<3>;