Hello @dokken , thank you for your answer.
-
I don’t understand why u shouldn’t be sent into solve. In fact, as I mentioned, this gradient implementation is created to obtain stress, but if I do not want stresses, the code works just fine and I can obtain u_x and u_y without any problem. So, this shouldn’t be the problem, I believe. But I would like to learn if there is any issue with this.
-
I do understand that V needs to be a TensorFunctionSpace if I want to project a gradient. So, I did the change:
gradu = nabla_grad(u) #in theory, should be a 2x2 matriz
V = TensorFunctionSpace(mesh, 'DG', 1)
uxp = project(gradu[0,0],V)
ux = uxp.compute_vertex_values(mesh)
But still I’m facing the same shape error. I did exactly the same implementation with antiplane problem, meaning u had only one component, and working with the gradient was just fine.
Additionally, I’m adding a minimal (but longer) code. There would be no problem in adding full codes, also to generate the mesh. I just feel it’s just too much.
Thanks.
msh2xdmf('malla_modo2.msh',2,directory='.')
mesh, mesh_function, association_table = import_mesh(
prefix='malla_modo2',
dim=2,
directory='.')
print(mesh)
V = VectorFunctionSpace(mesh, 'CG',1)
# Boundary definitions, Im not adding just not to make a giant code
disp_x0 = Expression('x[0] * (-0.5 * x[0] / pow(x[0]*x[0]+x[1]*x[1],0.5) - pow(x[0]*x[0]+x[1]*x[1],0.5) * ((2 * std::log(pow(x[0]*x[0]+x[1]*x[1],0.5)) + 1) * cos(2 * atan2(x[1], x[0])) + (-2 * atan2(x[1], x[0]) + 2 * pi) * sin(2 * atan2(x[1], x[0])) + 2 * std::log(pow(x[0]*x[0]+x[1]*x[1],0.5)) - 1) / (4 * pi)) / pow(x[0]*x[0]+x[1]*x[1],0.5) - x[1] * (0.5 * x[1] / pow(x[0]*x[0]+x[1]*x[1],0.5) + pow(x[0]*x[0]+x[1]*x[1],0.5) * ((2 - 2 * cos(2 * atan2(x[1], x[0]))) * (2 * atan2(x[1], x[0]) - 2 * pi) - (2 * std::log(pow(x[0]*x[0]+x[1]*x[1],0.5)) + 1) * sin(2 * atan2(x[1], x[0]))) / (4 * pi)) / pow(x[0]*x[0]+x[1]*x[1],0.5)',degree=3)
disp_x1 = Expression('x[0] * (0.5 * x[1] / pow(x[0]*x[0]+x[1]*x[1],0.5) + pow(x[0]*x[0]+x[1]*x[1],0.5) * ((2 - 2 * cos(2 * atan2(x[1], x[0]))) * (2 * atan2(x[1], x[0]) - 2 * pi) - (2 * std::log(pow(x[0]*x[0]+x[1]*x[1],0.5)) + 1) * sin(2 * atan2(x[1], x[0]))) / (4 * pi)) / pow(x[0]*x[0]+x[1]*x[1],0.5) + x[1] * (-0.5 * x[0] / pow(x[0]*x[0]+x[1]*x[1],0.5) - pow(x[0]*x[0]+x[1]*x[1],0.5) * ((2 * std::log(pow(x[0]*x[0]+x[1]*x[1],0.5)) + 1) * cos(2 * atan2(x[1], x[0])) + (-2 * atan2(x[1], x[0]) + 2 * pi) * sin(2 * atan2(x[1], x[0])) + 2 * std::log(pow(x[0]*x[0]+x[1]*x[1],0.5)) - 1) / (4 * pi)) / pow(x[0]*x[0]+x[1]*x[1],0.5)',degree=3)
r = Constant((1.0, 1.0))
g = Constant((0.0, 0.0))
f = Constant((0.0, 0.0))
disp_null = Constant(0)
bcd0 = DirichletBC(V.sub(0), disp_x0, boundary3, method='topological')
bcd1 = DirichletBC(V.sub(1), disp_x1, boundary3, method='topological')
bcd2 = DirichletBC(V.sub(0), disp_null, boundary1, method='topological')
bcd3 = DirichletBC(V.sub(1), disp_null, boundary1, method='topological')
bcd4 = DirichletBC(V.sub(0), disp_x0, boundary4, method='topological')
bcd5 = DirichletBC(V.sub(1), disp_x1, boundary4, method='topological')
bcd6 = DirichletBC(V.sub(0), disp_x0, boundary5, method='topological')
bcd7 = DirichletBC(V.sub(1), disp_x1, boundary5, method='topological')
bcs = [bcd1, bcd2, bcd3, bcd4, bcd5, bcd6, bcd7, bcd0]
ds = Measure('ds', domain = mesh, subdomain_data = Boundary_markers)
dx = Measure('dx', domain = mesh, subdomain_data = Boundary_markers)
u = TrialFunction(V)
v = TestFunction(V)
L = inner(f,v)*dx + inner(g,v)*ds
a = inner(grad(u), grad(v)) * dx + (r[0]*v[0]*u[0]+r[1]*v[1]*u[1]) * ds(1)
A = assemble(a)
b = assemble(L)
u = Function(V, name='Displacement')
solve (a==L,u,bcs)
gradu = nabla_grad(u) #in theory, should be a 2x2 matriz
V = TensorFunctionSpace(mesh, 'DG', 1)
uxp = project(gradu[0,0],V)
ux = uxp.compute_vertex_values(mesh) #vector composed by numbers
uyp = project(gradu[1,1],V)
uy = uyp.compute_vertex_values(mesh) #vector composed by numbers
uxyp = project(gradu[0,1],V)
uxy = uyp.compute_vertex_values(mesh) #vector composed by numbers
uyxp = project(gradu[1,0],V)
uyx = uyp.compute_vertex_values(mesh) #vector composed by numbers
x = mesh.coordinates()[:,0]
y = mesh.coordinates()[:,1]
sigmaxx = lmbda * (ux + uy) + 2*mu*ux