Hi,
I have an exact solution to a problem which I must calculate on mesh vertices, and I cannot simply use an Expression to define it. So I have to define it as a function. I think my problem when I solve it the solution is kind of “discretized” and I cannot “interpolate” on my domain. I do not understand what is causing it. I’d appreciate any help. Here is a simply example code to what I am trying to achieve:
from fenics import *
from mshr import *
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from dolfin import *
# Exact Solution Defined as a Function
def Analytic_Solution(x,y):
#this is just to show what I am trying to do.
u_ex = x**2+y**2
return u_ex
# Define geometry
radius_c = 1
c_points = 30
xcyl = 0
ycyl = 0
domain = Circle(Point(xcyl, ycyl), radius_c, c_points)
# Mesh the domain
mesh = generate_mesh(domain,10)
plot(mesh)
# I need help here
F = FunctionSpace(mesh, 'CG', 1)
n = F.dim()
d = mesh.geometry().dim()
f = Function(F)
F_dof_coordinates = F.tabulate_dof_coordinates()
F_dof_coordinates.resize((n, d))
F_dof_x = F_dof_coordinates[:, 0]
F_dof_y = F_dof_coordinates[:, 1]
# This part does not give a smooth solution
u_temp = Analytic_Solution(F_dof_x,F_dof_y)
f.vector().set_local(u_temp)
plot(f)