Periodic boundaries in FenicsX for non-linear problem on simple geometry

Hi All,

I am trying to maintain my workflow with Fenics with Conda after having changed system from Linux based to MaxOS with Apple silicon, but I am having issues. In retrospect Fenics is quite a big hammer for my task, but it is what I have been using and don’t want to completely start from scratch with a different package.

When I was on Linux I couldn’t get FenicsX working and so proceeded with legacy Fenics. Using the legacy package I was able to get it working well for my problem. However, when I attempt to install the legacy version on my new system, following Fenics :: Anaconda.org, with conda install -c conda-forge fenics, so that I can use my existing code, it fails with

PackagesNotFoundError: The following packages are not available from current channels:

  - fenics

From what I can tell this is because it is not supported for apple silicon. Is this correct?

Ok. So following https://fenicsproject.org/download/, I have installed FenicsX with

conda install -c conda-forge fenics-dolfinx mpich pyvista

But of course now I am facing the updated API. My case is simple - no complicated geometry or mesh - just lines, rectangles, cubes etc., but a multiple fields and non-linear dynamics in the PDE, and, crucially, it needs periodic boundary conditions.

I have made some progress updating the API calls in my code by following the demos, e.g. for the Cahn-Hilliard equation. However, I can’t find any resources, anywhere, about how to implement periodic boundary conditions in Fenicsx. Everything I see is for the legacy version which implements it by first defining a subclass of SubDomain with something like:

class PeriodicBoundary(SubDomain):

  m_L = 0.0

  def __init__(self,a_L):
    super(PeriodicBoundary,self).__init__()
    self.m_L = a_L

  def inside(self, x, on_boundary):
    return bool(x[0] < DOLFIN_EPS and x[0] > -DOLFIN_EPS and on_boundary)

  # Map right boundary to left boundary
  def map(self, x, y):
    y[0] = x[0] - self.m_L

Which is what I had working in legacy fenics, but doesn’t seem applicable in FenicsX. Is this correct?

Searching for an alternative, I found and installed the dolfinx_mpc package, as per Dolfinx Mpc :: Anaconda.org, and found examples employing periodic boundaries. However, beyond my not understanding the workflow for constraints with this package (requiring API calls to meshtags, locate_entities_boundary etc. that weren’t required in legacy fenics), if I understand correctly, the only API entry in dolfinx_mpc I can find is for “LinearProblem”, so I can’t apply it to my system.

I’m trying to do something seemingly simple, that I was able to do quite easily in legacy fenics, amounting to something like the Cahn-Hilliard example, but with periodic boundaries. How can I do this in FenicsX?

Thanks,

R.

Non-linear constraints have been covered by @nate in: dolfinx_mpc/python/tests/test_nonlinear_assembly.py at main · jorgensd/dolfinx_mpc · GitHub

It is unclear what you couldnt get working

See Fenics from Conda doesn't import - #19 by minrk

Thanks for the quick and comprehensive replies.

Re.

this isn’t relevant. It was >12 months ago, and could have been for any number of reasons and is not my question.

Looking towards FenicsX as a way of keeping up to date, with you test implementation in dolfinx_mpx notwithstanding, I’m still wondering:

In vanilla FenicsX, without third party add-ons, can periodic boundaries be implemented?

You could implement them yourself, for matching boundaries.
You would have to modify the dofmap such that dofs on one side is replaced by dofs from the other side. This is not trivial, but it is doable.

Ok, I’ll look into it. Thanks.