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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 821 - (hide annotations)
Mon Aug 28 08:36:30 2006 UTC (13 years, 10 months ago) by gross
File MIME type: text/x-python
File size: 9710 byte(s)
and some more work on drucker-prager
1 gross 814 # $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 gross 821 @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     @ivar velocity: =None
32 gross 814 """
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 gross 821 bulk_modulus=2., \
52 gross 814 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     self.__pde=LinearPDE(self.domain)
64 gross 821 self.__pde.setSymmetryOn()
65 gross 814 self.__displacement_old=self.displacement
66     self.stress_old=self.stress
67     self.__velocity_old=self.velocity
68     self.__temperature_old=self.temperature
69    
70     def doStepPreprocessing(self,dt):
71     """
72     step up pressure iteration
73    
74     if run within a time dependend problem extrapolation of pressure from previous time steps is used to
75     get an initial guess (that needs some work!!!!!!!)
76     """
77     self.__iter=0
78     self.__diff=self.UNDEF_DT
79     # set new values:
80     self.displacement=self.__displacement_old
81     self.stress=self.stress_old
82     self.velocity=self.__velocity_old
83     self.temperature=self.__temperature_old
84     self.__velocity_last=self.velocity
85    
86     def doStep(self,dt):
87     """
88    
89     performs an iteration step of the penalty method.
90     IterationDivergenceError is raised if pressure error cannot be reduced or max_iter is reached.
91    
92     requires self.S to be set
93     updates the thermal stress increment
94    
95     """
96     k3=kronecker(self.domain)
97     # set new thermal stress increment
98     if self.temperature:
99     self.dthermal_stress=self.bulk_modulus*self.self.expansion_coefficient*(self.temperature-self.__temperature_old)
100     else:
101     self.dthermal_stress=0.
102     # set PDE coefficients:
103     self.__pde.setValue(A=self.S)
104     self.__pde.setValue(X=self.stress_old-self.dthermal_stress*k3)
105     if self.internal_force: self.__pde.setValue(Y=self.internal_force)
106     if self.external_force: self.__pde.setValue(y=self.external_force)
107     self.__pde.setValue(r=self.prescribed_velocity, \
108     q=self.location_prescribed_velocity)
109     # solve the PDE:
110     self.__pde.setTolerance(self.rel_tol/100.)
111 gross 821 self.velocity=self.__pde.getSolution(verbose=True)
112 gross 814 # calculate convergence indicators:
113     self.__diff,diff_old=Lsup(self.velocity-self.__velocity_last),self.__diff
114     self.__velocity_last=self.velocity
115     self.displacement=self.__displacement_old+dt*self.velocity
116     self.__iter+=1
117 gross 821 if self.debug:
118     for i in range(self.domain.getDim()):
119     self.trace("velocity %d range %e:%e"%(i,inf(self.velocity[i]),sup(self.velocity[i])))
120     self.trace("velocity increment %s"%self.__diff)
121 gross 814 if self.__iter>2 and diff_old<self.__diff:
122     raise IterationDivergenceError,"no improvement in stress iteration"
123     if self.__iter>self.max_iter:
124     raise IterationDivergenceError,"Maximum number of iterations steps reached"
125    
126     def terminateIteration(self):
127     """iteration is terminateIterationd if relative pressure change is less then rel_tol"""
128     return self.__diff<=self.rel_tol*Lsup(self.velocity)+self.abs_tol
129    
130     def doStepPostprocessing(self,dt):
131     """
132     accept all the values:
133     """
134     self.displacement=self.__displacement_old
135     self.stress=self.stress_old
136     self.velocity=self.__velocity_old
137     self.temperature=self.__temperature_old
138    
139     def getSafeTimeStepSize(self,dt):
140     """
141     returns new step size
142     """
143     d=Lsup(self.velocity-self.__velocity_old)/dt
144     if d>0:
145     return Lsup(self.displacement)/d
146     else:
147     return self.UNDEF_DT
148    
149    
150    
151     class DruckerPrager(Mechanics):
152     """
153    
154     """
155    
156     def __init__(self,debug=False):
157     """
158     set up model
159     """
160     super(DruckerPrager, self).__init__(debug=debug)
161     self.declareParameter(plastic_stress=0.,
162     friction_parameter=0.,
163     dilatancy_parameter=0.,
164 gross 821 shear_length=1.e15)
165 gross 814
166     def doInitialization(self):
167     """
168     initialize model
169     """
170     super(DruckerPrager, self).doInitialization()
171     self.__plastic_stress_old=self.plastic_stress
172 gross 816 self.__tau_y_old=self.shear_length
173 gross 814
174     def doStepPreprocessing(self,dt):
175     """
176     step up pressure iteration
177    
178     if run within a time dependend problem extrapolation of pressure from previous time steps is used to
179     get an initial guess (that needs some work!!!!!!!)
180     """
181     super(DruckerPrager, self).doStepPreprocessing(dt)
182     self.plastic_stress=self.__plastic_stress_old
183    
184     def doStep(self,dt):
185     G=self.shear_modulus
186     K=self.bulk_modulus
187     alpha=self.friction_parameter
188     beta=self.dilatancy_parameter
189     tau_Y=self.shear_length
190     if self.__plastic_stress_old:
191     dps=self.plastic_stress-self.__plastic_stress_old
192 gross 816 h=(tau_Y-self.__tau_y_old)/(dps+self.abs_tol*whereZero(dps))
193 gross 814 else:
194     h=0
195     # set new tangential operator:
196     self.S=self.getTangentialTensor(self.stress,
197     tau_Y,G,K,alpha,beta,h)
198     # do the update step:
199     super(DruckerPrager, self).doStep(dt)
200    
201     # update stresses:
202     self.stress,self.plastic_stress=self.getNewStress(self.stress_old,self.__plastic_stress_old,
203     self.velocity*dt,
204     self.dthermal_stress,tau_Y,G,K,alpha,beta,h)
205    
206     def doStepPostprocessing(self,dt):
207     super(DruckerPrager, self).doStepPostprocessing(dt)
208     self.plastic_stress=self.__plastic_stress_old=self.plastic_stress
209    
210     def getNewStress(self,s,gamma_p,du,ds_therm,tau_Y,G,K,alpha,beta,h):
211     k3=kronecker(self.domain)
212     dt=1.
213     g=grad(du)
214     D=symmetric(g)
215     W=nonsymmetric(g)
216     s_e=s+ds_therm+dt*(2*G*D+(K-2./3*G)*trace(D)*k3 \
217     +2*nonsymmetric(matrix_mult(W,s)))
218     p_e=-1./3*trace(s_e)
219     s_e_dev=s_e+p_e*k3
220     tau_e=sqrt(1./2*inner(s_e_dev,s_e_dev))
221     F=tau_e-alpha*p_e-tau_Y
222     chi=whereNonNegative(F)
223     l=chi*F/(h+G+beta*K)
224     s=(1.-l*G/tau_e)*s_e_dev+(p_e+l*beta*K)*k3
225     gamma_p=gamma_p+l
226     return s, gamma_p
227    
228    
229     def getTangentialTensor(self,s,tau_Y,G,K,alpha,beta,h):
230     d=self.domain.getDim()
231     k3=kronecker(Function(self.domain))
232     p=-1./d*trace(s)
233     s_dev=s+p*k3
234     tau=sqrt(1./2*inner(s_dev,s_dev))
235     chi=whereNonNegative(tau-alpha*p-tau_Y)
236     sXk3=outer(s,k3)
237     k3Xk3=outer(k3,k3)
238     tmp=G*s_dev/tau
239     S=G*(swap_axes(k3Xk3,1,2)+swap_axes(k3Xk3,1,3)) \
240     + (K-2./3*G)*k3Xk3 \
241     + sXk3-swap_axes(sXk3,1,3) \
242 gross 821 + 1./2*(swap_axes(sXk3,0,3)-swap_axes(sXk3,1,2) \
243     -swap_axes(sXk3,1,3)+swap_axes(sXk3,0,2))
244 gross 814 # - chi/(h+G+alpha*beta*K)*outer(tmp+beta*K*k3,tmp+alpha*K*k3)\
245     return S

  ViewVC Help
Powered by ViewVC 1.1.26