Changeset 26376
- Timestamp:
- 08/03/21 13:52:37 (4 years ago)
- Location:
- issm/trunk-jpl/src/m/interp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/interp/averaging.m
r25758 r26376 73 73 linesize=rep*numberofelements; 74 74 75 %update weights that hold sthe volume of all the element holding the node i75 %update weights that hold the volume of all the element holding the node i 76 76 weights=sparse(line,ones(linesize,1),repmat(areas,rep,1),numberofnodes,1); 77 77 -
issm/trunk-jpl/src/m/interp/averaging.py
r26372 r26376 39 39 # Initialization 40 40 if layer == 0: 41 weights = np.zeros( md.mesh.numberofvertices,)41 weights = np.zeros((md.mesh.numberofvertices, )) 42 42 data = np.asarray(data).flatten() 43 43 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, :] 46 46 47 47 # Load some variables (it is much faster if the variables are loaded from md once for all) … … 56 56 57 57 # Build some variables 58 if md.mesh.dimension() == 3 and layer == 0:58 if (md.mesh.dimension() == 3) & (layer == 0): 59 59 rep = 6 60 60 areas = GetAreas(index, md.mesh.x, md.mesh.y, md.mesh.z) … … 67 67 68 68 index = index - 1 # Python indexes from zero 69 line = index.flatten()69 line=index.T.flatten() 70 70 areas = np.vstack(areas).reshape(-1, ) 71 summation = 1. / rep * np.ones( rep,)71 summation = 1. / rep * np.ones((rep,1) ) 72 72 linesize = rep * numberofelements 73 73 74 # Update weights that hold sthe volume of all the element holding the node i75 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)) 76 76 77 77 # Initialization 78 78 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 / weights79 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) 81 81 average_node = csc_matrix(average_node) 82 82 else: … … 85 85 # Loop over iteration 86 86 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 / weights87 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) 90 90 average_node = csc_matrix(average_node) 91 91
Note:
See TracChangeset
for help on using the changeset viewer.