Пример #1
0
def add_ball(m, r, lc):
    # add ball in 1D, 2D, 3D
    if len(m) == 3:
        return py4gmsh.add_ball(m, r, lc, with_volume=False)[2]
    elif len(m) == 2:
        return add_circle(m, r, lc)
    elif len(m) == 1:
        return [
            py4gmsh.Point([m[0] - r, 0, 0]),
            py4gmsh.Point([m[0] + r, 0, 0])
        ]
    else:
        raise Exception("Ball center m must have dimension 1, 2 or 3.")
Пример #2
0
    def entity_to_gmsh(self, e, dim, lc, gmshself=True):
        # do not duplicate entity in gmsh
        i = self.entities[dim].index(e)
        gmsh_e = self.gmsh_entities[dim][i]
        if gmsh_e is not None:
            return gmsh_e

        if dim==0: # create Point
            e = e + tuple(0. for i in range(3 - self.dim))
            gmsh_e = py4gmsh.Point(e, lc)
            self.gmsh_entities[0][i] = gmsh_e
            #print gmsh_e, e
            return gmsh_e

        # dim>0: recursively generate facets and entity itself
        facets = _facets(e)
        facets = [self.entity_to_gmsh(f, dim-1, lc)
            for f in facets]
        orient = _orientations(dim-1)
        loop = FacetLoop[dim-1]([o+s for o, s in izip(orient, facets)])
        if gmshself:
            gmsh_e = Entity[dim](loop)
            self.gmsh_entities[dim][i] = gmsh_e
            #print gmsh_e, e
            return gmsh_e
Пример #3
0
def entities_to_gmsh(entities, indexsets, esets, lc=.5):

    global gmsh_entities
    global dim
    global dimt

    dim = len(entities) - 1
    dimt = -1
    for en in entities:
        if en:
            dimt += 1

    gmsh_entities = [[None for e in k] for k in entities]

    # a shortcut
    _gmsh = lambda entity, k: gmsh_entities[k][entities[k].index(entity)]

    # add points
    for i, e in enumerate(entities[0]):
        #print e
        #print esets[0][i]
        # py4gmsh.Point expects three values x,y,z
        e = e + tuple(0. for i in range(3 - dim))
        # create point
        gmsh_entities[0][i] = py4gmsh.Point(e, lc)

    # add entities of dimension > 0
    for k in range(1, dim + 1):
        orient = _orientations(k - 1)

        for i, e in enumerate(entities[k]):
            #print e
            #print esets[k][i]

            # skip code creation for entity if not part of domain
            # what do we do with unnessecary facets??
            if k == dim and i not in indexsets[k]:
                #print "NOT INSIDE"
                #print
                continue

            # get surrounding facets (x,y,z in this order)
            facets = _facets(e)

            #for f in facets:
            #print f,

            # find corresponding gmsh facets
            facets = [_gmsh(l, k - 1) for l in facets]

            # create facet loop with correct orientations
            #print facets
            loop = FacetLoop[k - 1]([o + s for o, s in zip(orient, facets)])
            #print

            # add entity
            gmsh_entities[k][i] = Entity[k](loop)

    return gmsh_entities
Пример #4
0
 def insert_points(self, points, lc=1., dim=None, forbidden=()):
     if not points: return
     if dim is None: dim = len(points[0])
     vol = {1: "Line", 2: "Surface", 3: "Volume"}[dim]
     with Log("inserting points..."):
         for x in points:
             x_ = [x[i] if i < dim else 0. for i in range(3)]
             surf, name = self.get_gmsh_sub(x)
             #print p, surf, name
             if name not in forbidden:
                 p = py4gmsh.Point(x_, lc)
                 py4gmsh.raw_code(["Point{%s} In %s{%s};" % (p, vol, surf)])
Пример #5
0
    def Point(self, x, lc):
        if x in self.gmsh_nodes:
            return self.gmsh_nodes[x]

        #print x, lc
        if self.dim == 1:
            x1 = [x[1], 0., 0.]
        elif self.dim == 2:
            x1 = [x[0], x[1], 0.]
        else:
            x1 = [x[0], 0., x[1]]
        gmsh_x = gmsh.Point(x1, lc)
        self.gmsh_nodes[x] = gmsh_x
        return gmsh_x
Пример #6
0
def add_circle(m, r, lc):
    m0, m1 = m[0], m[1]
    point = lambda x, y: py4gmsh.Point([x, y, 0], lc)
    # add points.
    p = [
        point(m0, m1),
        point(m0 + r, m1),
        point(m0, m1 + r),
        point(m0 - r, m1),
        point(m0, m1 - r)
    ]
    # add circle lines
    return [
        py4gmsh.Circle([p[1], p[0], p[2]]),
        py4gmsh.Circle([p[2], p[0], p[3]]),
        py4gmsh.Circle([p[3], p[0], p[4]]),
        py4gmsh.Circle([p[4], p[0], p[1]])
    ]