vector XFESpace for xfem inclusion problem in elasticity

Dear Colleagues I’m writing a ngs-py file to deal with the inclusion problem and I’ve a problem with the dimension space when trying:

[code]Vh = H1(mesh, order=1, dirichlet=“left|right”, dim=mesh.dim)
Vhx = XFESpace(Vh, ci)
VhG = FESpace([Vh,Vhx])

NgException: Compound space of spaces with different dimensions is not allowed[/code]

Clearly the problem is because Vh is dim = 2 and Vhx is dim = 1.

My question then is :
Which flag I’ve to apply to XFESpace function to deal with the dimension of Vh


Sorry, I think this not fixable with a flag, yet. I will have to program this into the XFESpace. However, this will take some time for me to find the time for it…

Perhaps you can find a CutFEM-characterization for the same problem? With Compress(…) you can reduce the dofs to the same amount. Alternatively you could replace the vector-valued FESpace by multiple scalar FESpaces.


Thank you so much for the answer Mr Schruste, it would be so nice if you coul say me where can I find the CutFEM application, and my question about the multiple Scalar FESpace is how I could implemented this definition for example applying the Grad or Div, have I to define each one or I can Apply the operator directly

Thank you so much for your answer,

Best Regards

I think I have quite a similar problem, I’d like to do XFEM for linear elasticity, I defined the FE spaces like

Vh = VectorH1(mesh, order=1) Vhx = XFESpace(Vh,ci) VhG = FESpace([Vh,Vhx])

Now it hangs up when doing the neg() or pos() function like

u_std, u_x = VhG.TrialFunction() u = [u_std + neg(u_x)]


NgException: Dimensions don't match, op = + dims1 = 0: 2, dims2 = 0: 1

Is there a way to fix it, apart of using two FE spaces coordinatewise?



Oh, I completely forgot about this issue! Thanks for the reminder.

I fixed the XFESpace so that it is now able to deal with base FESpaces that have a higher dimension. The changes are in the master branch on github, but not yet in the release branch which is the standard branch on github (to come within a few weeks). So please checkout the latest “master” branch on github and recompile ngsxfem.

Afterwards, use H1(mesh, dim=mesh.dim) instead of VectorH1 (VectorH1 is still not supported by XFESpace). With dim=mesh.dim however elasticity should be possible now. Please give it a try! I’d be nice if you could report if things are working for you.


Hi Christoph,

The XFE Space workes fine, but I got another issue: I do need the transposed gradient, but gradu.trans with gradu = [grad(u_std) + op(u_x) for op in [neg_grad,pos_grad]] gives the error AttributeError: ‘list’ object has no attribute ‘trans’…
How can I do this?

BR, Nepomuk


Your gradu object is a python list where each entry is a TrialFunction of dimension dxd. You can only transpose the members of the list, not the list itself:

gradu_trans = [gt.trans for gt in gradu]