Exemple #1
0
    def test_same_dofs(self):
        #
        # Construct nested mesh
        #
        mesh = QuadMesh()
        mesh.record(0)

        for dummy in range(2):
            mesh.cells.refine()
        #
        # Define dofhandler
        #
        element = QuadFE(mesh.dim(), 'Q1')
        dofhandler = DofHandler(mesh, element)
        dofhandler.distribute_dofs()

        #
        # Define basis functions
        #
        phi0 = Basis(dofhandler, 'u', subforest_flag=0)
        phi0_x = Basis(dofhandler, 'ux', subforest_flag=0)
        phi1 = Basis(dofhandler, 'u')

        self.assertTrue(phi0.same_mesh(phi0_x))
        self.assertFalse(phi0.same_mesh(phi1))
Exemple #2
0
 def test_get_boundary_segments(self):
     """
     Test 
     """
     #
     # Define Mesh
     # 
     mesh = QuadMesh(resolution=(2,2))
     mesh.record('mesh_1')
     mesh.cells.get_child(2).mark('1')
     mesh.cells.refine(refinement_flag='1') 
     
     #
     # 
     # 
     for segment in mesh.get_boundary_segments(subforest_flag=None):
         for he in segment:
             pass
Exemple #3
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,))
Exemple #4
0
from mpl_toolkits import mplot3d
"""
Test the evaluation of basis functions over sub-meshes.

"""
# Test something with a dictionary
a = {}
a[None] = 1
a['other'] = 0
print(a[None])
print(a['other'])
print(a)
#%%

mesh = QuadMesh(box=[0, 1, 0, 2])
mesh.record('coarse')
mesh.cells.refine(new_label='fine')

Q1 = QuadFE(mesh.dim(), 'Q1')
Q0 = QuadFE(mesh.dim(), 'DQ0')

dhQ1 = DofHandler(mesh, Q1)
dhQ1.distribute_dofs()

dhQ0 = DofHandler(mesh, Q0)
dhQ0.distribute_dofs()

phi_0 = Basis(dhQ1)
print(phi_0.subforest_flag())
phi_1 = Basis(dhQ1, subforest_flag='coarse')
cell = mesh.cells.get_leaves(subforest_flag='coarse')[0]