Hello dr @dokken I am having some issues with dolfinx. I had previously done some work on one of my problems and the galerkin method was completely resolving the layer (images attached) for the same mesh size and diffusion coefficient epsilon. it is no longer resolving the fine layer of the solution. I am attaching my previous images I had and new ones as well. I am supposed to do some error analysis now but the I am not getting what I was expecting. I am not sure whether it is a bug in new 0.8 version or something else.
Code:
import numpy as np
from dolfinx.fem import (Constant, Function, functionspace,
assemble_scalar, dirichletbc, form, locate_dofs_geometrical)
from dolfinx.fem.petsc import LinearProblem
from dolfinx import fem, io, mesh
from dolfinx.mesh import create_unit_square
from mpi4py import MPI
import ufl
from ufl import SpatialCoordinate, TestFunction, TrialFunction, dot, dx, ds, grad, inner
from petsc4py.PETSc import ScalarType
def solve_adv_diff(N=100, eps= ScalarType(1), degree=1):
# define mesh and function space
msh = create_unit_square(MPI.COMM_WORLD,N,N)
V = functionspace(msh, ("Lagrange", degree))
u = TrialFunction(V)
v = TestFunction(V)
x = SpatialCoordinate(msh)
# define boundary conditions
# bottom left_facet
facet_1 = mesh.locate_entities_boundary(msh, dim=(msh.topology.dim - 1),
marker=lambda x: np.logical_and(np.isclose(x[1], 0),x[0]<=0.5))
dof_1 = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facet_1)
bc_1 = dirichletbc(ScalarType(1), dof_1,V)
# left facet
facet_2 = mesh.locate_entities_boundary(msh, dim=(msh.topology.dim - 1),
marker=lambda x: np.isclose(x[0], 0))
dof_2 = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facet_2)
bc_2 = dirichletbc(ScalarType(1), dof_2,V)
# bottom right_facet
facet_3 = mesh.locate_entities_boundary(msh, dim=(msh.topology.dim - 1),
marker=lambda x: np.logical_and(np.isclose(x[1], 0),x[0]>0.5))
dof_3 = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facet_3)
bc_3 = dirichletbc(ScalarType(0), dof_3,V)
bcs = [bc_1,bc_2, bc_3]
# define variational form
vec_f = Constant(msh,ScalarType((np.cos(np.pi/3),np.sin(np.pi/3))))
a = eps*dot(grad(u), grad(v))*dx + v*dot(vec_f,grad(u))*dx
f = Constant(msh, ScalarType(0))
L = f * v * dx
# solving problem
problem = LinearProblem(a, L, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
return problem.solve()
u_galerkin = solve_adv_diff(100,1)
# writing mesh and solution for visualization in paraview
from dolfinx import io
with io.XDMFFile(u_galerkin.function_space.mesh.comm, "u_h100_eps1.xdmf", "w") as file:
file.write_mesh(u_galerkin.function_space.mesh)
file.write_function(u_galerkin)
(New image)(old image)