Hello,
I am trying to convert FEniCS 2D field (scalar field or vector field) solutions and the corresponding x and y coordinates as 2D arrays in to separate Numpy arrays, got a bit confused by the conversion. Following is an example I am practicing on:
from dolfin import *
import numpy as np
mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "Lagrange", 1)
def boundary(x):
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", degree=2)
g = Expression("sin(5*x[0])", degree=2)
a = inner(grad(u), grad(v))*dx
L = f*v*dx + g*v*ds
u = Function(V)
solve(a == L, u, bc)
in this case, solution u is a 2D scalar field, how should I convert it into three 2D numpy arrays T, X, Y such that each contains the field values, x coordinates, y coordinate, respectively?
Also, for the case when u is a 2D vector field of temperature, how should I convert it into four 2D numpy arrays Ux, Uy, X, Y?
Thank you!