source:
issm/oecreview/Archive/25834-26739/ISSM-26375-26376.diff@
26740
Last change on this file since 26740 was 26740, checked in by , 3 years ago | |
---|---|
File size: 4.0 KB |
-
../trunk-jpl/src/m/interp/averaging.m
72 72 summation=1/rep*ones(rep,1); 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 78 78 %initialization -
../trunk-jpl/src/m/interp/averaging.py
38 38 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) 48 48 if layer == 0: … … 55 55 numberofelements = md.mesh.numberofelements2d 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) 61 61 elif md.mesh.dimension() == 2: … … 66 66 areas = GetAreas(index, md.mesh.x2d, md.mesh.y2d) 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: 83 83 average_node = csc_matrix(data.reshape(-1, 1)) … … 84 84 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 92 92 # Return output as a full matrix (C code does not like sparse matrices)
Note:
See TracBrowser
for help on using the repository browser.