Chaste  Release::3.4
ContinuumMechanicsProblemDefinition.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 <limits>
37 
38 #include "ContinuumMechanicsProblemDefinition.hpp"
39 #include "AbstractIncompressibleMaterialLaw.hpp"
40 #include "AbstractCompressibleMaterialLaw.hpp"
41 
42 
43 template<unsigned DIM>
44 const double ContinuumMechanicsProblemDefinition<DIM>::FREE = std::numeric_limits<double>::max();
45 
46 template<unsigned DIM>
48  : mrMesh(rMesh),
49  mDensity(1.0),
50  mBodyForceType(CONSTANT_BODY_FORCE),
51  mConstantBodyForce(zero_vector<double>(DIM)),
52  mTractionBoundaryConditionType(NO_TRACTIONS),
53  mVerboseDuringSolve(false)
54 {
55 }
56 
57 template<unsigned DIM>
59 {
60  assert(density>0.0);
61  mDensity = density;
62 }
63 
64 template<unsigned DIM>
66 {
67  return mDensity;
68 }
69 
70 template<unsigned DIM>
71 void ContinuumMechanicsProblemDefinition<DIM>::SetBodyForce(c_vector<double,DIM> bodyForce)
72 {
73  mBodyForceType = CONSTANT_BODY_FORCE;
74  mConstantBodyForce = bodyForce;
75 }
76 
77 template<unsigned DIM>
78 void ContinuumMechanicsProblemDefinition<DIM>::SetBodyForce(c_vector<double,DIM> (*pFunction)(c_vector<double,DIM>& rX, double t))
79 {
80  mBodyForceType = FUNCTIONAL_BODY_FORCE;
81  mpBodyForceFunction = pFunction;
82 }
83 
84 
85 template<unsigned DIM>
87 {
88  return mBodyForceType;
89 }
90 
91 template<unsigned DIM>
93 {
94  assert(mBodyForceType==CONSTANT_BODY_FORCE);
95  return mConstantBodyForce;
96 }
97 
98 template<unsigned DIM>
99 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::EvaluateBodyForceFunction(c_vector<double,DIM>& rX, double t)
100 {
101  assert(mBodyForceType==FUNCTIONAL_BODY_FORCE);
102  return (*mpBodyForceFunction)(rX,t);
103 }
104 
105 template<unsigned DIM>
106 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::GetBodyForce(c_vector<double,DIM>& rX, double t)
107 {
108  switch(mBodyForceType)
109  {
110  case CONSTANT_BODY_FORCE:
111  {
112  return mConstantBodyForce;
113  }
114  case FUNCTIONAL_BODY_FORCE:
115  {
116  return (*mpBodyForceFunction)(rX,t);
117  }
118  default:
120  }
121 }
122 
123 
124 template<unsigned DIM>
126 {
127  return mTractionBoundaryConditionType;
128 }
129 
130 template<unsigned DIM>
132  std::vector<c_vector<double,DIM> >& rElementwiseTractions)
133 {
134 
135  assert(rTractionBoundaryElements.size()==rElementwiseTractions.size());
136  mTractionBoundaryConditionType = ELEMENTWISE_TRACTION;
137  mTractionBoundaryElements = rTractionBoundaryElements;
138  mElementwiseTractions = rElementwiseTractions;
139 }
140 
141 template<unsigned DIM>
143  c_vector<double,DIM> (*pFunction)(c_vector<double,DIM>& rX, double t))
144 {
145  mTractionBoundaryConditionType=FUNCTIONAL_TRACTION;
146  mTractionBoundaryElements = rTractionBoundaryElements;
147  mpTractionBoundaryConditionFunction = pFunction;
148 }
149 
150 
151 template<unsigned DIM>
153  double normalPressure)
154 {
155  mTractionBoundaryConditionType = PRESSURE_ON_DEFORMED;
156  mTractionBoundaryElements = rTractionBoundaryElements;
157  mNormalPressure = normalPressure;
158  mOriginalNormalPressure = normalPressure;
159 
160 }
161 
162 template<unsigned DIM>
164  double (*pFunction)(double t))
165 {
166  mTractionBoundaryConditionType = FUNCTIONAL_PRESSURE_ON_DEFORMED;
167  mTractionBoundaryElements = rTractionBoundaryElements;
168  mpNormalPressureFunction = pFunction;
169 }
170 
171 
172 
173 
174 template<unsigned DIM>
175 void ContinuumMechanicsProblemDefinition<DIM>::SetZeroDirichletNodes(std::vector<unsigned>& rZeroDirichletNodes)
176 {
177  mDirichletNodes = rZeroDirichletNodes;
178 
179  for (unsigned i=0; i<mDirichletNodes.size(); i++)
180  {
181  assert(mDirichletNodes[i] < mrMesh.GetNumNodes());
182  }
183 
184  mDirichletNodeValues.clear();
185  for (unsigned i=0; i<mDirichletNodes.size(); i++)
186  {
187  mDirichletNodeValues.push_back(zero_vector<double>(DIM));
188  }
189 }
190 
191 template<unsigned DIM>
193 {
194  return mDirichletNodes;
195 }
196 
197 template<unsigned DIM>
199 {
200  return mDirichletNodeValues;
201 }
202 
203 template<unsigned DIM>
205 {
206  return mTractionBoundaryElements;
207 }
208 
209 
210 template<unsigned DIM>
212 {
213  assert(mTractionBoundaryConditionType==ELEMENTWISE_TRACTION);
214  return mElementwiseTractions;
215 }
216 
217 
218 template<unsigned DIM>
220 {
221  assert(mTractionBoundaryConditionType==PRESSURE_ON_DEFORMED);
222  return mNormalPressure;
223 }
224 
225 template<unsigned DIM>
226 c_vector<double,DIM> ContinuumMechanicsProblemDefinition<DIM>::EvaluateTractionFunction(c_vector<double,DIM>& rX, double t)
227 {
228  assert(mTractionBoundaryConditionType==FUNCTIONAL_TRACTION);
229  return (*mpTractionBoundaryConditionFunction)(rX,t);
230 }
231 
232 template<unsigned DIM>
234 {
235  assert(mTractionBoundaryConditionType==FUNCTIONAL_PRESSURE_ON_DEFORMED);
236  return (*mpNormalPressureFunction)(t);
237 }
238 
239 template<unsigned DIM>
241 {
242  assert(mTractionBoundaryConditionType==PRESSURE_ON_DEFORMED);
243  mNormalPressure = mOriginalNormalPressure*scaleFactor;
244 }
245 
246 template<unsigned DIM>
248 {
249  if(mDirichletNodes.size()==0)
250  {
251  EXCEPTION("No Dirichlet boundary conditions (eg fixed displacement or fixed flow) have been set");
252  }
253 }
254 
255 
256 
258 // Explicit instantiation
260 
263 
std::vector< BoundaryElement< DIM-1, DIM > * > & rGetTractionBoundaryElements()
ContinuumMechanicsProblemDefinition(AbstractTetrahedralMesh< DIM, DIM > &rMesh)
void SetTractionBoundaryConditions(std::vector< BoundaryElement< DIM-1, DIM > * > &rTractionBoundaryElements, std::vector< c_vector< double, DIM > > &rElementwiseTractions)
c_vector< double, DIM > EvaluateTractionFunction(c_vector< double, DIM > &rX, double t)
#define EXCEPTION(message)
Definition: Exception.hpp:143
TractionBoundaryConditionType GetTractionBoundaryConditionType()
void SetZeroDirichletNodes(std::vector< unsigned > &rZeroDirichletNodes)
std::vector< c_vector< double, DIM > > & rGetElementwiseTractions()
#define NEVER_REACHED
Definition: Exception.hpp:206
c_vector< double, DIM > GetBodyForce(c_vector< double, DIM > &rX, double t=0.0)
void SetBodyForce(c_vector< double, DIM > bodyForce)
std::vector< c_vector< double, DIM > > & rGetDirichletNodeValues()
void SetApplyNormalPressureOnDeformedSurface(std::vector< BoundaryElement< DIM-1, DIM > * > &rTractionBoundaryElements, double normalPressure)
c_vector< double, DIM > EvaluateBodyForceFunction(c_vector< double, DIM > &rX, double t)