@@ -138,6 +138,53 @@ def test_surface(self):
138138 self .assertEqual (m .cell [7 ].num_neighbours , 5 )
139139 self .assertEqual (m .cell [- 1 ].num_neighbours , 3 )
140140
141+ def test_bottom (self ):
142+
143+ dx = [10. ]* 3 ; dy = [12. ] * 3
144+ dz = [1. , 2. , 3. ]
145+
146+ bottom = {4 : - 3 }
147+ m = mesh .mesh (rectangular = (dx , dy , dz ), bottom = bottom )
148+ self .assertEqual (m .num_cells , 26 )
149+ self .assertEqual ([col .num_cells for col in m .column ],
150+ [3 , 3 , 3 , 3 , 2 , 3 , 3 , 3 , 3 ])
151+ self .assertEqual ([lay .num_cells for lay in m .layer ],
152+ [9 , 9 , 8 ])
153+ self .assertEqual (m .volume , 6120 )
154+ self .assertEqual ([c .index for c in m .surface_cells ],
155+ list (range (9 )))
156+ self .assertEqual ([c .index for c in m .bottom_cells ],
157+ [18 , 19 , 20 , 21 , 13 , 22 , 23 , 24 , 25 ])
158+
159+ bottom = [- 3 ] * 9
160+ m = mesh .mesh (rectangular = (dx , dy , dz ), bottom = bottom )
161+ self .assertEqual (m .num_cells , 18 )
162+ self .assertEqual ([col .num_cells for col in m .column ], [2 ] * 9 )
163+ self .assertEqual ([lay .num_cells for lay in m .layer ], [9 , 9 , 0 ])
164+ self .assertEqual (m .volume , 3240 )
165+ self .assertEqual ([c .index for c in m .surface_cells ], list (range (9 )))
166+ self .assertEqual ([c .index for c in m .bottom_cells ], list (range (9 , 18 )))
167+
168+ bottom = [- 1 , - 3 , - 6 ] * 3
169+ m = mesh .mesh (rectangular = (dx , dy , dz ), bottom = bottom )
170+ self .assertEqual ([col .num_cells for col in m .column ], [1 , 2 , 3 ] * 3 )
171+ self .assertEqual ([lay .num_cells for lay in m .layer ], [9 , 6 , 3 ])
172+ self .assertEqual (m .volume , 3600 )
173+ self .assertEqual ([c .index for c in m .bottom_cells ],
174+ [0 , 9 , 15 , 3 , 11 , 16 , 6 , 13 , 17 ])
175+
176+ surface = {2 : - 1 , 5 :- 1 , 8 :- 1 }
177+ bottom = [- 1 , - 3 , - 6 ] * 3
178+ m = mesh .mesh (rectangular = (dx , dy , dz ),
179+ surface = surface , bottom = bottom )
180+ self .assertEqual ([col .num_cells for col in m .column ], [1 , 2 , 2 ] * 3 )
181+ self .assertEqual ([lay .num_cells for lay in m .layer ], [6 , 6 , 3 ])
182+ self .assertEqual (m .volume , 3240 )
183+ self .assertEqual ([c .index for c in m .surface_cells ],
184+ [0 , 1 , 7 , 2 , 3 , 9 , 4 , 5 , 11 ])
185+ self .assertEqual ([c .index for c in m .bottom_cells ],
186+ [0 , 6 , 12 , 2 , 8 , 13 , 4 , 10 , 14 ])
187+
141188 def test_translate (self ):
142189
143190 dx = [10 , 20 , 30 ]; dy = [20 , 15 , 10 ]
@@ -194,6 +241,14 @@ def test_meshio_points_cells(self):
194241 self .assertEqual (len (points ), 14 * 4 )
195242 self .assertEqual (len (cells ['hexahedron' ]), 21 )
196243
244+ surface = {2 : - 1 , 5 :- 1 , 8 :- 1 }
245+ bottom = [- 1 , - 3 , - 6 ] * 3
246+ m = mesh .mesh (rectangular = (dx , dy , dz ),
247+ surface = surface , bottom = bottom )
248+ points , cells = m .meshio_points_cells
249+ self .assertEqual (len (points ), 48 )
250+ self .assertEqual (len (cells ['hexahedron' ]), 15 )
251+
197252 def test_find (self ):
198253
199254 poly = [[8 , - 5 ], [11 , 40 ], [20 , 35 ], [40 , 10 ], [20 , - 5 ]]
@@ -389,6 +444,20 @@ def test_find(self):
389444 c = m .find ([8 , - 8 , - 10 ], indices = True )
390445 self .assertEqual (c , 3 )
391446
447+ # surface and bottom:
448+ dx = [10. ]* 3 ; dy = [12. ] * 3 ; dz = [1. , 2. , 3. ]
449+ surface = {2 : - 1 , 5 :- 1 , 8 :- 1 }
450+ bottom = [- 1 , - 3 , - 6 ] * 3
451+ m = mesh .mesh (rectangular = (dx , dy , dz ),
452+ surface = surface , bottom = bottom )
453+
454+ lay = m .find (- 0.5 , indices = True )
455+ self .assertEqual (0 , lay )
456+ c = m .find ([5 , 8 ], indices = True )
457+ self .assertEqual (0 , c )
458+ c = m .find ([25 , 14 , - 5 ], indices = True )
459+ self .assertEqual (c , 13 )
460+
392461 def test_column_track (self ):
393462
394463 dx = [10 ] * 3 ; dy = [20 ] * 4
@@ -462,7 +531,9 @@ def test_io(self):
462531 dx = [10. ]* 3 ; dy = [12. ] * 3
463532 dz = [1. , 2. , 3. ]
464533 s = [0 , 0 , - 1.5 , - 1.8 , - 2.1 , - 2.8 , - 3 , - 1 , 0 ]
465- m1 = mesh .mesh (rectangular = (dx , dy , dz ), surface = s )
534+ b = [- 3 , - 3 , - 6 , - 3 , - 6 , - 6 , - 6 , - 6 , - 6 ]
535+ m1 = mesh .mesh (rectangular = (dx , dy , dz ),
536+ surface = s , bottom = b )
466537 refine_cols = m1 .find ([(0 , 0 ), (10 , 10 )])
467538 m1 .refine (refine_cols )
468539 filename = 'mesh.h5'
@@ -533,6 +604,16 @@ def f(pos): return -(0.1 * pos[0] + 0.01 * pos[0] * pos[1])
533604 for col in m .column ])
534605 self .assertTrue (np .allclose (expected [:, 2 ], m .surface ))
535606
607+ # surface and bottom:
608+ m = mesh .mesh (rectangular = (dx , dy , dz ))
609+ def f (pos ): return - (pos [0 ] / 150. + pos [0 ] * pos [1 ] / 300. )
610+ z = np .array ([f (p ) for p in colpos ])
611+ surface = np .hstack ((colpos , np .vstack (z )))
612+ bottom = surface - 3.
613+ m .fit_surface (surface )
614+ m .fit_bottom (bottom )
615+ self .assertEqual (21 , m .num_cells )
616+
536617 def test_refine (self ):
537618
538619 def cell_types_in_order (m ):
0 commit comments