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

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

CHG: added 25834-26739

File size: 4.0 KB
RevLine 
[26740]1Index: ../trunk-jpl/src/m/interp/averaging.m
2===================================================================
3--- ../trunk-jpl/src/m/interp/averaging.m (revision 26375)
4+++ ../trunk-jpl/src/m/interp/averaging.m (revision 26376)
5@@ -72,7 +72,7 @@
6 summation=1/rep*ones(rep,1);
7 linesize=rep*numberofelements;
8
9-%update weights that holds the volume of all the element holding the node i
10+%update weights that hold the volume of all the element holding the node i
11 weights=sparse(line,ones(linesize,1),repmat(areas,rep,1),numberofnodes,1);
12
13 %initialization
14Index: ../trunk-jpl/src/m/interp/averaging.py
15===================================================================
16--- ../trunk-jpl/src/m/interp/averaging.py (revision 26375)
17+++ ../trunk-jpl/src/m/interp/averaging.py (revision 26376)
18@@ -38,11 +38,11 @@
19
20 # Initialization
21 if layer == 0:
22- weights = np.zeros(md.mesh.numberofvertices, )
23+ weights = np.zeros((md.mesh.numberofvertices, ))
24 data = np.asarray(data).flatten()
25 else:
26- weights = np.zeros(md.mesh.numberofvertices2d, )
27- data = data[(layer - 1) * md.mesh.numberofvertices2d + 1:layer * md.mesh.numberofvertices2d, :]
28+ weights = np.zeros((md.mesh.numberofvertices2d, ))
29+ data = data[(layer - 1) * md.mesh.numberofvertices2d + 1:layer * md.mesh.numberofvertices2d - 1, :]
30
31 # Load some variables (it is much faster if the variables are loaded from md once for all)
32 if layer == 0:
33@@ -55,7 +55,7 @@
34 numberofelements = md.mesh.numberofelements2d
35
36 # Build some variables
37- if md.mesh.dimension() == 3 and layer == 0:
38+ if (md.mesh.dimension() == 3) & (layer == 0):
39 rep = 6
40 areas = GetAreas(index, md.mesh.x, md.mesh.y, md.mesh.z)
41 elif md.mesh.dimension() == 2:
42@@ -66,18 +66,18 @@
43 areas = GetAreas(index, md.mesh.x2d, md.mesh.y2d)
44
45 index = index - 1 # Python indexes from zero
46- line = index.flatten()
47+ line=index.T.flatten()
48 areas = np.vstack(areas).reshape(-1, )
49- summation = 1. / rep * np.ones(rep, )
50+ summation = 1. / rep * np.ones((rep,1) )
51 linesize = rep * numberofelements
52
53- # Update weights that holds the volume of all the element holding the node i
54- weights = csc_matrix((np.tile(areas, (rep, 1)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
55+ # Update weights that hold the volume of all the element holding the node i
56+ weights = csc_matrix((np.tile(areas, (1, rep)).reshape(-1,), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
57
58 # Initialization
59 if len(data) == numberofelements:
60- average_node = csc_matrix((np.tile(areas * data, (rep, 1)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
61- average_node = average_node / weights
62+ average_node = csc_matrix((np.tile(np.multiply(areas,data), (1, rep)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
63+ average_node = np.divide(average_node,weights)
64 average_node = csc_matrix(average_node)
65 else:
66 average_node = csc_matrix(data.reshape(-1, 1))
67@@ -84,9 +84,9 @@
68
69 # Loop over iteration
70 for i in np.arange(1, iterations + 1):
71- average_el = np.asarray(np.dot(average_node.todense()[index].reshape(numberofelements, rep), np.vstack(summation))).reshape(-1, )
72- average_node = csc_matrix((np.tile(areas * average_el.reshape(-1), (rep, 1)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
73- average_node = average_node / weights
74+ average_el = np.asarray(average_node.todense()[index].reshape(numberofelements, rep)*summation).reshape(-1, )
75+ average_node = csc_matrix((np.tile(np.multiply(areas,average_el.reshape(-1)), (1, rep)).reshape(-1, ), (line, np.zeros(linesize, ))), shape=(numberofnodes, 1))
76+ average_node = np.divide(average_node,weights)
77 average_node = csc_matrix(average_node)
78
79 # Return output as a full matrix (C code does not like sparse matrices)
Note: See TracBrowser for help on using the repository browser.