Exemple #1
0
def mesh_from_brep(brep_file, mesh_file, project_conf, inv_par):
    if project_conf.method == GenieMethod.ERT:
        data = pg.DataContainerERT("input_snapped.dat", removeInvalid=False)
    else:
        data = pg.DataContainer("input_snapped.dat",
                                sensorTokens='s g',
                                removeInvalid=False)

    el_pos = []
    for i in range(len(data.sensorPositions())):
        pos = data.sensorPosition(i)
        pos = np.array([pos[0], pos[1], pos[2]])
        el_pos.append(pos)

    model = gmsh.GeometryOCC("model_name")
    compound = model.import_shapes(brep_file, highestDimOnly=False)
    points = [model.point(pos).tags[0] for pos in el_pos]
    dist = field.distance_nodes(points)
    f_distance = field.threshold(dist,
                                 lower_bound=(inv_par.elementSize_d,
                                              inv_par.elementSize_d),
                                 upper_bound=(inv_par.elementSize_D,
                                              inv_par.elementSize_H))
    model.set_mesh_step_field(f_distance)
    model.mesh_options.CharacteristicLengthMin = 0.1
    model.mesh_options.CharacteristicLengthMax = 100
    model.make_mesh([compound])
    model.write_mesh(mesh_file, gmsh.MeshFormat.msh2)
Exemple #2
0
def test_minmax_nodes_2d():
    f_distance = field.min(10, field.max(5, field.distance_nodes(
        [1, 3])))  # points: (-50, -50), (50, 50)

    def ref_size(x):
        dist = min(np.linalg.norm(np.array(x) - np.array([-50, -50, 0])),
                   np.linalg.norm(np.array(x) - np.array([50, 50, 0])))
        return min(10, max(5, dist))

    apply_field(f_distance, ref_size, dim=2, tolerance=0.4, max_mismatch=10)
Exemple #3
0
def test_distance_nodes_2d():
    """
    For some reason the mesh size is actually close to half of the distance
    and naturally the error is quite high, up to 70%
    """
    f_distance = field.distance_nodes([1, 3])  # points: (-50, -50), (50, 50)

    def ref_size(x):
        dist = min(np.linalg.norm(np.array(x) - np.array([-50, -50, 0])),
                   np.linalg.norm(np.array(x) - np.array([50, 50, 0])))
        return max(0.5 * dist, 0.5)

    apply_field(f_distance,
                ref_size,
                dim=2,
                tolerance=0.7,
                max_mismatch=10,
                mesh_name="dist_2d")
Exemple #4
0
def test_threshold_sigmoid_2d():
    f_distance = field.threshold(field.distance_nodes([1, 3]),
                                 lower_bound=(10, 5),
                                 upper_bound=(30, 10),
                                 sigmoid=True)

    def thold(x, minx, miny, maxx, maxy):
        scaled_X = (x - minx) / (maxx - minx)
        y = 1 / (1 + np.exp(-scaled_X))
        return y * (maxy - miny) + miny

    def ref_size(x):
        dist = min(np.linalg.norm(np.array(x) - np.array([-50, -50, 0])),
                   np.linalg.norm(np.array(x) - np.array([50, 50, 0])))
        return thold(dist, 10, 5, 30, 10)

    apply_field(f_distance,
                ref_size,
                dim=2,
                tolerance=0.4,
                max_mismatch=8,
                mesh_name="thds")
Exemple #5
0
def test_threshold_2d():
    f_distance = field.threshold(field.distance_nodes([1, 3]),
                                 lower_bound=(10, 5),
                                 upper_bound=(30, 10))

    def thold(x, minx, miny, maxx, maxy):
        if x < minx:
            return miny
        elif x > maxx:
            return maxy
        else:
            return (x - minx) / (maxx - minx) * (maxy - miny) + miny

    def ref_size(x):
        dist = min(np.linalg.norm(np.array(x) - np.array([-50, -50, 0])),
                   np.linalg.norm(np.array(x) - np.array([50, 50, 0])))
        return thold(dist, 10, 5, 30, 10)

    apply_field(f_distance,
                ref_size,
                dim=2,
                tolerance=0.3,
                max_mismatch=3,
                mesh_name="thd")