# Boundary velocity function with chunk geometry

**URL:** <https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532>\
**Category:** ASPECT\
**Created:** [July 2, 2024, 3:32pm UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532 "2024-07-02T15:32:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nora](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/nora/32/1999_2.png) [@Nora](https://community.geodynamics.org/u/Nora)\
**Post date:** [July 2, 2024, 3:32pm UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/1 "2024-07-02T15:32:32Z")

</div>

Dear all,  
I would need to write a boundary velocity Function using the Chunk geometry. I used r, x and y as r, phi, theta variable names, and used the colatitude in the coordinates within the function (you can see the function below…). Also changed the component to r, phi theta.  
However, the velocity field is not as expected in my domain.

Surely is there something that I am doing wrong. Do you have any clues?

Thanks a lot!  
Eleonora

subsection Boundary velocity model  
set Tangential velocity boundary indicators = west, east  
set Prescribed velocity boundary indicators = top: function, north: zero velocity, south: zero velocity  
subsection Function  
set Coordinate system = spherical  
set Use spherical unit vectors = true  
set Variable names = z, x, y  
set Function constants = cm=0.01, year=1  
set Function expression = 0; if (x\<=-16.85 && y\>=90.0 | x\<=-25.41 && y\<=90.0,1.0_cm/year,-1.0_cm/year); 0  
end  
end

---

<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:** [July 2, 2024, 4:38pm UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/2 "2024-07-02T16:38:46Z")

</div>

@nora A good starting point for debugging problems is to be specific about what the _problem_ is, so that one can speculate about _solutions_. All you say is “Surely is there something that I am doing wrong. Do you have any clues?”, but we really don’t: We don’t even know that what you are doing is wrong because we don’t know what it is you get (and we can’t try ourselves because we don’t know what your complete input file is).

So here are some questions:

- What happens when you try with your function?
- Does the program provide an error?
- If not, does it run to completion?
- If it does, how does the solution look like?
- In which specific ways does what you see differ from what you expect?

Best  
W.

---

<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:** [July 2, 2024, 4:56pm UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/3 "2024-07-02T16:56:21Z")

</div>

@Nora - As you debug the issue following @bangerth’s suggestions above, it may be helpful to take a look at and try modifying the following test case where a 2D spherical shell has a velocity function applied on the top boundary - [boundary\_velocity\_function\_spherical.prm](https://github.com/geodynamics/aspect/blob/main/tests/boundary_velocity_function_spherical.prm).

---

<div class="post-metadata">

**Author:** ![Nora](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/nora/32/1999_2.png) [@Nora](https://community.geodynamics.org/u/Nora)\
**Post date:** [July 3, 2024, 8:12am UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/4 "2024-07-03T08:12:36Z")

</div>

Dear Wolfgang and John,  
thanks a lot for your replies. You are absolutely right, I was so unspecific about the problem. That’s because I was sure there was something macroscopically wrong in the function I was writing, but still without saying what I was expecting from my function, sorry for that!

The function I wrote should give a transform fault in the XY plane, in the middle of a 3d chunk domain.  
The program runs to completion without giving any error, but the velocity field on the top gives a flow in a unique direction, instead of giving a transform fault (see attached figure).

@jbnaliboff thanks for this suggestion, I will try implementing modifications to this .prm

Thanks and sorry again,  
Nora

 ![velocity_field.png](https://canada1.discourse-cdn.com/flex036/uploads/geodynamics/original/2X/4/4f6533bea62acef36ba775d153b76fce3bc1a931.png)

---

<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:** [July 4, 2024, 3:26am UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/5 "2024-07-04T03:26:57Z")

</div>

@Nora Separately, looking at your input file, here are a couple of comments:

- It is confusing to see the spherical coordinates named x,y,z. (Or, in fact, z,x,y.) Use the correct names that include r,phi,theta in an order you should verify. It is very difficult to debug problems when variable names suggest one thing, but represent another thing.
- You use `|` as the `or` operator. Should this be `||`?
- I _think_ that what the expression represents is something where you assume that `or` binds lower than `and` (`&&`). That’s perhaps true, but I’m always confused about this, and so are probably 50% of all programmers. It’s worth using parentheses.

Best  
W.

---

<div class="post-metadata">

**Author:** ![Nora](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/nora/32/1999_2.png) [@Nora](https://community.geodynamics.org/u/Nora)\
**Post date:** [July 5, 2024, 3:27pm UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/6 "2024-07-05T15:27:19Z")

</div>

@bangerth Thanks for your comments.

I changed the variable names to make the function clearer and used parentheses as below, also tried with both coordinates (with theta in colatitude) expressed in radians (commented option) and degrees (non commented option), but the result is always the velocity field attached in the previous email, so a unidirectional velocity field. It seems that the function is not using the “else” option.

subsection Function  
set Coordinate system = spherical  
set Use spherical unit vectors = true  
set Variable names = r, phi, theta  
set Function constants = cm=0.01, year=1

# set Function expression = 0; if (((phi\<=-0.44348816 && theta\>=1.5708) || (phi\<=-0.29408798 && theta\<=1.5708)), 1.451_cm/year, -1.451_cm/year); 0

set Function expression = 0; if ((phi\<=-25.41 && theta\>=90.0) && (phi\<=-16.85 && theta\<=90.0), 1.451_cm/year, -1.451_cm/year); 0  
end

Thanks a lot for your help.

Nora

---

<div class="post-metadata">

**Author:** ![bobmyhill](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/bobmyhill/32/38_2.png) [@bobmyhill](https://community.geodynamics.org/u/bobmyhill)\
**Post date:** [July 5, 2024, 3:46pm UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/7 "2024-07-05T15:46:27Z")

</div>

Dear Nora,

Can you attach your complete prm file? It would be useful to see the lat/lon edges of your domain.

Bob

---

<div class="post-metadata">

**Author:** ![Nora](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/nora/32/1999_2.png) [@Nora](https://community.geodynamics.org/u/Nora)\
**Post date:** [July 8, 2024, 9:24am UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/8 "2024-07-08T09:24:19Z")

</div>

Dear Bob,  
sure. Here my .prm file.

Thanks,  
Nora

[transform.prm](https://community.geodynamics.org/uploads/short-url/4hOkUKuVnnEdz5tSEH5OPOnzF49.prm) (4.13 KB)

---

<div class="post-metadata">

**Author:** ![bobmyhill](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/bobmyhill/32/38_2.png) [@bobmyhill](https://community.geodynamics.org/u/bobmyhill)\
**Post date:** [July 8, 2024, 5:13pm UTC](https://community.geodynamics.org/t/boundary-velocity-function-with-chunk-geometry/3532/9 "2024-07-08T17:13:49Z")

</div>

Dear Nora,

phi ranges between 0 and 2\*pi (so you should add 2pi to your negative phi values), and both theta and phi are in radians. Sorry for missing this at the beginning, it is also something that I had to look up.

Best wishes,  
Bob
