Beispiel #1
0
def test_calc_surfs_per_vol_vol():
    """Tests part of the calc_surfs_per_vol function"""
    three_vols = df.DagmcFile(test_env['three_vols'])
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, vol)
    three_vols_query.calc_surfs_per_vol()
    assert(sorted(three_vols_query._vol_data['surf_per_vol']) == [6])
Beispiel #2
0
def test_get_meshset_by_id():
    """
    Tests the get_meshset_by_id function given valid dim and id
    """
    three_vols = df.DagmcFile(test_env['single_cube'])
    test_pass = np.full(3, False)
    # get volume 0
    exp = three_vols._my_moab_core.get_entities_by_type_and_tag(
        three_vols.root_set, types.MBENTITYSET,
        three_vols.dagmc_tags['geom_dim'], [3])[0]
    obs = three_vols.get_meshset_by_id('volumes', ids=[1])
    if obs == exp:
        test_pass[0] = True

    obs_singular = three_vols.get_meshset_by_id('volume', ids=[1])
    obs_upper = three_vols.get_meshset_by_id('Volumes', ids=[1])
    obs_integer = three_vols.get_meshset_by_id(3, ids=[1])
    if obs == obs_singular == obs_upper == obs_integer:
        test_pass[1] = True

    # get volumes 0, 1
    exp = list(
        three_vols._my_moab_core.get_entities_by_type_and_tag(
            three_vols.root_set, types.MBENTITYSET,
            three_vols.dagmc_tags['geom_dim'], [3])[0:2])
    obs = three_vols.get_meshset_by_id('volumes', ids=[1, 2])
    if obs == exp:
        test_pass[2] = True
    assert (all(test_pass))
Beispiel #3
0
def test_get_entities_rootset():
    """Tests the get_entities function for rootset
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    three_vols_query = dq.DagmcQuery(three_vols, three_vols.root_set)
    exp = list(three_vols.entityset_ranges['surfaces'])
    assert(three_vols_query.meshset_lst == exp)
Beispiel #4
0
def test_calc_tris_per_surf_vol():
    """Tests part of the calc_tris_per_surf function"""
    three_vols = df.DagmcFile(test_env['three_vols'])
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, vol)
    three_vols_query.calc_tris_per_surf()
    assert(sorted(three_vols_query._surf_data['tri_per_surf']) == list(np.full(6,2)))
Beispiel #5
0
def test_calc_tris_per_vert_surf():
    """Tests the calc_tris_per_vert function for surface meshset
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    surf = three_vols.entityset_ranges['surfaces'][0]
    three_vols_query = dq.DagmcQuery(three_vols, surf)
    three_vols_query.calc_tris_per_vert()
    assert(sorted(three_vols_query._vert_data['tri_per_vert']) == [4, 4, 5, 5])
Beispiel #6
0
def test_calc_tris_per_vert_vol():
    """Tests part of the calc_tris_per_vert function"""
    three_vols = df.DagmcFile(test_env['three_vols'])
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, vol)
    three_vols_query.calc_tris_per_vert()
    assert(sorted(three_vols_query._vert_data['tri_per_vert']) == [
           4, 4, 4, 4, 5, 5, 5, 5])
Beispiel #7
0
def test_get_entities_vol():
    """Tests the get_entities function for volume meshset
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, vol)
    exp = list(three_vols._my_moab_core.get_child_meshsets(vol))
    assert(three_vols_query.meshset_lst == exp)
Beispiel #8
0
def test_get_entities_surf():
    """Tests the get_entities function for surface meshset
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    surf = three_vols.entityset_ranges['surfaces'][0]
    three_vols_query = dq.DagmcQuery(three_vols, surf)
    exp = [surf]
    assert(three_vols_query.meshset_lst == exp)
Beispiel #9
0
def test_get_tris_rootset():
    """Tests the tris variable given the rootset
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    three_vols_query = dq.DagmcQuery(three_vols, three_vols.root_set)
    obs_tris = three_vols_query.tris
    exp_tris = three_vols._my_moab_core.get_entities_by_type(
        three_vols.root_set, types.MBTRI)
    assert(sorted(obs_tris) == sorted(exp_tris))
Beispiel #10
0
def test_calc_area_triangle_vol():
    """Tests part of the calc_area_triangle function
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, vol)
    three_vols_query.calc_area_triangle()
    np.testing.assert_almost_equal(
        list(three_vols_query._tri_data['area']), list(np.full(12, 50)))
Beispiel #11
0
def test_coarseness():
    """Tests the calc coarseness function
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, vol)
    three_vols_query.calc_coarseness()
    np.testing.assert_almost_equal(
        list(three_vols_query._surf_data['coarseness']), list(np.full(6, 0.02)))
Beispiel #12
0
def test_set_dagmc_tags():
    """
    Tests different aspects of the set_dagmc_tags function
    """
    single_cube = df.DagmcFile(test_env['single_cube'])
    assert (len(single_cube.dagmc_tags) == 3)
    assert (single_cube.dagmc_tags['category'])
    assert (single_cube.dagmc_tags['geom_dim'])
    assert (single_cube.dagmc_tags['global_id'])
Beispiel #13
0
def test_get_entities_vol_and_surf():
    """Tests the get_entities function for a list of volume and surface meshsets
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    surf = three_vols.entityset_ranges['surfaces'][7]
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, [surf, vol])
    exp = list(list(three_vols._my_moab_core.get_child_meshsets(vol)) + [surf])
    assert(three_vols_query.meshset_lst == exp)
Beispiel #14
0
def test_get_tris_surf():
    """Tests the tris variable for surface meshset
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    surf = three_vols.entityset_ranges['surfaces'][0]
    three_vols_query = dq.DagmcQuery(three_vols, surf)
    obs_tris = three_vols_query.tris
    exp_tris = three_vols._my_moab_core.get_entities_by_type(
        surf, types.MBTRI)
    assert(sorted(obs_tris) == sorted(exp_tris))
Beispiel #15
0
def test_calc_triangle_aspect_ratio_vol():
    """Tests part of the calc_triangle_aspect_ratio function
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, vol)
    three_vols_query.calc_triangle_aspect_ratio()
    exp = (10*10*10*np.sqrt(2))/(8*5*np.sqrt(2)*5*np.sqrt(2)*(10-5*np.sqrt(2)))
    np.testing.assert_almost_equal(
        list(three_vols_query._tri_data['aspect_ratio']), list(np.full(12, exp)))
Beispiel #16
0
def test_get_meshset_by_id_empty_id():
    """
    Tests the get_meshset_by_id function given no id
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    exp = list(
        three_vols._my_moab_core.get_entities_by_type_and_tag(
            three_vols.root_set, types.MBENTITYSET,
            three_vols.dagmc_tags['geom_dim'], [3]))
    # When no id is passed in, get_meshset_by_id() function should return all the meshsets
    # of the given dimension.
    obs = three_vols.get_meshset_by_id('volumes', ids=[])
    assert (obs == exp)
Beispiel #17
0
def test_rationalize_meshset_rootset_in_list():
    """Tests the rationalize_meshset function for a list containing rootset
    """
    test_pass = np.full(2, False)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        three_vols = df.DagmcFile(test_env['three_vols'])
        vert = three_vols.entityset_ranges['nodes'][0]
        three_vols_query = dq.DagmcQuery(three_vols, [three_vols.root_set, vert])
        exp = list(three_vols.entityset_ranges['surfaces'])
        if len(w) == 0:
            test_pass[0] = True
        test_pass[1] = (three_vols_query.meshset_lst == exp)
    assert(all(test_pass))
Beispiel #18
0
def test_update_tri_data():
    """Tests the upadte_tri_data function
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    surf = three_vols.entityset_ranges['surfaces'][0]
    three_vols_query = dq.DagmcQuery(three_vols, surf)
    three_vols_query.calc_triangle_aspect_ratio()
    exp_tar = (10*10*10*np.sqrt(2))/(8*5*np.sqrt(2)
                                     * 5*np.sqrt(2)*(10-5*np.sqrt(2)))
    np.testing.assert_almost_equal(
        list(three_vols_query._tri_data['aspect_ratio']), list(np.full(2, exp_tar)))
    three_vols_query.calc_area_triangle()
    np.testing.assert_almost_equal(
        list(three_vols_query._tri_data['area']), list(np.full(2, 50)))
Beispiel #19
0
def test_set_entityset_ranges():
    """
    Tests different aspects of the set_entityset_ranges function
    """
    single_cube = df.DagmcFile(test_env['single_cube'])
    test_pass = np.full(len(single_cube.entityset_types), False)
    for dimension, set_type in single_cube.entityset_types.items():
        type_range = list(
            single_cube._my_moab_core.get_entities_by_type_and_tag(
                single_cube.root_set, types.MBENTITYSET,
                single_cube.dagmc_tags['geom_dim'], [dimension]))
        test_pass[dimension] = (
            type_range == single_cube.entityset_ranges[set_type])
    assert (all(test_pass))
Beispiel #20
0
def test_set_dimension_meshset():
    """
    Tests different aspects of the set_dimension_meshset function
    """
    test_pass = np.full(2, False)
    single_cube = df.DagmcFile(test_env['single_cube'])
    mb_entityset = single_cube._my_moab_core.get_entities_by_type(
        single_cube.root_set, types.MBENTITYSET)
    dim_list = ['nodes', 'curves', 'surfaces', 'volumes']
    test_pass[0] = (sorted(single_cube.dim_dict.keys()) == sorted(dim_list))
    # dimension meshsets are the last len(entityset_ranges) elements in mb_entityset
    num_dim_ms = len(single_cube.entityset_ranges)
    test_pass[1] = (sorted(single_cube.dim_dict.values()) == list(
        mb_entityset[-num_dim_ms:]))
    assert (all(test_pass))
Beispiel #21
0
def test_get_tris_vol():
    """Tests the tris variable for volume meshset
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    vol = three_vols.entityset_ranges['volumes'][0]
    three_vols_query = dq.DagmcQuery(three_vols, vol)
    obs_tris = three_vols_query.tris
    exp_tris = []
    meshset_lst = []
    surfs = three_vols._my_moab_core.get_child_meshsets(vol)
    meshset_lst.extend(surfs)
    for item in meshset_lst:
        exp_tris.extend(
            three_vols._my_moab_core.get_entities_by_type(item, types.MBTRI))
    assert(sorted(obs_tris) == sorted(exp_tris))
Beispiel #22
0
def test_duplicate_calc(function, message):
    """Tests the case where calc_tris_per_vert() is called on the same meshset for multiple times
    """
    test_pass = np.full(2, False)
    three_vols = df.DagmcFile(test_env['three_vols'])
    surf = three_vols.entityset_ranges['surfaces'][0]
    three_vols_query = dq.DagmcQuery(three_vols, surf)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        eval('three_vols_query.' + function)
        eval('three_vols_query.' + function)
        if len(w) == 1:
            test_pass[0] = True
            if message in str(w[-1].message):
                test_pass[1] = True
    assert(all(test_pass))
Beispiel #23
0
def test_pandas_data_frame():
    """Tests the initialization of pandas data frames
    """
    single_cube = df.DagmcFile(test_env['single_cube'])
    single_cube_query = dq.DagmcQuery(single_cube)
    exp_vert_data = pd.DataFrame()
    assert(single_cube_query._vert_data.equals(exp_vert_data))

    exp_tri_data = pd.DataFrame()
    assert(single_cube_query._tri_data.equals(exp_tri_data))

    exp_surf_data = pd.DataFrame()
    assert(single_cube_query._surf_data.equals(exp_surf_data))

    exp_vol_data = pd.DataFrame()
    assert(single_cube_query._vol_data.equals(exp_vol_data))
Beispiel #24
0
def test_get_meshset_by_id_invalid_dim():
    """
    Tests the get_meshset_by_id function given invalid dim
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    test_pass = np.full(3, False)
    exp = []
    with warnings.catch_warnings(record=True) as w:
        obs = three_vols.get_meshset_by_id('vertices', ids=[])
        warnings.simplefilter('always')
        if obs == exp:
            test_pass[0] = True
        if len(w) == 1:
            test_pass[1] = True
            if 'Invalid dim!' in str(w[-1].message):
                test_pass[2] = True
    assert (all(test_pass))
Beispiel #25
0
def test_set_native_ranges():
    """Tests set_native_ranges
    """
    single_cube = df.DagmcFile(test_env['single_cube'])
    test_pass = np.full(len(single_cube.entity_types), False)
    for i, native_range_type in enumerate(single_cube.entity_types):
        entity_range = single_cube._my_moab_core.get_entities_by_type(
            single_cube.root_set, native_range_type)
        if native_range_type == types.MBENTITYSET:
            # dimension meshsets are of type MBENTITYSE but not in native_ranges
            num_dim_ms = len(single_cube.entityset_ranges)
            test_pass[i] = (entity_range[:-num_dim_ms] ==
                            single_cube.native_ranges[native_range_type])
        else:
            test_pass[i] = (
                entity_range == single_cube.native_ranges[native_range_type])
    assert (all(test_pass))
Beispiel #26
0
def test_calc_surfs_per_vol_no_vol_meshset():
    """Tests the calc_surfs_per_vol function when no volume is given in the meshset:
    """
    test_pass = np.full(3, False)
    three_vols = df.DagmcFile(test_env['three_vols'])
    surf = three_vols.entityset_ranges['surfaces'][0]
    three_vols_query = dq.DagmcQuery(three_vols, surf)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        three_vols_query.calc_surfs_per_vol()
        if len(w) == 1:
            test_pass[0] = True
        if 'Volume list is empty.' in str(w[0].message):
            test_pass[1] = True
        if len(three_vols_query._vol_data) == 0:
            test_pass[2] = True
    assert(all(test_pass))
Beispiel #27
0
def test_roughness():
    """Tests the calc roughness function, __calc_average_roughness() function
    and __calc_tri_roughness() function.
    """
    test_pass = np.full(3, False)
    pyramid = df.DagmcFile(test_env['pyramid'])
    pyramid_query = dq.DagmcQuery(pyramid)
    pyramid_query.calc_roughness()
    
    gc_top = 2.0*np.pi-4*np.pi/3.0
    gc_bottom = 2.0*np.pi-2*np.pi/3.0-np.pi/2.0
    d_bottom = [1.0/np.tan(np.pi/3.0),
                0.5*(1.0/np.tan(np.pi/3.0)+1.0/np.tan(np.pi/4.0)), 0]
    lr_bottom = []
    lr_top = np.abs(gc_top - gc_bottom)
    lr_bottom.append(np.abs(gc_bottom - \
                (d_bottom[0]*gc_top+2*d_bottom[1]*gc_bottom) \
                /(d_bottom[0]+2*d_bottom[1])))
    lr_bottom.append(np.abs(gc_bottom - \
                (d_bottom[0]*gc_top+2*d_bottom[1]*gc_bottom+d_bottom[2]*gc_bottom) \
                /(d_bottom[0]+2*d_bottom[1]+d_bottom[2])))
    exp = [lr_bottom[0],lr_bottom[0],lr_bottom[1],lr_bottom[1],lr_top]
    obs = sorted(list(pyramid_query._vert_data['roughness']))
    test_pass[0] = np.allclose(obs,exp)
    
    # test the __calc_average_roughness function
    side_length = 5.0
    s_top = 4*(np.sqrt(3)/4*side_length**2)/3.0
    s_bottom = [(side_length**2/2.0+2*(np.sqrt(3)/4*side_length**2))/3.0,
                (side_length**2+2*(np.sqrt(3)/4*side_length**2))/3.0]
    num = lr_top*s_top+ \
                2*lr_bottom[0]*s_bottom[0] + \
                2*lr_bottom[1]*s_bottom[1]
    denom = s_top+sum(s_bottom)*2
    exp = num/denom
    obs = pyramid_query._global_averages['roughness_ave']
    test_pass[1] = np.allclose([obs],[exp])

    #test the __calc_tri_roughness function
    tri_roughness = [(lr_bottom[0]+lr_bottom[1]+lr_top)/3.0, (lr_bottom[0]*2+lr_bottom[1])/3.0]
    exp = [tri_roughness[0]] * 4 + [tri_roughness[1]] * 2
    obs = pyramid_query._tri_data['roughness']
    test_pass[2] = np.allclose(sorted(obs), sorted(exp))
    
    assert(all(test_pass))
Beispiel #28
0
def test_get_meshset_by_id_out_of_range_dim():
    """
    Tests the get_meshset_by_id function given id not in the dim
    """
    three_vols = df.DagmcFile(test_env['three_vols'])
    test_pass = np.full(3, False)
    exp = []
    with warnings.catch_warnings(record=True) as w:
        obs = three_vols.get_meshset_by_id('volumes', ids=[4])
        warnings.simplefilter('always')
        if obs == exp:
            test_pass[0] = True
        if len(w) == 1:
            test_pass[1] = True
            if 'ID is not in the given dimension range! Empty list will be returned.' in str(
                    w[-1].message):
                test_pass[2] = True
    assert (all(test_pass))
Beispiel #29
0
def test_get_entities_incorrect_dim():
    """Tests the get_entities function given incorrect dimension
    """
    test_pass = np.full(3, False)
    three_vols = df.DagmcFile(test_env['three_vols'])
    # check if __get_tris function generates warning for meshset with invalid dimension
    vert = three_vols.entityset_ranges['nodes'][0]
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        three_vols_query = dq.DagmcQuery(three_vols, vert)
        if len(w) == 2:
            test_pass[0] = True
            if 'Meshset is not a volume nor a surface!' in str(w[0].message) and \
               'Specified meshset(s) are not surfaces or ' + \
               'volumes. Rootset will be used by default.' in str(w[-1].message):
                test_pass[1] = True
        exp = list(three_vols.entityset_ranges['surfaces'])
        test_pass[2] = (three_vols_query.meshset_lst == exp)
    assert(all(test_pass))
Beispiel #30
0
def test_load_file():
    """Tests loading file and check the values of all the variables that are
    set in the constructor
    """
    single_cube = df.DagmcFile(test_env['single_cube'])
    assert (single_cube.root_set == 0)