source: issm/oecreview/Archive/25834-26739/ISSM-26375-26376.diff@ 27230

Last change on this file since 27230 was 26740, checked in by Mathieu Morlighem, 3 years ago

CHG: added 25834-26739

File size: 4.0 KB
  • ../trunk-jpl/src/m/interp/averaging.m

     
    7272summation=1/rep*ones(rep,1);
    7373linesize=rep*numberofelements;
    7474
    75 %update weights that holds the volume of all the element holding the node i
     75%update weights that hold the volume of all the element holding the node i
    7676weights=sparse(line,ones(linesize,1),repmat(areas,rep,1),numberofnodes,1);
    7777
    7878%initialization
  • ../trunk-jpl/src/m/interp/averaging.py

     
    3838
    3939    # Initialization
    4040    if layer == 0:
    41         weights = np.zeros(md.mesh.numberofvertices, )
     41        weights = np.zeros((md.mesh.numberofvertices, ))
    4242        data = np.asarray(data).flatten()
    4343    else:
    44         weights = np.zeros(md.mesh.numberofvertices2d, )
    45         data = data[(layer - 1) * md.mesh.numberofvertices2d + 1:layer * md.mesh.numberofvertices2d, :]
     44        weights = np.zeros((md.mesh.numberofvertices2d, ))
     45        data = data[(layer - 1) * md.mesh.numberofvertices2d + 1:layer * md.mesh.numberofvertices2d - 1, :]
    4646
    4747    # Load some variables (it is much faster if the variables are loaded from md once for all)
    4848    if layer == 0:
     
    5555        numberofelements = md.mesh.numberofelements2d
    5656
    5757    # Build some variables
    58     if md.mesh.dimension() == 3 and layer == 0:
     58    if (md.mesh.dimension() == 3) & (layer == 0):
    5959        rep = 6
    6060        areas = GetAreas(index, md.mesh.x, md.mesh.y, md.mesh.z)
    6161    elif md.mesh.dimension() == 2:
     
    6666        areas = GetAreas(index, md.mesh.x2d, md.mesh.y2d)
    6767
    6868    index = index - 1  # Python indexes from zero
    69     line = index.flatten()
     69    line=index.T.flatten()
    7070    areas = np.vstack(areas).reshape(-1, )
    71     summation = 1. / rep * np.ones(rep, )
     71    summation = 1. / rep * np.ones((rep,1) )
    7272    linesize = rep * numberofelements
    7373
    74     # Update weights that holds the volume of all the element holding the node i
    75     weights = csc_matrix((np.tile(areas, (rep, 1)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
     74    # Update weights that hold the volume of all the element holding the node i
     75    weights = csc_matrix((np.tile(areas, (1, rep)).reshape(-1,), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
    7676
    7777    # Initialization
    7878    if len(data) == numberofelements:
    79         average_node = csc_matrix((np.tile(areas * data, (rep, 1)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
    80         average_node = average_node / weights
     79        average_node = csc_matrix((np.tile(np.multiply(areas,data), (1, rep)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
     80        average_node = np.divide(average_node,weights)
    8181        average_node = csc_matrix(average_node)
    8282    else:
    8383        average_node = csc_matrix(data.reshape(-1, 1))
     
    8484
    8585    # Loop over iteration
    8686    for i in np.arange(1, iterations + 1):
    87         average_el = np.asarray(np.dot(average_node.todense()[index].reshape(numberofelements, rep), np.vstack(summation))).reshape(-1, )
    88         average_node = csc_matrix((np.tile(areas * average_el.reshape(-1), (rep, 1)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
    89         average_node = average_node / weights
     87        average_el = np.asarray(average_node.todense()[index].reshape(numberofelements, rep)*summation).reshape(-1, )
     88        average_node = csc_matrix((np.tile(np.multiply(areas,average_el.reshape(-1)), (1, rep)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
     89        average_node = np.divide(average_node,weights)
    9090        average_node = csc_matrix(average_node)
    9191
    9292    # Return output as a full matrix (C code does not like sparse matrices)
Note: See TracBrowser for help on using the repository browser.