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