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

  ViewVC Help
Powered by ViewVC 1.1.26