Changeset 13482


Ignore:
Timestamp:
09/28/12 16:04:47 (12 years ago)
Author:
jschierm
Message:

NEW: New python functions in support of test514.py (which doesn't yet work).

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/mesh/ComputeHessian.m

    r9734 r13482  
    2020        error('ComputeHessian error message: the given field size not supported yet');
    2121end
    22 if strcmpi(type,'node') & strcmpi(type,'element'),
     22if ~strcmpi(type,'node') & ~strcmpi(type,'element'),
    2323        error('ComputeHessian error message: only ''node'' or ''element'' type supported yet');
    2424end
     
    2828linesize=3*numberofelements;
    2929
    30 %get areas and  nodal functions coefficients N(x,y)=alpha x + beta y + gamma
     30%get areas and nodal functions coefficients N(x,y)=alpha x + beta y + gamma
    3131[alpha beta]=GetNodalFunctionsCoeff(index,x,y);
    3232areas=GetAreas(index,x,y);
    3333
    34 %comput weights that holds the volume of all the element holding the node i
     34%compute weights that hold the volume of all the element holding the node i
    3535weights=sparse(line,ones(linesize,1),repmat(areas,3,1),numberofnodes,1);
    3636
  • issm/trunk-jpl/src/m/mesh/ComputeMetric.m

    r9224 r13482  
    99%      metric=ComputeMetric(hessian,2/9,10^-1,100,10^5,find(md.nodeonwater)
    1010
    11 %first, find the eigen values of eah line of H=[hessian(i,1) hessian(i,2); hessian(i,2) hessian(i,3)]
     11%first, find the eigen values of each line of H=[hessian(i,1) hessian(i,2); hessian(i,2) hessian(i,3)]
    1212a=hessian(:,1); b=hessian(:,2); d=hessian(:,3);
    13 lambda1=0.5*((a+d)+sqrt(4*b.^2+(a-d).^2));
    14 lambda2=0.5*((a+d)-sqrt(4*b.^2+(a-d).^2));
     13lambda1=0.5*((a+d)+sqrt(4.*b.^2+(a-d).^2));
     14lambda2=0.5*((a+d)-sqrt(4.*b.^2+(a-d).^2));
    1515pos1=find(lambda1==0);
    1616pos2=find(lambda2==0);
     
    1818
    1919%Modify the eigen values to control the shape of the elements
    20 lambda1=min(max(abs(lambda1)*scale/epsilon,1/hmax^2),1/hmin^2);
    21 lambda2=min(max(abs(lambda2)*scale/epsilon,1/hmax^2),1/hmin^2);
     20lambda1=min(max(abs(lambda1)*scale/epsilon,1./hmax^2),1./hmin^2);
     21lambda2=min(max(abs(lambda2)*scale/epsilon,1./hmax^2),1./hmin^2);
    2222
    2323%compute eigen vectors
    24 norm1=sqrt(8*b.^2+2*(d-a).^2+2*(d-a).*sqrt((a-d).^2+4*b.^2));
    25 v1x=2*b./norm1;
    26 v1y=((d-a)+sqrt((a-d).^2+4*b.^2))./norm1;
    27 norm2=sqrt(8*b.^2+2*(d-a).^2-2*(d-a).*sqrt((a-d).^2+4*b.^2));
    28 v2x=2*b./norm2;
    29 v2y=((d-a)-sqrt((a-d).^2+4*b.^2))./norm2;
     24norm1=sqrt(8.*b.^2+2.*(d-a).^2+2.*(d-a).*sqrt((a-d).^2+4.*b.^2));
     25v1x=2.*b./norm1;
     26v1y=((d-a)+sqrt((a-d).^2+4.*b.^2))./norm1;
     27norm2=sqrt(8.*b.^2+2.*(d-a).^2-2.*(d-a).*sqrt((a-d).^2+4.*b.^2));
     28v2x=2.*b./norm2;
     29v2y=((d-a)-sqrt((a-d).^2+4.*b.^2))./norm2;
    3030
    31 v1x(pos3)=1; v1y(pos3)=0;
    32 v2x(pos3)=0; v2y(pos3)=1;
     31v1x(pos3)=1.; v1y(pos3)=0.;
     32v2x(pos3)=0.; v2y(pos3)=1.;
    3333
    3434%Compute new metric (for each node M=V*Lambda*V^-1)
     
    3838
    3939%some corrections for 0 eigen values
    40 metric(pos1,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos1),1);
    41 metric(pos2,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos2),1);
     40metric(pos1,:)=repmat([1./hmax^2 0. 1./hmax^2],length(pos1),1);
     41metric(pos2,:)=repmat([1./hmax^2 0. 1./hmax^2],length(pos2),1);
    4242
    4343%take care of water elements
    44 metric(pos,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos),1);
     44metric(pos,:)=repmat([1./hmax^2 0. 1./hmax^2],length(pos),1);
    4545
    4646%take care of NaNs if any (use Matlab eig in a loop)
     
    5454                lambda1=v(1,1);
    5555                lambda2=v(2,2);
    56                 v(1,1)=min(max(abs(lambda1)*scale/epsilon,1/hmax^2),1/hmin^2);
    57                 v(2,2)=min(max(abs(lambda2)*scale/epsilon,1/hmax^2),1/hmin^2);
     56                v(1,1)=min(max(abs(lambda1)*scale/epsilon,1./hmax^2),1./hmin^2);
     57                v(2,2)=min(max(abs(lambda2)*scale/epsilon,1./hmax^2),1./hmin^2);
    5858
    5959                metricTria=u*v*u^(-1);
  • issm/trunk-jpl/src/m/mesh/GetNodalFunctionsCoeff.py

    r13472 r13482  
    1919
    2020        #make columns out of x and y
    21         x=x.rshape(-1)
    22         y=y.rshape(-1)
     21        x=x.reshape(-1)
     22        y=y.reshape(-1)
    2323
    2424        #get nels and nods
     
    4848
    4949        #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)))
     50        alpha=numpy.hstack(((invdet*(y2-y3)).reshape(-1,1),(invdet*(y3-y1)).reshape(-1,1),(invdet*(y1-y2)).reshape(-1,1)))
     51        beta =numpy.hstack(((invdet*(x3-x2)).reshape(-1,1),(invdet*(x1-x3)).reshape(-1,1),(invdet*(x2-x1)).reshape(-1,1)))
    5252
    5353        #get gamma if requested
    5454        gamma=numpy.zeros((nels,3))
    55         gamma=numpy.hstack((invdet*(x2*y3-x3*y2),invdet*(y1*x3-y3*x1),invdet*(x1*y2-x2*y1)))
     55        gamma=numpy.hstack(((invdet*(x2*y3-x3*y2)).reshape(-1,1),(invdet*(y1*x3-y3*x1)).reshape(-1,1),(invdet*(x1*y2-x2*y1)).reshape(-1,1)))
    5656
    5757        return alpha,beta,gamma
  • issm/trunk-jpl/src/m/mesh/bamg.py

    r13470 r13482  
    262262
    263263        elif isinstance(md.private.bamg,dict) and 'geometry' in md.private.bamg:
    264                 bamg_geometry=bamggeom(md.private.bamg['geometry'])
     264                bamg_geometry=bamggeom(md.private.bamg['geometry'].__dict__)
    265265        else:
    266266                #do nothing...
     
    310310
    311311        #call Bamg
    312         bamgmesh_out,bamggeom_out=BamgMesher(bamg_mesh.__dict__,bamg_geometry.__dict__,bamg_options)
     312        [bamgmesh_out,bamggeom_out]=BamgMesher(bamg_mesh.__dict__,bamg_geometry.__dict__,bamg_options)
    313313
    314314        # plug results onto model
  • issm/trunk-jpl/src/m/miscellaneous/MatlabFuncs.py

    r13436 r13482  
    7474                raise TypeError("MatlabFunc.det only implemented for shape (2, 2), not for shape %s." % str(a.shape))
    7575
     76def sparse(ivec,jvec,svec,m=0,n=0,nzmax=0):
     77        import numpy
     78
     79        if not m:
     80                m=numpy.max(ivec)
     81        if not n:
     82                n=numpy.max(jvec)
     83
     84        a=numpy.zeros((m,n))
     85
     86        for i,j,s in zip(ivec.reshape(-1,order='F'),jvec.reshape(-1,order='F'),svec.reshape(-1,order='F')):
     87                a[i-1,j-1]+=s
     88
     89        return a
     90
Note: See TracChangeset for help on using the changeset viewer.