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