Equations involve different mesh spaces

Dear everyone:

I am trying to implement Cahn-hilliard equation with dynamic boundary conditions, whose weak formula follows as:

With this weak formula, I define Problem cahn([ u , ub , ϕ ] , [ζ , ξ , η ] ) to solve.

However, as pointed in red line in the figure, ϕ belong to 2D mesh and test function ξ belong to 2D boundary mesh , error follows that" all the finites elements spaces must be defined on the same mesh in solve" .

So my question is :

  1. Can I solve it by using Vary(to calculate the stiffness matrix) and assemble the full equations to solve?
  2. If cant , or, is there a simple way to solve this kind of problem?

Remark : I also tried to define test function /xi in 2D mesh spcae, however it fails to solve( I guss the matrix will be notI nvertible in this way ) .

Thans for your help and best wishes :slight_smile:

New features implemented in the develop branch allow you to do what you want, i.e. define coupled weak formulas where unknowns can belong to different meshes, or even mesh types. These features will be included in the next FreeFEM release, which should come within a few weeks.

Here you can find two simple Stokes examples demonstrating this feature, where we use two different meshes for the velocity and pressure: FreeFem-sources/stokes_composite.edp at develop · FreeFem/FreeFem-sources · GitHub FreeFem-sources/stokes_periodic_composite.edp at develop · FreeFem/FreeFem-sources · GitHub
You will see that the syntax is a little bit different depending on whether you want to use the problem/solve syntax or the varf/matrix approach.
You can also find a volume/surface coupling FEM/BEM example here FreeFem-sources/Helmholtz-2d-FEM-BEM-coupling-MUMPS-composite.edp at develop · FreeFem/FreeFem-sources · GitHub but it is a little bit more involved.
The documentation for these new features should hopefully come soon.


Pierre-Henri Tournier, thanks for your reply !
I read the simple examples of Stokes equation, and I think it will be helpful to deal with my problem. However they cant run in my release , for “<>” cant be used in solve in the first example , and “composite FE space” cant be defined in the second. So you mean this two examples are for the next release to come, right?

Yes, this will be available in the next release. In the meantime, if you compile the develop branch from source on your machine, you can use these features right now. You can get the develop branch with

git clone -b develop https://github.com/FreeFem/FreeFem-sources

and follow these steps GitHub - FreeFem/FreeFem-sources: FreeFEM source code to compile it.

Very appreciate for your kind help , and merci beucoup!

If you don’t mind me asking, what are you doing and do you have a validated
example with solution? I’m looking at etching right now and hope to get
to simple examples leading to blood coagulation. One of the benefits of thie
approach you are likely using is to avoid boundaries as everything is now
continuous except for steep gradients. Boundaries can charge and aligning chemical
potentials may be a bit involved. Just curious if you have some specific thing
that may be suitable for differing approaches.


Hello Mike,
In fact I am preparing for my master’s thesis, its about C-H equation with dynamic bcs( so I cant avoid boundaries ). I have several numerical examples for C-H eqs of other kind boundary(Neumann , Allen-Cahn types), and am trying to write examples for this topic’s. But I dont think my example will help you , as it is just a mixed FEM, and there are some examples in freefem’s documentation.

As for avoiding boundaries, I cant(and dont know how to implement) because boundary is my target.

I think I may not get to the point you want to express( for my poor English comprehension).

Have you looked at isoline? Maybe some of the FF people can comment on its
utility to specify dynamic boundaries. I’m using the variable “c” between 0 and
1 to indicate a solid metal (1) or liquid(0) and wanted to define a border
as the metal etches. I used the code below although I’m not sure I use
the surface for anything now but earlier I could fix the potential on the surface
to avoid dealing with physics in the metal. I’ve also written some c++ code
to explore other issues with the surface ( effects of curvature in isolation for example).

The macro below may be a bit too complicated and cryptic but basically you can define
a square mesh and add arbitrary curved surfaces - there are examples in the ff manual.

macro buildisomesh(Thold,Th,a,c,lvl)
{int nbce = isoline(Thold, c, iso#a, close=0, iso=lvl, beginend=isopt#a, smoothing=0.1);
int cui=0;
int del=0;
int i0=isopt#a[2*cui];
int i1=isopt#a[2*cui+1]-1;
real cf=.45;
while (1==1)
if ( iso#a(0,del)< -cf*szx)  { ++del; continue; }
if ( iso#a(0,del)> cf*szx)  { ++del; continue; }
if ( iso#a(1,del)< -cf*szy)  { ++del; continue; }
if ( iso#a(1,del)> cf*szy)  { ++del; continue; }
real base=iso#a(2,del);
for(int jj=i0+del; jj<=(i1-del); ++jj) iso#a(2,jj)-=base;
int npts=i1-i0+1;
cout<<" npts "<<npts<<" del "<<del<<endl; cout.flush;
if (false) cout<<" del "<<iso#a(0,(i0+del):(i1-del))<<endl; cout.flush;
border Curve0(t=0, 1){

P=Curve(iso#a, i0+del, i1-del, t);
border left(t=0, 1){x=-szx/2; y=szy*(t-.5);label=1; }
border top(t=0, 1){x=szx*(t-.5);y=szy/2; label=2; }
border right(t=0, 1){x=szx/2; y=-szy*(t-.5);label=3; }
border bottom(t=0, 1){x=-szx*(t-.5);y=-szy/2; label=4; }
if (false)
    Th = buildmesh(left(-ny)+top(-nx)+right(-nx)+bottom(-ny)+Curve0(npts));
Th = buildmesh(left(-ny)+top(-nx)+right(-nx)+bottom(-ny)+Curve0(100+(npts/2)));
fespace Xx(Th,P2);
Xx xx=region;
if (false) plot(xx,cmm="isoed mesh ",wait=1,fill=1);
} // EOM

Hi, Pierre-Henri Tournier

I am following the step in your link to compile the sources. My system is Windows10 and I use Msys2(without MS MPI 7). Everything is fine until PETSc section:

I fail to solve this problem and get stuck.

Hi marchywka
I read your post several times but still cant understand it. I just have a very narrow knowledge about phase filed problem.
Thanks for your sharing but I cant follow it :slight_smile:

To your build issue, normally you just make the whole project following
the provedure in README or whatever is there. Building each dir like that may
not work. Once built the edp files with the FF code
are probably in examples and tutorials directory IIRC. What happens
when you try to configure and build the whole FF ?

I was just suggesting looking at “isoline” as something that may be useful
if you want to create a boarder based on some parameter like that.
I had a lot of other junk thrown in there but you can insert curves into
a 2D mesh and apply boundary conditions at these curves.

“looking at “isoline” as something that may be useful
if you want to create a boarder based on some parameter”

Yes for parameter type or implicit boundary , this method will be useful(I just use boundary of a square in general).

This is from 2013 and uses a square grid but with offset boundaries curious
how this relates to state of the art,

[1]A conservative numerical method for the Cahn-Hilliard equation with Dirichlet boundary conditions in complex domains, Li , Yibao[ ...] Kim , Junseok; Computers \& Mathematics with Applications. 2013 

I think they are different branch for the problem. Your paper is to solve CH eq in complex domain( In fact it has no relation with “square boundary”, the article use square grid because finite difference method must uses square grid, but for FEM, we can just define the boundary).

I dont know whats the frontier of CH eq, but if you are interested, what I refer to is CH for CH type boundary condition , this kind of bc is proposed inW-L model in a mathematical way.

PETSc requires MPI, so in order to get the full install you will need to get MS MPI. If for some reason you can’t or don’t want to install MS MPI on your system, you can ignore the make petsc-slepc step. You will get a working FreeFEM but you will not be able to perform parallel computations.

I finished autoreconf -i , ./3rdparty/getall -a, and skip all the process for PETSc.
Error arises that I cant make

did you ./configure ?

Here is the log :
config.log (24.1 KB)

You do not have any fortran compiler ; you can try to ./configure --disable-fortran but if that doesn’t work, your best bet would be to get MS MPI and compile petsc, which should take care of fortran problems.

I choose to wait for the next release :face_holding_back_tears: Thanks again for your help.