How can I plot the result of the velocity using plot function in vedo.dolfin instead of using paraview.
Of course, if there was other way to show the velocity in Fenics not in paraview, I will appreciate it.
The following is the code.
from dolfin import *
from fenics import *
from fenics_adjoint import *
from vedo.dolfin import plot
mu = 1.05e-3
rho = 1000
cp = Constant(4182) # J/kgK
mesh = BoxMesh(Point(0.0, 0.0, 0.0), Point(36.0e-3, 31.0e-3, 0.8e-3), 36, 31, 3)
V = VectorElement("P", mesh.ufl_cell(), 2)
Q = FiniteElement("P", mesh.ufl_cell(), 1)
TH = MixedElement([V, Q])
W = FunctionSpace(mesh, TH)
# Defining the boundary
# plot(self.mesh)
inflow1 = 'near(x[0], 0.0)'
outflow = 'near(x[0], 36.0e-3)'
walls = 'near(x[1], 0.0) || near(x[1], 31.0e-3) || near(x[2], 0.0) || near(x[2], 0.8e-3)'
bcu_inflow = DirichletBC(W.sub(0), Constant((0.01, 0.0, 0)), inflow1)
bcp_outflow = DirichletBC(W.sub(1), Constant(0), outflow)
bcu_noslip = DirichletBC(W.sub(0), Constant((0.0, 0.0, 0.0)), walls)
bcs = [bcu_noslip, bcu_inflow, bcp_outflow]
# Define variational forms
v, q = TestFunctions(W)
w = Function(W)
dw = TrialFunction(W)
u, p = split(w)
F1 = (
mu * inner(grad(u), grad(v)) * dx
+ rho * inner(dot(grad(u), u), v) * dx
- inner(p, div(v)) * dx
+ inner(q, div(u)) * dx
)
J = derivative(F1, w, dw)
newton_solver_parameters = {
"nonlinear_solver": "newton",
"newton_solver": {
"linear_solver": "mumps",
"maximum_iterations": 50,
"report": True,
"error_on_nonconvergence": True,
},
}
problem = NonlinearVariationalProblem(F1, w, bcs, J)
solver = NonlinearVariationalSolver(problem)
solver.parameters.update(newton_solver_parameters)
(itera, converged) = solver.solve()
u_plot, p_plot = w.split()
plot(u_plot)
vtkfile_u = File('results/u.pvd')
vtkfile_u << u_plot