コード例 #1
0
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)
    def reset_geom_params(self):
        """
        Reset the necessary parameters to create a new geometry.
        Returns:

        """
        # Reset the mesh object.
        self.my_mesh = Mesh()

        # Initialize physical groups and geometry parameters.
        self.p_dict = dict(
        )  # Create a dictionary containing all the points of the geometry.
        self.interface_points = dict(
        )  # Dictionary that will isolate the points conforming the interface.
        self.list_points_interface = list()
        self.refinement_points_tip = None  # List containing the refinement points of the tip.
        self.refinement_points_knee = None  # List containing the refinement points of the knee.
        self.point_num = 1  # Number of points counter.
        self.key = ''  # Variable creating the dicts of the self.p_dict variable.
        self.interface_end_point = None  # Locator of the last point defining the interface
        self.interface_end_point_z = None  # Locator of the z coordinate of the last point defining the interface
        self.inlet = Entity.PhysicalGroup(name='Inlet', mesh=self.my_mesh)
        self.twr = Entity.PhysicalGroup(name='Tube_Wall_R', mesh=self.my_mesh)
        self.twl = Entity.PhysicalGroup(name='Tube_Wall_L', mesh=self.my_mesh)
        self.bw = Entity.PhysicalGroup(name='Bottom_Wall', mesh=self.my_mesh)
        self.lwr = Entity.PhysicalGroup(name='Lateral_Wall_R',
                                        mesh=self.my_mesh)
        self.tw = Entity.PhysicalGroup(name='Top_Wall', mesh=self.my_mesh)
        self.lwl = Entity.PhysicalGroup(name='Lateral_Wall_L',
                                        mesh=self.my_mesh)
        self.interface = Entity.PhysicalGroup(name='Interface',
                                              mesh=self.my_mesh)

        self.vacuum = Entity.PhysicalGroup(name='Vacuum', mesh=self.my_mesh)
        self.liquid = Entity.PhysicalGroup(name='Liquid', mesh=self.my_mesh)
    def __init__(self):
        self.geoPath = ''  # Initialize the path where the .geo file will be stored.
        self.filename = ''  # Initialize the name of the .geo file.
        self.refinement = ''  # This string will be later modified by the user to indicate the refinement of mesh.
        self.msh_filename = ''
        self.geo_filename = ''
        self.mesh_filename = ''
        self.app = None  # Variable containing all the mesh details specified by the user.

        # Define the geometry and mesh object, as well as some of its properties.
        self.my_mesh = Mesh()
        self.max_element_size = None
        self.min_element_size = None
        self.length_from_curvature = None
        self.length_extend = None

        # Define auxiliary variables.
        self.interface_fun = ''
        self.interface_fun_r = ''
        self.interface_fun_z = ''

        # Initialize physical groups and geometry parameters.
        self.p_dict = dict(
        )  # Create a dictionary containing all the points of the geometry.
        self.interface_points = dict(
        )  # Dictionary that will isolate the points conforming the interface.
        self.list_points_interface = list()
        self.refinement_points_tip = None  # List containing the refinement points of the tip.
        self.refinement_points_knee = None  # List containing the refinement points of the knee.
        self.point_num = 1  # Number of points counter.
        self.key = ''  # Variable creating the dicts of the self.p_dict variable.
        self.interface_end_point = None  # Locator of the last point defining the interface
        self.interface_end_point_z = None  # Locator of the z coordinate of the last point defining the interface
        self.inlet = Entity.PhysicalGroup(name='Inlet', mesh=self.my_mesh)
        self.twr = Entity.PhysicalGroup(name='Tube_Wall_R', mesh=self.my_mesh)
        self.twl = Entity.PhysicalGroup(name='Tube_Wall_L', mesh=self.my_mesh)
        self.bw = Entity.PhysicalGroup(name='Bottom_Wall', mesh=self.my_mesh)
        self.lwr = Entity.PhysicalGroup(name='Lateral_Wall_R',
                                        mesh=self.my_mesh)
        self.tw = Entity.PhysicalGroup(name='Top_Wall', mesh=self.my_mesh)
        self.lwl = Entity.PhysicalGroup(name='Lateral_Wall_L',
                                        mesh=self.my_mesh)
        self.interface = Entity.PhysicalGroup(name='Interface',
                                              mesh=self.my_mesh)

        self.vacuum = Entity.PhysicalGroup(name='Vacuum', mesh=self.my_mesh)
        self.liquid = Entity.PhysicalGroup(name='Liquid', mesh=self.my_mesh)
コード例 #4
0
def geometry_to_gmsh(domain):
    import py2gmsh
    from py2gmsh.Mesh import *
    from py2gmsh.Entity import *
    from py2gmsh.Fields import *
    self = domain
    lines_dict = {}

    mesh = Mesh()

    if self.boundaryTags:
        for i, tag in enumerate(self.boundaryTags):
            phys = PhysicalGroup(nb=i, name=tag)
            mesh.addGroup(phys)

    for i, v in enumerate(self.vertices):
        if domain.nd == 2:
            p = Point([v[0], v[1], 0.])
        else:
            p = Point(v)
        mesh.addEntity(p)
        g = mesh.groups.get(self.vertexFlags[i])
        if g:
            g.addEntity(p)
    nb_points = i + 1
    for i in range(nb_points):
        lines_dict[i] = {}

    for i, s in enumerate(self.segments):
        lines_dict[s[0]][s[1]] = i
        l = Line([mesh.points[s[0] + 1], mesh.points[s[1] + 1]])
        mesh.addEntity(l)
        g = mesh.groups.get(self.segmentFlags[i])
        if g:
            g.addEntity(l)

    for i, f in enumerate(self.facets):
        if self.nd == 3 or (self.nd == 2 and i not in self.holes_ind):
            lineloops = []
            for j, subf in enumerate(f):
                lineloop = []
                # vertices in facet
                for k, ver in enumerate(subf):
                    if ver in lines_dict[subf[k - 1]].keys():
                        lineloop += [lines_dict[subf[k - 1]][ver] + 1]
                    elif subf[k - 1] in lines_dict[ver].keys():
                        # reversed
                        lineloop += [(lines_dict[ver][subf[k - 1]] + 1)]
                    else:
                        l = Line([
                            mesh.points[subf[k - 1] + 1], mesh.points[ver + 1]
                        ])
                        mesh.addEntity(l)
                        lineloop += [l.nb]
                ll = LineLoop(mesh.getLinesFromIndex(lineloop))
                mesh.addEntity(ll)
                lineloops += [ll.nb]
            s = PlaneSurface([mesh.lineloops[loop] for loop in lineloops])
            mesh.addEntity(s)
            g = mesh.groups.get(self.facetFlags[i])
            if g:
                g.addEntity(s)

    for i, V in enumerate(self.volumes):
        surface_loops = []
        if i not in self.holes_ind:
            for j, sV in enumerate(V):
                sl = SurfaceLoop((np.array(sV) + 1).tolist())
                mesh.addEntity(sl)
                surface_loops += [sl.nb]
            vol = Volume(surface_loops)
            mesh.addEntity(vol)
            g = mesh.groups.get(self.regionFlags[i])
            if g:
                g.addEntity(vol)

    return mesh
コード例 #5
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]
コード例 #6
0
T_inf_innan = 95
T_inf_utan = 18
h_utan = 45
k = 16
t_veggur = 0.003
d = 0.003
a = 0.01
L = 0.01
d1 = 0.0005
d2 = 0.0005
V_sk = np.pi * (a / 2)**2 * t_veggur + np.pi * (d / 2)**2 * (L)
print('initial volume: {}'.format(V_sk))

tolerance = 1e-10  #tolerance for volume
# create Mesh class instance
my_mesh = Mesh()
i = 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
コード例 #7
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]
コード例 #8
0
T_inf_innan = 95
T_inf_utan = 18
h_utan = 45
k = 16
t_veggur = 0.003
d = 0.003
a = 0.01
L = 0.01
d1 = 0.0005
d2 = 0.0005
V_sk = np.pi * (a / 2)**2 * t_veggur + np.pi * (d / 2)**2 * (L)
print('initial volume: {}'.format(V_sk))

tolerance = 6e-11  #tolerance for volume
# create Mesh class instance
my_mesh = Mesh()
i = 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
コード例 #9
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]
コード例 #10
0
    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
コード例 #11
0
ファイル: test.py プロジェクト: JoelInga/skoli
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]
コード例 #12
0
d = 0.003
a = 0.01
L = 0.01
x0 = [0.00240825, 0.00944295, 0.02112096]
d = x0[0]
a = x0[1]
L = x0[2]
d1 = 0.0002
d2 = 0.0005
V_sk = 1.8849555921538741e-06
tolerance = 6e-013  #tolerance for volume
V_sk = np.pi * (a / 2)**2 * t_veggur + np.pi * (d / 2)**2 * L
print(V_sk * 2)

# create Mesh class instance
my_mesh = Mesh()

# create points
p1 = Entity.Point([0., -a / 2, 0., d1])  #fyrsti punktur neðri vinstri
# add point to mesh
my_mesh.addEntity(p1)
#create more points
p2 = Entity.Point([0., a - a / 2, 0., d1])  #2. punktur efri vinstri
my_mesh.addEntity(p2)
p3 = Entity.Point([t_veggur, a - 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)