Changeset 26376


Ignore:
Timestamp:
08/03/21 13:52:37 (4 years ago)
Author:
schlegel
Message:

CHG: update comment and clean up python averaging

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/interp/averaging.m

    r25758 r26376  
    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
  • issm/trunk-jpl/src/m/interp/averaging.py

    r26372 r26376  
    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)
     
    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)
     
    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:
     
    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
Note: See TracChangeset for help on using the changeset viewer.