Dolfinx equivalent of DirichletBC.apply(Function(v).vector()) method in Dolfin

I am looking for the Dolfinx equivalent of the .apply method() for Dolfin’s DirichletBC class, Dolfin Docs, as used for example in

bc1 = DirichletBC(V.sub(0), Constant(0.0), point1, method="pointwise")
bc2= DirichletBC(V, r, right)
u_ = Function(V)
u_.vector()[:] = 1

bcs = [bc1,bc2´]
[bc.apply(u_.vector()) for bc in bcs]

In Dolfinx one gets an error message 'DirichletBC' object has no attribute 'apply' , after e.g.

bc1= fem.dirichletbc(PETSc.ScalarType(0), node_1, V.sub(1))
bc2 = fem.dirichletbc(PETSc.ScalarType(0), node_2, V.sub(1))
bcs = [bc1, bc2]
[bc.apply(u_.vector()) for bc in bcs]

Looking on the docs Dolfinx Dirichlet BC docs I cannot find anything equivalent.

Second point, I cannot even find the dolfinx.fem.bcs.DirichletBC class. In Dolfinx Docs I see the dolfinx.fem.dirichletbc ` function, classes such as dolfinx.cpp.fem.DirichletBC_float32, a MetaClass dolfinx.fem.DirichletBCMetaClass. so I am stuck, thanks for any hint.

See: Boundary conditions about Mixed space - #2 by dokken
i.e. you can use dolfinx.fem.petsc.set_bc

This is very helpful thanks. I do hate to nag such helpful fellows, but can I re-iterate the second part of my problem above, about the dolfinx.fem.bcs.DirichletBC class.
I know this class exists as is the output of

bc = fem.dirichletbc(PETSc.ScalarType(0.), node_1, V) type(bc) `
cannot find in the docs. Search for “dolfinx.fem.bcs.DirichletBC” or Search for “DirichletBC”

MY concrete problem.
I am trying to run this Notebook_Gradient Damage_Maurini

It requires the module

There are issues immediately in the first class definition
def __init__(self, F: ufl.form.Form, J: ufl.form.Form, u: dolfinx.Function, bcs: List[dolfinx.DirichletBC]):

This class set up structures for solving a non-linear problem using Newton’s method.
module 'dolfinx' has no attribute 'Function'
I modify to dolfinx.fem.Function but the next problem is

module 'dolfinx' has no attribute 'DirichletBC'

I tried hence to modify dolfinx.DirichletBC in the class _init function definition to
dolfinx.fem.bcs. DirichletBC
but get same some error
module 'dolfinx.fem.bcs' has no attribute 'DirichletBC'
I tried out of desperation to add .cpp in various combos. Without even finding it on the docs it is difficult. The notebook is from 2021 I think.

New NewFrac notebooks are outdated, and the class you are looking for is DirichletBCMetaClass, which is for instance used in:

Thanks. So I guess this happened on Dolfinx 0.0.7.
I am using Dolfinx 0.0.6, and it seems to me that a class


still existed, as it is the output of type called on a dirichlet boundary condition.
`` bc = fem.dirichletbc(PETSc.ScalarType(0.), node_1, V) type(bc) ``
on my notebook right now.

I should then be able to use when modifyng the module I mentioned above, no?
Why do I get the error
`` module 'dolfinx.fem.bcs' has no attribute 'DirichletBC' ``
I understand those notebooks are outdated but should still be possible to sort them out, or have the changes been very dramatic?
Thank you so much I appreciate I am being a tad dense here.

Where do you see that?
Here is the source code:
where def dirichletbc returns a DirichletBCMetaClass:

Well I say the class dolfinx.fem.bcs.DirichletBC exists as it is the output of the type issues with a bc as argument

bc = fem.dirichletbc(PETSc.ScalarType(0.), node_1, V)

and I get dolfinx.fem.bcs.DirichletBC, the class the object belongs to.
Now I worry I have not got Dolfinx 6.0.0, I cannot even find it in conda list in the conda environment where I installed it, via conda forge. dolfinx -v or dolfinx -version do not work.

But the point remains, if in my version a dolfinx.fem.bcs.DirichletBC class exists, why do I get an error

module 'dolfinx' has no attribute 'DirichletBC'

when trying to modify

def __init__(self, F: ufl.form.Form, J: ufl.form.Form, u: dolfinx.Function, bcs: List[dolfinx.DirichletBC]):

in the module?
Am I getting it totally wrong? The type command shoul return the class of the object used as argument. Thanks a bunch

I think i got it.
Looking into the Source for dirichletbc function, the dirichletbc function returns

raise NotImplementedError(f"Type {value.dtype} not supported.") except AttributeError: raise AttributeError("Boundary condition value must have a dtype attribute.") formcls = type("DirichletBC", (DirichletBCMetaClass, bctype), {}) return formcls(value, dofs, V)

which is why I see DirichletBC and not DirichletBCMetaClass
Thanks a lot