# Calculating Average of Variable at Periodic Boundary

**URL:** <https://pyfr.discourse.group/t/calculating-average-of-variable-at-periodic-boundary/1343>\
**Category:** Development\
**Created:** [23 February 2026 09:59 UTC](https://pyfr.discourse.group/t/calculating-average-of-variable-at-periodic-boundary/1343 "2026-02-23T09:59:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![fredmorin18](https://yyz2.discourse-cdn.com/free1/user_avatar/pyfr.discourse.group/fredmorin18/32/755_2.png) [@fredmorin18](https://pyfr.discourse.group/u/fredmorin18)\
**Post date:** [24 February 2026 17:28 UTC](https://pyfr.discourse.group/t/calculating-average-of-variable-at-periodic-boundary/1343/3 "2026-02-24T17:28:07Z")

</div>

The averaging over the periodic surface is working now 🙂

My next issue is that I can’t seem to be able to pass an external value to the kernels.

I attempted to replicate what was done here (and something similar worked for a plugin I made a while ago), but it throws “invalid argument specification”

> [@Expressions for boundary condition as a function of neural-network outputs](https://pyfr.discourse.group/t/expressions-for-boundary-condition-as-a-function-of-neural-network-outputs/1189):
>
> Hi, I am trying to reproduce [a study](https://www.cambridge.org/core/journals/journal-of-fluid-mechanics/article/artificial-neural-networks-trained-through-deep-reinforcement-learning-discover-control-strategies-for-active-flow-control/D5B80D809DFFD73760989A07F5E11039) of active flow control of the flow over a 2D cylinder with 2 jets positioned at ±90 degrees. I am solving the compressible NS equations for now. As a start, I set the boundary conditions for the jet as, for example, [soln-bcs-jet\_top] type = sub-in-frv theta = atan2(y,x) ; theta, not used for now omega = 10\*pi/180 ; jet width in radians theta0\_top = 90\*pi/180 ; center of jet R = 0.5 ; radius of cylinder rho = rhoc u = 0.09 / (%(omega)s\*%(R)s\*%(R)s) \* x v = …

My class is similar to the MassFlowBC one, and is structured as follows (I only want to use the external value in the `comm_flux` kernel):

```auto
class ACNavierStokesPintInters(ScalarPeriodic, BaseAdvectionDiffusionIntInters):
    def __init__ (self, be, lhs, rhs, elemap, cfg):
        super(). __init__ (be, lhs, rhs, elemap, cfg)

        # Pointwise template arguments
        rsolver = self.cfg.get('solver-interfaces', 'riemann-solver')
        tplargs = dict(ndims=self.ndims, nvars=self.nvars, rsolver=rsolver,
                       c=self.c)
                       
        kprefix = 'pyfr.solvers.acnavstokes.kernels'
        self._be.pointwise.register(f'{kprefix}.pintconu')
        self._be.pointwise.register(f'{kprefix}.pintcflux')
        
        self.kernels['con_u'] = lambda: self._be.kernel(
            'pintconu', tplargs=tplargs, dims=[self.ninterfpts],
            ulin=self._scal_lhs, urin=self._scal_rhs,
            ulout=self._comm_lhs, urout=self._comm_rhs
        )
        self.kernels['comm_flux'] = lambda: self._be.kernel(
            'pintcflux', tplargs=tplargs, dims=[self.ninterfpts],
            extrns=self._external_args, ul=self._scal_lhs, 
            ur=self._scal_rhs, gradul=self._vect_lhs, 
            gradur=self._vect_rhs, nl=self._pnorm_lhs
        )

```

and the relevant parts from the `ScalarPeriodic` class:

```auto
class ScalarPeriodic:
    def __init__ (self, be, lhs, rhs, elemap, cfg):
        super(). __init__ (be, lhs, rhs, elemap, cfg)
        
        self.cfgsect = f'scalar-periodic'
        self.name = f'periodic'
        
        # Setting the desired average value of scalar T
        self.T_sp = self.cfg.getfloat(self.cfgsect, 'T_avg', 1.0)
        
        # Controlling inlet (LHS) scalar avg
        self.cf = be.matrix((1, 1), tags={'align'})
        self.cf.set(np.full((1, 1), 1.0))
        self._set_external('cf', f'in broadcast fpdtype_t[1][1]', value=self.cf)
...

    @classmethod
    def preparefn(cls, pciface, mesh, elemap):
        if pciface:
            return pciface.prepare
        else:
            return None

    def prepare(self, system, ubank, t, kerns): 
        solns = dict(zip(system.ele_types, system.ele_scal_upts(ubank)))
        self.mT = self.calculate_scalar_avg(solns)
        self.cf.set(np.full((1, 1), self.T_sp / self.mT))

```

Finally, the mako kernel:

```auto
...
<%pyfr:kernel name='pintcflux' ndim='1' params='ul, ur, gradul, nl' externs='cf'>
...

```

When I had tried to use the bind method on a scalar like in the MassFlowBC class, it threw ‘PointwiseKernel’ object has no attribute ‘bind’ so I’m wondering if I did something wrong in my solvers/base/system.py file…

Can you see what I’m doing wrong at a glance?

Thank you,

Fred

---

_[View the full topic](https://pyfr.discourse.group/t/calculating-average-of-variable-at-periodic-boundary/1343)._
