Chaste  Release::3.4
PolynomialMaterialLaw3d.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "PolynomialMaterialLaw3d.hpp"
37 
38 double PolynomialMaterialLaw3d::Get_dW_dI1(double I1, double I2)
39 {
40  double ret = 0.0;
41  // notes: use ints not unsigned as doing p-1
42  // (except indexing from p=1 because multiplying by p, but
43  // still safer to use ints)
44  for (int p=1; p<=(int)mN; p++)
45  {
46  for (int q=0; q<=(int)mN-p; q++)
47  {
48  ret += mAlpha[p][q] * p * pow(I1-3,p-1) * pow(I2-3,q);
49  }
50  }
51 
52  return ret;
53 }
54 
55 double PolynomialMaterialLaw3d::Get_dW_dI2(double I1, double I2)
56 {
57  double ret = 0.0;
58  // notes: use ints not unsigned as doing q-1
59  // (except indexing from q=1 because multiplying by q, but
60  // still safer to use ints)
61  for (int p=0; p<=(int)mN; p++)
62  {
63  for (int q=1; q<=(int)mN-p; q++)
64  {
65  ret += mAlpha[p][q] * q * pow(I1-3,p) * pow(I2-3,q-1);
66  }
67  }
68  return ret;
69 }
70 
71 double PolynomialMaterialLaw3d::Get_d2W_dI1(double I1, double I2)
72 {
73  double ret = 0.0;
74 
75  // notes: use ints not unsigned as doing p-1
76  // (except indexing from p=2 because multiplying by p(p-1), but
77  // still safer to use ints)
78  for (int p=2; p<=(int)mN; p++)
79  {
80  for (int q=0; q<=(int)mN-p; q++)
81  {
82  ret += mAlpha[p][q] * p * (p-1) * pow(I1-3,(p-1)*(p-2)) * pow((double)I2-3,(double)q);
83  }
84  }
85  return ret;
86 }
87 
88 double PolynomialMaterialLaw3d::Get_d2W_dI2(double I1, double I2)
89 {
90  double ret = 0.0;
91 
92  // notes: use ints not unsigned as doing q-1
93  // (except indexing from q=2 because multiplying by q(q-1), but
94  // still safer to use ints)
95  for (int p=0; p<=(int)mN; p++)
96  {
97  for (int q=2; q<=(int)mN-p; q++)
98  {
99  ret += mAlpha[p][q] * q * (q-1) * pow((double)I1-3,(double)p) * pow(I2-3,(q-1)*(q-2));
100  }
101  }
102  return ret;
103 }
104 
105 double PolynomialMaterialLaw3d::Get_d2W_dI1I2(double I1, double I2)
106 {
107  double ret = 0.0;
108 
109  // notes: use ints not unsigned as doing p-1
110  // (except indexing from p=1,q=1 because multiplying by pq, but
111  // still safer to use ints)
112  for (int p=1; p<=(int)mN; p++)
113  {
114  for (int q=1; q<=(int)mN-p; q++)
115  {
116  ret += mAlpha[p][q] * p * q * pow(I1-3,p-1) * pow(I2-3,q-1);
117  }
118  }
119  return ret;
120 }
121 
122 double PolynomialMaterialLaw3d::GetAlpha(unsigned i, unsigned j)
123 {
124  assert(i+j > 0);
125  assert(i+j <= mN);
126 
127  return mAlpha[i][j];
128 }
129 
130 PolynomialMaterialLaw3d::PolynomialMaterialLaw3d(unsigned n, std::vector<std::vector<double> > alpha)
131 {
132  if (n==0)
133  {
134  EXCEPTION("n must be positive");
135  }
136 
137  mN = n;
138 
139  // error checking: must have alpha[p][q]=0 if p+q>n
140  for (unsigned p=0; p<=mN; p++)
141  {
142  if (alpha[p].size() < mN+1-p)
143  {
144  EXCEPTION("alpha not big enough");
145  }
146 
147  for (unsigned q=0; q<alpha[p].size(); q++)
148  {
149  if ((p+q>mN) && (fabs(alpha[p][q]) > 1e-12))
150  {
151  EXCEPTION("alpha[" << p << "][" << q << "] should be zero, as p+q > " << n);
152  }
153  }
154  }
155 
156  mAlpha = alpha;
157 }
158 
159 std::vector<std::vector<double> > PolynomialMaterialLaw3d::GetZeroedAlpha(unsigned n)
160 {
161  std::vector<std::vector<double> > alpha(n+1);
162 
163  for (unsigned i=0; i<n+1; i++)
164  {
165  alpha[i].resize(n+1);
166  for (unsigned j=0; j<n+1; j++)
167  {
168  alpha[i][j] = 0.0;
169  }
170  }
171 
172  return alpha;
173 }
double Get_d2W_dI1(double I1, double I2)
double GetAlpha(unsigned i, unsigned j)
#define EXCEPTION(message)
Definition: Exception.hpp:143
double Get_d2W_dI1I2(double I1, double I2)
static std::vector< std::vector< double > > GetZeroedAlpha(unsigned n)
double Get_d2W_dI2(double I1, double I2)
double Get_dW_dI2(double I1, double I2)
double Get_dW_dI1(double I1, double I2)
PolynomialMaterialLaw3d(unsigned n, std::vector< std::vector< double > > alpha)
std::vector< std::vector< double > > mAlpha