# Defining multiple local meshes using buildDmesh

**URL:** <https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949>\
**Category:** General Discussion\
**Created:** [April 27, 2021, 12:49pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949 "2021-04-27T12:49:37Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![KBarrett](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@KBarrett](https://community.freefem.org/u/KBarrett)\
**Post date:** [April 27, 2021, 12:49pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/1 "2021-04-27T12:49:37Z")

</div>

Hello all,

I am using the `macro_ddm.idp` to use `buildDmesh` and `createMat` with` macro def(i) [i, i#B, i#C] //` to solve the 3D elasticity equation in parallel using PETSc. I also need to solve a 1D and 2D varf in the same parallel script - how can I solve the varf of different dimension using the same local mesh, or how can I define another local mesh with different dimension (ex. `def(i) i//` ) using `buildDmesh`?

Thank you.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 27, 2021, 1:16pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/2 "2021-04-27T13:16:47Z")

</div>

Are your 1D and 2D meshes somehow related to the 3D mesh?

---

<div class="post-metadata">

**Author:** ![KBarrett](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@KBarrett](https://community.freefem.org/u/KBarrett)\
**Post date:** [April 27, 2021, 1:28pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/3 "2021-04-27T13:28:19Z")

</div>

Yes - they use the same 3D global mesh.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 27, 2021, 1:30pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/4 "2021-04-27T13:30:20Z")

</div>

Could you please share a minimalist _sequential_ script with your various global meshes so that it’s better to see how they interact one with another?

---

<div class="post-metadata">

**Author:** ![KBarrett](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@KBarrett](https://community.freefem.org/u/KBarrett)\
**Post date:** [April 27, 2021, 1:57pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/5 "2021-04-27T13:57:55Z")

</div>

I’ve attached a simplified sequential version (ie. no mesh decomposition). The solver doesn’t work in this sequential case, but this is just so you can see what I intend to do/solve.

[Example.edp](https://community.freefem.org/uploads/short-url/nMXJXB4Dui6gOuQMAqBlyqlsB26.edp) (6.0 KB)

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 27, 2021, 2:02pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/6 "2021-04-27T14:02:02Z")

</div>

I just see a single 3D mesh `Omega` in this script, is this alright?

---

<div class="post-metadata">

**Author:** ![KBarrett](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@KBarrett](https://community.freefem.org/u/KBarrett)\
**Post date:** [April 27, 2021, 2:04pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/7 "2021-04-27T14:04:58Z")

</div>

Yes - that is the single domain over which the integrals in both varfs are applied.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 27, 2021, 2:06pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/8 "2021-04-27T14:06:22Z")

</div>

But both `varf` are defined on `Omega`, your single 3D mesh. You said initially that you have “1D and 2D varf”, but I don’t see any `varf` using either a `mesh` or `meshL`.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 27, 2021, 2:09pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/9 "2021-04-27T14:09:38Z")

</div>

If the “only” issue is mixing vectorial and scalar finite element spaces, you can just do the following.

```auto
load "PETSc"
macro dimension()3//
include "macro_ddm.idp"

mesh3 Omega = cube(10, 10, 10);

buildDmesh(Omega);
Mat A, B;
{
    macro def(i)[i, i#B, i#C]//
    macro init(i)[i, i, i]//
    createMat(Omega, A, [P2, P2, P2]);
}
{
    macro def(i)i// not mandatory
    macro init(i)i// not mandatory
    createMat(Omega, B, P1);
}

```

---

<div class="post-metadata">

**Author:** ![KBarrett](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@KBarrett](https://community.freefem.org/u/KBarrett)\
**Post date:** [April 27, 2021, 2:12pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/10 "2021-04-27T14:12:04Z")

</div>

This is what I was trying to explain - thank you! My apologies for doing such a poor job at explaining, but this is exactly what I was trying to figure out.

Thank you again!

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 27, 2021, 2:12pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/11 "2021-04-27T14:12:32Z")

</div>

OK, good then! No problem at all 😄

---

<div class="post-metadata">

**Author:** ![cnfernandez](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@cnfernandez](https://community.freefem.org/u/cnfernandez)\
**Post date:** [March 14, 2024, 3:14pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/12 "2024-03-14T15:14:48Z")

</div>

Hi Pierre!

How about solving in the same parallel script a problem in one mesh and another in a part of this mesh. For example, if you consider a 2D mesh and then solve a problem into a 1D mesh extract from this 2D mesh.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [March 14, 2024, 3:27pm UTC](https://community.freefem.org/t/defining-multiple-local-meshes-using-builddmesh/949/13 "2024-03-14T15:27:54Z")

</div>

Not a problem at all, in fact, that’s exactly what’s done in, e.g., [FreeFem-sources/examples/hpddm/helmholtz-coupled-2d-PETSc-complex.edp at develop · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/helmholtz-coupled-2d-PETSc-complex.edp).
