# Equations involve different mesh spaces

**URL:** <https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453>\
**Category:** General Discussion\
**Created:** [May 12, 2023, 5:38am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453 "2023-05-12T05:38:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 12, 2023, 5:38am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/1 "2023-05-12T05:38:54Z")

</div>

Dear everyone:

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

 ![微信图片_20230512131529|6strong text90x225](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/529ee4e0d9319e50f95effd13404db39ec15f8d1.png)

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 🙂

---

<div class="post-metadata">

**Author:** ![phtournier](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@phtournier](https://community.freefem.org/u/phtournier)\
**Post date:** [May 12, 2023, 8:07am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/2 "2023-05-12T08:07:28Z")

</div>

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](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/examples/stokes_composite.edp) [FreeFem-sources/stokes\_periodic\_composite.edp at develop · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/examples/stokes_periodic_composite.edp)  
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](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/mpi/Helmholtz-2d-FEM-BEM-coupling-MUMPS-composite.edp) but it is a little bit more involved.  
The documentation for these new features should hopefully come soon.

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 12, 2023, 9:30am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/3 "2023-05-12T09:30:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![phtournier](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@phtournier](https://community.freefem.org/u/phtournier)\
**Post date:** [May 12, 2023, 1:25pm UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/4 "2023-05-12T13:25:05Z")

</div>

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

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

```

and follow these steps [GitHub - FreeFem/FreeFem-sources: FreeFEM source code](https://github.com/FreeFem/FreeFem-sources#freefem) to compile it.

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 12, 2023, 3:36pm UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/5 "2023-05-12T15:36:30Z")

</div>

Very appreciate for your kind help , and merci beucoup!

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 12, 2023, 6:35pm UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/6 "2023-05-12T18:35:39Z")

</div>

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.

Thanks.

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 13, 2023, 2:26am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/7 "2023-05-13T02:26:30Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 13, 2023, 10:46am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/8 "2023-05-13T10:46:00Z")

</div>

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.

```auto
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; }
break;
}
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);
label=5;
}
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

```

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 14, 2023, 7:11am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/9 "2023-05-14T07:11:28Z")

</div>

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:

 ![dev](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/ad57846975a7c3d4f3ee1f1ae11104926186b61f.png)

I fail to solve this problem and get stuck.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 14, 2023, 7:19am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/10 "2023-05-14T07:19:02Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 14, 2023, 8:12am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/11 "2023-05-14T08:12:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 14, 2023, 8:38am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/12 "2023-05-14T08:38:16Z")

</div>

“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).

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [May 15, 2023, 1:03am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/13 "2023-05-15T01:03:55Z")

</div>

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

```auto
[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 
[https://www.sciencedirect.com/science/article/pii/S0898122112006463](https://www.sciencedirect.com/science/article/pii/S0898122112006463)

```

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 15, 2023, 2:51am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/14 "2023-05-15T02:51:25Z")

</div>

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](https://arxiv.org/pdf/1810.09817.pdf) , this kind of bc is proposed in[W-L model](https://arxiv.org/pdf/1710.08318.pdf) in a mathematical way.

---

<div class="post-metadata">

**Author:** ![phtournier](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@phtournier](https://community.freefem.org/u/phtournier)\
**Post date:** [May 15, 2023, 7:38am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/15 "2023-05-15T07:38:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 15, 2023, 7:54am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/16 "2023-05-15T07:54:40Z")

</div>

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

 ![15](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/d/ddaf2ab80696f856316e4e3cd8486e59159ac590.png)

---

<div class="post-metadata">

**Author:** ![phtournier](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@phtournier](https://community.freefem.org/u/phtournier)\
**Post date:** [May 15, 2023, 10:42am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/17 "2023-05-15T10:42:50Z")

</div>

did you `./configure` ?

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 15, 2023, 10:59am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/18 "2023-05-15T10:59:57Z")

</div>

Here is the log :  
[config.log](https://community.freefem.org/uploads/short-url/gkJvxNe5YSTWZnmgE2Y8keqL262.log) (24.1 KB)

---

<div class="post-metadata">

**Author:** ![phtournier](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@phtournier](https://community.freefem.org/u/phtournier)\
**Post date:** [May 15, 2023, 6:04pm UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/19 "2023-05-15T18:04:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Starivers](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/starivers/32/1694_2.png) [@Starivers](https://community.freefem.org/u/Starivers)\
**Post date:** [May 16, 2023, 10:55am UTC](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453/20 "2023-05-16T10:55:34Z")

</div>

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

[Next page](https://community.freefem.org/t/equations-involve-different-mesh-spaces/2453.md?page=2)
