@@ -107,6 +107,40 @@ def test_corsen(self):
107107 assert M ._index ([0 , 2 , 2 ]) not in M
108108 assert M ._index ([2 , 2 , 2 ]) not in M
109109
110+ def test_h_gridded_2D (self ):
111+ hx , hy = np .ones (4 ), np .r_ [1. , 2. , 3. , 4. ]
112+
113+ M = discretize .TreeMesh ([hx , hy ])
114+
115+ def refinefcn (cell ):
116+ xyz = cell .center
117+ d = (xyz ** 2 ).sum ()** 0.5
118+ if d < 3 :
119+ return 2
120+ return 1
121+
122+ M .refine (refinefcn )
123+ H = M .h_gridded
124+
125+ test_hx = np .all (H [:, 0 ] == np .r_ [1. , 1. , 1. , 1. , 2. , 2. , 2. ])
126+ test_hy = np .all (H [:, 1 ] == np .r_ [1. , 1. , 2. , 2. , 3. , 7. , 7. ])
127+
128+ self .assertTrue (test_hx and test_hy )
129+
130+ def test_h_gridded_updates (self ):
131+ mesh = discretize .TreeMesh ([8 , 8 ])
132+ mesh .refine (1 )
133+
134+ H = mesh .h_gridded
135+ self .assertTrue (np .all (H [:, 0 ] == 0.5 * np .ones (4 )))
136+ self .assertTrue (np .all (H [:, 1 ] == 0.5 * np .ones (4 )))
137+
138+ # refine the mesh and make sure h_gridded is updated
139+ mesh .refine (2 )
140+ H = mesh .h_gridded
141+ self .assertTrue (np .all (H [:, 0 ] == 0.25 * np .ones (16 )))
142+ self .assertTrue (np .all (H [:, 1 ] == 0.25 * np .ones (16 )))
143+
110144 def test_faceDiv (self ):
111145
112146 hx , hy = np .r_ [1. , 2 , 3 , 4 ], np .r_ [5. , 6 , 7 , 8 ]
@@ -233,6 +267,26 @@ def test_VectorIdenties(self):
233267 assert np .max (np .abs ((M .faceDiv * M .edgeCurl ).todense ().flatten ())) < TOL
234268 assert np .max (np .abs ((Mr .faceDiv * Mr .edgeCurl ).todense ().flatten ())) < TOL
235269
270+ def test_h_gridded_3D (self ):
271+ hx , hy , hz = np .ones (4 ), np .r_ [1. , 2. , 3. , 4. ], 2 * np .ones (4 )
272+
273+ M = discretize .TreeMesh ([hx , hy , hz ])
274+
275+ def refinefcn (cell ):
276+ xyz = cell .center
277+ d = (xyz ** 2 ).sum ()** 0.5
278+ if d < 3 :
279+ return 2
280+ return 1
281+
282+ M .refine (refinefcn )
283+ H = M .h_gridded
284+
285+ test_hx = np .all (H [:, 0 ] == np .r_ [1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 2. , 2. , 2. , 2. , 2. , 2. , 2. ])
286+ test_hy = np .all (H [:, 1 ] == np .r_ [1. , 1. , 2. , 2. , 1. , 1. , 2. , 2. , 3. , 7. , 7. , 3. , 3. , 7. , 7. ])
287+ test_hz = np .all (H [:, 2 ] == np .r_ [2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. , 4. , 4. , 4. , 4. , 4. , 4. , 4. ])
288+
289+ self .assertTrue (test_hx and test_hy and test_hz )
236290
237291class Test2DInterpolation (unittest .TestCase ):
238292
0 commit comments