/[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 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (9 months ago) by uqaeller
File MIME type: text/x-python
File size: 12458 byte(s)
Updated the copyright header.


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

  ViewVC Help
Powered by ViewVC 1.1.26