slowing down of code and if-then-else statement

Submitted by sohaibmalik on Fri, 02/04/2022 - 00:34

Hi there,
I am trying to implement a drag force on particles flowing through a hopper with a upper cylindrical section and lower conical section. The drag force is to be calculated based on "void fraction" around each particle, then scaling of superficial velocity of the gas by the void fraction, and then getting value of Reynolds number, coefficient of drag, inputing into formula for drag. Snippet of the code is given below. I am facing some issues.

1. The code easily gives the void fraction with VORONOI/atom command. However when I reach to (line 8) and only perform mathematical operation of scaling the fluid superficial fluid velocity by void, the code slows down and taking ages to proceed. I am not able to get the reason of slowing down because of only one mathematical operation.

2. In implementation of (if-then-else) statement at (line 17) (attached is a picture of equation at line 17). code is giving errors although I am following syntax of the statement given in the documentation.

3. In implementation f equation at (line 18) (another picture is attached for equation at line 18).

I would appreciate your help in solving the issues.

Thanks,
Sohaib

#================= Finding Void Fraction ===================#
1. compute VoroRadius all property/atom radius
2. variable r2 atom c_VoroRadius
3. compute voro all voronoi/atom radius v_r2
4. variable volume atom 4/3*3.1415*v_r2^3
#==calculate voronoi volume for all atoms
5. variable voro1 atom c_voro[1]
6. variable void1 atom (v_voro1-v_volume)/v_voro1

#==specifying superficial velocity===#
7. variable Uinf equal -1.03
8. variable U atom v_Uinf/v_void1

9. variable Rho equal 1.65
10. variable Mu equal 3.86e-5
11. variable Diameter equal 0.06
12. variable Across equal 1.0/4.0*v_Diameter^2*3.1415
13. variable Vrx atom -vx
14. variable Vry atom -vy
15. variable Vrz atom v_U-vz

16. variable Re atom abs(v_Vrz)*v_Rho*v_Diameter/v_Mu #variable Re atom v_Vr*v_Rho*v_Diameter/v_Mu

#==implementing a piecewise function equation using if - then - else command==#
17. if "${v_Re} > 1000" then "variable Cd atom 0.44" else "variable Cd atom 24*(1+(0.15*(v_Re^0.687)))/v_Re"

#==implementing beta equation ===#
18. variable beta atom v_void1^(-1*(3.7-0.65*(exp((-1*(1.5-log(v_Re))^2)/2))))

#variable Dragx atom 0.5*v_Rho*v_Vr*v_Cd*v_Across*v_Vrx
#variable Dragy atom 0.5*v_Rho*v_Vr*v_Cd*v_Across*v_Vry

#==calculating drag==#
19. variable Dragz atom 0.5*v_Rho*abs(v_Vrz)*v_Cd*v_Across*v_Vrz*v_beta

##==applying drag force to all atoms===#
20. fix adddrag1 all addforce 0 0 v_Dragz

AttachmentSize
Image icon equation_line_17.png50.87 KB
Image icon equation_line_18.png17.58 KB
Image icon fixviscousmodify.png190.19 KB

mschramm | Fri, 02/04/2022 - 06:52

Hello,
I would recommend moving this from a script to a fix.
I would look at fix_viscous as a starting point and create a fix_custom_dram that implements your script but in compiled code.

Liggghts is slow here because it has to parse each line in your loop each time it interacts with it.

sohaibmalik | Fri, 02/18/2022 - 20:40

Thank you, Matt, for your helpful reply.
So, I tried to modify the already there fix_viscous.cpp, first. I was able to read the "atom" class variables like "velocity, radius, force, etc." to code for "Drag force" (picture attached). then I ran "Make Auto" and it worked.
Now, I wanted to include "variable porosity" in the script by calculating "vorovolume" using compute and the variable "c_voro[1]" for voronoi volume. This fix_viscous is not able to access that as a "per-atom" property since its not defined in the base "atom" class. Could you help me find a way to be able to read the per atom "voronoi volume" in the fix in that way I could get important parameters like "actual vecloity, Reynolds number, voidage coefficient and drag force that are dependent on local void/porosity values". I would appreciate your guidance.
Thanks,
Sohaib

mschramm | Mon, 02/21/2022 - 17:21

Hello,
You are looking for the (not as widely used) find compute command.
You can see how the find compute command is used in the following compute
https://github.com/CFDEMproject/LIGGGHTS-PUBLIC/blob/master/src/compute_...

If you need fixes, there are many examples for this....
grep modify..find_fix *.cpp
and
grep modify..add_fix *.cpp