# Defining weighted averages

Hello, i’ll give some context first:
Let \mathscr{P} be a partition of the domain \Omega into N_{E} disjoint open elements \Omega_{e} :

\bar{\Omega}=\bigcup_{e=1}^{N_{E}} \bar{\Omega}_{e} \quad \text { and } \quad \Omega_{e} \cap \Omega_{f}=\emptyset \quad \text { for } e \neq f

where \bar{\Omega} is the closure of \Omega. Each element \Omega_{e} has a boundary \partial \Omega_{e} and the outward unit normal to \partial \Omega_{e} is \mathbf{n}_{e}. Let \Gamma be the ensemble of interelement boundaries \Gamma_{l}=\partial \Omega_{e} \cap \partial \Omega_{f} with e>f inside the domain, with all possible combinations:

\bar{\Gamma}=\bigcup_{l=1}^{N_{\Gamma}} \bar{\Gamma}_{l} \quad \text { and } \quad \Gamma_{l} \cap \Gamma_{m}=\emptyset \quad \text { for } l \neq m

where N_{\Gamma} is the number of elements in \Gamma. Each \Gamma_{l} \in \Gamma is associated with a unique unit normal vector \mathbf{n} which points from \Omega_{e} to \Omega_{f}.

Now i’m triyng to define

\langle\mathbf{s}\rangle=\frac{1}{2}\left(\mathbf{s}_{\mid \Omega_{e}}+\mathbf{s}_{\mid\Omega_{f}}\right)

and

\langle\mathbf{s}\rangle_{\lambda}=(1 / 2+\lambda) \mathbf{s}_{\mid \Omega_{e}}+(1 / 2-\lambda) \mathbf{s}_{\mid \Omega_{f}},

I know i can write \langle\mathbf{s}\rangle as

avg(s)


How can i write \langle\mathbf{s}\rangle_{\lambda}? Thanks for the help!

1 Like

consider

lamb = Constant(0)
s_lamb = (1/2+lamb)*s("+")+(1/2-lamb)*s("-")
3 Likes

something along these lines? Keep in mind that if \lambda is also multivalued you’ll need to restrict it to the appropriate side of the facet.

from dolfin import *

mesh = UnitSquareMesh(1, 1)
V = FunctionSpace(mesh, "CG", 1)
s = interpolate(Constant(1.0), V)

F1 = avg(s)*dS

print(assemble(F1))

lmbda = Constant(1.0)
F2 = (((0.5 + lmbda)*s)("+") + ((0.5 - lmbda)*s)("-"))*dS

print(assemble(F2))

2 Likes

If you consistently mark the domains \Omega_e with a cell function, the the restrictions s("+") and s("-") is consistently ordered, as shown in:

and therefore you can define

def avg_gamma(u, gamma):
return (0.5+gamma)*u("+") + (0.5-gamma)*u("-")

3 Likes

I’m not sure i understand what you mean by “consistently mark the domains with a cell function”, i’ve defined a mesh as a domain and some boundary markers as subdomains and wrote:

ds = Measure('ds', domain=mesh, subdomain_data=boundary_markers)


so my intention is to do something like:

F = inner(anything,v)*dx + inner(avg_gamma(u,gamma),v)*ds


Please read the post I linked to for clarification and details.