Пример #1
0
def test_read_database_nolevels_error():
    """read_database throws error no levels are defined"""
    # create obj and read database
    ig = isg.IsGm()
    with pytest.raises(RuntimeError) as error_info:
        ig.read_database()
    assert "levels defined" in str(error_info)
Пример #2
0
def test_set_tags(tagname, tagval, expname, expval, exptype):
    """test tags are set on root set for various lengths and data types."""
    ig = isg.IsGm()
    tags = {tagname: tagval}
    # set tags
    ig.set_tags(tags)
    # check tag names, data, and type
    rs = ig.mb.get_root_set()
    r = np.full(3, False)
    try:
        # try to get tag by expected name
        tag_out = ig.mb.tag_get_handle(expname)
        r[0] = True
    except:
        # fails if tag does not exist
        r[0] = False
    # only test the rest if tag exists
    if r[0]:
        data_out = ig.mb.tag_get_data(tag_out, rs)
        # check data value
        if list(data_out[0]) == expval:
            r[1] = True
        # check data type
        if type(data_out[0][0]) is exptype:
            r[2] = True
    assert (all(r))
Пример #3
0
def test_read_ivdb_incomplete():
    """raise error if incomplete ivdb obj"""
    iv = __ivdb_obj(False)
    ig = isg.IsGm()
    with pytest.raises(RuntimeError) as error_info:
        ig.read_ivdb(iv)
    assert "Incomplete IvDb object" in str(error_info)
Пример #4
0
def test_read_database_numfiles_error():
    """read_database throws error if num levels and files mismatch"""
    # create obj and read database
    ig = isg.IsGm(levels=[300], data=data, db=exp_db)
    with pytest.raises(RuntimeError) as error_info:
        ig.read_database()
    assert "does not match number" in str(error_info)
Пример #5
0
def test_separate_isovols_single_interior():
    """test a single interior vol is unchanged when it is separated"""
    # load mesh that does not need separation
    ig = isg.IsGm()
    fs = ig.mb.create_meshset()
    ig.mb.load_file(test_dir + '/vol-files/single-box-1.stl', file_set=fs)
    # create useable meshset dict
    ig.isovol_meshsets[(0, fs)] = {}
    # manually set the geometric extents so that no surface is on the
    # exterior
    ig.xmin = -15.
    ig.xmax = 15.
    ig.ymin = ig.zmin = -15.
    ig.ymax = ig.zmax = 15.
    # separate the volumes
    ig.separate_isovols()
    # check there is one new surfaces
    r = np.full(3, False)
    num_surfs = len(ig.isovol_meshsets[(0, fs)]['surfs_EH'])
    if num_surfs == 1:
        r[0] = True
    # check number of triangles and vertices in surfaces (8 verts, 12 tris)
    surf = ig.isovol_meshsets[(0, fs)]['surfs_EH'][0]
    verts = ig.mb.get_entities_by_type(surf, types.MBVERTEX)
    tris = ig.mb.get_entities_by_type(surf, types.MBTRI)
    if len(verts) == 8:
        r[1] = True
    if len(tris) == 12:
        r[2] = True
    assert (all(r))
Пример #6
0
def test_write_geometry_ext():
    """generated file should have a different name than supplied + warnings"""
    r = np.full(4, False)
    # write file with incorrect extension
    ig = isg.IsGm()
    sname = 'write-test.bad'
    # check for a warning
    with warnings.catch_warnings(record=True) as w:
        ig.write_geometry(sname, test_dir)
        warnings.simplefilter("always")
    r[0:2] = __check_warning(w, ["File will be saved as type .h5m"], 1)
    # check that file exists
    good_file = test_dir + '/write-test.h5m'
    bad_file = test_dir + '/' + sname
    if isfile(good_file):
        # check that name was changed
        r[2] = True
        remove(good_file)
    if not isfile(bad_file):
        # check that bad name was not used
        r[3] = True
    else:
        # file exists, needs removed
        remove(bad_file)
    assert (all(r))
Пример #7
0
def test_calc_centroid_error():
    """test that error is raised if wrong number of values in centroid calc"""
    ig = isg.IsGm()
    # incorrect list of only 2 coords (6 values)
    coords = [3., 0., 0., 0., 3., 0.]
    with pytest.raises(RuntimeError) as error_info:
        ig._IsGm__calc_centroid(coords)
    assert "Cannot calculate centroid" in str(error_info)
Пример #8
0
def test_check_exterior_true(point):
    """test that point is correctly identified as being on the surface"""
    ig = isg.IsGm()
    # define the geometric extents to be -5 to 5 in all directions
    ig.xmin = ig.ymin = ig.zmin = -5.
    ig.xmax = ig.ymax = ig.zmax = 5.
    # test points on each surface (every point should be on a surface)
    result = ig._IsGm__check_exterior(point)
    assert (result)
Пример #9
0
def test_check_exterior_false():
    """test that point is correctly identified as being on the interior"""
    ig = isg.IsGm()
    # define the geometric extents to be -5 to 5 in all directions
    ig.xmin = ig.ymin = ig.zmin = -5.
    ig.xmax = ig.ymax = ig.zmax = 5.
    point = [0, 0, 0]  # interior
    result = ig._IsGm__check_exterior(point)
    assert (not result)
Пример #10
0
def main():

    # get args
    args = parse_arguments()

    # generate level info if necessary
    # levels is either a list of values or path to file
    levels = get_levels(args)

    # get database information
    db = os.getcwd() + '/' + args.db[0]

    # get dataname
    data = args.dataname[0]

    # run steps depending on mode
    mode = args.which
    visit_modes = ["full", "visit"]
    moab_modes = ["full", "moab"]
    iv = None  # initialize

    if mode in visit_modes:
        iv = ivdb.IvDb(levels=levels, data=data, db=db)
        driver.generate_volumes(iv, args.meshfile[0])

    if mode in moab_modes:
        if args.tags:
            tags = process_tags(args.tags)
        else:
            tags = None

        # pass IvDb info if object exists from previous step
        if iv is not None:
            ig = isg.IsGm(ivdb=iv)
        else:
            ig = isg.IsGm(levels=levels, data=data, db=db)

        # create geom from info
        driver.create_geometry(ig,
                               tag_for_viz=args.tagviz,
                               norm=args.norm[0],
                               tags=tags,
                               sname=args.geomfile[0],
                               sdir=args.savepath[0])
Пример #11
0
def test_separate_isovols_exterior():
    """test that disjoint volumes are properly separated"""
    # load mesh that needs separation
    ig = isg.IsGm()
    fs = ig.mb.create_meshset()
    ig.mb.load_file(test_dir + '/vol-files/separate-vols.stl', file_set=fs)
    # create useable meshset dict
    ig.isovol_meshsets[(0, fs)] = {}
    # manually set the geometric extents
    # these are chosen such that the volume file aligns on the x plane
    # geometric extents (-10, 15). The volume file y and z are -5 to 5,
    # so if this is considered to be one volume in a larger geometry,
    # only one the surfaces on the x planes are considered exterior.
    ig.xmin = -10.
    ig.xmax = 15.
    ig.ymin = ig.zmin = -15.
    ig.ymax = ig.zmax = 15.
    # separate the volumes
    ig.separate_isovols()
    # check there are four new surfaces
    r = np.full(4, False)
    num_surfs = len(ig.isovol_meshsets[(0, fs)]['surfs_EH'])
    if num_surfs == 4:
        r[0] = True
    # check that no triangles are shared between the each of the surfaces
    surf0 = ig.isovol_meshsets[(0, fs)]['surfs_EH'][0]
    tris0 = set(ig.mb.get_entities_by_type(surf0, types.MBTRI))
    surf1 = ig.isovol_meshsets[(0, fs)]['surfs_EH'][1]
    tris1 = set(ig.mb.get_entities_by_type(surf1, types.MBTRI))
    surf2 = ig.isovol_meshsets[(0, fs)]['surfs_EH'][2]
    tris2 = set(ig.mb.get_entities_by_type(surf2, types.MBTRI))
    surf3 = ig.isovol_meshsets[(0, fs)]['surfs_EH'][3]
    tris3 = set(ig.mb.get_entities_by_type(surf3, types.MBTRI))
    common_tris = [
        list(tris0 & tris1),
        list(tris0 & tris2),
        list(tris0 & tris3),
        list(tris1 & tris2),
        list(tris1 & tris3),
        list(tris2 & tris3)
    ]
    if not common_tris == 0:
        r[1] = True
    # check that two surfaces have 10 tris and two surfaces have 2 tris
    num_tris = sorted([len(tris0), len(tris1), len(tris2), len(tris3)])
    if num_tris == [2, 2, 10, 10]:
        r[2] = True
    # check that 2 surfs have 8 verts and 2 surfs have 4 verts
    verts0 = set(ig.mb.get_entities_by_type(surf0, types.MBVERTEX))
    verts1 = set(ig.mb.get_entities_by_type(surf1, types.MBVERTEX))
    verts2 = set(ig.mb.get_entities_by_type(surf2, types.MBVERTEX))
    verts3 = set(ig.mb.get_entities_by_type(surf3, types.MBVERTEX))
    num_verts = sorted([len(verts0), len(verts1), len(verts2), len(verts3)])
    if num_verts == [4, 4, 8, 8]:
        r[3] = True
    assert (all(r))
Пример #12
0
def test_calc_centroid():
    """test centroid calculation"""
    ig = isg.IsGm()
    # triangle defined by coordinates (3, 0, 0), (0, 3, 0), (0, 0, 3)
    coords = [3., 0., 0., 0., 3., 0., 0., 0., 3.]
    # expected centroid:
    # x = (3 + 0 + 0)/3 = 1
    # y = (0 + 3 + 0)/3 = 1
    # z = (0 + 0 + 3)/3 = 1
    exp_centroid = [1., 1., 1.]
    centroid = ig._IsGm__calc_centroid(coords)
    assert (exp_centroid == list(centroid))
Пример #13
0
def test_write_geometry():
    """test that a file of the correct name is created"""
    # write a file
    ig = isg.IsGm()
    sname = 'write-test.h5m'
    ig.write_geometry(sname, test_dir)
    # check that file exists
    exp_file = test_dir + '/' + sname
    r = False
    if isfile(exp_file):
        r = True
        remove(exp_file)
    assert (r)
Пример #14
0
def test_list_coords():
    """test list coords returns correct dictionary"""
    # setup IsGm instance
    ig = isg.IsGm()
    ig.mb = core.Core()
    # create some vertices
    coords = np.array((1., 2., 3.), dtype='float64')
    ig.mb.create_vertices(coords)
    rs = ig.mb.get_root_set()
    eh = list(ig.mb.get_entities_by_type(rs, types.MBVERTEX))[0]
    exp_coords_dict = {eh: (1., 2., 3.)}
    # list coords
    coords_out = ig._IsGm__list_coords(rs)
    assert (exp_coords_dict == coords_out)
Пример #15
0
def test_init_input():
    r = np.full(5, False)
    ig = isg.IsGm(levels=levels, data=data, db=exp_db, extents=exts)
    if ig.levels == exp_levels:
        r[0] = True
    if ig.data == data:
        r[1] = True
    if ig.db == exp_db:
        r[2] = True
    if ig.xmin == ig.ymin == ig.zmin == exp_ext_min:
        r[3] = True
    if ig.xmax == ig.ymax == ig.zmax == exp_ext_max:
        r[4] = True
    assert (all(r))
Пример #16
0
def test_init_input_ivdb():
    """test that info from ivdb overwrites other input"""
    r = np.full(5, False)
    iv = __ivdb_obj(True)
    ig = isg.IsGm(ivdb=iv, levels=[0, 2], data='nonsense', db='fake_db')
    if ig.levels == exp_levels:
        r[0] = True
    if ig.data == data:
        r[1] = True
    if ig.db == exp_db:
        r[2] = True
    if ig.xmin == ig.ymin == ig.zmin == exp_ext_min:
        r[3] = True
    if ig.xmax == ig.ymax == ig.zmax == exp_ext_max:
        r[4] = True
    assert (all(r))
Пример #17
0
def test_init_none():
    r = np.full(6, False)
    ig = isg.IsGm()
    if ig.levels is None:
        r[0] = True
    if ig.data is None:
        r[1] = True
    if ig.db == getcwd() + "/tmp":
        r[2] = True
    if isinstance(ig.mb, type(core.Core())):
        r[3] = True
    if ig.isovol_meshsets == {}:
        r[4] = True
    if ig.xmin == ig.xmax == ig.ymin == ig.ymax == ig.zmin == ig.zmax is None:
        r[5] = True
    assert (all(r))
Пример #18
0
def test_init_ivdb():
    """test that info is taken from ivdb"""
    r = np.full(5, False)
    iv = __ivdb_obj(True)
    ig = isg.IsGm(ivdb=iv)
    if ig.levels == exp_levels:
        r[0] = True
    if ig.data == data:
        r[1] = True
    if ig.db == exp_db:
        r[2] = True
    if ig.xmin == ig.ymin == ig.zmin == exp_ext_min:
        r[3] = True
    if ig.xmax == ig.ymax == ig.zmax == exp_ext_max:
        r[4] = True
    assert (all(r))
Пример #19
0
def test_read_ivdb():
    """read info from ivdb obj"""
    iv = __ivdb_obj(True)
    ig = isg.IsGm()
    ig.read_ivdb(iv)
    r = np.full(5, False)
    if ig.levels == exp_levels:
        r[0] = True
    if ig.data == data:
        r[1] = True
    if ig.db == exp_db:
        r[2] = True
    if ig.xmin == ig.ymin == ig.zmin == exp_ext_min:
        r[3] = True
    if ig.xmax == ig.ymax == ig.zmax == exp_ext_max:
        r[4] = True
    assert (all(r))
Пример #20
0
def test_read_database():
    """check that meshsets are properly populated with read_database"""
    # create obj and read database
    ig = isg.IsGm(levels=levels, data=data, db=exp_db)
    ig.read_database()
    # expected meshset entity handles
    ehs = [
        12682136550675316737, 12682136550675316738, 12682136550675316739,
        12682136550675316740, 12682136550675316741
    ]
    # setup truth array
    res = np.full(len(ehs) + 1, False)
    # check that meshsets exist in the moab instance
    for r, eh in enumerate(ehs):
        try:
            # any moab call that will work if meshet exists, else
            # it will fail
            ig.mb.get_child_meshsets(eh)
        except RuntimeError:
            pass
        else:
            res[r] = True
    # check meshets and bound information are in dictionary
    exp_meshsets = {
        (0, ehs[0]): {
            'bounds': (None, 5.0)
        },
        (1, ehs[1]): {
            'bounds': (5.0, 15.0)
        },
        (2, ehs[2]): {
            'bounds': (15.0, 25.0)
        },
        (3, ehs[3]): {
            'bounds': (25.0, 35.0)
        },
        (4, ehs[4]): {
            'bounds': (35.0, None)
        }
    }
    if sorted(ig.isovol_meshsets) == sorted(exp_meshsets):
        res[-1] = True
    # assert all pass
    assert (all(res))
Пример #21
0
def test_separate_isovols_single_exterior():
    """test a single vol with an exterior surface is split in separation"""
    # load mesh that does not need separation
    ig = isg.IsGm()
    fs = ig.mb.create_meshset()
    ig.mb.load_file(test_dir + '/vol-files/single-box-1.stl', file_set=fs)
    # create useable meshset dict
    ig.isovol_meshsets[(0, fs)] = {}
    # manually set the geometric extents
    # these are chosen such that the volume file aligns on the -x plane
    # geometric extents (-5). The volume file x, y, and z are -5 to 5,
    # so if this is considered to be one volume in a larger geometry,
    # only one the surfaces on the -x plane is considered exterior.
    ig.xmin = -5.
    ig.xmax = 15.
    ig.ymin = ig.zmin = -15.
    ig.ymax = ig.zmax = 15.
    # separate the volumes
    ig.separate_isovols()
    # check there are two new surfaces
    r = np.full(4, False)
    num_surfs = len(ig.isovol_meshsets[(0, fs)]['surfs_EH'])
    if num_surfs == 2:
        r[0] = True
    # check that no triangles are shared between the each of the surfaces
    surf0 = ig.isovol_meshsets[(0, fs)]['surfs_EH'][0]
    tris0 = set(ig.mb.get_entities_by_type(surf0, types.MBTRI))
    surf1 = ig.isovol_meshsets[(0, fs)]['surfs_EH'][1]
    tris1 = set(ig.mb.get_entities_by_type(surf1, types.MBTRI))
    common_tris = tris0 & tris1
    if len(common_tris) == 0:
        r[1] = True
    # check that one surface has 2 triangles and the other has 10
    num_tris = sorted([len(tris0), len(tris1)])
    if num_tris == [2, 10]:
        r[2] = True
    # check that one surface has 8 verts and the other has 4
    verts0 = set(ig.mb.get_entities_by_type(surf0, types.MBVERTEX))
    verts1 = set(ig.mb.get_entities_by_type(surf1, types.MBVERTEX))
    num_verts = sorted([len(verts0), len(verts1)])
    if num_verts == [4, 8]:
        r[3] = True
    assert (all(r))
Пример #22
0
def test_get_surf_triangles_all():
    """get triangles when all coords are good"""
    # setup IsGm instance
    ig = isg.IsGm()
    ig.mb = core.Core()
    # make two sets of verts
    all_coords = np.array((0., 0., 0., 1., 0., 0., .5, 1., 0., 2., 1., 0.),
                          dtype='float64')
    ig.mb.create_vertices(all_coords)
    rs = ig.mb.get_root_set()
    verts_all = ig.mb.get_entities_by_type(rs, types.MBVERTEX)
    verts1 = verts_all[0:3]
    verts2 = verts_all[1:]
    # make two triangles
    tri1 = ig.mb.create_element(types.MBTRI, verts1)
    tri2 = ig.mb.create_element(types.MBTRI, verts2)
    # test get surf tris
    tris_out = ig._IsGm__get_surf_triangles(verts_all)
    assert (sorted(tris_out) == sorted([tri1, tri2]))
Пример #23
0
def test_tag_for_viz():
    """test visualization tags are added to triangles"""
    # load volume
    ig = isg.IsGm()
    fs = ig.mb.create_meshset()
    ig.mb.load_file(test_dir + '/vol-files/single-box-1.stl', file_set=fs)
    iv = (0, fs)
    ig.isovol_meshsets[iv] = {}
    ig.separate_isovols()  # use this to get surface EHs
    # set val_tag (used for viz)
    val = 5.0
    surf = ig.isovol_meshsets[iv]['surfs_EH'][0]
    ig.mb.tag_set_data(ig.val_tag, surf, val)
    # tag for viz
    ig.tag_for_viz()
    # test viz tags
    all_tris = ig.mb.get_entities_by_type(surf, types.MBTRI)
    vals_out = list(ig.mb.tag_get_data(ig.val_tag, all_tris))
    vals_exp = list(np.full(12, 5.0))
    assert (vals_exp == vals_out)
Пример #24
0
def test_get_surf_triangles():
    """get triangles when one coord is not good"""
    # setup IsGm instance
    ig = isg.IsGm()
    ig.mb = core.Core()
    # make good and bad coords/verts
    all_coords = np.array((0., 0., 0., 1., 0., 0., .5, 1., 0., 2., 1., 0.),
                          dtype='float64')
    ig.mb.create_vertices(all_coords)
    rs = ig.mb.get_root_set()
    verts_all = ig.mb.get_entities_by_type(rs, types.MBVERTEX)
    verts_good = verts_all[0:3]
    verts_bad = verts_all[1:]
    # make good triangle with coords:
    tri_good = ig.mb.create_element(types.MBTRI, verts_good)
    # make bad triangle:
    tri_bad = ig.mb.create_element(types.MBTRI, verts_bad)
    # test get surf tris
    tris_out = ig._IsGm__get_surf_triangles(verts_good)
    assert (tris_out == tri_good)
Пример #25
0
def __setup_geom():
    """function for other tests to create a useable isogeom object"""
    # load two coincident volumes that need merging
    ig = isg.IsGm()
    fs1 = ig.mb.create_meshset()
    ig.mb.load_file(test_dir + '/vol-files/single-box-1.stl', file_set=fs1)
    fs2 = ig.mb.create_meshset()
    ig.mb.load_file(test_dir + '/vol-files/single-box-2.stl', file_set=fs2)
    # create useable meshset dict
    # assign arbitrary values for levels 0, 5, 10
    iv1 = (0, fs1)
    iv2 = (1, fs2)
    ig.isovol_meshsets[iv1] = {}
    ig.isovol_meshsets[iv1]['bounds'] = (0., 5.)
    ig.isovol_meshsets[iv2] = {}
    ig.isovol_meshsets[iv2]['bounds'] = (5., 10.)
    ig.levels = [5., 10.]
    ig.data = 'dataname'
    ig.xmin = -5.
    ig.xmax = 15.
    ig.ymin = ig.zmin = -5.
    ig.ymax = ig.zmax = 5.
    ig.separate_isovols()  # use this to get surface EHs
    return ig
Пример #26
0
def test_init_input_file():
    ig = isg.IsGm(levels=exp_levelfile)
    assert (ig.levels == exp_levels)