Exemplo n.º 1
0
    def _addrem_contour2(self):
        simp, sep, an, names, nnames = \
            [self.get_option(x) for x in ['simplify', 'separate',
                                          'angle', 'names', 'new_names']]
        if len(nnames) < names:
            for i, n in enumerate(names):
                if i >= len(nnames):
                    nnames.append(n)
        added = []
        # make copies
        for i, nm in enumerate(names):
            cont = self.any_acont_by_name(nm).deepcopy()
            added.append((cont, nnames[i]))

        # simplify
        if simp:
            for c in added:
                c2core.simplify(c[0].cdata, an, True)

        # separate
        if sep:
            newadded = []
            for c in added:
                for cc in c2core.quick_separate(c[0].cdata):
                    newadded.append((Contour2(cc), c[1]))
            added = newadded

        return added, []
Exemplo n.º 2
0
 def _addrem_contour2(self):
     c1 = self.any_cont_by_name(self.get_option('c1'))
     c2 = self.any_cont_by_name(self.get_option('c2'))
     op = self.get_option('oper')
     c3 = c2core.clip_domain(c1.cdata, c2.cdata, op,
                             self.get_option('simplify'))
     return [(Contour2(c3), self.get_option('name'))], []
Exemplo n.º 3
0
 def _addrem_contour2(self):
     conts = map(self.any_cont_by_name, self.get_option('src'))
     cc = [c.cdata for c in conts]
     fx = self.get_option('fix')
     close = self.get_option('close')
     shift = self.get_option('shiftnext')
     ret = c2core.connect_subcontours(cc, fx, close, shift)
     return [(Contour2(ret), self.get_option('name'))], []
Exemplo n.º 4
0
 def _addrem_contour2(self):
     s = self.any_cont_by_name(self.get_option('source'))
     nm = self.get_option('name')
     nc = c2core.decompose_contour(s.cdata)
     ret = []
     for n in nc:
         ret.append((Contour2(n), nm))
     return ret, []
Exemplo n.º 5
0
def _cont2_from_id(gid):
    from hybmeshpack.hmcore import c2
    from hybmeshpack.gdata.cont2 import Contour2
    if not isinstance(gid, list):
        return flow.receiver.get_any_contour(gid).contour2()
    else:
        ret = map(flow.receiver.get_any_contour, gid)
        ret = map(lambda x: x.contour2(), ret)
        cd = c2.concatenate([r.cdata for r in ret])
        return Contour2(cd)
Exemplo n.º 6
0
    def _build_grid(self):
        # unite domain and constraints
        domc, domcc = [], []
        for n in self.get_option('domain'):
            domc.append(self.any_cont_by_name(n))
            domcc.append(domc[-1].cdata)
        fulldom = Contour2(c2core.unite_contours(domcc))

        conc, concc = [], []
        if len(self.get_option('constr')) > 0:
            for n in self.get_option('constr'):
                conc.append(self.any_cont_by_name(n))
                concc.append(conc[-1].cdata)
            fullconst = Contour2(c2core.unite_contours(concc))
        else:
            fullconst = Contour2.empty()

        # call builder
        pts = self.get_option('pts')
        return self.call_c_proc(fulldom.cdata, fullconst.cdata, pts)
Exemplo n.º 7
0
    def _addrem_contour2(self):
        nm = self.get_option('name')
        src = self.get_option('sources')

        scont = []
        for s in src:
            scont.append(self.any_cont_by_name(s))
        pscont = [c.cdata for c in scont]
        newcont = c2core.unite_contours(pscont)

        return [(Contour2(newcont), nm)], []
Exemplo n.º 8
0
 def _addrem_contour2(self):
     c = self.any_cont_by_name(self.get_option('src'))
     plist = self.get_option('plist')
     if self.get_option('project_to') == 'vertex':
         plist = c.closest_points(plist, 'vertex')
     elif self.get_option('project_to') == 'line':
         plist = c.closest_points(plist, 'edge')
     elif self.get_option('project_to') == 'corner':
         c2 = c.deepcopy()
         c2core.simplify(c2.cdata, 0., False)
         plist = c2.closest_points(plist, 'vertex')
     ret = c2core.extract_subcontours(c.cdata, plist)
     rr = [(Contour2(it), self.get_option('name')) for it in ret]
     return rr, []
Exemplo n.º 9
0
 def _addrem_contour2(self):
     op0 = self.get_option('p0')
     b = self.get_option('bnd')
     rad = self.get_option('rad')
     na = self.get_option('na')
     astep = 2 * math.pi / na
     pts = []
     for i in range(na):
         angle = i * astep
         pts.append([
             op0[0] + rad * math.cos(angle), op0[1] + rad * math.sin(angle)
         ])
     c = c2core.build_from_points(pts, True, [b])
     return [(Contour2(c), self.get_option('name'))], []
Exemplo n.º 10
0
 def _addrem_contour2(self):
     c = self.any_cont_by_name(self.get_option('base'))
     ccond, c_ccond = [], []
     for it in self.get_option('cconts'):
         ccond.append(self.any_cont_by_name(it))
         c_ccond.append(ccond[-1].cdata)
     cpts = self.get_option('cpts')
     step = self.get_option('step')
     infdist = self.get_option('infdist')
     power = self.get_option('power')
     a0 = self.get_option('angle0')
     c_ret = c2core.matched_partition(c.cdata, c_ccond, cpts, step, infdist,
                                      power, a0)
     return [(Contour2(c_ret), self.get_option('name'))], []
Exemplo n.º 11
0
def flow_and_framework_fromfile(filename, flow, cb=None):
    doc, root, statenodes = 0, 0, []
    try:
        cb.pycall("Loading commands", "Reading xml", 0, 0)
        doc, root = hmxml.open_doc(filename)
        pstring = hmxml.purged_string(doc)
        pyside_root = ET.fromstring(pstring)
        pyside_flownode = pyside_root.findall('FLOW')
        if len(pyside_flownode) == 0:
            raise Exception('No proper data in xml file')
        else:
            pyside_flownode = pyside_flownode[0]

        # load commands
        cb.pycall("Loading commands", "Parsing", 0.5, 0)
        _load_command_flow(flow, pyside_flownode)
        cb.pycall("Loading commands", "Done", 1, 1)

        # state
        statenodes = hmxml.query(root, "FLOW/STATE")
        pyside_statenode = pyside_flownode.findall('STATE')
        if len(statenodes) > 0:
            statenode = statenodes[0]
            pyside_statenode = pyside_statenode[0]
        else:
            statenode = None
            pyside_statenode = None

        data = framework.Framework()
        if statenode is not None:
            # load boundary types
            _load_btypes(data, pyside_statenode)

            # load data
            c, g, s3, g3, cn, gn, s3n, g3n =\
                native_import.all_geom(doc, statenode, cb)
            for k, v in zip(cn, c):
                data.append_contour2(Contour2(v), k)
            for k, v in zip(gn, g):
                data.append_grid2(Grid2(v), k)
            for k, v in zip(s3n, s3):
                data.append_surface3(Surface3(v), k)
            for k, v in zip(g3n, g3):
                data.append_grid3(Grid3(v), k)
        flow.set_receiver(data)
    except:
        raise
    finally:
        hmxml.close_doc(doc, [root] + statenodes)
Exemplo n.º 12
0
 def _addrem_contour2(self):
     gn = self.get_option('grid_name')
     cn = self.get_option('cont_name')
     if cn is None:
         cn = gn + '_contour'
     simp = self.get_option('simplify')
     sep = self.get_option('separate')
     cc = self.grid2_by_name(gn).contour().contour2()
     if simp:
         c2core.simplify(cc.cdata, 0., True)
     if sep:
         cc = c2core.quick_separate(cc.cdata)
         for i, c in enumerate(cc):
             cc[i] = (Contour2(c), cn)
     else:
         cc = [(cc, cn)]
     return cc, []
Exemplo n.º 13
0
 def _addrem_contour2(self):
     c = self.any_cont_by_name(self.get_option('base'))
     algo = self.get_option('algo')
     step = self.get_option('step')
     a0 = self.get_option('angle0')
     keepbnd = self.get_option('keepbnd')
     ned = self.get_option('nedges')
     crosses_cont = []
     for nm in self.get_option('crosses'):
         crosses_cont.append(self.any_cont_by_name(nm))
     crosses = []
     for cr in crosses_cont:
         crosses.append(cr.cdata)
     keeppts = self.get_option('keep_pts')
     start = self.get_option('start')
     end = self.get_option('end')
     ret = c2core.contour_partition(c.cdata, step, algo, a0, keepbnd, ned,
                                    crosses, keeppts, start, end)
     return [(Contour2(ret), self.get_option('name'))], []
Exemplo n.º 14
0
    def _addrem_objects(self):
        self.__check_file_existance()
        g2list, c2list, g3list, s3list = [], [], [], []
        self._init_read()
        c2 = self._read_cont2()
        g2 = self._read_grid2()
        s3 = self._read_surf3()
        g3 = self._read_grid3()
        self._fin_read()
        for i, c in enumerate(c2):
            c2list.append((Contour2(c), self._c2name(i)))
        for i, c in enumerate(g2):
            g2list.append((Grid2(c), self._g2name(i)))
        for i, c in enumerate(s3):
            s3list.append((Surface3(c), self._s3name(i)))
        for i, c in enumerate(g3):
            g3list.append((Grid3(c), self._g3name(i)))

        return g2list, [], c2list, [], g3list, [], s3list, []
Exemplo n.º 15
0
    def __adjust_arg1(self, op):
        """ changes 'source' from name to AbstractContour object
            if end points are None changes them to actual values
            and adds options for multiply connected domains
        """
        # separate contour
        sep = c2core.quick_separate(op['source'].cdata)
        sep = [Contour2(s) for s in sep]

        # if end points are None:
        #    transform them to real contour point
        #    create set of options for multiply connected domains
        newops = []
        if op['start'] is None or op['end'] is None:
            for s in sep:
                p0, p1 = s.end_points()
                if p0 is None:
                    continue
                addto = op
                if op['start'] is not None and op['end'] is not None:
                    _t, op['source'] = op['source'], None
                    newops.append(copy.deepcopy(op))
                    op['source'] = _t
                    addto = newops[-1]
                # addto['source'] = s
                addto['source'] = op['source']
                addto['start'] = copy.deepcopy(p0)
                addto['end'] = copy.deepcopy(p1)
            if op['start'] is None or op['end'] is None:
                raise Exception("cannot find correct source for boundary grid",
                                self)

        # if points coincide find closest subcontour
        elif op['start'][0] == op['end'][0] and op['start'][1] == op['end'][1]:
            subcont = closest_contour(sep, op['start'])
            p0, p1 = subcont.end_points()
            if p0 != p1:
                op['start'] = p0
                op['end'] = p1

        return newops
Exemplo n.º 16
0
def info_contour(cid):
    """Get contour structure information

    :param cid: contour or grid identifier

    :returns:
       dictionary representing contour length, total number of nodes, edges,
       number of edges in each subcontour and number of edges
       of each boundary type::

         {'Nnodes': int,
          'Nedges': int,
          'subcont': [list-of-int],    # edges number in each subcontour
          'btypes': {btype(int): int}  # boundary type: number of edges
          'length': float
         }

    """
    icheck(0, ACont2D())

    cont = flow.receiver.get_any_contour(cid).contour2()
    ret = {}
    ret['Nnodes'] = cont.n_vertices()
    ret['Nedges'] = cont.n_edges()

    sep = [Contour2(s) for s in c2core.quick_separate(cont.cdata)]
    ret['subcont'] = [s.n_edges() for s in sep]

    bt = cont.raw_data('bt')
    ret['btypes'] = {}
    for s in bt:
        if s not in ret['btypes']:
            ret['btypes'][s] = 1
        else:
            ret['btypes'][s] += 1
    ret['length'] = cont.length()
    return ret
Exemplo n.º 17
0
 def _addrem_contour2(self):
     p0, p1 = self.get_option('p0'), self.get_option('p1')
     pts = [[p0[0], p0[1]], [p1[0], p0[1]], [p1[0], p1[1]], [p0[0], p1[1]]]
     bnds = self.get_option('bnds')
     c = c2core.build_from_points(pts, True, bnds)
     return [(Contour2(c), self.get_option('name'))], []
Exemplo n.º 18
0
 def _addrem_contour2(self):
     c = c2core.build_from_points(self.get_option('points'), False,
                                  self.get_option('bnds'))
     return [(Contour2(c), self.get_option('name'))], []
Exemplo n.º 19
0
 def _addrem_contour2(self):
     c = c2core.spline(self.get_option('points'), self.get_option('bnds'),
                       self.get_option('nedges'))
     return [(Contour2(c), self.get_option('name'))], []