Hi! In the below MWE, nh is a function in the cartesian frame on the boundary of a circle. I need to plot nh as a function of \theta. I tried to find some posts in the community page but didn’t come across any. I tried a transformation matrix but it didn’t work. Can anyone please help me with this?
MWE:
from __future__ import print_function
from fenics import *
import matplotlib.pyplot as plt
from dolfin import *
import meshio
from dolfin import Mesh, XDMFFile, File, MeshValueCollection, cpp
# Optimization options for the form compiler
parameters["form_compiler"]["cpp_optimize"] = True
ffc_options = {"optimize": True, \
"eliminate_zeros": True, \
"precompute_basis_const": True, \
"precompute_ip_const": True}
import numpy as np
import meshio
from mshr import Circle, generate_mesh
from dolfin import Mesh, File, MeshFunction, Point, BoundaryMesh, SubDomain, plot, File
import matplotlib.pyplot as plt
from dolfin import *
from mshr import *
class boundary(SubDomain):
def inside(self, x, on_boundary):
return on_boundary
class disk(SubDomain):
def inside(self, x, on_boundary):
return True
mesh = generate_mesh(Circle(Point(0, 0), 3), 50)
boundary_markers = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
surface_markers = MeshFunction("size_t", mesh, mesh.topology().dim(), 0)
boundary().mark(boundary_markers, 2)
disk().mark(surface_markers, 1)
ds = Measure('ds', subdomain_data=boundary_markers)
dx = Measure('dx', subdomain_data=surface_markers)
n = FacetNormal(mesh)
W1 = FunctionSpace(mesh, "Lagrange", 1)
n = FacetNormal(mesh)
G , mu = 1, 0.1
u_D=Constant(0.0)
bc = DirichletBC(W1, u_D, boundary_markers, 2)
# Define variational problem
u = TrialFunction(W1)
v = TestFunction(W1)
f = Constant(-G/mu) # f=-G/mu
a = dot(grad(u), grad(v))*dx
L = -f*v*dx
# Compute solution
u = Function(W1)
solve(a == L, u, bc)
# Calculating shear stress S
Ux=0.0
Uy=0.0
Uz=u
U = as_vector((Uy, u))
N = as_matrix([[0.0,0.5],
[0.0,0.0]])
Sn = mu/2 * dot(grad(U) + grad(U).T, (N.T)*n)
print(assemble(Sn[1]*ds))
S=Sn[1]
u = TrialFunction(W1)
v = TestFunction(W1)
a = inner(u,v)*ds
l = inner(S, v)*ds
A = assemble(a, keep_diagonal=True)
L = assemble(l)
A.ident_zeros()
nh = Function(W1)
solve(A, nh.vector(), L)
File("c2ps.pvd") << nh # This (nh) is the function I need to convert to a polar frame.
x = mesh.coordinates()[:,0] # Defining x as the x-coordinates of the mesh
y = mesh.coordinates()[:,1] # Defining y as the y-coordinates of the mesh
def r(x, y): # Defining r as a function of x and y
return [sqrt(x*x + y*y)] # Returning the formula for r
def theta(x, y): # Defining theta as a function of x and y
return [atan(y,x)] # Returning the formula for theta
How to change the x and y in nh to nh(\theta)?
Any suggestion would be great.