Source code for pyfr.solvers.euler.elements

# -*- coding: utf-8 -*-

from pyfr.solvers.baseadvec import BaseAdvectionElements

class BaseFluidElements:
    formulations = ['std', 'dual']

    privarmap = {2: ['rho', 'u', 'v', 'p'],
                 3: ['rho', 'u', 'v', 'w', 'p']}

    convarmap = {2: ['rho', 'rhou', 'rhov', 'E'],
                 3: ['rho', 'rhou', 'rhov', 'rhow', 'E']}

    dualcoeffs = convarmap

    visvarmap = {
        2: [('density', ['rho']),
            ('velocity', ['u', 'v']),
            ('pressure', ['p'])],
        3: [('density', ['rho']),
            ('velocity', ['u', 'v', 'w']),
            ('pressure', ['p'])]

    def pri_to_con(pris, cfg):
        rho, p = pris[0], pris[-1]

        # Multiply velocity components by rho
        rhovs = [rho*c for c in pris[1:-1]]

        # Compute the energy
        gamma = cfg.getfloat('constants', 'gamma')
        E = p/(gamma - 1) + 0.5*rho*sum(c*c for c in pris[1:-1])

        return [rho] + rhovs + [E]

    def con_to_pri(cons, cfg):
        rho, E = cons[0], cons[-1]

        # Divide momentum components by rho
        vs = [rhov/rho for rhov in cons[1:-1]]

        # Compute the pressure
        gamma = cfg.getfloat('constants', 'gamma')
        p = (gamma - 1)*(E - 0.5*rho*sum(v*v for v in vs))

        return [rho] + vs + [p]

[docs]class EulerElements(BaseFluidElements, BaseAdvectionElements):
[docs] def set_backend(self, *args, **kwargs): super().set_backend(*args, **kwargs) # Can elide interior flux calculations at p = 0 if self.basis.order == 0: return # Register our flux kernels self._be.pointwise.register('pyfr.solvers.euler.kernels.tflux') self._be.pointwise.register('pyfr.solvers.euler.kernels.tfluxlin') # Template parameters for the flux kernels tplargs = { 'ndims': self.ndims, 'nvars': self.nvars, 'nverts': len(self.basis.linspts), 'c': self.cfg.items_as('constants', float), 'jac_exprs': self.basis.jac_exprs } # Helpers c, l = 'curved', 'linear' r, s = self._mesh_regions, self._slice_mat if c in r and 'flux' not in self.antialias: self.kernels['tdisf_curved'] = lambda uin: self._be.kernel( 'tflux', tplargs=tplargs, dims=[self.nupts, r[c]], u=s(self.scal_upts[uin], c), f=s(self._vect_upts, c), smats=self.curved_smat_at('upts') ) elif c in r: self.kernels['tdisf_curved'] = lambda: self._be.kernel( 'tflux', tplargs=tplargs, dims=[self.nqpts, r[c]], u=s(self._scal_qpts, c), f=s(self._vect_qpts, c), smats=self.curved_smat_at('qpts') ) if l in r and 'flux' not in self.antialias: self.kernels['tdisf_linear'] = lambda uin: self._be.kernel( 'tfluxlin', tplargs=tplargs, dims=[self.nupts, r[l]], u=s(self.scal_upts[uin], l), f=s(self._vect_upts, l), verts=self.ploc_at('linspts', l), upts=self.upts ) elif l in r: self.kernels['tdisf_linear'] = lambda: self._be.kernel( 'tfluxlin', tplargs=tplargs, dims=[self.nqpts, r[l]], u=s(self._scal_qpts, l), f=s(self._vect_qpts, l), verts=self.ploc_at('linspts', l), upts=self.qpts )