Chaste  Release::3.4
SolidMechanicsProblemDefinition.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 
37 #include "SolidMechanicsProblemDefinition.hpp"
38 #include "AbstractIncompressibleMaterialLaw.hpp"
39 #include "AbstractCompressibleMaterialLaw.hpp"
40 
41 
42 template<unsigned DIM>
45  mSolveUsingSnes(false)
46 {
47 }
48 
49 
50 
51 template<unsigned DIM>
52 void SolidMechanicsProblemDefinition<DIM>::SetFixedNodes(std::vector<unsigned>& rFixedNodes, std::vector<c_vector<double,DIM> >& rFixedNodeLocations)
53 {
54  assert(rFixedNodes.size()==rFixedNodeLocations.size());
55  this->mDirichletNodes = rFixedNodes;
56 
57  this->mDirichletNodeValues.clear();
58  for (unsigned i=0; i<this->mDirichletNodes.size(); i++)
59  {
60  unsigned index = this->mDirichletNodes[i];
61  c_vector<double,DIM> displacement;
62  for(unsigned j=0; j<DIM; j++)
63  {
64  double location = rFixedNodeLocations[i](j);
65 
66  // compute the displacement, assuming the node
67  // is not free in this direction
68  if(location != this->FREE)
69  {
70  displacement(j) = location - this->mrMesh.GetNode(index)->rGetLocation()[j];
71  }
72  else
73  {
74  displacement(j) = this->FREE;
75  }
76  }
77  this->mDirichletNodeValues.push_back(displacement);
78  }
79 }
80 
81 
82 template<unsigned DIM>
83 void SolidMechanicsProblemDefinition<DIM>::SetMaterialLaw(CompressibilityType compressibilityType,
84  AbstractMaterialLaw<DIM>* pMaterialLaw)
85 {
86  mIsHomogeneousMaterial = true;
87  mCompressibilityType = compressibilityType;
88 
89  mIncompressibleMaterialLaws.clear();
90  mCompressibleMaterialLaws.clear();
91 
92  assert(pMaterialLaw);
93 
94  if(compressibilityType==INCOMPRESSIBLE)
95  {
97  CheckCastSuccess(compressibilityType, p_law);
98  mIncompressibleMaterialLaws.push_back(p_law);
99  }
100  else
101  {
103  CheckCastSuccess(compressibilityType, p_law);
104  mCompressibleMaterialLaws.push_back(p_law);
105  }
106 }
107 
108 
109 template<unsigned DIM>
110 void SolidMechanicsProblemDefinition<DIM>::SetMaterialLaw(CompressibilityType compressibilityType,
111  std::vector<AbstractMaterialLaw<DIM>*>& rMaterialLaws)
112 {
113  mIsHomogeneousMaterial = false;
114  mCompressibilityType = compressibilityType;
115 
116  mIncompressibleMaterialLaws.clear();
117  mCompressibleMaterialLaws.clear();
118 
119  assert(this->mrMesh.GetNumElements()==rMaterialLaws.size());
120 
121  if(compressibilityType==INCOMPRESSIBLE)
122  {
123  for(unsigned i=0; i<rMaterialLaws.size(); i++)
124  {
125  assert(rMaterialLaws[i]);
126  AbstractIncompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractIncompressibleMaterialLaw<DIM>*>(rMaterialLaws[i]);
127  CheckCastSuccess(compressibilityType, p_law);
128  mIncompressibleMaterialLaws.push_back(p_law);
129  }
130  }
131  else
132  {
133  for(unsigned i=0; i<rMaterialLaws.size(); i++)
134  {
135  assert(rMaterialLaws[i]);
136  AbstractCompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractCompressibleMaterialLaw<DIM>*>(rMaterialLaws[i]);
137  CheckCastSuccess(compressibilityType, p_law);
138  mCompressibleMaterialLaws.push_back(p_law);
139  }
140  }
141 }
142 
143 
144 
145 
146 template<unsigned DIM>
148 {
149  // if this fails, SetMaterialLaw() hasn't been called
150  assert(mIncompressibleMaterialLaws.size()!=0 || mCompressibleMaterialLaws.size()!=0 );
151  return mIsHomogeneousMaterial;
152 }
153 
154 template<unsigned DIM>
156 {
157  // if this fails, SetMaterialLaw() hasn't been called
158  assert(mIncompressibleMaterialLaws.size()!=0 || mCompressibleMaterialLaws.size()!=0 );
159  return mCompressibilityType;
160 }
161 
162 
163 
164 
165 template<unsigned DIM>
167 {
168  assert(mCompressibilityType==INCOMPRESSIBLE);
169  assert(mIncompressibleMaterialLaws.size()>0);
170  assert(mCompressibleMaterialLaws.size()==0);
171 
172  if(mIsHomogeneousMaterial)
173  {
174  return mIncompressibleMaterialLaws[0];
175  }
176  else
177  {
178  assert(elementIndex < this->mrMesh.GetNumNodes());
179  return mIncompressibleMaterialLaws[elementIndex];
180  }
181 }
182 
183 template<unsigned DIM>
185 {
186  assert(mCompressibilityType==COMPRESSIBLE);
187  assert(mIncompressibleMaterialLaws.size()==0);
188  assert(mCompressibleMaterialLaws.size()>0);
189 
190  if(mIsHomogeneousMaterial)
191  {
192  return mCompressibleMaterialLaws[0];
193  }
194  else
195  {
196  assert(elementIndex < this->mrMesh.GetNumNodes());
197  return mCompressibleMaterialLaws[elementIndex];
198  }
199 }
200 
201 template<unsigned DIM>
202 void SolidMechanicsProblemDefinition<DIM>::CheckCastSuccess(CompressibilityType compressibilityType,
203  AbstractMaterialLaw<DIM>* pMaterialLaw)
204 {
205  if(compressibilityType==INCOMPRESSIBLE && pMaterialLaw==NULL)
206  {
207  // then dynamic_cast to AbstractIncompressibleMaterialLaw failed
208  EXCEPTION("Compressibility type was declared as INCOMPRESSIBLE but a compressible material law was given");
209  }
210 
211  if(compressibilityType==COMPRESSIBLE && pMaterialLaw==NULL)
212  {
213  // then dynamic_cast to AbstractCompressibleMaterialLaw failed
214  EXCEPTION("Incompressibility type was declared as COMPRESSIBLE but an incompressible material law was given");
215  }
216 }
217 
218 
219 template<unsigned DIM>
221 {
223 
224  if((mIncompressibleMaterialLaws.size()==0) && (mCompressibleMaterialLaws.size()==0))
225  {
226  EXCEPTION("No material law has been set");
227  }
228 }
230 // Explicit instantiation
232 
235 
void SetFixedNodes(std::vector< unsigned > &rFixedNodes, std::vector< c_vector< double, DIM > > &rFixedNodeLocation)
#define EXCEPTION(message)
Definition: Exception.hpp:143
AbstractIncompressibleMaterialLaw< DIM > * GetIncompressibleMaterialLaw(unsigned elementIndex)
void SetMaterialLaw(CompressibilityType compressibilityType, AbstractMaterialLaw< DIM > *pMaterialLaw)
AbstractCompressibleMaterialLaw< DIM > * GetCompressibleMaterialLaw(unsigned elementIndex)
void CheckCastSuccess(CompressibilityType compressibilityType, AbstractMaterialLaw< DIM > *pMaterialLaw)
SolidMechanicsProblemDefinition(AbstractTetrahedralMesh< DIM, DIM > &rMesh)