
[Sponsors] 
April 7, 2021, 12:30 
momentum source problem

#1 
New Member
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 4 
hello, everyone.
I want to simulate a 2d rectangular container that moves in the xdirection and is partially filled with liquid. Usually, the container's acceleration profile is known and it can easily be applied to the container via a DEFINE_SOURCE udf. However, I aim to apply a certain force to the container. Newton's second law of motion for this container can be written as follow: m (d^2x / dt^2) = F_L + F_T where m is the container's mass (excluding the liquid), F_T is the thrust force that is applied to the container and is known, and finally, F_L is the net liquid force applied to the container walls. The momentum source for this case is written as f_b = rho * (d^2x / dt^2) = rho * ( F_L + F_T ) / m This can be easily applied via a DEFINE_SOURCE UDF. But, one must keep in mind that F_L, or the net liquid force on the container wall, is itself a function of liquid pressure as written below: F_L = integral ( P(x=right wall, y, t) dy)  integral ( P(x = left wall, y, t) dy) Considering the equations above, one can write the momentum equation in the xdirection as du / dt + u * du / dx + v * du / dy =  1 / rho * grad(P) ... + g rho * {integral ( P(x=right wall, y, t) dy)...  integral ( P(x = left wall, y, t) dy) + F_T } / m This is where the problem arises. As you can see, the highlighted momentum source in the equation above consists of the integral of pressure in the container's boundary. I have managed to implement this via a DEFINE_ADJUST and DEFINE_SOURCE UDF, however the simulation diverges on its first time step. Does anyone know the problem? My UDFs: # include "udf.h" # define dy 0.002 # define m 1 # define count 1001 float xForce = 1; //The constant applied force// float netXForce = 0; //net wall force applied by the liquid// DEFINE_ADJUST(test, d) { int rightWallID = 6; int leftWallID = 5; float pressure; float sumRightWall = 0; float sumLeftWall = 0; float rightWallForce; float leftWallForce; float netForce; Thread *rightWall = Lookup_Thread(d, rightWallID); Thread *leftWall = Lookup_Thread(d, leftWallID); cell_t c; begin_c_loop(c, rightWall) { pressure = C_P(c, rightWall); sumRightWall += pressure; } end_c_loop(c, rightWall) begin_c_loop(c, leftWall) { pressure = C_P(c, leftWall); sumLeftWall += pressure; } end_c_loop(c, leftWall) rightWallForce = sumRightWall * dy; leftWallForce = sumLeftWall * dy; netXForce = rightWallForce  leftWallForce; printf("net wall force : %f\n", netXForce); } DEFINE_SOURCE(xMomentum, c, t, dS, eqn) { real source, density; density = C_R(c, t); source = density * (xForce + netXForce) / m; dS[eqn] = 0; return source; } 

April 7, 2021, 17:42 

#2 
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 18 
First, the integration you are doing is not right ... every value of the pressure should be multiplied by the area ... at the end of the loop, you need to use PRF_GRSUM1(sum) to account for the parallel work.
There is an example in the manual that calculate the pressure force on a wall .. you can find it under DEFINE_CG_MOTION ... you need to follow the same procedure 

April 7, 2021, 17:44 

#3 
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 18 
Second, I am surprised this code worked for you ... Left and Right walls according to my understanding are walls .. so, you should loop on faces, not cells .. and use F_P(f,t) instead of C_P(c,t)


April 7, 2021, 17:47 

#4 
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 18 
Third, when Fluent calculate the forces, it comes with the sign .. So, you don't need to subtract forces on left and right walls, just add them


April 7, 2021, 17:49 

#5 
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 18 
Fourth, I think you can model this in an easier way as a SDOF body ... Writing one UDF that will include only transnational motion and external force.


April 8, 2021, 02:52 

#6 
New Member
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 4 
Thank you Yasser for taking your time and looking at my problem.
However, the value of the force is not the problem, since I checked the value with the value that is given by the fluent in report force section. But your solution to finding forces is more reasonable and I try to implement it. My problem is that apparently by using a changing value at every iteration, specifically netXForce (wall force), in DEFINE_SOURCE UDF, causes instability in the solution which results in divergence at the first time step. Do you a way to feedback the wall forces into the equations without it bricking? 

April 8, 2021, 07:36 

#7 
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 18 
By using DEFINE_SOURCE , you add the force to every single cell. This is regardless of the cell being an internal cell or being adjacent to the wall.


April 8, 2021, 08:24 

#8 
New Member
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 4 
I know, but the problem is still the divergence of the solution, regardless of the way to acquire the value of forces.


April 8, 2021, 08:31 

#9 
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 18 
Instead of adding the force one time to the fluid body, you are adding this thousands of times through every cell


April 8, 2021, 11:15 

#10 
New Member
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 4 
Well that's how it should be, isn't it?
If not, can you elaborate a bit more on how to apply the external force and take into account the liquid force on the container's wall simultaneously? 

April 8, 2021, 18:54 

#11 
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 18 
I do not clearly understand what you want to get out of simulation as based on this, I might be able to recommend a procedure.
As I mentioned earlier, if you want to simulate the motion of the tank "as CG_Motion, the force should be calculated from as the sum of P*dA on all the faces ... this force is applied on the tank. The force applied on the fluid by the tank, is already included in the momentum equation for the boundary cells. You do not need to do anything here. Any other external force applied on the tank, should be included in your CG_MOTION function to solve for the tank velocity. Also You can use SDOF which will make your function much easier. If you have a predefined external acceleration applied, and You want to simulate the free surface due to this acceleration, you just need to add this as an expression in the gravity ... 

April 9, 2021, 02:30 

#12 
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 25 
You write down Newton's second law for the container, but then apply it on the liquid... I think you make a mistake there. Follow Yasser's advice.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". 

April 9, 2021, 03:19 

#13 
New Member
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 4 
Ok, I see what you mean now.
Thank you for your suggestions. I will definitely try them out. 

Tags 
momentum sources, udf 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
SU27.0.1 on ubuntu 18.04  hyunko  SU2 Installation  7  March 16, 2020 04:37 
[Other] Adding solvers from DensityBasedTurbo to foamextend 3.0  Seroga  OpenFOAM Community Contributions  9  June 12, 2015 17:18 
Problem compiling a custom Lagrangian library  brbbhatti  OpenFOAM Programming & Development  2  July 7, 2014 11:32 
centOS 5.6 : paraFoam not working  yossi  OpenFOAM Installation  2  October 9, 2013 01:41 
[swak4Foam] swak4FoamgroovyBC build problem  zxj160  OpenFOAM Community Contributions  18  July 30, 2013 13:14 