[13980] | 1 | Index: ../trunk-jpl/src/m/geometry/GetAreas.py
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- ../trunk-jpl/src/m/geometry/GetAreas.py (revision 0)
|
---|
| 4 | +++ ../trunk-jpl/src/m/geometry/GetAreas.py (revision 13472)
|
---|
| 5 | @@ -0,0 +1,52 @@
|
---|
| 6 | +import numpy
|
---|
| 7 | +
|
---|
| 8 | +def GetAreas(index,x,y,z=numpy.array([])):
|
---|
| 9 | + """
|
---|
| 10 | + GETAREAS - compute areas or volumes of elements
|
---|
| 11 | +
|
---|
| 12 | + compute areas of triangular elements or volumes
|
---|
| 13 | + of pentahedrons
|
---|
| 14 | +
|
---|
| 15 | + Usage:
|
---|
| 16 | + areas =GetAreas(index,x,y);
|
---|
| 17 | + volumes=GetAreas(index,x,y,z);
|
---|
| 18 | +
|
---|
| 19 | + Examples:
|
---|
| 20 | + areas =GetAreas(md.mesh.elements,md.mesh.x,md.mesh.y);
|
---|
| 21 | + volumes=GetAreas(md.mesh.elements,md.mesh.x,md.mesh.y,md.z);
|
---|
| 22 | + """
|
---|
| 23 | +
|
---|
| 24 | + #get number of elements and number of nodes
|
---|
| 25 | + nels=numpy.size(index,axis=0)
|
---|
| 26 | + nods=numpy.size(x)
|
---|
| 27 | +
|
---|
| 28 | + #some checks
|
---|
| 29 | + if numpy.size(y)!=nods or (z and numpy.size(z)!=nods):
|
---|
| 30 | + raise TypeError("GetAreas error message: x,y and z do not have the same length.")
|
---|
| 31 | + if numpy.max(index)>nods:
|
---|
| 32 | + raise TypeError("GetAreas error message: index should not have values above %d." % nods)
|
---|
| 33 | + if (not z and numpy.size(index,axis=1)!=3):
|
---|
| 34 | + raise TypeError("GetAreas error message: index should have 3 columns for 2d meshes.")
|
---|
| 35 | + if (z and numpy.size(index,axis=1)!=6):
|
---|
| 36 | + raise TypeError("GetAreas error message: index should have 6 columns for 3d meshes.")
|
---|
| 37 | +
|
---|
| 38 | + #initialization
|
---|
| 39 | + areas=numpy.zeros(nels)
|
---|
| 40 | + x1=x[index[:,0].astype(int)-1]
|
---|
| 41 | + x2=x[index[:,1].astype(int)-1]
|
---|
| 42 | + x3=x[index[:,2].astype(int)-1]
|
---|
| 43 | + y1=y[index[:,0].astype(int)-1]
|
---|
| 44 | + y2=y[index[:,1].astype(int)-1]
|
---|
| 45 | + y3=y[index[:,2].astype(int)-1]
|
---|
| 46 | +
|
---|
| 47 | + #compute the volume of each element
|
---|
| 48 | + if not z:
|
---|
| 49 | + #compute the surface of the triangle
|
---|
| 50 | + areas=(0.5*((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1)))
|
---|
| 51 | + else:
|
---|
| 52 | + #V=area(triangle)*1/3(z1+z2+z3)
|
---|
| 53 | + thickness=numpy.mean(z[index[:,3:6].astype(int)-1])-numpy.mean(z[index[:,0:3].astype(int)-1])
|
---|
| 54 | + areas=(0.5*((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1)))*thickness
|
---|
| 55 | +
|
---|
| 56 | + return areas
|
---|
| 57 | +
|
---|
| 58 | Index: ../trunk-jpl/src/m/mesh/GetNodalFunctionsCoeff.py
|
---|
| 59 | ===================================================================
|
---|
| 60 | --- ../trunk-jpl/src/m/mesh/GetNodalFunctionsCoeff.py (revision 0)
|
---|
| 61 | +++ ../trunk-jpl/src/m/mesh/GetNodalFunctionsCoeff.py (revision 13472)
|
---|
| 62 | @@ -0,0 +1,58 @@
|
---|
| 63 | +import numpy
|
---|
| 64 | +
|
---|
| 65 | +def GetNodalFunctionsCoeff(index,x,y):
|
---|
| 66 | + """
|
---|
| 67 | + GETNODELFUNCTIONSCOEFF - compute nodal functions coefficients
|
---|
| 68 | +
|
---|
| 69 | + Compute the coefficients alpha beta and optionaly gamma of
|
---|
| 70 | + 2d triangular elements. For each element, the nodal function
|
---|
| 71 | + is defined as:
|
---|
| 72 | + N(x,y)=sum(i=1:3) alpha_i * x + beta_i * y + gamma_i
|
---|
| 73 | +
|
---|
| 74 | + Usage:
|
---|
| 75 | + [alpha beta]=GetNodalFunctionsCoeff(index,x,y);
|
---|
| 76 | + [alpha beta gamma]=GetNodalFunctionsCoeff(index,x,y);
|
---|
| 77 | +
|
---|
| 78 | + Example:
|
---|
| 79 | + [alpha beta gamma]=GetNodalFunctionsCoeff(md.mesh.elements,md.mesh.x,md.mesh.y);
|
---|
| 80 | + """
|
---|
| 81 | +
|
---|
| 82 | + #make columns out of x and y
|
---|
| 83 | + x=x.rshape(-1)
|
---|
| 84 | + y=y.rshape(-1)
|
---|
| 85 | +
|
---|
| 86 | + #get nels and nods
|
---|
| 87 | + nels=numpy.size(index,axis=0)
|
---|
| 88 | + nods=numpy.size(x)
|
---|
| 89 | +
|
---|
| 90 | + #some checks
|
---|
| 91 | + if numpy.size(y)!=nods:
|
---|
| 92 | + raise TypeError("GetNodalFunctionsCoeff error message: x and y do not have the same length.")
|
---|
| 93 | + if numpy.max(index)>nods:
|
---|
| 94 | + raise TypeError("GetNodalFunctionsCoeff error message: index should not have values above %d." % nods)
|
---|
| 95 | + if numpy.size(index,axis=1)!=3:
|
---|
| 96 | + raise TypeError("GetNodalFunctionsCoeff error message: only 2d meshes supported. index should have 3 columns.")
|
---|
| 97 | +
|
---|
| 98 | + #initialize output
|
---|
| 99 | + alpha=numpy.zeros((nels,3))
|
---|
| 100 | + beta=numpy.zeros((nels,3))
|
---|
| 101 | +
|
---|
| 102 | + #compute nodal functions coefficients N(x,y)=alpha x + beta y +gamma
|
---|
| 103 | + x1=x[index[:,0].astype(int)-1]
|
---|
| 104 | + x2=x[index[:,1].astype(int)-1]
|
---|
| 105 | + x3=x[index[:,2].astype(int)-1]
|
---|
| 106 | + y1=y[index[:,0].astype(int)-1]
|
---|
| 107 | + y2=y[index[:,1].astype(int)-1]
|
---|
| 108 | + y3=y[index[:,2].astype(int)-1]
|
---|
| 109 | + invdet=1./(x1*(y2-y3)-x2*(y1-y3)+x3*(y1-y2))
|
---|
| 110 | +
|
---|
| 111 | + #get alpha and beta
|
---|
| 112 | + alpha=numpy.hstack((invdet*(y2-y3),invdet*(y3-y1),invdet*(y1-y2)))
|
---|
| 113 | + beta =numpy.hstack((invdet*(x3-x2),invdet*(x1-x3),invdet*(x2-x1)))
|
---|
| 114 | +
|
---|
| 115 | + #get gamma if requested
|
---|
| 116 | + gamma=numpy.zeros((nels,3))
|
---|
| 117 | + gamma=numpy.hstack((invdet*(x2*y3-x3*y2),invdet*(y1*x3-y3*x1),invdet*(x1*y2-x2*y1)))
|
---|
| 118 | +
|
---|
| 119 | + return alpha,beta,gamma
|
---|
| 120 | +
|
---|