Chaste Release::3.1
PolynomialMaterialLaw3d.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 "PolynomialMaterialLaw3d.hpp"
00037 
00038 double PolynomialMaterialLaw3d::Get_dW_dI1(double I1, double I2)
00039 {
00040     double ret = 0.0;
00041     // notes: use ints not unsigned as doing p-1
00042     // (except indexing from p=1 because multiplying by p, but
00043     // still safer to use ints)
00044     for (int p=1; p<=(int)mN; p++)
00045     {
00046         for (int q=0; q<=(int)mN-p; q++)
00047         {
00048             ret += mAlpha[p][q] * p * pow(I1-3,p-1) * pow(I2-3,q);
00049         }
00050     }
00051 
00052     return ret;
00053 }
00054 
00055 double PolynomialMaterialLaw3d::Get_dW_dI2(double I1, double I2)
00056 {
00057     double ret = 0.0;
00058     // notes: use ints not unsigned as doing q-1
00059     // (except indexing from q=1 because multiplying by q, but
00060     // still safer to use ints)
00061     for (int p=0; p<=(int)mN; p++)
00062     {
00063         for (int q=1; q<=(int)mN-p; q++)
00064         {
00065             ret += mAlpha[p][q] * q * pow(I1-3,p) * pow(I2-3,q-1);
00066         }
00067     }
00068     return ret;
00069 }
00070 
00071 double PolynomialMaterialLaw3d::Get_d2W_dI1(double I1, double I2)
00072 {
00073     double ret = 0.0;
00074 
00075     // notes: use ints not unsigned as doing p-1
00076     // (except indexing from p=2 because multiplying by p(p-1), but
00077     // still safer to use ints)
00078     for (int p=2; p<=(int)mN; p++)
00079     {
00080         for (int q=0; q<=(int)mN-p; q++)
00081         {
00082             ret += mAlpha[p][q] * p * (p-1) * pow(I1-3,(p-1)*(p-2)) * pow(I2-3,q);
00083         }
00084     }
00085     return ret;
00086 }
00087 
00088 double PolynomialMaterialLaw3d::Get_d2W_dI2(double I1, double I2)
00089 {
00090     double ret = 0.0;
00091 
00092     // notes: use ints not unsigned as doing q-1
00093     // (except indexing from q=2 because multiplying by q(q-1), but
00094     // still safer to use ints)
00095     for (int p=0; p<=(int)mN; p++)
00096     {
00097         for (int q=2; q<=(int)mN-p; q++)
00098         {
00099             ret += mAlpha[p][q] * q * (q-1) * pow(I1-3,p) * pow(I2-3,(q-1)*(q-2));
00100         }
00101     }
00102     return ret;
00103 }
00104 
00105 double PolynomialMaterialLaw3d::Get_d2W_dI1I2(double I1, double I2)
00106 {
00107     double ret = 0.0;
00108 
00109     // notes: use ints not unsigned as doing p-1
00110     // (except indexing from p=1,q=1 because multiplying by pq, but
00111     // still safer to use ints)
00112     for (int p=1; p<=(int)mN; p++)
00113     {
00114         for (int q=1; q<=(int)mN-p; q++)
00115         {
00116             ret += mAlpha[p][q] * p * q * pow(I1-3,p-1) * pow(I2-3,q-1);
00117         }
00118     }
00119     return ret;
00120 }
00121 
00122 double PolynomialMaterialLaw3d::GetAlpha(unsigned i, unsigned j)
00123 {
00124     assert(i+j > 0);
00125     assert(i+j <= mN);
00126 
00127     return mAlpha[i][j];
00128 }
00129 
00130 PolynomialMaterialLaw3d::PolynomialMaterialLaw3d(unsigned n, std::vector<std::vector<double> > alpha)
00131 {
00132     if (n==0)
00133     {
00134         EXCEPTION("n must be positive");
00135     }
00136 
00137     mN = n;
00138 
00139     // error checking: must have alpha[p][q]=0 if p+q>n
00140     for (unsigned p=0; p<=mN; p++)
00141     {
00142         if (alpha[p].size() < mN+1-p)
00143         {
00144             EXCEPTION("alpha not big enough");
00145         }
00146 
00147         for (unsigned q=0; q<alpha[p].size(); q++)
00148         {
00149             if ((p+q>mN) && (fabs(alpha[p][q]) > 1e-12))
00150             {
00151                 EXCEPTION("alpha[" << p << "][" << q << "] should be zero, as p+q > " << n);
00152             }
00153         }
00154     }
00155 
00156     mAlpha = alpha;
00157 }
00158 
00159 std::vector<std::vector<double> > PolynomialMaterialLaw3d::GetZeroedAlpha(unsigned n)
00160 {
00161     std::vector<std::vector<double> > alpha(n+1);
00162 
00163     for (unsigned i=0; i<n+1; i++)
00164     {
00165         alpha[i].resize(n+1);
00166         for (unsigned j=0; j<n+1; j++)
00167         {
00168             alpha[i][j] = 0.0;
00169         }
00170     }
00171 
00172     return alpha;
00173 }