# How to limit the maximal velocities

 Register Blogs Members List Search Today's Posts Mark Forums Read

 October 21, 2015, 14:46 How to limit the maximal velocities #1 New Member   Matej Muller Join Date: Oct 2011 Location: Slovenia Posts: 22 Rep Power: 7 Hello! I'm having some trouble with limiting the maximal velocities inside the whole domain. I've tried with a loop, something like in this thread http://www.cfd-online.com/Forums/ope...terfoam-2.html When i try Code: ``` forAll(U,celli) { if (U[celli].component(vector::X) > 1){ U[celli].component(vector::X) = 1;} if (U[celli].component(vector::Y) > 1){ U[celli].component(vector::Y) = 1;} if (U[celli].component(vector::Z) > 1){ U[celli].component(vector::Z) = 1;} }``` and call it right after the Ueqn.h, it compiles without errors, but the velocities from the results are still greater than 1. I'm pretty new to openfoam code...I've read that one should do this without a loop... has anyone any idea how to do that? Thanks in advance! Matej

 October 21, 2015, 23:13 #2 Senior Member     Kyle Mooney Join Date: Jul 2009 Location: Amherst, MA USA - San Diego, CA USA Posts: 320 Rep Power: 10 You probably want to double check that you're performing the limit after the last time U is updated. With piso this is often at the very end of the timestep loop. See line #128: https://github.com/OpenFOAM/OpenFOAM...oam/pisoFoam.C

 October 23, 2015, 20:32 #3 New Member   Matej Muller Join Date: Oct 2011 Location: Slovenia Posts: 22 Rep Power: 7 Hi! Thank you for your answer. That was actually the problem... However, I also want to bound the max k and epsilon values when using a k-epsilon model and k and omega values when using a k-omega model. But when I use Code: `forAll(k, celli)` in interfoam.c, at compiling I get the message: Code: `error: ‘k’ was not declared in this scope` Do I have to compile a new turbulence model? Perhaps there is a simpler way to do this? I would imagine openfoam has this already implemented but where can i define the max values? Regards, Matej

October 23, 2015, 20:35
#4
Senior Member

Kyle Mooney
Join Date: Jul 2009
Location: Amherst, MA USA - San Diego, CA USA
Posts: 320
Rep Power: 10
Quote:
 Originally Posted by matejmuller Hi! Thank you for your answer. That was actually the problem... However, I also want to bound the max k and epsilon values when using a k-epsilon model and k and omega values when using a k-omega model. But when I use Code: `forAll(k, celli)` in interfoam.c, at compiling I get the message: Code: `error: ‘k’ was not declared in this scope` Do I have to compile a new turbulence model? Perhaps there is a simpler way to do this? I would imagine openfoam has this already implemented but where can i define the max values? Regards, Matej

Hi Matej,

You just need to lookup the field of interest before trying to operate on it at the top level of the solver.

This should explain how:
https://openfoamwiki.net/index.php/Contrib/IOReferencer

Cheers!
Kyle

 October 24, 2015, 10:03 #5 New Member   Matej Muller Join Date: Oct 2011 Location: Slovenia Posts: 22 Rep Power: 7 Hi Kyle! So I've looked in the code kEpsilon.H, and k nad epsilon are IObjects. But when compiling with: Code: `const volScalarField& k = db().lookupObject("k");` I get: Code: `error: ‘db’ was not declared in this scope` What does " // The "db()" above may vary" in your provided link mean? Thanks in advance! Matej

 October 24, 2015, 15:04 #6 Senior Member     Kyle Mooney Join Date: Jul 2009 Location: Amherst, MA USA - San Diego, CA USA Posts: 320 Rep Power: 10 Instead of Code: `db()` try: Code: `mesh` Which should work in the top level solver (for most solvers).

 October 26, 2015, 18:22 #7 New Member   Matej Muller Join Date: Oct 2011 Location: Slovenia Posts: 22 Rep Power: 7 Hi! Thanks for the response. The mesh part did the trick. However, I couldn't access the k and epsilon values, because they are somehow write-protected. I have found it easier to compile a new turbulence model according to http://www.tfd.chalmers.se/~hani/kur...lenceModel.pdf and manipulated the k and epsilon values in it. Regards, Matej

 July 25, 2016, 14:20 #8 New Member   Vitor Geraldes Join Date: Dec 2009 Location: Lisbon, Portugal Posts: 19 Rep Power: 9 I managed to ensure that the velocity can not increase beyond a given threshold value by introducing an artificial hydrodynamic resistance that increases polynomially as the velocity magnitude approaches that limit. The code is this one forAll(Rdamp,cellI) { Rdamp[cellI] = Rref.value()*Foam:ow((mag(U[cellI])/maxVelocity.value()),10); } Rdamp.correctBoundaryConditions(); Rdamp.relax(); fvVectorMatrix UEqn ( fvm::ddt(rho, U) + fvm::div(rhoPhi, U) - fvm::laplacian(mu, U) - fvc::div(mu*fvc::grad(U)().T()) + fvm::Sp(Rdamp, U) ); In my case, the units of Rdamp are [1 -3 -1 0 0 0 0]. With this technique, the pressure correction equation remains conservative. I imposed an high power of 10 to ensure that the dampening resistance is negligible when the velocity is slightly lower than the threshold value. Underelaxation of Rdamp on the order of 0.5 - 0.8 appears to have good effects on the numerical stability of the algorithm. I would be glad to know if this numerical trick works for other cases too.

 Tags celli, limit, loop, max velocity

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post kus CFX 9 April 21, 2013 01:54 torsy87 OpenFOAM Paraview & paraFoam 1 April 14, 2013 08:09 Far Site Help, Feedback & Discussions 0 January 13, 2013 11:45 alpha754293 CFX 1 November 28, 2012 09:28 xl2000 Main CFD Forum 0 April 27, 2012 11:50

All times are GMT -4. The time now is 15:05.