Ignore:
Timestamp:
06/07/17 10:50:54 (8 years ago)
Author:
Eric.Larour
Message:

CHG: merged branch back to trunk-jpl 21754.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/branches/trunk-larour-NatGeoScience2016/src/py3/interp/averaging.py

    r19895 r21759  
    1 import numpy as npy
     1import numpy as np
    22from GetAreas import GetAreas
    33from scipy.sparse import csc_matrix
     
    3636        #initialization
    3737        if layer==0:
    38                 weights=npy.zeros(md.mesh.numberofvertices,)
     38                weights=np.zeros(md.mesh.numberofvertices,)
    3939                data=data.flatten(1)
    4040        else:
    41                 weights=npy.zeros(md.mesh.numberofvertices2d,)
     41                weights=np.zeros(md.mesh.numberofvertices2d,)
    4242                data=data[(layer-1)*md.mesh.numberofvertices2d+1:layer*md.mesh.numberofvertices2d,:]
    4343       
     
    6666        index=index-1 # since python indexes starting from zero
    6767        line=index.flatten(1)
    68         areas=npy.vstack(areas).reshape(-1,)
    69         summation=1./rep*npy.ones(rep,)
     68        areas=np.vstack(areas).reshape(-1,)
     69        summation=1./rep*np.ones(rep,)
    7070        linesize=rep*numberofelements
    7171       
    7272        #update weights that holds the volume of all the element holding the node i
    73         weights=csc_matrix( (npy.tile(areas,(rep,1)).reshape(-1,),(line,npy.zeros(linesize,))), shape=(numberofnodes,1))
     73        weights=csc_matrix( (np.tile(areas,(rep,1)).reshape(-1,),(line,np.zeros(linesize,))), shape=(numberofnodes,1))
    7474       
    7575        #initialization
    7676        if len(data)==numberofelements:
    77                 average_node=csc_matrix( (npy.tile(areas*data,(rep,1)).reshape(-1,),(line,npy.zeros(linesize,))), shape=(numberofnodes,1))
     77                average_node=csc_matrix( (np.tile(areas*data,(rep,1)).reshape(-1,),(line,np.zeros(linesize,))), shape=(numberofnodes,1))
    7878                average_node=average_node/weights
    7979                average_node = csc_matrix(average_node)
     
    8282
    8383        #loop over iteration
    84         for i in npy.arange(1,iterations+1):
    85                 average_el=npy.asarray(npy.dot(average_node.todense()[index].reshape(numberofelements,rep),npy.vstack(summation))).reshape(-1,)
    86                 average_node=csc_matrix( (npy.tile(areas*average_el.reshape(-1),(rep,1)).reshape(-1,),(line,npy.zeros(linesize,))), shape=(numberofnodes,1))
     84        for i in np.arange(1,iterations+1):
     85                average_el=np.asarray(np.dot(average_node.todense()[index].reshape(numberofelements,rep),np.vstack(summation))).reshape(-1,)
     86                average_node=csc_matrix( (np.tile(areas*average_el.reshape(-1),(rep,1)).reshape(-1,),(line,np.zeros(linesize,))), shape=(numberofnodes,1))
    8787                average_node=average_node/weights
    8888                average_node=csc_matrix(average_node)
    8989       
    9090        #return output as a full matrix (C code do not like sparse matrices)
    91         average=npy.asarray(average_node.todense()).reshape(-1,)
     91        average=np.asarray(average_node.todense()).reshape(-1,)
    9292
    9393        return average
Note: See TracChangeset for help on using the changeset viewer.