Beispiel #1
0
    def _pair_periodic_fluid_faces(self, bpart, resid):
        pfaces = defaultdict(list)
        nodepts = self._nodepts

        for k, (lpent, rpent) in self._pfacespents.items():
            for pftype in bpart[lpent]:
                lfnodes = bpart[lpent][pftype]
                rfnodes = bpart[rpent][pftype]

                lfpts = np.array([[nodepts[n] for n in fn] for fn in lfnodes])
                rfpts = np.array([[nodepts[n] for n in fn] for fn in rfnodes])

                lfidx = fuzzysort(lfpts.mean(axis=1).T, range(len(lfnodes)))
                rfidx = fuzzysort(rfpts.mean(axis=1).T, range(len(rfnodes)))

                for lfn, rfn in zip(lfnodes[lfidx], rfnodes[rfidx]):
                    # Add periodic face flags: periodic BC number offset plus 1 to avoid +/- 0
                    flg = int(k) + 1

                    # Left = +, right = -
                    lf = resid.pop(tuple(sorted(lfn)))[:-1] + (flg, )
                    rf = resid.pop(tuple(sorted(rfn)))[:-1] + (-flg, )

                    pfaces[pftype].append([lf, rf])

        return pfaces
Beispiel #2
0
    def _pair_periodic_fluid_faces(self, bpart, resid):
        pfaces = defaultdict(list)
        nodepts = self._nodepts

        for lpent, rpent in self._pfacespents.itervalues():
            for pftype in bpart[lpent]:
                lfnodes = bpart[lpent][pftype]
                rfnodes = bpart[rpent][pftype]

                lfpts = np.array([[nodepts[n] for n in fn] for fn in lfnodes])
                rfpts = np.array([[nodepts[n] for n in fn] for fn in rfnodes])

                lfidx = fuzzysort(lfpts.mean(axis=1).T, xrange(len(lfnodes)))
                rfidx = fuzzysort(rfpts.mean(axis=1).T, xrange(len(rfnodes)))

                for lfn, rfn in izip(lfnodes[lfidx], rfnodes[rfidx]):
                    lf = resid.pop(tuple(sorted(lfn)))
                    rf = resid.pop(tuple(sorted(rfn)))

                    pfaces[pftype].append([lf, rf])

        return pfaces
Beispiel #3
0
    def _pair_periodic_fluid_faces(self, bpart, resid):
        pfaces = defaultdict(list)
        nodepts = self._nodepts

        for lpent, rpent in self._pfacespents.values():
            for pftype in bpart[lpent]:
                lfnodes = bpart[lpent][pftype]
                rfnodes = bpart[rpent][pftype]

                lfpts = np.array([[nodepts[n] for n in fn] for fn in lfnodes])
                rfpts = np.array([[nodepts[n] for n in fn] for fn in rfnodes])

                lfidx = fuzzysort(lfpts.mean(axis=1).T, range(len(lfnodes)))
                rfidx = fuzzysort(rfpts.mean(axis=1).T, range(len(rfnodes)))

                for lfn, rfn in zip(lfnodes[lfidx], rfnodes[rfidx]):
                    lf = resid.pop(tuple(sorted(lfn)))
                    rf = resid.pop(tuple(sorted(rfn)))

                    pfaces[pftype].append([lf, rf])

        return pfaces
Beispiel #4
0
    def __init__(self, basiscls, eles, cfg):
        self._be = None

        self._eles = eles
        self._cfg = cfg

        self.nspts = nspts = eles.shape[0]
        self.neles = neles = eles.shape[1]
        self.ndims = ndims = eles.shape[2]

        # Subclass checks
        assert self._dynvarmap
        assert self._nscal_fpts >= 1
        assert self._nvect_upts >= 1
        assert self._nvect_fpts >= 0

        # Check the dimensionality of the problem
        if ndims != basiscls.ndims or ndims not in self._dynvarmap:
            raise ValueError('Invalid element matrix dimensions')

        # Determine the number of dynamical variables
        self.nvars = len(self._dynvarmap[ndims])

        # Generate a symbol for each dimension (p,q or p,q,r)
        dims = sy.symbols('p q r')[:ndims]

        # Instantiate the basis class
        self._basis = basis = basiscls(dims, nspts, cfg)

        # Sizes
        self.nupts = basis.nupts
        self.nfpts = basis.nfpts

        # Transform matrices at the soln points
        self._gen_rcpdjac_smat_upts()

        # Physical normals at the flux points
        self._gen_pnorm_fpts()

        # Construct the physical location operator matrix
        plocop = np.asanyarray(basis.sbasis_at(basis.fpts), dtype=np.float)

        # Apply the operator to the mesh elements and reshape
        plocfpts = np.dot(plocop, eles.reshape(nspts, -1))
        plocfpts = plocfpts.reshape(self.nfpts, neles, ndims)
        plocfpts = plocfpts.transpose(1, 2, 0).tolist()

        srtd_face_fpts = [[fuzzysort(pts, ffpts) for pts in plocfpts]
                          for ffpts in basis.facefpts]
        self._srtd_face_fpts = np.array(srtd_face_fpts).swapaxes(0, 1)
Beispiel #5
0
    def __init__(self, basiscls, eles, cfg):
        self._be = None

        self.eles = eles
        self.cfg = cfg

        self.nspts = nspts = eles.shape[0]
        self.neles = neles = eles.shape[1]
        self.ndims = ndims = eles.shape[2]

        # Kernels we provide
        self.kernels = {}

        # Check the dimensionality of the problem
        if ndims != basiscls.ndims or ndims not in self.privarmap:
            raise ValueError('Invalid element matrix dimensions')

        # Determine the number of dynamical variables
        self.nvars = len(self.privarmap[ndims])

        # Instantiate the basis class
        self.basis = basis = basiscls(nspts, cfg)

        # See what kind of projection the basis is using
        self.antialias = basis.antialias

        # If we need quadrature points or not
        haveqpts = 'flux' in self.antialias or 'div-flux' in self.antialias

        # Sizes
        self.nupts = basis.nupts
        self.nqpts = basis.nqpts if haveqpts else None
        self.nfpts = basis.nfpts
        self.nfacefpts = basis.nfacefpts

        # Physical normals at the flux points
        self._gen_pnorm_fpts()

        # Construct the physical location operator matrix
        plocop = basis.sbasis.nodal_basis_at(basis.fpts)

        # Apply the operator to the mesh elements and reshape
        plocfpts = np.dot(plocop, eles.reshape(nspts, -1))
        self.plocfpts = plocfpts.reshape(self.nfpts, neles, ndims)
        plocfpts = self.plocfpts.transpose(1, 2, 0).tolist()

        self._srtd_face_fpts = [[fuzzysort(pts, ffpts) for pts in plocfpts]
                                for ffpts in basis.facefpts]
Beispiel #6
0
    def __init__(self, basiscls, eles, cfg):
        self._be = None

        self._eles = eles
        self._cfg = cfg

        self.nspts = nspts = eles.shape[0]
        self.neles = neles = eles.shape[1]
        self.ndims = ndims = eles.shape[2]

        # Kernels we provide
        self.kernels = {}

        # Check the dimensionality of the problem
        if ndims != basiscls.ndims or ndims not in self._dynvarmap:
            raise ValueError('Invalid element matrix dimensions')

        # Determine the number of dynamical variables
        self.nvars = len(self._dynvarmap[ndims])

        # Instantiate the basis class
        self._basis = basis = basiscls(nspts, cfg)

        # See what kind of projection the basis is using
        self.antialias = basis.antialias

        # If we need quadrature points or not
        haveqpts = 'flux' in self.antialias or 'div-flux' in self.antialias

        # Sizes
        self.nupts = basis.nupts
        self.nqpts = basis.nqpts if haveqpts else None
        self.nfpts = basis.nfpts
        self.nfacefpts = basis.nfacefpts

        # Physical normals at the flux points
        self._gen_pnorm_fpts()

        # Construct the physical location operator matrix
        plocop = basis.sbasis.nodal_basis_at(basis.fpts)

        # Apply the operator to the mesh elements and reshape
        plocfpts = np.dot(plocop, eles.reshape(nspts, -1))
        plocfpts = plocfpts.reshape(self.nfpts, neles, ndims)
        plocfpts = plocfpts.transpose(1, 2, 0).tolist()

        self._srtd_face_fpts = [[fuzzysort(pts, ffpts) for pts in plocfpts]
                                for ffpts in basis.facefpts]
Beispiel #7
0
    def _srtd_face_fpts(self):
        plocfpts = self.plocfpts.transpose(1, 2, 0)

        return [[np.array(fuzzysort(pts.tolist(), ffpts)) for pts in plocfpts]
                for ffpts in self.basis.facefpts]
Beispiel #8
0
    def _srtd_face_fpts(self):
        plocfpts = self.plocfpts.transpose(1, 2, 0).tolist()

        return [[fuzzysort(pts, ffpts) for pts in plocfpts]
                for ffpts in self.basis.facefpts]
Beispiel #9
0
    def get_connectivity(self):
        # For connectivity a first-order representation is sufficient
        eles = self._to_first_order(self._elenodes)

        # Split into fluid and boundary parts
        fpart, bpart = self._split_fluid(eles)

        # Extract the faces of the fluid elements
        ffaces = self._extract_faces(fpart)

        # Pair the fluid-fluid faces
        fpairs, resid = self._pair_fluid_faces(ffaces)

        # Identify periodic boundary face pairs

        # ---- Create periodic boundary tags ---
        pbc = {}
        for k in self._pfacespents:
            pbc['periodic_' + str(k) + '_l'] = bpart[self._pfacespents[k][0]]
            pbc['periodic_' + str(k) + '_r'] = bpart[self._pfacespents[k][1]]

        pbcfaces = defaultdict(list)
        nodepts = self._nodepts

        ret = {}
        for lpent in pbc:
            for pftype in pbc[lpent]:
                lfnodes = pbc[lpent][pftype]
                lfpts = np.array([[nodepts[n] for n in fn] for fn in lfnodes])

                lfidx = fuzzysort(lfpts.mean(axis=1).T, range(len(lfnodes)))

                for lfn in lfnodes[lfidx]:
                    lf = resid[tuple(sorted(lfn))]
                    pbcfaces[lpent].append(lf)

        for k, v in pbcfaces.items():
            ret['pcon_{0}_p0'.format(k)] = np.array(v, dtype='S4,i4,i1,i1')

        # -------

        pfpairs = self._pair_periodic_fluid_faces(bpart, resid)

        # Identify the fixed boundary faces
        bf = self._ident_boundary_faces(bpart, resid)

        if any(resid.values()):
            raise ValueError('Unpaired faces in mesh')

        # Flattern the face-pair dicts
        pairs = chain(chain.from_iterable(fpairs.values()),
                      chain.from_iterable(pfpairs.values()))

        # Generate the internal connectivity array
        con = list(pairs)

        # Generate boundary condition connectivity arrays
        bcon = {}
        for pbcrgn, pent in self._bfacespents.items():
            bcon[pbcrgn] = bf[pent]

        # Output
        ret['con_p0'] = np.array(con, dtype='S4,i4,i1,i1').T

        for k, v in bcon.items():
            ret['bcon_{0}_p0'.format(k)] = np.array(v, dtype='S4,i4,i1,i1')

        return ret