# Upwinding in Gridap

**URL:** <https://discourse.julialang.org/t/upwinding-in-gridap/127571>\
**Category:** General Usage\
**Tags:** gridap\
**Created:** [March 31, 2025, 8:06pm UTC](https://discourse.julialang.org/t/upwinding-in-gridap/127571 "2025-03-31T20:06:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simons](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@Simons](https://discourse.julialang.org/u/Simons)\
**Post date:** [March 31, 2025, 8:06pm UTC](https://discourse.julialang.org/t/upwinding-in-gridap/127571/1 "2025-03-31T20:06:54Z")

</div>

Hi all,

I want to solve an advection-diffusion problem with DG and upwinding.  
Specifically, I need to define the form

```julia
f1(u,v) = ∫( upwinded(u, b, n_Λ) * v )dΛ

```

where upwinded(u, b, n\_Λ) = u.plus if dot(b, n\_\Lambda.plus) \> 0 else u.minus if dot(b, n\_\Lambda.plus) \< 0 else mean(u)  
So the two parts to the question are

1. how does one create a conditional function that can be used with the Gridap interface?
2. Specifically for upwinding, how can we implement the conditions if dot(b, n\_\Lambda) as it is a CellField object?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![marteaua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marteaua/32/214927_2.png) [@marteaua](https://discourse.julialang.org/u/marteaua)\
**Post date:** [June 17, 2026, 1:48pm UTC](https://discourse.julialang.org/t/upwinding-in-gridap/127571/2 "2026-06-17T13:48:27Z")

</div>

Hey @Simons, late answer, sorry.

I don’t know about upwinding, but, let me assume `Λ` is a `SkeletonTriangulation` and `n_Λ` is `get_normal_vector(Λ)`.

What is `b` ? Assuming it is a CellField, you need to specify a side for evaluation of operation with the skeleton cell field `n_Λ` even if it’s not discontinuous: `b.⁺ ⋅ n_Λ.⁺`.

Then, since `max` or `isless` are not automatically supported operations between cell fields, you have to “fix” the comparisons to 0 to get a 1-argument operations (for later composition):

```julia-auto
ispos = >(0)
isneg = <(0)

```

and finally you can use composition and multiplication to select the term you want:

```julia-auto
function f1(u,v)
  trace = b.⁺ ⋅ n_Λ.⁺
  ∫( ispos∘trace * u.⁺  
     + isneg∘trace * u.⁻
     + iszero∘trace * mean(u) )dΛ
end

```
