# One dimension weak form

**URL:** <https://fenicsproject.discourse.group/t/one-dimension-weak-form/10770>\
**Category:** General\
**Created:** [March 25, 2023, 12:30pm UTC](https://fenicsproject.discourse.group/t/one-dimension-weak-form/10770 "2023-03-25T12:30:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![emi](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@emi](https://fenicsproject.discourse.group/u/emi)\
**Post date:** [March 25, 2023, 12:30pm UTC](https://fenicsproject.discourse.group/t/one-dimension-weak-form/10770/1 "2023-03-25T12:30:59Z")

</div>

Lets assume I have a one dimensional differential equation

-\frac{d}{dx}\left(a(x)\frac{du}{dx}\right)=f(x) \quad on \quad x\in(x\_L,x\_R)

One term of the weak form would be -a(x\_R)\frac{du}{dx}(x\_R)v(x\_R)+a(x\_L)\frac{du}{dx}(x\_L)v(x\_L). How could that additional term be formulated in the weak form in dolfinx.  
The current weak form looks like

```
  a*ufl.Dx(u,0)*ufl.Dx(v,0)*ufl.dx

```

and works fine with dirichlet boundary conditions.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [March 25, 2023, 1:05pm UTC](https://fenicsproject.discourse.group/t/one-dimension-weak-form/10770/2 "2023-03-25T13:05:18Z")

</div>

See:  
[https://jsdokken.com/dolfinx-tutorial/chapter3/robin\_neumann\_dirichlet.html](https://jsdokken.com/dolfinx-tutorial/chapter3/robin_neumann_dirichlet.html)

---

<div class="post-metadata">

**Author:** ![emi](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@emi](https://fenicsproject.discourse.group/u/emi)\
**Post date:** [March 25, 2023, 1:50pm UTC](https://fenicsproject.discourse.group/t/one-dimension-weak-form/10770/3 "2023-03-25T13:50:18Z")

</div>

thanks. As your example is two dimensional I did not try that.  
Does that mean that e.g. ds =ufl.Measure(“ds”,…) in connection with e.g. u_v_ds in a one dimensional mesh reduces to a point like evaluation at start and endpoint? Does the ufl library provide also a “Evaluate at point” Operator?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [March 25, 2023, 2:37pm UTC](https://fenicsproject.discourse.group/t/one-dimension-weak-form/10770/4 "2023-03-25T14:37:02Z")

</div>

> [@emi](#):
>
> Does that mean that e.g. ds =ufl.Measure(“ds”,…) in connection with e.g. u_v_ds in a one dimensional mesh reduces to a point like evaluation at start and endpoint?

Yes, `ds` is an integral over a facet of your cell, which in this case is a vertex.

> [@emi](#):
>
> Does the ufl library provide also a “Evaluate at point” Operator?

Not as part of variational forms (except for special cases such as a vertices of 1D integrals (through ds or the dS operator).

---

<div class="post-metadata">

**Author:** ![emi](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@emi](https://fenicsproject.discourse.group/u/emi)\
**Post date:** [March 26, 2023, 7:24am UTC](https://fenicsproject.discourse.group/t/one-dimension-weak-form/10770/5 "2023-03-26T07:24:59Z")

</div>

To summarize with an example

-\frac{d}{dx}\left(a(x)\frac{du}{dx}\right)+\beta u=f(x) \quad on \quad x\in(x\_L,x\_R)

and

a\frac{du}{dn}+\gamma u = q

at left and right boundary

```
from mpi4py import MPI
import dolfinx as dox
import numpy as np
import ufl

aa=1
bb=2
NN=4

#mesh and space
mesh = dox.mesh.create_interval(MPI.COMM_WORLD, NN,[aa,bb])
V = dox.fem.FunctionSpace(mesh, ("Lagrange", 1))

x = ufl.SpatialCoordinate(mesh)
alpha = x[0]**2
beta = x[0]
f = -x[0]**3
gamma = 3*x[0]
qq = 3*x[0]+1

u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)

# weak form
K=alpha*ufl.Dx(u,0)*ufl.Dx(v,0)*ufl.dx + beta*u*v*ufl.dx
D=f*v*ufl.dx

# boundary
all_v=np.arange(NN+1,dtype=np.int32)
marker_v = np.zeros(NN+1,dtype=np.int32)
marker_v[0]=1
marker_v[-1]=1
v_tags = dox.mesh.meshtags(mesh, 0 ,all_v , marker_v)

# boundary part weak form
ds = ufl.Measure("ds", domain=mesh, subdomain_data=v_tags)
K += gamma*u*v*ds(1)
D += qq*v*ds(1)

problem = dox.fem.petsc.LinearProblem(K, D, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})

```
