# Coefficient is custmized for each cell in the weak formulation, pointwise expression on each cell

**URL:** <https://fenicsproject.discourse.group/t/coefficient-is-custmized-for-each-cell-in-the-weak-formulation-pointwise-expression-on-each-cell/13367>\
**Category:** General\
**Created:** [January 21, 2024, 11:38pm UTC](https://fenicsproject.discourse.group/t/coefficient-is-custmized-for-each-cell-in-the-weak-formulation-pointwise-expression-on-each-cell/13367 "2024-01-21T23:38:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rui\_Fang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rui_fang/32/5226_2.png) [@Rui\_Fang](https://fenicsproject.discourse.group/u/Rui_Fang)\
**Post date:** [January 21, 2024, 11:38pm UTC](https://fenicsproject.discourse.group/t/coefficient-is-custmized-for-each-cell-in-the-weak-formulation-pointwise-expression-on-each-cell/13367/1 "2024-01-21T23:38:57Z")

</div>

Hi guys,

I am solving the Navier-Stokes equation with some customized coefficients for each cell, the area of each cell.

I was checking the past post, and figure out the area but I don’t know how to put it back in the weak form.

Area: define mesh

```auto
nx = 2
ny = 2
msh = mesh.create_rectangle(MPI.COMM_WORLD, [np.array([-1, -1]), np.array([1, 1])], [nx, ny], dolfinx.cpp.mesh.CellType.triangle)
cell=msh.ufl_cell()
tdim = msh.topology.dim
num_cells = msh.topology.index_map(tdim).size_local
h = dolfinx.cpp.mesh.h(msh, tdim, range(num_cells)) #h is the largest edge
print(num_cells)
print("edge length", h)

DG0 = dolfinx.fem.FunctionSpace(msh, ("DG", 0))
v_DG0 = ufl.TestFunction(DG0)
cell_area_form = dolfinx.fem.form(v_DG0*ufl.dx)
cell_area = dolfinx.fem.assemble_vector(cell_area_form)
print(cell_area.array)

```

What I need:  
( grad u ,grad v)\_over the domain _dx + sum over the area of the cell_ (div(u) ,div(v))\_for each cell _dx = (f,v)\_over the domain_dx

then solve for the u, where v is the test function, u is the trail function

Thank you so much!

Rui

---

<div class="post-metadata">

**Author:** ![Rui\_Fang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rui_fang/32/5226_2.png) [@Rui\_Fang](https://fenicsproject.discourse.group/u/Rui_Fang)\
**Post date:** [January 27, 2024, 4:14am UTC](https://fenicsproject.discourse.group/t/coefficient-is-custmized-for-each-cell-in-the-weak-formulation-pointwise-expression-on-each-cell/13367/2 "2024-01-27T04:14:00Z")

</div>

Can anyone take a look? It’s been a week! Thank you!

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [January 27, 2024, 6:22am UTC](https://fenicsproject.discourse.group/t/coefficient-is-custmized-for-each-cell-in-the-weak-formulation-pointwise-expression-on-each-cell/13367/3 "2024-01-27T06:22:55Z")

</div>

We cannot run the example you posted and formatting was missing. Please read [Read before posting: How do I get my question answered?](https://fenicsproject.discourse.group/t/read-before-posting-how-do-i-get-my-question-answered/21)

That being said, for the second integral you may want to have a look at `ufl.CellVolume`.
