Hi,
I have found related posts but none of those solves my problem.
After solving a == L, I want to compute an integral over a subdomain of the function space, but the integral is very inaccurate.
The code is like
a = assemble(u*dx(2))
Are there any ways we can use to improve the accuracy? I tried a mesh with higher resolution but still inaccurate.
Update:
Here is a sample code. Is there a way to improve the accuracy of integral inside the circle?
from fenics import *
import numpy as np
from mshr import *
import matplotlib.pyplot as plt
# Create mesh and define function space
domain = Rectangle(Point(-0.5,-0.5), Point(0.5,0.5))
domain_setter = domain
domain.set_subdomain(1, domain_setter)
cir = Circle(Point(0, 0), 0.05)
domain.set_subdomain(2, cir)
mesh = generate_mesh(domain, 8)#UnitSquareMesh(nx, ny)
markers = MeshFunction('size_t', mesh, mesh.topology().dim(), mesh.domains())
non_cir_mesh = MeshView.create(markers, 1)
cir_mesh = MeshView.create(markers, 2)
V1 = FunctionSpace(cir_mesh, 'CG', 1)
V2 = FunctionSpace(non_cir_mesh, 'CG', 1)
total_vol = 1
u1_bar_true = 0.001*(1-np.pi*0.1**2) / total_vol
u2_bar_true = 0.0002*(np.pi*0.1**2) / total_vol
u1 = project(0.001, V1)
u2 = project(0.0002, V2)
dx_all = dx_halfeps_packing = Measure('dx', domain=mesh)
dx_non_cir = dx_halfeps_packing = Measure('dx', domain=non_cir_mesh)
dx_cir = dx_halfeps_packing = Measure('dx', domain=cir_mesh)
u1_bar_cal = assemble(u1*dx_non_cir)/total_vol
u2_bar_cal = assemble(u2*dx_cir)/total_vol
print(u1_bar_cal, u1_bar_true)
print(u2_bar_cal, u2_bar_true)