Ignore:
Timestamp:
10/11/16 01:24:07 (8 years ago)
Author:
bdef
Message:

CHG: replacing npy by np for numpy abreviation

File:
1 edited

Legend:

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

    r19466 r21254  
    1 import numpy as npy
     1import numpy as np
    22from GetNodalFunctionsCoeff import GetNodalFunctionsCoeff
    33from results import results
     
    2727        #       raise StandardError('only 2D model supported currently')
    2828
    29         if npy.any(md.flowequation.element_equation!=2):
     29        if np.any(md.flowequation.element_equation!=2):
    3030                print 'Warning: the model has some non SSA elements. These will be treated like SSA elements'
    3131
     
    3535            if len(damage)!=md.mesh.numberofvertices:
    3636                raise ValueError('if damage is supplied it should be of size ' + md.mesh.numberofvertices)
    37             if npy.ndim(damage)==2:
     37            if np.ndim(damage)==2:
    3838                damage=damage.reshape(-1,)
    3939        else: damage=None
    4040
    41         if npy.ndim(vx)==2:
     41        if np.ndim(vx)==2:
    4242                vx=vx.reshape(-1,)
    43         if npy.ndim(vy)==2:
     43        if np.ndim(vy)==2:
    4444                vy=vy.reshape(-1,)
    4545       
     
    4848        numberofvertices=md.mesh.numberofvertices
    4949        index=md.mesh.elements
    50         summation=npy.array([[1],[1],[1]])
    51         directionsstress=npy.zeros((numberofelements,4))
    52         directionsstrain=npy.zeros((numberofelements,4))
    53         valuesstress=npy.zeros((numberofelements,2))
    54         valuesstrain=npy.zeros((numberofelements,2))
     50        summation=np.array([[1],[1],[1]])
     51        directionsstress=np.zeros((numberofelements,4))
     52        directionsstrain=np.zeros((numberofelements,4))
     53        valuesstress=np.zeros((numberofelements,2))
     54        valuesstrain=np.zeros((numberofelements,2))
    5555       
    5656        #compute nodal functions coefficients N(x,y)=alpha x + beta y +gamma
     
    6060        vxlist=vx[index-1]/md.constants.yts
    6161        vylist=vy[index-1]/md.constants.yts
    62         ux=npy.dot((vxlist*alpha),summation).reshape(-1,)
    63         uy=npy.dot((vxlist*beta),summation).reshape(-1,)
    64         vx=npy.dot((vylist*alpha),summation).reshape(-1,)
    65         vy=npy.dot((vylist*beta),summation).reshape(-1,)
     62        ux=np.dot((vxlist*alpha),summation).reshape(-1,)
     63        uy=np.dot((vxlist*beta),summation).reshape(-1,)
     64        vx=np.dot((vylist*alpha),summation).reshape(-1,)
     65        vy=np.dot((vylist*beta),summation).reshape(-1,)
    6666        uyvx=(vx+uy)/2.
    6767        #clear vxlist vylist
    6868       
    6969        #compute viscosity
    70         nu=npy.zeros((numberofelements,))
    71         B_bar=npy.dot(md.materials.rheology_B[index-1],summation/3.).reshape(-1,)
     70        nu=np.zeros((numberofelements,))
     71        B_bar=np.dot(md.materials.rheology_B[index-1],summation/3.).reshape(-1,)
    7272        power=((md.materials.rheology_n-1.)/(2.*md.materials.rheology_n)).reshape(-1,)
    7373        second_inv=(ux**2.+vy**2.+((uy+vx)**2.)/4.+ux*vy).reshape(-1,)
    7474       
    7575        #some corrections
    76         location=npy.nonzero(npy.logical_and(second_inv==0,power!=0))
     76        location=np.nonzero(np.logical_and(second_inv==0,power!=0))
    7777        nu[location]=10^18      #arbitrary maximum viscosity to apply where there is no effective shear
    7878       
    7979        if 'matice' in md.materials.__module__:
    80                 location=npy.nonzero(second_inv)
     80                location=np.nonzero(second_inv)
    8181                nu[location]=B_bar[location]/(second_inv[location]**power[location])
    82                 location=npy.nonzero(npy.logical_and(second_inv==0,power==0))
     82                location=np.nonzero(np.logical_and(second_inv==0,power==0))
    8383                nu[location]=B_bar[location]
    84                 location=npy.nonzero(npy.logical_and(second_inv==0,power!=0))
     84                location=np.nonzero(np.logical_and(second_inv==0,power!=0))
    8585                nu[location]=10^18
    8686        elif 'matdamageice' in md.materials.__module__ and damage is not None:
    8787                print 'computing damage-dependent properties!'
    88                 Zinv=npy.dot(1-damage[index-1],summation/3.).reshape(-1,)
    89                 location=npy.nonzero(second_inv)
    90                 nu[location]=Zinv[location]*B_bar[location]/npy.power(second_inv[location],power[location])
    91                 location=npy.nonzero(npy.logical_and(second_inv==0,power==0))
     88                Zinv=np.dot(1-damage[index-1],summation/3.).reshape(-1,)
     89                location=np.nonzero(second_inv)
     90                nu[location]=Zinv[location]*B_bar[location]/np.power(second_inv[location],power[location])
     91                location=np.nonzero(np.logical_and(second_inv==0,power==0))
    9292                nu[location]=Zinv[location]*B_bar[location]
    9393                #clear Zinv
     
    101101       
    102102        #compute principal properties of stress
    103         for i in npy.arange(numberofelements):
     103        for i in np.arange(numberofelements):
    104104       
    105105                #compute stress and strainrate matrices
    106                 stress=npy.array([ [tau_xx[i], tau_xy[i]], [tau_xy[i], tau_yy[i]] ])
    107                 strain=npy.array([ [ux[i], uyvx[i]], [uyvx[i], vy[i]] ])
     106                stress=np.array([ [tau_xx[i], tau_xy[i]], [tau_xy[i], tau_yy[i]] ])
     107                strain=np.array([ [ux[i], uyvx[i]], [uyvx[i], vy[i]] ])
    108108       
    109109                #eigenvalues and vectors for stress
    110                 value,directions=npy.linalg.eig(stress);
     110                value,directions=np.linalg.eig(stress);
    111111                idx=abs(value).argsort()[::-1] # sort in descending order
    112112                value=value[idx]
     
    116116
    117117                #eigenvalues and vectors for strain
    118                 value,directions=npy.linalg.eig(strain);
     118                value,directions=np.linalg.eig(strain);
    119119                idx=abs(value).argsort()[::-1] # sort in descending order
    120120                value=value[idx]
     
    133133        stress.principalvalue2=valuesstress[:,1]
    134134        stress.principalaxis2=directionsstress[:,2:4]
    135         stress.effectivevalue=1./npy.sqrt(2.)*npy.sqrt(stress.xx**2+stress.yy**2+2.*stress.xy**2)
     135        stress.effectivevalue=1./np.sqrt(2.)*np.sqrt(stress.xx**2+stress.yy**2+2.*stress.xy**2)
    136136        md.results.stress=stress
    137137       
     
    144144        strainrate.principalvalue2=valuesstrain[:,1]*md.constants.yts
    145145        strainrate.principalaxis2=directionsstrain[:,2:4]
    146         strainrate.effectivevalue=1./npy.sqrt(2.)*npy.sqrt(strainrate.xx**2+strainrate.yy**2+2.*strainrate.xy**2)
     146        strainrate.effectivevalue=1./np.sqrt(2.)*np.sqrt(strainrate.xx**2+strainrate.yy**2+2.*strainrate.xy**2)
    147147        md.results.strainrate=strainrate
    148148       
     
    155155        deviatoricstress.principalvalue2=valuesstress[:,1]
    156156        deviatoricstress.principalaxis2=directionsstress[:,2:4]
    157         deviatoricstress.effectivevalue=1./npy.sqrt(2.)*npy.sqrt(stress.xx**2+stress.yy**2+2.*stress.xy**2)
     157        deviatoricstress.effectivevalue=1./np.sqrt(2.)*np.sqrt(stress.xx**2+stress.yy**2+2.*stress.xy**2)
    158158        md.results.deviatoricstress=deviatoricstress
    159159
Note: See TracChangeset for help on using the changeset viewer.