sailfish-team / sailfish

Lattice Boltzmann (LBM) simulation package for GPUs (CUDA, OpenCL)
http://sailfish.us.edu.pl
230 stars 85 forks source link

Generalized SC model for binary fluid simulations #26

Closed nlooije closed 10 years ago

nlooije commented 10 years ago

I have modified to code to allow setting interaction strengths between any combination of components. The SC drop example case is converted to a binary fluid case and used to test self-interaction for the model. The other binary_fluid example cases are updated to work with the new interaction strength symbols.

lb_binary.py:

  1. added force couplings between all components
  2. added arguments for interaction strengths G11, G12 and G22
  3. setting interaction strength G12 sets G21=G12 by default

shan_chen.mako:

  1. initialized 'sca0' before function call to shan_chen_force() instead of as 'force' in shan_chen_force()
  2. shan_chen_force() is now called for every interaction in the 'force_couplings' dictionary between component 'grid_idx' and component 'dists[1]' unless the 'coupling_const' is equal to 0.0. The results are added to sca0. For example, setting G11 and G12 results in the code:

// for grid_idx = 0: float sca0[2]={}: if (isWetNode(type)) {
shan_chen_force(gi, g0m0, gg0m0, G11, sca0, gx, gy); shan_chen_force(gi, g0m0, gg1m0, G12, sca0, gx, gy); // Convert momentum and force into velocity and acceleration. sca0[0] /= g1m0; sca0[1] /= g1m0; }

// for grid_idx = 1: float sca0[2]={}: if (isWetNode(type)) {
shan_chen_force(gi, g1m0, gg0m0, G21, sca0, gx, gy); // Convert momentum and force into velocity and acceleration. sca0[0] /= g1m0; sca0[1] /= g1m0; }

nlooije commented 10 years ago
  1. It would be best if I could test the code using an example code. The problem is i do not know of any validation case which requires both G11 and G12 to be set. Do you have any idea?
  2. Please correct me on any part of the code which isn't up to par with the syntax or is poor programming. I can only learn from it!
mjanusz commented 10 years ago

Could you please also update subdomains/binary_pbc.py to use G12 instead of G?

mjanusz commented 10 years ago

Completely agreed re test case. Unfortunately, I don't know of any such case either. When you decided to work on this generalization of the SC implementation, did you have some specific use cases in mind? If so, perhaps having some code related to these could be helpful...

nlooije commented 10 years ago

The case i had in mind when implementing was a two component system with G11 set instead of G12, i.e. have one ideal gas and a liquid-vapor component. The original code was only for setting G12, thats why i decided to modify it. As far as i know there is no physical system that requires setting both G11 and G12/G21.

mjanusz commented 10 years ago

If you set G11, but not G12, wouldn't you end up with two components that would not interact with themselves at all? I.e. wouldn't that be the same as running two simulations simultaneously, one for each component: 1) single-phase Shan-Chen (G11), 2) standard single component fluid flow?

nlooije commented 10 years ago

From the perspective of the Shan-Chen force implementation there would be no interaction between component 1 and 2 due to G12=G21=0 (i.e. ideal interactions). However, the equilibrium velocities are still based on a common mixture velocity: v = ( sum_c rho_c*v_c/tau_c ) / (sum_c rho_c/tau_c) regardless if they are being shifted by a force or not. So technically they do interact, just not through the force term.

mjanusz commented 10 years ago

Makes sense, thanks for explaining that. I forgot about the mixture velocity when I wrote my comment..

mjanusz commented 10 years ago

I merged your code into the master branch (after collapsing several G12 update commits to one). Thanks Niels!