### Simple integration of constant fails

69

views

0

Hi all,

I have a very dummy problem with integrating a constant over a domain but I cannot realize what can be wrong. I have the function compute_area here below, and when I run compute_area() I get the error message

ufl.log.UFLException: This integral is missing an integration domain.

I have tried to run the code on python 3.6.5 and python 2.7.15.

Any help would be appreciated.

I have a very dummy problem with integrating a constant over a domain but I cannot realize what can be wrong. I have the function compute_area here below, and when I run compute_area() I get the error message

ufl.log.UFLException: This integral is missing an integration domain.

I have tried to run the code on python 3.6.5 and python 2.7.15.

Any help would be appreciated.

```
def compute_area():
import dolfin as dl
mesh = dl.UnitSquareMesh(200,200)
degree = 1
domainscoarse = dl.CellFunction("size_t", mesh)
domainscoarse.set_all(0)
dxcoarse = dl.Measure("dx")[domainscoarse]
areaval = 1.0*dxcoarse
Area = dl.assemble(areaval)
return Area
```

Community: FEniCS Project

### 2 Answers

2

```
import dolfin as dl
mesh = dl.UnitSquareMesh(200,200)
degree = 1
domainscoarse = dl.MeshFunction('size_t', mesh, mesh.topology().dim(), 0)
dxcoarse = dl.Measure('dx')(subdomain_data=domainscoarse)
areaval = 1.0*dxcoarse(domain=mesh)
Area = dl.assemble(areaval)
print Area
```

2

The following works for me in version 2017.2.0:

Thank you so much! Then the problem is that I was not specifying domain=mesh in dxcoarse.

```
import dolfin as dl
mesh = dl.UnitSquareMesh(200,200)
degree = 1
# This gives a deprecation warning:
#domainscoarse = dl.CellFunction("size_t", mesh)
#domainscoarse.set_all(0)
# Preferred syntax:
domainscoarse = dl.MeshFunction("size_t", mesh, mesh.topology().dim(), 0)
# This works, but gives a deprecation warning:
#dxcoarse = dl.Measure("dx",domain=mesh)[domainscoarse]
# Preferred syntax:
dxcoarse = dl.Measure("dx",subdomain_data=domainscoarse,domain=mesh)
areaval = 1.0*dxcoarse
Area = dl.assemble(areaval)
print(Area)
areaval = 1.0*dxcoarse(0)
Area = dl.assemble(areaval)
print(Area)
```

written
8 weeks ago by
Laura Scarabosio

Please login to add an answer/comment or follow this question.