How to implement Directional Periodic Boundary Conditions

How to implement periodic boundary conditions in FEniCS 2019, such that, if there is a displacement/force along the y-axis, then the periodic boundary condition will apply only to the x-axis, and vice versa?
What modification can be done the default pbc formulation, which is

class PeriodicBoundary(SubDomain):

    # Left boundary is "target domain" G
    def inside(self, x, on_boundary):
        return bool(x[0] < DOLFIN_EPS and x[0] > -DOLFIN_EPS and on_boundary)

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

I recommend using the much more powerful dolfinx_mpc for your task. I donā€™t remember if old FEniCSā€™s constrained domain mechanic supports mixed elements. GitHub - jorgensd/dolfinx_mpc: Extension for dolfinx to handle multi-point constraints.

I am actually a bit hesitant to use dolfinx_mpc since it is only available in a docker container, and Iā€™m not familiar with docker. Iā€™m using Ubuntu WSL with Jupyter to run FEniCS. I did see something regarding ā€˜Sourceā€™ on the github page, but Iā€™m not sure how to use that.

EDIT : I cloned the dolfinx_mpc github in the jupyter notebook, and import dolfinx_mpc works, so I think I can use it

I tried to use only x or y coordinates in the map function, but then I get the error

Error: Unable to periodic boundary mapping.
*** Reason: Need to set coordinate 0 in sub_domain.map.

it is only available in a docker container

This doesnā€™t make sense. There is a docker image available, but this is not the exclusive method by which dolfinx_mpc may be used.

I did see something regarding ā€˜Sourceā€™ on the github page

This implies using the source code. If youā€™re running the components of FEniCSx with whatever method youā€™ve chosen, thereā€™s nothing stopping you from compiling dolfinx_mpc.

Hi, kindly check the edit.

This doesnā€™t make sense. There is a docker image available, but this is not the exclusive method by which dolfinx_mpc may be used

Well, I couldnā€™t find any other way other than Source and Docker (Those are mentioned on the github page, Obviously I later realized that Jupyter can clone github repositories, and decided to run git clone).

Installing from source means:

  1. Clone the github repository
  2. Checkout to the relevant version you would like to use (should be compatible with the DOLFINx version you are running)
  3. Run the steps explained in: GitHub - jorgensd/dolfinx_mpc: Extension for dolfinx to handle multi-point constraints.
1 Like

OK, thank you for the explanation.

I went through the GitHub and I noticed 2 functions, create_periodic_constraint_geometrical and create_general_constraint

From the doctrings that the first function constraints all dofs, but the 2nd function seems to gives more freedom in terms of the dofs
The example section reads

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:
{numpy.array([d0, d1], dtype=numpy.float64).tobytes():
{numpy.array([e0, e1], dtype=numpy.float64).tobytes(): alpha,
numpy.array([f0, f1], dtype=numpy.float64).tobytes(): beta}}

What I want to do is apply the periodic boundary condition in only 1 direction, x or y, on an edge of a square plate. Should I use the 2nd function to do that or is there any way to use the 1st one.

The second one gives you more freedom, but if you want it to work in parallel, you would have to do all necessary parallel communications your-self.

As the documentation says, you can supply a sub space: dolfinx_mpc/multipointconstraint.py at f7809a69699c4aaf2f602ed097a1ed4cf36e5968 Ā· jorgensd/dolfinx_mpc Ā· GitHub as illustrated with the topological version in dolfinx_mpc/demo_periodic3d_topological.py at f7809a69699c4aaf2f602ed097a1ed4cf36e5968 Ā· jorgensd/dolfinx_mpc Ā· GitHub

1 Like

I donā€™t remember if old FEniCSā€™s constrained domain mechanic supports mixed elements.

Any way for me to verify this? I am going through the GitHub of dolfin

See:Bitbucket

1 Like

Run the steps explained in: GitHub - jorgensd/dolfinx_mpc: Extension for dolfinx to handle multi-point constraints.

Where do I put those lines? Conda channel (fenicsx-env) or base?

To install the dolfinx_mpc -library run the following code from this directory:

Iā€™m not sure what ā€˜this directoryā€™ means

You clone the github repo dolfin_mpc, navigate into the root of the repository, i.e. dolfinx_mpc and run the commands from there

dolfinx_mpc
Is this the root which you are referring to?

Yes, it is the root im referring to

1 Like

When I try to run the 1st command, I get

Could not find a configuration file for package ā€œDOLFINXā€ that is
compatible with requested version ā€œ0.5.1ā€.
The following configuration files were considered but not accepted:
/home/sarvesh/anaconda3/envs/fenicsx-env/lib/cmake/dolfinx/DOLFINXConfig.cmake, version: 0.5.0

This seems to be a version mismatch, so how do I edit those lines to install a compatible version?

Checkout v0.5.0 (Release v0.5.0 Ā· jorgensd/dolfinx_mpc Ā· GitHub)

Iā€™m sorry but I donā€™t understand how to install thatā€¦I see two compressed files, if Iā€™m supposed to download those how do I do that (in the correct directory).

EDIT
I used wget and patool to download and extract, but now I get the error

CMake Error at CMakeLists.txt:137 (add_library):
Target ā€œdolfinx_mpcā€ links to target ā€œhdf5::hdf5ā€ but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?

If you go to the git repo you cloned, you can call git checkout v0.5.0 to get the correct version.

Yes, I was able to download and extract, kindly check the edit.