# Mesh refinement with three layers?

**URL:** <https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798>\
**Category:** ASPECT\
**Created:** [September 10, 2019, 8:10pm UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798 "2019-09-10T20:10:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SophieCoulson](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/sophiecoulson/32/147_2.png) [@SophieCoulson](https://community.geodynamics.org/u/SophieCoulson)\
**Post date:** [September 10, 2019, 8:10pm UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798/1 "2019-09-10T20:10:42Z")

</div>

Hi all,

Looking for advice on the best way to create a mesh with three different layers of refinement. For example, something like a spherical shell with refinement 3 below 1000km depth, refinement 5 above this and then refinement 6 above 300km depth.  
I’ve previously used the minimum and maximum refinement functions with an if statement to create a two layered shell with higher refinement in the upper mantle, e.g. below, but I can’t figure out how to do this for 3 layers.

subsection Minimum refinement function  
set Coordinate system = depth  
set Function constants = TZ=1000e3  
set Function expression = if(x\<TZ,5,3)  
end  
subsection Maximum refinement function  
set Coordinate system = depth  
set Function constants = TZ=1000e3  
set Function expression = if(x\<TZ,5,3)  
end

Thanks in advance for your guidance!  
Sophie

---

<div class="post-metadata">

**Author:** ![MFraters](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/mfraters/32/66_2.png) [@MFraters](https://community.geodynamics.org/u/MFraters)\
**Post date:** [September 10, 2019, 8:28pm UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798/2 "2019-09-10T20:28:43Z")

</div>

Hey Sophie,

You should be able to do that by nesting if statements: if(x \< 300e3, 6, if(x \<TZ, 5, 3)).

Hope this helps!

Menno

---

<div class="post-metadata">

**Author:** ![jbnaliboff](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jbnaliboff](https://community.geodynamics.org/u/jbnaliboff)\
**Post date:** [September 10, 2019, 8:41pm UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798/3 "2019-09-10T20:41:00Z")

</div>

Hi Sophie,

If I am interpreting the desired mesh structure correctly, I think you can do this just with the Minimum refinement function.

The minimum refinement level in the entire model is 3, so `Initial global refinement = 3`. Assuming z is depth, you can then structure the function in the following manner:  
`if (z> height_1, if ( z>height_2, 5, 4), 3)`

Let us know if this works!

John

EDIT: Menno beat me to it 🙂, but same idea. Also, you would replace `, 5, 4)` with `, 6, 5` above. Either this or Menno’s version of the function should work.

---

<div class="post-metadata">

**Author:** ![SophieCoulson](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/sophiecoulson/32/147_2.png) [@SophieCoulson](https://community.geodynamics.org/u/SophieCoulson)\
**Post date:** [September 10, 2019, 9:04pm UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798/4 "2019-09-10T21:04:30Z")

</div>

Thanks both, this works great!

While I’m here - I’m currently using the ruler in paraview to figure out the dimensions of the cells, is there a more elegant way to know what size they are for a specific geometry?

---

<div class="post-metadata">

**Author:** ![MFraters](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/mfraters/32/66_2.png) [@MFraters](https://community.geodynamics.org/u/MFraters)\
**Post date:** [September 11, 2019, 12:27am UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798/5 "2019-09-11T00:27:24Z")

</div>

What you can do is compute the dimensions of every refinement level by hand. If you have a 2d cartesian box of 200x400 and you have an initial subdivision in the length, the coarsest element is 200x200, one refinement up is 100x100, etc. Then you only need to know at what refinement level each cell is, which is usually easy to estimate.

Would this work for you?

---

<div class="post-metadata">

**Author:** ![SophieCoulson](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/sophiecoulson/32/147_2.png) [@SophieCoulson](https://community.geodynamics.org/u/SophieCoulson)\
**Post date:** [September 11, 2019, 4:33pm UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798/6 "2019-09-11T16:33:36Z")

</div>

Yea that makes sense. But is there a specific number of cells we start with? i.e. for a spherical shell how many cells will there be for refinement 0?

---

<div class="post-metadata">

**Author:** ![bangerth](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/bangerth/32/52_2.png) [@bangerth](https://community.geodynamics.org/u/bangerth)\
**Post date:** [September 11, 2019, 4:51pm UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798/7 "2019-09-11T16:51:35Z")

</div>

There’s an input parameter “Cells along circumference” that you can set  
in the .prm file. If you don’t set one, ASPECT will take the default,  
which is 12 in 2d and 96 in 3d.

Best  
W.

---

<div class="post-metadata">

**Author:** ![SophieCoulson](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/sophiecoulson/32/147_2.png) [@SophieCoulson](https://community.geodynamics.org/u/SophieCoulson)\
**Post date:** [September 11, 2019, 5:04pm UTC](https://community.geodynamics.org/t/mesh-refinement-with-three-layers/798/8 "2019-09-11T17:04:10Z")

</div>

Ah, great! Thank you!
