Beispiel #1
0
 def test_bin_points(self):
     # Construct mesh
     mesh = QuadMesh(resolution=(2,2))
     mesh.record(1)
     mesh.cells.get_child(0).mark('refine')
     mesh.cells.refine(refinement_flag='refine')
     
     #
     # Bin random points using the coarsest mesh
     #
     x = np.random.rand(5,2)
     bins = mesh.bin_points(x,subforest_flag=1)
     for cell, dummy in bins:
         self.assertEqual(cell.get_depth(),0)
     
     #
     # x
     # 
     x = np.array([[0.125,0.125]])
     bins = mesh.bin_points(x, subforest_flag=1)
     self.assertEqual(len(bins),1)
     for cell, dummy in bins:
         # Cell should be on level 0
         self.assertEqual(cell.get_depth(),0)
         
     # Bin over all cells
     bins = mesh.bin_points(x)
     self.assertEqual(len(bins),1)
     for cell, dummy in bins:
         # Cell should now be on level  1
         self.assertEqual(cell.get_depth(),1)
     
     # 
     # Out of bounds x
     # 
     x = np.array([[-1,-1]])
     self.assertRaises(Exception, mesh.bin_points, *(x,))
Beispiel #2
0
phi_y = Basis(dh_Q1, 'vy')

# =============================================================================
# Parameters
# =============================================================================
#

#
#  Locations of production wells (measurements)
#
n_production = (4, 3)  # resolution
x_production = np.linspace(0.5, 1.5, n_production[0])
y_production = np.linspace(0.2, 0.8, n_production[1])
X, Y = np.meshgrid(x_production, y_production)
xy = np.array([X.ravel(), Y.ravel()]).T
cells_production = mesh.bin_points(xy)

# Mark vertices
for cell, dummy in cells_production:
    cell.get_vertex(2).mark('production')

# Extract degrees of freedom
production_dofs = dh_Q1.get_region_dofs(entity_type='vertex',
                                        entity_flag='production')

v_production = dh_Q1.get_dof_vertices(dofs=production_dofs)

# Target pressure at production wells
z_fn = Explicit(f=lambda x: 3 - 4 * (x[:, 0] - 1)**2 - 8 * (x[:, 1] - 0.5)**2,
                dim=2,
                mesh=mesh)