/[escript]/trunk/modellib/py_src/mechanics.py
ViewVC logotype

Contents of /trunk/modellib/py_src/mechanics.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 841 - (show annotations)
Wed Sep 6 09:48:37 2006 UTC (13 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 10981 byte(s)
drucker-prager is working but I am not entirely happy yet as the step size control is very tight.
1 # $Id:$
2
3 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
4 http://www.access.edu.au
5 Primary Business: Queensland, Australia"""
6 __license__="""Licensed under the Open Software License version 3.0
7 http://www.opensource.org/licenses/osl-3.0.php"""
8
9 from esys.escript import *
10 from esys.escript.modelframe import Model,IterationDivergenceError
11 from esys.escript.linearPDEs import LinearPDE
12
13 class Mechanics(Model):
14 """
15 base class for mechanics models in updated lagrangean framework
16
17 @ivar domain: domain (in)
18 @ivar internal_force: =Data()
19 @ivar external_force: =Data()
20 @ivar prescribed_velocity: =Data()
21 @ivar location_prescribed_velocity: =Data()
22 @ivar temperature: = None
23 @ivar expansion_coefficient: = 0.
24 @ivar bulk_modulus: =1.
25 @ivar shear_modulus: =1.
26 @ivar rel_tol: =1.e-3
27 @ivar abs_tol: =1.e-15
28 @ivar max_iter: =10
29 @ivar displacement: =None
30 @ivar stress: =None
31 """
32 SAFTY_FACTOR_ITERATION=1./100.
33 def __init__(self,debug=False):
34 """
35 set up the model
36
37 @param debug: debug flag
38 @type debug: C{bool}
39 """
40 super(Mechanics, self).__init__(self,debug=debug)
41 self.declareParameter(domain=None, \
42 displacement=None, \
43 stress=None, \
44 velocity=None, \
45 internal_force=Data(), \
46 external_force=Data(), \
47 prescribed_velocity=Data(), \
48 location_prescribed_velocity=Data(), \
49 temperature = None, \
50 expansion_coefficient = 0., \
51 bulk_modulus=2., \
52 shear_modulus=1., \
53 rel_tol=1.e-3,abs_tol=1.e-15,max_iter=10)
54 self.__iter=0
55
56 def doInitialization(self):
57 """
58 initialize model
59 """
60 if not self.displacement: self.displacement=Vector(0.,ContinuousFunction(self.domain))
61 if not self.velocity: self.velocity=Vector(0.,ContinuousFunction(self.domain))
62 if not self.stress: self.stress=Tensor(0.,ContinuousFunction(self.domain))
63 # save the old values:
64 self.__stress_safe=self.stress
65 self.__temperature_safe=self.temperature
66 self.__displacement_safe=self.displacement
67 self.__velocity_safe=self.velocity
68 self.__velocity_old=None
69 self.__old_dt=None
70 self.__very_old_dt=None
71 # get node cooridnates and apply initial displacement
72 self.__x=self.domain.getX()
73 self.domain.setX(self.__x+self.displacement)
74 # open PDE:
75 self.__pde=LinearPDE(self.domain)
76 self.__pde.setSolverMethod(self.__pde.DIRECT)
77 # self.__pde.setSymmetryOn()
78
79 def doStepPreprocessing(self,dt):
80 """
81 step up pressure iteration
82
83 if run within a time dependend problem extrapolation of pressure from previous time steps is used to
84 get an initial guess (that needs some work!!!!!!!)
85 """
86 # reset iteration counters:
87 self.__iter=0
88 self.__diff=self.UNDEF_DT
89 # set initial guesses for the iteration:
90 self.displacement=self.__displacement_safe
91 self.stress=self.__stress_safe
92 self.velocity=self.__velocity_safe
93 # update geometry
94 self.domain.setX(self.__x+self.displacement)
95
96 def doStep(self,dt):
97 """
98 """
99 self.__iter+=1
100 k3=kronecker(self.domain)
101 # set new thermal stress increment
102 if self.temperature:
103 self.deps_th=self.self.expansion_coefficient*(self.temperature-self.__temperature_safe)
104 else:
105 self.deps_th=0.
106 # set PDE coefficients:
107 self.__pde.setValue(A=self.S)
108 self.__pde.setValue(X=-self.stress-self.bulk_modulus*self.deps_th*k3)
109 if self.internal_force: self.__pde.setValue(Y=self.internal_force)
110 if self.external_force: self.__pde.setValue(y=self.external_force)
111 self.__pde.setValue(q=self.location_prescribed_velocity, \
112 r=Data())
113 if not self.prescribed_velocity.isEmpty() and self.__iter==1:
114 self.__pde.setValue(r=dt*self.prescribed_velocity)
115 # solve the PDE:
116 self.__pde.setTolerance(self.rel_tol**2)
117 self.du=self.__pde.getSolution(verbose=True)
118 # update geometry
119 self.displacement=self.displacement+self.du
120 self.domain.setX(self.__x+self.displacement)
121 self.velocity=(self.displacement-self.__displacement_safe)/dt
122
123 if self.debug:
124 for i in range(self.domain.getDim()):
125 self.trace("du %d range %e:%e"%(i,inf(self.du[i]),sup(self.du[i])))
126 for i in range(self.domain.getDim()):
127 self.trace("displacement %d range %e:%e"%(i,inf(self.displacement[i]),sup(self.displacement[i])))
128 for i in range(self.domain.getDim()):
129 self.trace("velocity %d range %e:%e"%(i,inf(self.velocity[i]),sup(self.velocity[i])))
130 self.__stress_last=self.stress
131
132 def terminateIteration(self):
133 """iteration is terminateIterationd if relative pressure change is less then rel_tol"""
134 if self.__iter>self.max_iter:
135 raise IterationDivergenceError,"Maximum number of iterations steps reached"
136 if self.__iter==0:
137 self.__diff=self.UNDEF_DT
138 else:
139 self.__diff,diff_safe=Lsup(self.stress-self.__stress_last),self.__diff
140 s_sup=Lsup(self.stress)
141 self.trace("stress max and increment :%e, %e"%(s_sup,self.__diff))
142 if self.__iter>2 and diff_safe<self.__diff:
143 raise IterationDivergenceError,"no improvement in stress iteration"
144 return self.__diff<=self.rel_tol*self.SAFTY_FACTOR_ITERATION*s_sup+self.abs_tol
145
146 def doStepPostprocessing(self,dt):
147 """
148 accept all the values:
149 """
150 self.__displacement_safe=self.displacement
151 self.__temperature_safe=self.temperature
152 self.__stress_safe=self.stress
153 self.__velocity_safe=self.velocity
154
155 def getSafeTimeStepSize(self,dt):
156 """
157 returns new step size
158 """
159 a=sup(length(self.velocity)/self.domain.getSize())
160 if a>0:
161 return 1./a
162 else:
163 return self.UNDEF_DT
164
165
166
167 class DruckerPrager(Mechanics):
168 """
169
170 """
171
172 def __init__(self,debug=False):
173 """
174 set up model
175 """
176 super(DruckerPrager, self).__init__(debug=debug)
177 self.declareParameter(plastic_stress=0.,
178 hardening=0.,
179 friction_parameter=0.,
180 dilatancy_parameter=0.,
181 shear_length=1.e15)
182 def doInitialization(self):
183 """
184 """
185 super(DruckerPrager, self).doInitialization()
186 self.__plastic_stress_safe=self.plastic_stress
187 self.__shear_length_safe=self.shear_length
188 self.__hardening_safe=self.hardening
189 self.__chi_safe=0
190 self.__tau_safe=0
191
192 def doStepPreprocessing(self,dt):
193 """
194 """
195 super(DruckerPrager, self).doStepPreprocessing(dt)
196 # set initial guess for iteration:
197 self.shear_length=self.__shear_length_safe
198 self.plastic_stress=self.__plastic_stress_safe
199 self.hardening=self.__hardening_safe
200 self.__chi=self.__chi_safe
201 self.__tau=self.__tau_safe
202
203 def doStep(self,dt):
204 # set new tangential operator:
205 self.setTangentialTensor()
206 # do the update step:
207 super(DruckerPrager, self).doStep(dt)
208 # update stresses:
209 self.setStress()
210
211 def doStepPostprocessing(self,dt):
212 super(DruckerPrager, self).doStepPostprocessing(dt)
213 self.__plastic_stress_safe=self.plastic_stress
214 self.__shear_length_safe=self.shear_length
215 self.__hardening_safe=self.hardening
216 self.__chi_safe=self.__chi
217 self.__tau_safe=self.__tau
218
219 def setStress(self):
220 d=self.domain.getDim()
221 G=self.shear_modulus
222 K=self.bulk_modulus
223 alpha=self.friction_parameter
224 beta=self.dilatancy_parameter
225 h=self.hardening
226 k3=kronecker(self.domain)
227 # elastic trial stress:
228 g=grad(self.du)
229 D=symmetric(g)
230 W=nonsymmetric(g)
231 s_e=self.stress+K*self.deps_th*k3+ \
232 2*G*D+(K-2./3*G)*trace(D)*k3 \
233 +2*symmetric(matrix_mult(W,self.stress))
234 p_e=-1./d*trace(s_e)
235 s_e_dev=s_e+p_e*k3
236 tau_e=sqrt(1./2*inner(s_e_dev,s_e_dev))
237 # yield conditon for elastic trial stress:
238 F=tau_e-alpha*p_e-self.shear_length
239 self.__chi=whereNonNegative(F+(self.rel_tol*(self.SAFTY_FACTOR_ITERATION)**2)*self.shear_length)
240 # plastic stress increment:
241 l=self.__chi*F/(h+G+beta*K)
242 self.__tau=tau_e-G*l
243 self.stress=self.__tau/(tau_e+self.abs_tol*whereZero(tau_e,self.abs_tol))*s_e_dev-(p_e+l*beta*K)*k3
244 self.plastic_stress=self.plastic_stress+l
245 # update hardening
246 self.hardening=(self.shear_length-self.__shear_length_safe)/(l+self.abs_tol*whereZero(l))
247
248 def setTangentialTensor(self):
249 d=self.domain.getDim()
250 G=self.shear_modulus
251 K=self.bulk_modulus
252 alpha=self.friction_parameter
253 beta=self.dilatancy_parameter
254 tau_Y=self.shear_length
255 chi=self.__chi
256 tau=self.__tau
257 h=self.hardening
258 k3=kronecker(Function(self.domain))
259
260 sXk3=outer(self.stress,k3)
261 k3Xk3=outer(k3,k3)
262 s_dev=self.stress-trace(self.stress)*(k3/d)
263 tmp=G*s_dev/(tau+self.abs_tol*whereZero(tau,self.abs_tol))
264
265 self.S=G*(swap_axes(k3Xk3,0,3)+swap_axes(k3Xk3,1,3)) \
266 + (K-2./3*G)*k3Xk3 \
267 + (sXk3-swap_axes(swap_axes(sXk3,1,2),2,3)) \
268 + 1./2*(swap_axes(swap_axes(sXk3,0,2),2,3) \
269 -swap_axes(swap_axes(sXk3,0,3),2,3) \
270 -swap_axes(sXk3,1,2) \
271 +swap_axes(sXk3,1,3) ) \
272 - outer(chi/(h+G+alpha*beta*K)*(tmp+beta*K*k3),tmp+alpha*K*k3)

  ViewVC Help
Powered by ViewVC 1.1.26