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)
Example #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]
Example #3
0
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
#my_mesh.Options.Mesh.CharacteristicLengthMax = 0.1

# adding Coherence option
my_mesh.Coherence = True
# write the geofile
my_mesh.writeGeo('my_mesh.geo')
os.system('gmsh my_mesh.geo -2 -o my_mesh.msh')
#os.system('gmsh my_mesh.geo')

x1, y1, tri1, T1, V1, q1 = axifem.axiHeatCond('my_mesh.msh', \
        {'ribba':k}, {'ytri':(h_utan,-h_utan*T_inf_utan),'innri':(h_innan,-h_innan*T_inf_innan),'einangrun':(0,0)})

virkni = q['ytri'][1] / q1['ytri'][1]

from matplotlib.pyplot import *
print('Ribbuvirkni {}:'.format(virkni))
print('Rúmmál {}'.format(V['ribba']))
print('Varmaflutningur: {:g}'.format(q['ytri'][1]))
print('Hámarkshitastig: {:g}'.format(max(T)))
print('Lágmarkshitastig: {:g}'.format(min(T)))
figure(figsize=(16, 3))
Example #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]
Example #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]
Example #6
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]