# Small help with velocity function to vary along the side walls in 3D

**URL:** <https://community.geodynamics.org/t/small-help-with-velocity-function-to-vary-along-the-side-walls-in-3d/3460>\
**Category:** ASPECT\
**Created:** [May 20, 2024, 6:47pm UTC](https://community.geodynamics.org/t/small-help-with-velocity-function-to-vary-along-the-side-walls-in-3d/3460 "2024-05-20T18:47:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanybit](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/hanybit/32/1931_2.png) [@hanybit](https://community.geodynamics.org/u/hanybit)\
**Post date:** [May 20, 2024, 6:47pm UTC](https://community.geodynamics.org/t/small-help-with-velocity-function-to-vary-along-the-side-walls-in-3d/3460/1 "2024-05-20T18:47:08Z")

</div>

So I have a 3D model of extension and I am trying to vary velocity along the side walls left and right so that extension vary from 5mm/yr at upper corner to 15mm/yr at lower corner, I wrote this function, but seems there is issue, is this a good way to construct it? The expression of variying velocity [-1\*ymax / y \* (vmax-vmin) + vmax] is correct if the code consider y as a variable of all ponts along the y coordnates of the left and right walls.

subsection Boundary velocity model  
set Tangential velocity boundary indicators = bottom  
set Prescribed velocity boundary indicators = left: function, right:function

subsection Function  
set Coordinate system = cartesian  
set Variable names = x,y,z,t

```
set Function constants = ymax= 400.e3, xmin=0.e3, xmax=200.e3, vmax=15, vmin=5, v= -1*ymax / y * (vmax-vmin) + vmax
set Function expression = if (x=xmax, v*mm/yr, -v*mm/yr);

```

end  
end

---

<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:** [May 20, 2024, 8:19pm UTC](https://community.geodynamics.org/t/small-help-with-velocity-function-to-vary-along-the-side-walls-in-3d/3460/2 "2024-05-20T20:19:28Z")

</div>

Dear Hany,

A couple of things:

- Your `v` isn’t a constant, so it shouldn’t be in the `Function constants` parameter.
- Testing that a float (`x`) is exactly equal to another float is generally a bad idea because of floating point precision. Better to use an inequality.

If you still have problems, please describe what you expect the code to do, attach a minimal non-working prm file that demonstrates the unexpected behaviour, and provide the associated error message if there is one.

Best wishes,  
Bob

---

<div class="post-metadata">

**Author:** ![hanybit](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/hanybit/32/1931_2.png) [@hanybit](https://community.geodynamics.org/u/hanybit)\
**Post date:** [May 21, 2024, 8:06pm UTC](https://community.geodynamics.org/t/small-help-with-velocity-function-to-vary-along-the-side-walls-in-3d/3460/3 "2024-05-21T20:06:18Z")

</div>

Hey Bob,  
so I rewrote the function and got another small error, so basically i try to vary the velocity to start from 5mm/yr and increases to 15mm/yr along the left and right sides of the model.

my function I wrote is:  
subsection Boundary velocity model  
#set Tangential velocity boundary indicators = bottom  
set Prescribed velocity boundary indicators = left x: function, right x:function, bottom z: function

subsection Function  
set Coordinate system = cartesian  
set Variable names = x,y,z,t

```
set Function constants = mm=0.001, yr=1,y_max= 400e3 ,vx_full_min=5.000 , vx_full_max=15.000 , vy_full=0.0000, DZ=200e3, DX=200e3 

set Function expression = if(x<100e3, -1*(-1*y_max / y * ((vx_full_max/2)-(vx_full_min/2)) + (vx_full_max/2)) *mm/yr), (-1*y_max / y * ((vx_full_max/2)-(vx_full_min/2)) + (vx_full_max/2)) *mm/yr); \
                          if(x<100e3, vy_full/2*mm/yr, -vy_full/2*mm/yr); \

```

end  
end

but I got this error:  
Message: \<Too few parameters for function “if” at expression position 89\>  
Formula: \<if(x\<100e3, -1\*(-1\*y\_max/ y \* ((vx\_full\_max/2)-(vx\_full\_min/2)) + (vx\_full\_max/2)) _mm/yr), (-1_y\_max/ y \* ((vx\_full\_max/2)-(vx\_full\_min/2)) + (vx\_full\_max/2)) \*mm/yr) \>  
Token:   
Position: \<89\>  
Errc: \<15\>

---

<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:** [May 21, 2024, 8:34pm UTC](https://community.geodynamics.org/t/small-help-with-velocity-function-to-vary-along-the-side-walls-in-3d/3460/4 "2024-05-21T20:34:33Z")

</div>

Perhaps check your brackets?

Best wishes,  
Bob

---

<div class="post-metadata">

**Author:** ![hanybit](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/hanybit/32/1931_2.png) [@hanybit](https://community.geodynamics.org/u/hanybit)\
**Post date:** [May 21, 2024, 8:53pm UTC](https://community.geodynamics.org/t/small-help-with-velocity-function-to-vary-along-the-side-walls-in-3d/3460/5 "2024-05-21T20:53:59Z")

</div>

Thanks Bob alot, any idea what does that error means??

The solver reported the following error:

```
--------------------------------------------------------
An error occurred in line <2688> of file
</home/bbkeheck/aspect/source/utilities.cc> in function
void aspect::Utilities::linear_solver_failed(const string&, const
string&, const std::vector<dealii::SolverControl>&, const
std::exception&, ompi_communicator_t* const&, const string&)
The violated condition was:
false
Additional information:
The iterative (top left) solver in BlockSchurPreconditioner::vmult did
not converge.

The required residual for convergence is: -nan

The solver reported the following error:

--------------------------------------------------------
An error occurred in line <497> of file
</home/projects/bbp00039/fastscape_build_files/misc/deal.IIdev-master-15th-feb-22/tmp/unpack/deal.II-master/source/lac/trilinos_solver.cc>

in function
void dealii::TrilinosWrappers::SolverBase::do_solve(const
Preconditioner&) [with Preconditioner =
dealii::TrilinosWrappers::PreconditionBase]
The violated condition was:
false
Additional information:
AztecOO::Iterate error code -2: numerical breakdown

```

---

<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:** [May 21, 2024, 9:24pm UTC](https://community.geodynamics.org/t/small-help-with-velocity-function-to-vary-along-the-side-walls-in-3d/3460/6 "2024-05-21T21:24:14Z")

</div>

I recommend checking your function. The division by y is surprising to me and could produce a divide by zero error.
