# Add on NGsolve: ngsxfem, levelset, NEG domain mesh boundary elements

Hello,
is there any way to add boundary condition on the formulation

``a+= SymbolicBFI(lset_neg,form = u*v) ?``

I tried

``a += SymbolicBFI(lset_neg,form = u*v, skeleton=True, definedon=lset_neg.Boundaries())``

[color=purple]File “”, line 82, in
AttributeError: ‘xfem.ngsxfem_utils_py.BitArrayCF’ object has no attribute 'Boundaries[/color]
Thank you

best wishes
Makis

Attachment: NEG_mesh_bc.py

To impose boundary conditions in a finite element formulation, you have to put the conditions either into the finite element spaces or enforce them (weakly) in a variational formulation.
In unfitted FEM (used in level set methods and the ngsxfem package) we have no degrees of freedom that are explicitly associated to the level set boundary. This is by construction of the unfitted method (the d.o.f. are defined by the background mesh and independent of the level set domains). Hence, we can not impose Dirichlet boundary conditions through the finite element space directly. What you tried in your example fails not due to implementation issues but simply due to the design paradigm of unfitted FEM.

Instead, one typically chooses to impose boundary conditions only weakly (e.g. with Lagrange multipliers or Nitsche’s method), as in the fictdom_ghostpen.py example.

Best,
Christoph

Dear Christoph,

deeply thank you for your response, and sorry for the basic level questions, I am new in ngsolve/ngsxfem and I am trying to understand the way it works (it is really great software).

Yes I am trying to make some tests with the provided tools for an embedded method imposing Nitsche’s terms in the boundary elements of the lset_neg area (these boundary elements which are inside the NEG area) and not these in the “lset_if” area …with quads or not. I used the GetFacetWithNeighborTypes as in the attached file with some success but I didn’t manage to have exactly the elements I want.

Is there maybe any way to manage this please?

Best regards and many thanks
Makis

Attachment: 3-NEG_mesh_bc_2017-11-13-4.py

Dear Makis,

I am still not sure what you are trying to do. I understand that you want to select some certain elements, but don’t know which ones and what the ultimate goal behind the marking of these is.

Your script files seems to do something meaningful. It marks all the facets between uncut interior elements and cut elements. The drawing is then done on the corresponding neighbors (to circumvent the difficulty of visualizing marked facets).
In case you want only the interior uncut elements of the previous selection you can use a simple intersection (test &= hasneg).

Best,
Christoph

Hi,
one more question please, related to the above marking (i attach again the related .py file after adding two lines), and trying to apply the SymbolicBFI onto specific elements using the commands:

```#lset_IF = { "levelset" : lsetp1, "domain_type" : IF, "subdivlvl" : 0} #it works #a += SymbolicBFI(lset_IF,form = u*v) #it works lset_test = { "levelset" : lsetp1, "domain_type" : test, "subdivlvl" : 0} #It does not give any error print("type(lset_test)=",type(lset_test),"\n") # <class 'dict'> a += SymbolicBFI(lset_test,form = u*v) ```
even if lset_test and lset_IF both are the same <class ‘dict’> type I see the error
[i] [color=purple]File “”, line 65, in
File “/install/ngsolve/2017-11-16-ef89d2d0/petsc-2017-09-30-c91a011401-3.8/lib/python3.6/site-packages/xfem/init.py”, line 169, in SymbolicBFI *args, **kwargs)
TypeError: SymbolicCutBFI(): incompatible function arguments. The following argument types are supported:
1. (lset: ngsolve.fem.CoefficientFunction, domain_type: xfem.ngsxfem_py.DOMAIN_TYPE=DOMAIN_TYPE.NEG, force_intorder: int=-1, subdivlvl: int=0, form: ngsolve.fem.CoefficientFunction, VOL_or_BND: ngsolve.comp.VorB=VorB.VOL, element_boundary: bool=False, skeleton: bool=False, definedon: object=<ngsolve.ngstd.DummyArgument>, definedonelements: object=<ngsolve.ngstd.DummyArgument>) → ngsolve.fem.BFI

Invoked with: kwargs: lset=<ngsolve.comp.GridFunction object at 0x7f3a48b0e7d8>, domain_type=<ngsolve.ngstd.BitArray object at 0x7f3a48b14c38>, force_intorder=-1, subdivlvl=0, form=<ngsolve.fem.CoefficientFunction object at 0x7f3a48b14e68>[/color][/i]

do I have to use somehow the CoefficientFunction as it is mentioned in the error message? And how can I avoid the SymbolicCutBFI() mentioned in the error message (I don’t want to use any cut element integration), thank you,

best regards
Makis

Attachment: 3-NEG_mesh_bc_2017-11-13-4_2017-11-17.py

Hi,

one can pass a BitArray to SymbolicBFI by means of definedonelements:

```lset_test = { "levelset" : lsetp1, "domain_type" : NEG, "subdivlvl" : 0} a += SymbolicBFI(lset_test,form = u*v,definedonelements=test) ```
This restricts the integration to elements or facets (if skeleton=True) which are marked True.

Best regards,
Janosch