Hi,
I am implementing nullspace to apply constrains in alternative to lagrange multiplier in dolfinx. The MWE is:
from mpi4py import MPI
from dolfinx import mesh
import numpy as np
from ufl import Jacobian, as_vector, dot, cross,sqrt, conditional, replace
from ufl import lt,SpatialCoordinate, as_tensor, VectorElement, FiniteElement, MixedElement, Measure
mesh = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8, mesh.CellType.quadrilateral)
Em = 50e3
num = 0.2
Er = 210e3
nur = 0.3
material_parameters = [(Em, num), (Er, nur)]
nphases = len(material_parameters)
def eps_te(v):
E1=as_vector([0,v[2].dx(0),0,0,v[1].dx(0),v[0].dx(1)])
return as_tensor([(E1[0],0.5*E1[5],0.5*E1[4]),(0.5*E1[5],E1[1],0.5*E1[3]),(0.5*E1[4],0.5*E1[3],E1[2])]),E1
def sigma(v,i,Eps):
E,nu=material_parameters[i]
lmbda = E*nu/(1+nu)/(1-2*nu)
mu = E/2/(1+nu)
C1=lmbda+2*mu
C=as_tensor([(C1,lmbda,lmbda,0,0,0),(lmbda,C1,lmbda,0,0,0),(lmbda,lmbda,C1,0,0,0),(0,0,0,mu,0,0),(0,0,0,0,mu,0),(0,0,0,0,0,mu)])
s1= dot(C,eps_te(v)[1]+Eps)
return as_tensor([(s1[0],s1[5],s1[4]),(s1[5],s1[1],s1[3]),(s1[4],s1[3],s1[2])]), C
from dolfinx.fem import FunctionSpace, form, Function
import numpy as np
from ufl import TrialFunction, TestFunction, inner, form, lhs, rhs, dx
Ve = VectorElement("S", mesh.ufl_cell(), 2,dim=3)
V = FunctionSpace(mesh, Ve)
dv = TrialFunction(V)
v_ = TestFunction(V)
Eps= as_vector((1,0,0,0,0,0))
dx = Measure('dx')(domain=mesh)
F2 = sum([inner(sigma(dv, 0, Eps)[0], eps_te(v_)[0])*dx])
a=lhs(F2)
L=rhs(F2)
- I am getting error to delete cache file to work lhs. After deleting cache file, it starts working. Do I need to do this everytime?
- Getting error in making ufl.form
a_cpp = form(a)
f_cpp = form(L)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[20], line 3
1 a=lhs(F2)
2 L=rhs(F2)
----> 3 a_cpp = form(a)
4 f_cpp = form(L)
TypeError: 'module' object is not callable
3.a Based on singular poisson example using null space where the constraint was \int u dx =0 . And
below code is used. Does, 1 shown in (C.array,1.0) represents any arbitrary constant coming after integration.
Can you explain in detail where does the 3 constraints are applied (for u1,u2,u3 averaged to 0 over entire dx) ?
3b. I got error in c.interpolate. I donāt understand its significance of using x.shape. What should be for this example?
c = Function(V)
c.interpolate(lambda x: np.ones(x.shape[1]))
C = c.vector
assert np.allclose(C.array, 1.0) # because V is a Lagrange space
-
if I want a constraint like \int dv.dx(0) =0, how can I implement this ?
-
how can I implement periodic boundary condition. Previously, we give argument in defining function space of mixedelement
constrained_domain=PeriodicBoundary(vertices, tolerance=1e-10)
. I donāt know where should I implement it?
Any help is appreciated in using nullspace.