Constraint nodes value

Hi,

I am a beginner at Fenics. Is there any way to set up a constraint condition for the nodes? I am testing with a basic heat conduction problem. and created a simple bifurcation mesh:

editor.add_vertex(0, np.array([0.0,0.0,0.0]))
editor.add_vertex(1, np.array([0.0279,0,0]))
editor.add_vertex(2, np.array([0.0279,0.0,0]))
editor.add_vertex(3, np.array([0.043032,0.015132,0]))
editor.add_vertex(4, np.array([0.0279,0.0,0]))
editor.add_vertex(5, np.array([0.043032,-0.015132,0]))

editor.add_cell(0, np.array([0,1], dtype=np.uintp))
editor.add_cell(1, np.array([2,3], dtype=np.uintp))
editor.add_cell(2, np.array([4,5], dtype=np.uintp))

Is that possible to set a constrain that node1=node2+node4?

Many Thanks!

That is a multi point constraint and has been implemented as an add on to dolfin-x. See:

And

Note that you are constraining degrees of freedom (located at vertices). In dolfin and dolfinx the mesh and function space is decoupled. This means that you can have an arbitrary order function space on a first order geometry

1 Like

Thank you very much
I will take a look

Hi,
I am facing an issue when I try to run your demo code: demo_contact_3D.py,
which error showing as:
HDF5-DIAG: Error detected in HDF5 (1.10.4) MPI-process 0:
#000: …/…/…/src/H5F.c line 444 in H5Fcreate(): unable to create file
major: File accessibilty
minor: Unable to open file
#001: …/…/…/src/H5Fint.c line 1364 in H5F__create(): unable to open file
major: File accessibilty
minor: Unable to open file
#002: …/…/…/src/H5Fint.c line 1557 in H5F_open(): unable to open file: time = Thu May 20 22:50:27 2021
, name = ‘results/demo_contact_3D.h5’, tent_flags = 13
major: File accessibilty
minor: Unable to open file
#003: …/…/…/src/H5FD.c line 734 in H5FD_open(): open failed
major: Virtual File Layer
minor: Unable to initialize object
#004: …/…/…/src/H5FDsec2.c line 346 in H5FD_sec2_open(): unable to open file: name = ‘results/demo_contact_3D.h5’, errno = 2, error message = ‘No such file or directory’, flags = 13, o_flags = 242
major: File accessibilty
minor: Unable to open file
Traceback (most recent call last):
File “demo_contact_3D.py”, line 242, in
outfile = dolfinx.io.XDMFFile(comm, “results/demo_contact_3D.xdmf”, “w”)
RuntimeError: Failed to create HDF5 file.
I assume this is a core issue, but not sure how to fix it, can you give me some advice?
Many thanks

Simply create the directory results in the folder containing the demo

1 Like

Thank you so much, I resolve the issue and the code looks good.
Btw, it that still able to use the MeshEditor() function in dolfinx?

No, the interface in dolfinx does not require a mesheditor. We have an interface Where you pass in the mesh topology and geometry. See for instance: dolfinx/demo_gmsh.py at main · FEniCS/dolfinx · GitHub

Thanks, is there a better way that I can update the existing dolfinx image in docker once new things have added from your side. Cause I just realize I do not have nonlinearproblem in fem folder, I have to pull the dolfinx from dockerhub again and run the latest image.
Many thanks

I will soon make a docker image with the 0.1.0version of dolfinx/dolfinx_mpc.

Please note that you need to create your own custom nonlinear solver if you want to use it with MPC.

I see, appreciate that

Hi dokken,
Sorry to bother again
I use to define Initial condition and Boundary conditions in dolfin as:
IC:
V =FunctionSpace(mesh, ‘Lagrange’, 1)
u_dd=Expression(‘1.4’,degree=1)
u_n = interpolate(u_dd, V)

BC:
u0 = abs(round(1 + (Pa_L-PT)/alpha_L,2))
def u0_boundary(x, on_boundary):
tol = 1e-14;
return abs(x[0] - term_nodes_coord[0][0]) < tol
bcL = DirichletBC(V, u0, u0_boundary)

The question is how should I write code in dofinx to achieve the same result?
Many Thanks

Please have a look through the DOLFINx tutorial I have written: The FEniCS-X tutorial — FEniCS-X tutorial

Thanks!! I was looking for this

Hi Dokken,

I am actually working on a 1D problem, I still do not quite understand how to set up a constant value for the boundary condition. seems the Constant() function does not work as before where I use to write:

u0=Constant(5)
DirichletBC(V, u0, u0_boundary)

Now is showing me: init() missing 1 required positional argument: ‘c’

can you teach about this?
Thanks for your time

Please make a minimal code example that reproduces the error.

V = dolfinx.FunctionSpace(mesh, (“CG”, 1))
BC_test = Constant(mesh, 0)
BC_test.value = 5

dofs_L = dolfinx.fem.locate_dofs_geometrical(V, lambda x: np.isclose(x[0], 0))

bc_L = dolfinx.DirichletBC(BC_test, dofs_L)

Error showing:
bc_L = dolfinx.DirichletBC(BC_test, dofs_L)
File “/usr/local/dolfinx-real/lib/python3.8/dist-packages/dolfinx/fem/dirichletbc.py”, line 147, in init
raise NotImplementedError
NotImplementedError

DOLFINx does currently not support the usage of Constant in Dirichlet boundary conditions. However, you can set a constant value as shown in: Component-wise Dirichlet BC — FEniCSx tutorial
simply use:

with uDx.vector.localForm() as uDx_loc:
    uDx_loc.set(5)

@sunsystem I have now created a docker image with the 0.1.0 release of dolfinx and dolfinx_mpc at: Docker Hub
which can be obtained by running

docker pull dokken92/dolfinx_mpc:0.1.0

Hi, Dokken
I have a question about the MPC code, where in the function ‘‘create_general_constraint(V, slave_master_dict)’’ the ‘‘slave_master_dict’’ is decribed as:
If the dof D located at [d0,d1] should be constrained to the dofs
E and F at [e0,e1] and [f0,f1] as
D = alpha E + beta F
the dictionary should be:
{np.array([d0, d1], dtype=np.float64).tobytes():
{np.array([e0, e1], dtype=np.float64).tobytes(): alpha,
np.array([f0, f1], dtype=np.float64).tobytes(): beta}}
I am a little confuse here, what is location mean?Does it mean the physical location of one point on the mesh (say a 1cm segmanet, point D at [0.15cm, 0cm]), or it means the nodes index (5 nodes in the segment, node D is the 3rd node at [3, 0])?
And how should I write this part in a 1D mesh (the sample you give is for a 2D mesh, the constrained point is given in 2D form)?

Thanks for your time, and appreciate your help!

The location is the location of the degree of freedom you would like to constrain. I.e. given a 1D mesh on the interval [0,2], say I would like the condition u(0) = 2\cdot u(2).
This would be implemented as follows:

s_m_c = {l2b([0]): {l2b([2]): 2}}

mpc = dolfinx_mpc.MultiPointConstraint(V)
mpc.create_general_constraint(s_m_c)
mpc.finalize()

Full working example below:

# Copyright (C) 2021 Jørgen S. Dokken
#
# This file is part of DOLFINX_MPC
#
# SPDX-License-Identifier:    LGPL-3.0-or-later

import dolfinx
import dolfinx.io
import dolfinx_mpc
import dolfinx_mpc.utils
import numpy as np
import pytest
import ufl
from mpi4py import MPI
from petsc4py import PETSc


# Create mesh and function space

mesh = dolfinx.IntervalMesh(MPI.COMM_WORLD, 10, [np.array([0]), np.array([2])])
V = dolfinx.FunctionSpace(mesh, ("Lagrange", 1))

# Solve Problem without MPC for reference
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
x = ufl.SpatialCoordinate(mesh)
f = 2 * x[0]**2
a = ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx
rhs = ufl.inner(f, v) * ufl.dx

# Create multipoint constraint


def l2b(li):
    return np.array(li, dtype=np.float64).tobytes()


s_m_c = {l2b([0]): {l2b([2]): 2}}

mpc = dolfinx_mpc.MultiPointConstraint(V)
mpc.create_general_constraint(s_m_c)
mpc.finalize()

problem = dolfinx_mpc.LinearProblem(a, rhs, mpc, bcs=[],
                                    petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()

with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "u1d.xdmf", "w") as xdmf:
    xdmf.write_mesh(mesh)
    xdmf.write_function(uh)