def writeGEO(grid, mesh, filename):
    """Example: grid = np.array([[0,0],[0.5,0.5],[0,0.5]]), mesh = np.array([1,4,3])"""
    # with pygmsh.geo.Geometry() as geom:
    #     for e in range(mesh.shape[0] // 3):
    #         p1 = grid[mesh[3*e]]
    #         p2 = grid[mesh[3*e+1]]
    #         p3 = grid[mesh[3*e+2]]
    #
    #         geom.add_polygon(
    #             [
    #                 list(p1),list(p2),list(p3)
    #             ],
    #         )
    #     mesh = geom.generate_mesh()
    #
    # mesh.write(filename)

    mesh_geo = Mesh()
    pt_list = []
    for i in range(grid.shape[0]):
        p = Entity.Point(grid[i, :])
        pt_list.append(p)
        mesh_geo.addEntity(p)
    for e in range(mesh.shape[0] // 3):
        p1 = pt_list[mesh[3 * e]]
        p2 = pt_list[mesh[3 * e + 1]]
        p3 = pt_list[mesh[3 * e + 2]]
        l1 = Entity.Curve([p1, p2])
        l2 = Entity.Curve([p2, p3])
        l3 = Entity.Curve([p3, p1])
        # entities can also be added in a batch
        mesh_geo.addEntities([l1, l2, l3])
    mesh_geo.writeGeo(filename)
Exemple #2
0
def objective(x, sign=-1.0):
    my_mesh = Mesh()
    d = x[0]
    a = x[1]
    L = x[2]
    if volume(x) > 10 * V_sk:
        d1 = 0.05
    elif volume(x) > 2 * V_sk:
        d1 = 0.005
    else:
        d1 = 0.0005

    filename = 'my_mesh'
    # create points
    p1 = Entity.Point([0., 0., 0., d1])  #fyrsti punktur neðri vinstri
    # add point to mesh
    my_mesh.addEntity(p1)
    #create more points
    p2 = Entity.Point([0., a / 2, 0., d1])  #2. punktur efri vinstri
    my_mesh.addEntity(p2)
    p3 = Entity.Point([t_veggur, a / 2, 0., d1])  #3. punktur efri hægri
    my_mesh.addEntity(p3)

    p4 = Entity.Point([t_veggur, (a - d) / 2 + d - a / 2, 0.,
                       d1])  #4. punktur niður frá efri hægri
    my_mesh.addEntity(p4)

    p5 = Entity.Point([t_veggur + L, (a - d) / 2 + d - a / 2, 0.,
                       d1])  #5.punktur endi á ribbu efri
    my_mesh.addEntity(p5)
    p6 = Entity.Point([t_veggur + L, 0., 0.,
                       d1])  #6. punktur endi á ribbu neðri
    my_mesh.addEntity(p6)
    # create curves
    l1 = Entity.Curve([p1, p2])  #innri bein lína upp
    l2 = Entity.Curve([p2, p3])  # efri hlið einangrun
    l3 = Entity.Curve([p3, p4])  # ytri bein lína upp
    l4 = Entity.Curve([p4, p5])  #ribba bein lína upp
    l5 = Entity.Curve([p5, p6])  #ribba endi
    l6 = Entity.Curve([p6, p1])  #ribba bein lína niðri

    my_mesh.addEntities([l1, l2, l3, l4, l5, l6])

    ll1 = Entity.CurveLoop([l1, l2, l3, l4, l5, l6], mesh=my_mesh)

    s1 = Entity.PlaneSurface([ll1], mesh=my_mesh)

    g1 = Entity.PhysicalGroup(name='innri')
    g2 = Entity.PhysicalGroup(name='ytri')
    g3 = Entity.PhysicalGroup(name='ribba')
    g4 = Entity.PhysicalGroup(name='einangrun')
    my_mesh.addEntities([g1, g2, g3, g4])
    g1.addEntities([l1])
    g2.addEntities([l3, l4, l5, l6])
    g4.addEntities([l2])
    g3.addEntities([s1])
    # set max element size
    #my_mesh.Options.Mesh.CharacteristicLengthMax = 0.1

    # adding Coherence option
    my_mesh.Coherence = True
    # write the geofile
    #os.system('rm .geo')
    try:
        my_mesh.writeGeo('{}.geo'.format(filename))
        os.system('gmsh {}.geo -2 -o {}.msh'.format(filename, filename))
    except:
        return -0.1
    #os.system('gmsh my_mesh.geo')
    try:
        xu, y, tri, T, V, q = axifem.axiHeatCond('{}.msh'.format(filename), \
                    {'ribba':k}, {'ytri':(h_utan,-h_utan*T_inf_utan),'innri':(h_innan,-h_innan*T_inf_innan),'einangrun':(0,0)})
        print(sign * q['ytri'][1])
    except:
        return -0.1
    return sign * q['ytri'][1]
Exemple #3
0
#create more points
p2 = Entity.Point([0., a / 2, 0., d1])  #2. punktur efri vinstri
my_mesh.addEntity(p2)
p3 = Entity.Point([t_veggur, a / 2, 0., d1])  #3. punktur efri hægri
my_mesh.addEntity(p3)

p4 = Entity.Point([t_veggur, 0., 0., d1])  #4. punktur niður frá efri hægri
my_mesh.addEntity(p4)

# create curves
l1 = Entity.Curve([p1, p2])  #innri bein lína upp
l2 = Entity.Curve([p2, p3])  # efri hlið einangrun
l3 = Entity.Curve([p3, p4])  # ytri bein lína upp
l4 = Entity.Curve([p4, p1])  #neðri lína

my_mesh.addEntities([l1, l2, l3, l4])

ll1 = Entity.CurveLoop([l1, l2, l3, l4], mesh=my_mesh)

s1 = Entity.PlaneSurface([ll1], mesh=my_mesh)

g1 = Entity.PhysicalGroup(name='innri')
g2 = Entity.PhysicalGroup(name='ytri')
g3 = Entity.PhysicalGroup(name='ribba')
g4 = Entity.PhysicalGroup(name='einangrun')
my_mesh.addEntities([g1, g2, g3, g4])
g1.addEntities([l1])
g2.addEntities([l3, l4])
g4.addEntities([l2])
g3.addEntities([s1])
# set max element size
Exemple #4
0
def objective(x, sign=-1.0):
    print(x)
    my_mesh = Mesh()
    filename = 'my_mesh'
    a = x[1]
    L = x[2]
    s = x[3:]

    # create points
    p1 = Entity.Point([0., -a / 2, 0., d1])  #fyrsti punktur neðri vinstri

    p2 = Entity.Point([0., a - a / 2, 0., d1])  #2. punktur efri vinstri

    p3 = Entity.Point([t_veggur, a - a / 2, 0., d1])  #3. punktur efri hægri
    pe = []
    pn = []

    my_mesh.addEntities([p1, p2, p3])

    for j in range(0, len(s)):
        pe.append(
            Entity.Point(
                [t_veggur + L / (len(s) - 1) * j, a - s[j] - a / 2, 0., d1]))

        pn.append(
            Entity.Point([
                t_veggur + L / (len(s) - 1) * (len(s) - j - 1),
                s[len(s) - 1 - j] - a / 2, 0., d1
            ]))

    my_mesh.addEntities(pe)
    my_mesh.addEntities(pn)

    p10 = Entity.Point([t_veggur, 0. - a / 2, 0.,
                        d1])  #síðasti punktur neðri hægri

    my_mesh.addEntities([p10])
    # create curves
    l1 = Entity.Curve([p1, p2])  #innri bein lína upp
    l2 = Entity.Curve([p2, p3])  # efri hlið einangrun
    l3 = Entity.Curve([p3, pe[0]])  # ytri bein lína upp
    le = []
    ln = []
    my_mesh.addEntities([l1, l2, l3])

    for i in range(0, len(pe) - 1):
        le.append(Entity.Curve([pe[i], pe[i + 1]]))

    ln.append(Entity.Curve([pe[-1], pn[0]]))
    for i in range(0, len(pn) - 1):
        ln.append(Entity.Curve([pn[i], pn[i + 1]]))
    l9 = Entity.Curve([pn[-1], p10])
    l10 = Entity.Curve([p10, p1])  #einangrun neðri

    my_mesh.addEntities(le)
    my_mesh.addEntities(ln)
    my_mesh.addEntities([l9])
    my_mesh.addEntities([l10])

    lines = []
    lines.append(l1)
    lines.append(l2)
    lines.append(l3)
    for line in le:
        lines.append(line)
    for line in ln:
        lines.append(line)
    lines.append(l9)
    lines.append(l10)

    ll1 = Entity.CurveLoop(lines, mesh=my_mesh)

    s1 = Entity.PlaneSurface([ll1], mesh=my_mesh)

    g1 = Entity.PhysicalGroup(name='innri')
    g2 = Entity.PhysicalGroup(name='ytri')
    g3 = Entity.PhysicalGroup(name='ribba')
    g4 = Entity.PhysicalGroup(name='einangrun')
    my_mesh.addEntities([g1, g2, g3, g4])
    g1.addEntities([l1])
    g2.addEntities([l3])
    g2.addEntities(le)
    g2.addEntities(ln)
    g2.addEntities([l9])
    g4.addEntities([l2, l10])
    g3.addEntities([s1])
    # set max element size
    #my_mesh.Options.Mesh.CharacteristicLengthMax = 0.1
    # adding Coherence option
    my_mesh.Coherence = True
    # write the geofile
    #os.system('rm .geo')
    try:
        my_mesh.writeGeo('{}.geo'.format(filename))
        os.system('gmsh {}.geo -2 -o {}.msh'.format(filename, filename))
    except:
        return -0.5
    #os.system('gmsh my_mesh.geo')
    try:
        xu, y, tri, T, V, q = axifem.axiHeatCond('{}.msh'.format(filename), \
                    {'ribba':k}, {'ytri':(h_utan,-h_utan*T_inf_utan),'innri':(h_innan,-h_innan*T_inf_innan),'einangrun':(0,0)})
        print(sign * q['ytri'][1])
    except:
        return -0.5

    return sign * q['ytri'][1]
Exemple #5
0
def objective(x, sign=-1.0):
    #x = [d,a,L,n,t,r]
    my_mesh = Mesh()
    filename = 'my_mesh'
    d = x[0]
    a = x[1]
    L = x[2]
    n = int(x[3])
    t = x[4]
    r = x[5]
    dx = x[6]

    if volume(x) > 10 * V_sk:
        d1 = 0.05
    elif volume(x) > 2 * V_sk:
        d1 = 0.005
    else:
        d1 = 0.0005

    # create points
    p1 = Entity.Point([0., 0., 0., d1])  #fyrsti punktur neðri vinstri

    p2 = Entity.Point([0., a / 2, 0., d1])  #2. punktur efri vinstri

    p3 = Entity.Point([t_veggur, a / 2, 0., d1])  #3. punktur efri hægri
    pe = []

    my_mesh.addEntities([p1, p2, p3])

    pe.append(Entity.Point([t_veggur, d / 2, 0., d1]))  #fyrsti punktur á ribbu

    for i in range(0, n):
        delta_x = dx + i * (dx + t)
        pe.append(Entity.Point([t_veggur + delta_x, d / 2, 0., d1]))
        pe.append(Entity.Point([t_veggur + delta_x, r / 2, 0., d1]))
        pe.append(Entity.Point([t_veggur + delta_x + t, r / 2, 0., d1]))
        pe.append(Entity.Point([t_veggur + delta_x + t, d / 2, 0., d1]))

    my_mesh.addEntities(pe)

    p10 = Entity.Point([t_veggur + dx * n + t * n, 0., 0.,
                        d1])  #síðasti punktur neðri hægri

    my_mesh.addEntities([p10])
    # create curves
    l1 = Entity.Curve([p1, p2])  #innri bein lína upp
    l2 = Entity.Curve([p2, p3])  # efri hlið einangrun
    l3 = Entity.Curve([p3, pe[0]])  # ytri bein lína upp
    le = []
    my_mesh.addEntities([l1, l2, l3])

    for i in range(0, len(pe) - 1):
        le.append(Entity.Curve([pe[i], pe[i + 1]]))

    le.append(Entity.Curve([pe[-1], p10]))  #klára ferð niður

    l9 = Entity.Curve([p10, p1])  #lína niðri

    my_mesh.addEntities(le)

    my_mesh.addEntities([l9])

    lines = []
    lines.append(l1)
    lines.append(l2)
    lines.append(l3)
    for line in le:
        lines.append(line)
    lines.append(l9)

    ll1 = Entity.CurveLoop(lines, mesh=my_mesh)

    s1 = Entity.PlaneSurface([ll1], mesh=my_mesh)

    g1 = Entity.PhysicalGroup(name='innri')
    g2 = Entity.PhysicalGroup(name='ytri')
    g3 = Entity.PhysicalGroup(name='ribba')
    g4 = Entity.PhysicalGroup(name='einangrun')
    my_mesh.addEntities([g1, g2, g3, g4])
    g1.addEntities([l1])
    g4.addEntities([l2])
    g2.addEntities([l3])
    for line in le:
        g2.addEntities([line])
    g3.addEntities([s1])
    # set max element size
    #my_mesh.Options.Mesh.CharacteristicLengthMax = 0.1
    # adding Coherence option
    my_mesh.Coherence = True
    # write the geofile
    #os.system('rm .geo')
    try:
        my_mesh.writeGeo('{}.geo'.format(filename))
        os.system('gmsh {}.geo -2 -o {}.msh'.format(filename, filename))
    except:
        return min(-0.5 * (dx + t) * n, -0.5 * random())
    #os.system('gmsh my_mesh.geo')
    try:
        xu, y, tri, T, V, q = axifem.axiHeatCond('{}.msh'.format(filename), \
                    {'ribba':k}, {'ytri':(h_utan,-h_utan*T_inf_utan),'innri':(h_innan,-h_innan*T_inf_innan),'einangrun':(0,0)})
        print(sign * q['ytri'][1])
        if sign * q['ytri'][1] != sign * q['ytri'][1]:
            return min(-0.5 * (dx + t) * n, -0.5 * random())
    except:
        return min(-0.5 * (dx + t) * n, -0.5 * random())

    return sign * q['ytri'][1]
    def _mesh_geometry(
        self,
        x_camber: np.ndarray,
        upper_curve: np.ndarray,
        lower_curve: np.ndarray,
    ) -> Mesh:
        """
        Function computing a triangulation of the airfoil domain.

        :params:
        x_camber: x-coeficients of points used in the discretization.
        upper_curve: y-coefficients of the upper profile of the sampled airfoil.
            The discretization is evaluated at x_camber points.
        lower_curve: y-coefficients of the lower profile of the sampled airfoil.
            The discretization is evaluated at x_camber points.
        :returns:
        mash: airfoil's triangulation computed using GMSH package.
        """

        mesh = Mesh()

        top_left = Entity.Point([*self.top_left_corner, 0])
        top_right = Entity.Point(
            [self.bottom_right_corner[0], self.top_left_corner[1], 0])
        bottom_left = Entity.Point(
            [self.top_left_corner[0], self.bottom_right_corner[1], 0])
        bottom_right = Entity.Point([*self.bottom_right_corner, 0])

        # Add domain's corners to the geometry
        mesh.addEntity(top_left)
        mesh.addEntity(top_right)
        mesh.addEntity(bottom_left)
        mesh.addEntity(bottom_right)

        # Define the outer boundary
        top_boundary = Entity.Curve([top_left, top_right])
        right_boundary = Entity.Curve([top_right, bottom_right])
        bottom_boundary = Entity.Curve([bottom_right, bottom_left])
        left_boundary = Entity.Curve([bottom_left, top_left])

        domain_outer_boundary = [
            top_boundary,
            right_boundary,
            bottom_boundary,
            left_boundary,
        ]
        mesh.addEntities(domain_outer_boundary)

        # Add airfoil points
        airfoil_points = []

        for x, y in zip(x_camber, upper_curve):
            point = Entity.Point([x, y, 0])
            airfoil_points.append(point)
            mesh.addEntity(point)

        for x, y in zip(x_camber[::-1][1:-1], lower_curve[::-1][1:-1]):
            point = Entity.Point([x, y, 0])
            airfoil_points.append(point)
            mesh.addEntity(point)

        # Discretize the airfoil profile
        intervals = []
        for i in range(len(airfoil_points) - 1):
            point1 = airfoil_points[i]
            point2 = airfoil_points[i + 1]
            interval = Entity.Curve([point1, point2])
            intervals.append(interval)

        # Close the profile using endpoints
        point1 = airfoil_points[-1]
        point2 = airfoil_points[0]
        interval = Entity.Curve([point1, point2])
        intervals.append(interval)

        mesh.addEntities(intervals)

        field_boundary_layer = Field.BoundaryLayer(mesh=mesh)

        # Setting boundary layer parameters
        field_boundary_layer.EdgesList = intervals
        field_boundary_layer.AnisoMax = 1.0
        field_boundary_layer.hfar = 0.2
        field_boundary_layer.hwall_n = 0.001
        field_boundary_layer.thickness = 0.05
        field_boundary_layer.ratio = 1.1
        field_boundary_layer.Quads = 1
        field_boundary_layer.IntersectMetrics = 0
        mesh.BoundaryLayerField = field_boundary_layer

        # set max element size
        mesh.Options.Mesh.CharacteristicLengthMax = 0.3

        return mesh
Exemple #7
0
def objective(x, sign=-1.0):
    time.sleep(0.1)
    my_mesh = Mesh()
    filename = 'my_mesh'
    d = x[0]
    a = x[1]
    L = x[2]
    s1 = x[3]
    s2 = x[4]
    s3 = x[5]

    # create points
    p1 = Entity.Point([0., -a / 2, 0., d1])  #fyrsti punktur neðri vinstri

    p2 = Entity.Point([0., a - a / 2, 0., d1])  #2. punktur efri vinstri

    p3 = Entity.Point([t_veggur, a - a / 2, 0., d1])  #3. punktur efri hægri

    p4 = Entity.Point([t_veggur, a - s1 - a / 2, 0., d1])  #fyrsti ribbup ef

    p5 = Entity.Point([t_veggur + L / 2, a - s2 - a / 2, 0.,
                       d1])  # 2 ribbup ef

    p6 = Entity.Point([t_veggur + L, s3 - a / 2, 0., d1])  #síðast ribbup ef

    p7 = Entity.Point([t_veggur + L, s3 - a / 2, 0., d1])  #síðast ribbup ne

    p8 = Entity.Point([t_veggur + L / 2, s2 - a / 2, 0, d1])  #2. ribbup ne

    p9 = Entity.Point([t_veggur, s1 - a / 2, 0., d1])  #1. ribbup ef

    p10 = Entity.Point([t_veggur, 0. - a / 2, 0.,
                        d1])  #síðasti punktur neðri hægri

    my_mesh.addEntities([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10])
    # create curves
    l1 = Entity.Curve([p1, p2])  #innri bein lína upp
    l2 = Entity.Curve([p2, p3])  # efri hlið einangrun
    l3 = Entity.Curve([p3, p4])  # ytri bein lína upp
    l4 = Entity.Curve([p4, p5])  #ribba 1. 2. p e

    l5 = Entity.Curve([p5, p6])  #ribba 2. 3. p e
    l6 = Entity.Curve([p6, p7])  #ribba endi
    l7 = Entity.Curve([p7, p8])  #ribba 3. 2. n
    l8 = Entity.Curve([p8, p9])  #ribba 2. 1. n
    l9 = Entity.Curve([p9, p10])  #neðri bein lína upp
    l10 = Entity.Curve([p10, p1])  #einangrun neðri

    my_mesh.addEntities([l1, l2, l3, l4, l5, l6, l7, l8, l9, l10])

    ll1 = Entity.CurveLoop([l1, l2, l3, l4, l5, l6, l7, l8, l9, l10],
                           mesh=my_mesh)

    s1 = Entity.PlaneSurface([ll1], mesh=my_mesh)

    g1 = Entity.PhysicalGroup(name='innri')
    g2 = Entity.PhysicalGroup(name='ytri')
    g3 = Entity.PhysicalGroup(name='ribba')
    g4 = Entity.PhysicalGroup(name='einangrun')
    my_mesh.addEntities([g1, g2, g3, g4])
    g1.addEntities([l1])
    g2.addEntities([l3, l4, l5, l6, l7, l8, l9])
    g4.addEntities([l2, l10])
    g3.addEntities([s1])
    # set max element size
    #my_mesh.Options.Mesh.CharacteristicLengthMax = 0.1
    # adding Coherence option
    my_mesh.Coherence = True
    # write the geofile
    #os.system('rm .geo')
    my_mesh.writeGeo('{}.geo'.format(filename))
    os.system('gmsh {}.geo -2 -o {}.msh'.format(filename, filename))
    #os.system('gmsh my_mesh.geo')
    try:
        xu, y, tri, T, V, q = axifem.axiHeatCond('{}.msh'.format(filename), \
                    {'ribba':k}, {'ytri':(h_utan,-h_utan*T_inf_utan),'innri':(h_innan,-h_innan*T_inf_innan),'einangrun':(0,0)})
        print(sign * q['ytri'][1])
    except:
        return 0
    return sign * q['ytri'][1]
Exemple #8
0
p7 = Entity.Point([t_veggur, (a - d) / 2 - a / 2, 0.,
                   d1])  #7. punktur byrjun á ribbu neðri
my_mesh.addEntity(p7)
p8 = Entity.Point([t_veggur, -a / 2, 0., d1])  #síðasti punktur neðri hægri
my_mesh.addEntity(p8)
# create curves
l1 = Entity.Curve([p1, p2])  #innri bein lína upp
l2 = Entity.Curve([p2, p3])  # efri hlið einangrun
l3 = Entity.Curve([p3, p4])  # ytri bein lína upp
l4 = Entity.Curve([p4, p5])  #ribba bein lína upp
l5 = Entity.Curve([p5, p6])  #ribba endi
l6 = Entity.Curve([p6, p7])  #ribba bein lína niðri
l7 = Entity.Curve([p7, p8])  # ytri bein lína niðri
l8 = Entity.Curve([p8, p1])  #neðri hlið einangrun

my_mesh.addEntities([l1, l2, l3, l4, l5, l6, l7, l8])

ll1 = Entity.CurveLoop([l1, l2, l3, l4, l5, l6, l7, l8], mesh=my_mesh)

s1 = Entity.PlaneSurface([ll1], mesh=my_mesh)

g1 = Entity.PhysicalGroup(name='innri')
g2 = Entity.PhysicalGroup(name='ytri')
g3 = Entity.PhysicalGroup(name='ribba')
g4 = Entity.PhysicalGroup(name='einangrun')
my_mesh.addEntities([g1, g2, g3, g4])
g1.addEntities([l1])
g2.addEntities([l3, l4, l5, l6, l7])
g4.addEntities([l2, l8])
g3.addEntities([s1])
# set max element size