source: issm/oecreview/Archive/13393-13976/ISSM-13471-13472.diff@ 13980

Last change on this file since 13980 was 13980, checked in by Mathieu Morlighem, 12 years ago

preparing oecreview for 13393-13976'

File size: 4.0 KB
  • ../trunk-jpl/src/m/geometry/GetAreas.py

     
     1import numpy
     2
     3def GetAreas(index,x,y,z=numpy.array([])):
     4        """
     5        GETAREAS - compute areas or volumes of elements
     6
     7           compute areas of triangular elements or volumes
     8           of pentahedrons
     9
     10           Usage:
     11              areas  =GetAreas(index,x,y);
     12              volumes=GetAreas(index,x,y,z);
     13
     14           Examples:
     15              areas  =GetAreas(md.mesh.elements,md.mesh.x,md.mesh.y);
     16              volumes=GetAreas(md.mesh.elements,md.mesh.x,md.mesh.y,md.z);
     17        """
     18
     19        #get number of elements and number of nodes
     20        nels=numpy.size(index,axis=0)
     21        nods=numpy.size(x)
     22
     23        #some checks
     24        if numpy.size(y)!=nods or (z and numpy.size(z)!=nods):
     25                raise TypeError("GetAreas error message: x,y and z do not have the same length.")
     26        if numpy.max(index)>nods:
     27                raise TypeError("GetAreas error message: index should not have values above %d." % nods)
     28        if (not z and numpy.size(index,axis=1)!=3):
     29                raise TypeError("GetAreas error message: index should have 3 columns for 2d meshes.")
     30        if (z and numpy.size(index,axis=1)!=6):
     31                raise TypeError("GetAreas error message: index should have 6 columns for 3d meshes.")
     32
     33        #initialization
     34        areas=numpy.zeros(nels)
     35        x1=x[index[:,0].astype(int)-1]
     36        x2=x[index[:,1].astype(int)-1]
     37        x3=x[index[:,2].astype(int)-1]
     38        y1=y[index[:,0].astype(int)-1]
     39        y2=y[index[:,1].astype(int)-1]
     40        y3=y[index[:,2].astype(int)-1]
     41
     42        #compute the volume of each element
     43        if not z:
     44                #compute the surface of the triangle
     45                areas=(0.5*((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1)))
     46        else:
     47                #V=area(triangle)*1/3(z1+z2+z3)
     48                thickness=numpy.mean(z[index[:,3:6].astype(int)-1])-numpy.mean(z[index[:,0:3].astype(int)-1])
     49                areas=(0.5*((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1)))*thickness
     50
     51        return areas
     52
  • ../trunk-jpl/src/m/mesh/GetNodalFunctionsCoeff.py

     
     1import numpy
     2
     3def GetNodalFunctionsCoeff(index,x,y):
     4        """
     5        GETNODELFUNCTIONSCOEFF - compute nodal functions coefficients
     6
     7           Compute the coefficients alpha beta and optionaly gamma of
     8           2d triangular elements. For each element, the nodal function
     9           is defined as:
     10           N(x,y)=sum(i=1:3) alpha_i * x + beta_i * y + gamma_i
     11
     12           Usage:
     13              [alpha beta]=GetNodalFunctionsCoeff(index,x,y);
     14              [alpha beta gamma]=GetNodalFunctionsCoeff(index,x,y);
     15
     16           Example:
     17              [alpha beta gamma]=GetNodalFunctionsCoeff(md.mesh.elements,md.mesh.x,md.mesh.y);
     18        """
     19
     20        #make columns out of x and y
     21        x=x.rshape(-1)
     22        y=y.rshape(-1)
     23
     24        #get nels and nods
     25        nels=numpy.size(index,axis=0)
     26        nods=numpy.size(x)
     27
     28        #some checks
     29        if numpy.size(y)!=nods:
     30                raise TypeError("GetNodalFunctionsCoeff error message: x and y do not have the same length.")
     31        if numpy.max(index)>nods:
     32                raise TypeError("GetNodalFunctionsCoeff error message: index should not have values above %d." % nods)
     33        if numpy.size(index,axis=1)!=3:
     34                raise TypeError("GetNodalFunctionsCoeff error message: only 2d meshes supported. index should have 3 columns.")
     35
     36        #initialize output
     37        alpha=numpy.zeros((nels,3))
     38        beta=numpy.zeros((nels,3))
     39
     40        #compute nodal functions coefficients N(x,y)=alpha x + beta y +gamma
     41        x1=x[index[:,0].astype(int)-1]
     42        x2=x[index[:,1].astype(int)-1]
     43        x3=x[index[:,2].astype(int)-1]
     44        y1=y[index[:,0].astype(int)-1]
     45        y2=y[index[:,1].astype(int)-1]
     46        y3=y[index[:,2].astype(int)-1]
     47        invdet=1./(x1*(y2-y3)-x2*(y1-y3)+x3*(y1-y2))
     48
     49        #get alpha and beta
     50        alpha=numpy.hstack((invdet*(y2-y3),invdet*(y3-y1),invdet*(y1-y2)))
     51        beta =numpy.hstack((invdet*(x3-x2),invdet*(x1-x3),invdet*(x2-x1)))
     52
     53        #get gamma if requested
     54        gamma=numpy.zeros((nels,3))
     55        gamma=numpy.hstack((invdet*(x2*y3-x3*y2),invdet*(y1*x3-y3*x1),invdet*(x1*y2-x2*y1)))
     56
     57        return alpha,beta,gamma
     58
Note: See TracBrowser for help on using the repository browser.