Changeset 17622


Ignore:
Timestamp:
04/01/14 16:47:34 (11 years ago)
Author:
cborstad
Message:

python-izing some mech functions

Location:
issm/trunk-jpl/src/m/mech
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/mech/analyticaldamage.py

    r16065 r17622  
    11import numpy as npy
    2 from pairoptions import pairoptions
    32from averaging import averaging
    43from plotmodel import plotmodel
     4from thomasparams import thomasparams
    55
    6 def analyticaldamage(md,*args):
     6def analyticaldamage(md,**kwargs):
    77        '''
    88        ANALYTICALDAMAGE - compute damage for an ice shelf
     
    1414       
    1515           Available options:
    16                         - 'eq'                  : analytical equation to use in the calculation.  Must be one of:
     16                        -eq                     : analytical equation to use in the calculation.  Must be one of:
    1717                                                                        'Weertman1D' for a confined ice shelf free to flow in one direction
    1818                                                                        'Weertman2D' for an unconfined ice shelf free to spread in any direction
    1919                                                                        'Thomas' for a 2D ice shelf, taking into account full strain rate tensor (default)
    20                         - 'smoothing'   : the amount of smoothing to be applied to the strain rate data.
     20                        -smoothing      : the amount of smoothing to be applied to the strain rate data.
    2121                                                                        Type 'help averaging' for more information on its usage.
    22                         - 'sigmab'              : a compressive backstress term to be subtracted from the driving stress
     22                        -coordsys       : coordinate system for calculating the strain rate
     23                                                components. Must be one of:
     24                        -sigmab         : a compressive backstress term to be subtracted from the driving stress
    2325                                                                        in the damage calculation
    2426       
     
    3436       
    3537           Usage:
    36               [damage,B,backstress]=analyticaldamage(md,options)
     38              damage,B,backstress=analyticaldamage(md,kwargs)
    3739       
    3840           Example:
    39               [damage,B,backstress]=analyticaldamage(md,'eq','Weertman2D','smoothing',2,'backstress',10e3)
     41              damage,B,backstress=analyticaldamage(md,eq='Weertman2D',smoothing=2,sigmab=10e3)
    4042        '''
     43
     44        #unpack kwargs
     45        eq=kwargs.pop('eq','Thomas')
     46        if 'eq' in kwargs: del kwargs['eq']
     47        smoothing=kwargs.pop('smoothing',0)
     48        if 'smoothing' in kwargs: del kwargs['smoothing']
     49        coordsys=kwargs.pop('coordsys','longitudinal')
     50        if 'coordsys' in kwargs: del kwargs['coordsys']
     51        sigmab=kwargs.pop('sigmab',0)
     52        if 'sigmab' in kwargs: del kwargs['sigmab']
     53        assert len(kwargs)==0, 'error, unexpected or misspelled kwargs'
     54
     55        if len(sigmab)==1:
     56                sigmab=sigmab*npy.ones((md.mesh.numberofvertices,))
    4157
    4258        # check inputs
    4359        if 'strainrate' not in md.results.__dict__:
    4460                raise StandardError('md.results.strainrate not present.  Calculate using md=mechanicalproperties(md,vx,vy)')
    45         if md.mesh.dimension!=2:
    46                 raise StandardError('only 2D model supported currently')
     61        if not '2d' in md.mesh.__doc__:
     62                raise StandardError('only 2d (planview) model supported currently')
    4763        if npy.any(md.flowequation.element_equation!=2):
    4864                print 'Warning: the model has some non SSA elements. These will be treated like SSA elements'
    4965
    50         # process options
    51         options = pairoptions(*args)
    52         eq = options.getfieldvalue('eq','Thomas')
    53         smoothing = options.getfieldvalue('smoothing',0)
    54         sigmab = options.getfieldvalue('sigmab',0)
    55         if len(sigmab==1):
    56                 sigmab=sigmab*npy.ones(md.mesh.numberofvertices,)
    57        
    58         # average element strain rates onto vertices
    59         e1=averaging(md,md.results.strainrate.principalvalue1,smoothing)/md.constants.yts # convert to s^-1
    60         e2=averaging(md,md.results.strainrate.principalvalue2,smoothing)/md.constants.yts
    61         exx=averaging(md,md.results.strainrate.xx,smoothing)/md.constants.yts
    62         eyy=averaging(md,md.results.strainrate.yy,smoothing)/md.constants.yts
    63         exy=averaging(md,md.results.strainrate.xy,smoothing)/md.constants.yts
    64        
    65         # checks: any of e1 or e2 equal to zero?
    66         pos=npy.nonzero(e1==0)
    67         if npy.any(pos==1):
    68                 print 'WARNING: first principal strain rate equal to zero.  Value set to 1e-13 s^-1'
    69                 e1[pos]=1e-13
    70         pos=npy.nonzero(e2==0)
    71         if npy.any(pos==1):
    72                 disp('WARNING: second principal strain rate equal to zero.  Value set to 1e-13 s^-1');
    73                 e2[pos]=1e-13
    74        
    75         ## old method using principal strain rates {{{
    76         ## ex=maximum principal tensile strain rate
    77         #ex=e1;
    78         #a=e2./e1;
    79         #pos=find(e1<0 & e2>0); # longitudinal compression and lateral tension
    80         #a(pos)=e1(pos)./e2(pos);
    81         #ex(pos)=e2(pos);
    82         #pos2=find(e1<0 & e2<0 & abs(e1)<abs(e2)); # lateral and longitudinal compression
    83         #a(pos2)=e1(pos2)./e2(pos2);
    84         #ex(pos2)=e2(pos2);
    85         #pos3=find(e1>0 & e2>0 & abs(e1)<abs(e2)); # lateral and longitudinal tension
    86         #a(pos3)=e1(pos3)./e2(pos3);
    87         #ex(pos3)=e2(pos3);
    88         #id=find(e1<0 & e2<0);
    89         #a(id)=-a(id); # where both strain rates are compressive, enforce negative alpha
    90         #
    91         ## }}}
    92        
    93         # new method using longitudinal strain rates defined by observed velocity vector
    94         velangle=npy.arctan(md.initialization.vy/md.initialization.vx)
    95         ex=0.5*(exx+eyy)+0.5*(exx-eyy)*npy.cos(2.*velangle)+exy*npy.sin(2.*velangle)
    96         ey=exx+eyy-ex # trace of strain rate tensor is invariant
    97         exy=-0.5*(exx-eyy)*npy.sin(2.*velangle)+exy*npy.cos(2.*velangle)
    98         a=ey/ex
    99         b=exy/ex
    100         pos=npy.nonzero(npy.logical_and(ex<0,ey<0))
    101         #length(pos)
    102         a[pos]=-a[pos]
    103        
    104         # a < -1 in areas of strong lateral compression or longitudinal compression
    105         # and theta is undefined at a = -2
    106         pos=npy.nonzero(abs((abs(a)-2))<1e-3)
    107         a[pos]=-2+1e-3
     66        a,b,theta,ex=thomasparams(md,eq=eq,smoothing=smoothing,coordsys=coordsys)
    10867       
    10968        # spreading stress
     
    11776        n=averaging(md,md.materials.rheology_n,0)
    11877       
    119         if eq=='Weertman1D':
    120                 theta=1./8*npy.ones(md.mesh.numberofvertices,)
    121                 a=npy.zeros(md.mesh.numberofvertices,)
    122         elif eq=='Weertman2D':
    123                 theta=1./9*npy.ones(md.mesh.numberofvertices,1)
    124                 a=npy.ones(md.mesh.numberofvertices,)
    125         elif eq=='Thomas':
    126                 theta=((1+a+a**2+b**2)**((n-1)/2))/(abs(2+a)**n)
    127         else:
    128                 raise StandardError('argument passed to "eq" not valid.  Type "help analyticaldamage" for usage')
    129        
    130         D=1-(1+a+a**2+b**2)**((n-1)/(2*n))/abs(ex)**(1./n)*(T-sigmab)/B/(2+a)/npy.sign(ex)
    131        
    132         backstress=npy.zeros(md.mesh.numberofvertices,)
     78        D=1.-(1.+a+a**2+b**2)**((n-1.)/(2.*n))/npy.abs(ex)**(1./n)*(T-sigmab)/B/(2.+a)/npy.sign(ex)
    13379       
    13480        # D>1 where (2+a).*sign(ex)<0, compressive regions where high backstress needed
     
    13682        D[pos]=0
    13783       
    138         # backstress to bring damage to zero
    139         backstress[pos]=T[pos]-(1-D[pos])*B[pos]*npy.sign(ex[pos])*(2+a[pos])*abs(ex[pos])**(1./n[pos])/(1+a[pos]+a[pos]**2)**((n[pos]-1)/2./n[pos])
     84        backstress=npy.zeros((md.mesh.numberofvertices,))
     85       
     86        # backstress to bring D down to one
     87        backstress[pos]=T[pos]-(1.-D[pos])*B[pos]*npy.sign(ex[pos])*(2.+a[pos])*npy.abs(ex[pos])**(1./n[pos])/(1.+a[pos]+a[pos]**2)**((n[pos]-1.)/2./n[pos])
    14088       
    14189        pos=npy.nonzero(D<0)
     90        #mask=ismember(1:md.mesh.numberofvertices,pos);
    14291        D[pos]=0
    143 
     92       
    14493        # backstress to bring negative damage to zero
    145         backstress[pos]=T[pos]-(1-D[pos])*B[pos]*npy.sign(ex[pos])*(2+a[pos])*abs(ex[pos])**(1./n[pos])/(1+a[pos]+a[pos]**2)**((n[pos]-1)/2./n[pos])
     94        backstress[pos]=T[pos]-(1.-D[pos])*B[pos]*npy.sign(ex[pos])*(2.+a[pos])*npy.abs(ex[pos])**(1./n[pos])/(1.+a[pos]+a[pos]**2)**((n[pos]-1.)/2./n[pos])
    14695       
    14796        pos=npy.nonzero(backstress<0)
    14897        backstress[pos]=0
    14998       
    150         # increased rigidity to bring negative damage to zero
    151         B[pos]=npy.sign(ex[pos])/(2+a[pos])*(1+a[pos]+a[pos]**2)**((n[pos]-1)/2./n[pos])*T[pos]/abs(ex[pos])**(1./n[pos]);
     99        # rigidity from Thomas relation for D=0 and backstress=0
     100        B=npy.sign(ex)/(2.+a)*(1.+a+a**2)**((n-1.)/2./n)*T/(npy.abs(ex)**(1./n))
     101        pos=npy.nonzero(B<0)
     102        B[pos]=md.materials.rheology_B[pos]
    152103       
    153104        damage=D
  • issm/trunk-jpl/src/m/mech/mechanicalproperties.py

    r17395 r17622  
    2323        if len(vx)!=md.mesh.numberofvertices or len(vy)!=md.mesh.numberofvertices:
    2424                raise ValueError('the input velocity should be of size ' + md.mesh.numberofvertices)
    25 
    26         if md.mesh.dimension!=2:
    27                 raise StandardError('only 2D model supported currently')
     25       
     26        #if md.mesh.dimension!=2:
     27        #       raise StandardError('only 2D model supported currently')
    2828
    2929        if npy.any(md.flowequation.element_equation!=2):
Note: See TracChangeset for help on using the changeset viewer.