CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

momentum source problem

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 7, 2021, 13:30
Post momentum source problem
  #1
New Member
 
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 5
sSoLeNeSs is on a distinguished road
hello, everyone.

I want to simulate a 2-d rectangular container that moves in the x-direction 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 x-direction 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;
}
sSoLeNeSs is offline   Reply With Quote

Old   April 7, 2021, 18:42
Default
  #2
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
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
Yasser is offline   Reply With Quote

Old   April 7, 2021, 18:44
Default
  #3
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
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)
Yasser is offline   Reply With Quote

Old   April 7, 2021, 18:47
Default
  #4
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
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
Yasser is offline   Reply With Quote

Old   April 7, 2021, 18:49
Default
  #5
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
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.
Yasser is offline   Reply With Quote

Old   April 8, 2021, 03:52
Default
  #6
New Member
 
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 5
sSoLeNeSs is on a distinguished road
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?
sSoLeNeSs is offline   Reply With Quote

Old   April 8, 2021, 08:36
Default
  #7
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
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.
Yasser is offline   Reply With Quote

Old   April 8, 2021, 09:24
Default
  #8
New Member
 
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 5
sSoLeNeSs is on a distinguished road
I know, but the problem is still the divergence of the solution, regardless of the way to acquire the value of forces.
sSoLeNeSs is offline   Reply With Quote

Old   April 8, 2021, 09:31
Default
  #9
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
Instead of adding the force one time to the fluid body, you are adding this thousands of times through every cell
Yasser is offline   Reply With Quote

Old   April 8, 2021, 12:15
Default
  #10
New Member
 
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 5
sSoLeNeSs is on a distinguished road
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?
sSoLeNeSs is offline   Reply With Quote

Old   April 8, 2021, 19:54
Default
  #11
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
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 ...
Yasser is offline   Reply With Quote

Old   April 9, 2021, 03:30
Default
  #12
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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".
pakk is offline   Reply With Quote

Old   April 9, 2021, 04:19
Default
  #13
New Member
 
Amirhossein Vahidibejestani
Join Date: Apr 2021
Posts: 5
Rep Power: 5
sSoLeNeSs is on a distinguished road
Ok, I see what you mean now.
Thank you for your suggestions.
I will definitely try them out.
sSoLeNeSs is offline   Reply With Quote

Reply

Tags
momentum sources, udf


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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 22:13.