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.

I’m getting an error when i write:

def norma2(u):
    return sqrt(dot(u,u) + DOLFIN_EPS)
def avg_gamma(u, gamma):
     return (0.5+gamma("+"))*u("+") + (0.5-gamma("-"))*u("-")
lbda = conditional(gt(dot(u,ν),0),0.5*dot(u,ν)/abs(dot(u,ν)),0) 
θ=0.5
H=η+h
H_n=η_n+h
B = inner((η-η_out)/(2*k),ϕ)*dx + inner((u-u_n)/k,w)*dx \
    -θ*inner(h*u,grad(ϕ))*dx \
    -(1-θ)*inner(h*u_out,grad(ϕ))*dx \
    +inner(η_n*u_n,grad(ϕ))*dx \
    -dot(u_n,div(outer(w,u_n)))*dx \
    +θ*(inner(f*R*u+1/H_n*(c_d*norma2(u_n)*u),w)*dx + g*inner(grad(η),w)*dx) \
    +(1-θ)*(inner(f*R*u_n+1/H_n*(c_d*norma2(u_n)*u_n),w)*dx + g*inner(grad(η_n),w)*dx) \
    +inner(avg_gamma(dot(u_n,ν)*u_n,lbda),jump(w))*dS
a1 = lhs(B)
L1 = rhs(B)

the error says: UFLException: Found Argument in Conditional id=139882664075424>, this is an invalid expression.
If i remove the last term in the form B it works, what am i doing wrong?

Please make a minimal example; as described in: Read before posting: How do I get my question answered?

I think the error i get may not be related to this, i’ll make a new post. Thanks!