Hello everyone,
I am working on a non-local plasticity example. For the obtained solution of the plasticity I need to define a irreversability constraint, where the previous solution is supposed to be the lower threshhold (here an simple function called x0_func). This also called ad-hoc condition. That means at time n+1, we have:
alpha_n+1 > alpha_n
In order to realize that I am using ufl.conditional. When I define the function in the space of (‘DG’, 0), I get really good results. However, this is not the case when the functions are defined in (‘CG’, 1).
The code and the outputs are as follows:
import dolfinx
from dolfinx import mesh
from dolfinx.fem import (Function, FunctionSpace)
from petsc4py import PETSc
from mpi4py import MPI
import ufl as ufl
import numpy as np
from dolfinx.io import XDMFFile
L = 100.0
H = 100.0
dL = 30
dH = 30
domain = mesh.create_box(MPI.COMM_WORLD,[[0,0,0], [L, L, H]], [dL, dL, dH], mesh.CellType.tetrahedron)
x = ufl.SpatialCoordinate(domain)
# For plasticity problem
V_pl = FunctionSpace(domain, ('CG', 1))
#V_pl = FunctionSpace(domain, ('DG', 0)) #precise
pl = Function(V_pl)
with pl.vector.localForm() as pl_loc:
pl_loc.set(-1.0)
x0_func = Function(V_pl)
x0_ufl = x[0]
x0 = lambda x: eval(str(x0_ufl))
x0_func.interpolate(x0)
print("min of x0_func:", min(x0_func.vector.array), flush=True)
with XDMFFile(MPI.COMM_WORLD, "test.xdmf", "w") as xdmf:#, encoding=XDMFFile.Encoding.HDF5) #FIXME
xdmf.write_mesh(domain)
xdmf.write_function(x0_func)
def project(v, target_func, bcs=[]):
# Ensure we have a mesh and attach to measure
V = target_func.function_space
dx = ufl.dx(V.mesh)
# Define variational problem for projection
w = ufl.TestFunction(V)
Pv = ufl.TrialFunction(V)
a = dolfinx.fem.form(ufl.inner(Pv, w) * dx)
L = dolfinx.fem.form(ufl.inner(v, w) * dx)
# Assemble linear system
A = dolfinx.fem.petsc.assemble_matrix(a, bcs)
A.assemble()
b = dolfinx.fem.petsc.assemble_vector(L)
dolfinx.fem.petsc.apply_lifting(b, [a], [bcs])
b.ghostUpdate(addv=PETSc.InsertMode.ADD, mode=PETSc.ScatterMode.REVERSE)
dolfinx.fem.petsc.set_bc(b, bcs)
# Solve linear system
solver = PETSc.KSP().create(A.getComm())
solver.setOperators(A)
solver.solve(b, target_func.vector)
def Pl_max(pl_, pln_):
return ufl.conditional(ufl.gt(pl_, pln_), pl_, pln_)
project(Pl_max(pl, x0_func), pl)
print("min of plasticity:", min(pl.vector.array), flush=True)
Output for V_pl = FunctionSpace(domain, (‘CG’, 1))
min of x0_func: -5.244705219161143e-17
min of plasticity: -2.950809850125471e-05
Output for V_pl = FunctionSpace(domain, (‘DG’, 0))
min of x0_func: 0.8333333333333334
min of plasticity: 0.8333333333334109
Thank you