Skip to content

Commit

Permalink
Clean up of the 3-component Shan-Chen code.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlooije authored and mjanusz committed Mar 16, 2014
1 parent 41cbc41 commit b8b28f7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.pyc
*.*~
*~
11 changes: 4 additions & 7 deletions examples/ternary_fluid/sc_drop_2d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

"""Stationary droplet in ternary system with multiple self-interactions"""

import numpy as np
import matplotlib.pyplot as plt

Expand All @@ -13,8 +15,8 @@ def boundary_conditions(self, hx, hy):
pass

def initial_conditions(self, sim, hx, hy):

radius = 32

drop_map1 = (hx-self.gx/4)**2 + (hy-self.gy/4)**2 <= radius**2
drop_map2 = (hx-3*self.gx/4)**2 + (hy-3*self.gy/4)**2 <= radius**2

Expand All @@ -30,9 +32,6 @@ def initial_conditions(self, sim, hx, hy):
sim.phi[drop_map2] = 0.02
sim.theta[drop_map2] = 2.0

ny, nx = sim.rho.shape
hy, hx = np.mgrid[0:ny, 0:nx]

class SCSim(LBTernaryFluidShanChen):
subdomain = DropSubdomain

Expand All @@ -50,12 +49,10 @@ def update_defaults(cls, defaults):
})

def after_step(self, runner):

every_n = 10000

if self.iteration % every_n == every_n - 1:
self.need_sync_flag = True

elif self.iteration % every_n == 0:
rho = runner._sim.rho.astype(np.float64)
phi = runner._sim.phi.astype(np.float64)
Expand Down
2 changes: 1 addition & 1 deletion sailfish/lb_ternary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Classes for binary fluid lattice Boltzmann simulations."""
"""Classes for ternary fluid lattice Boltzmann simulations."""

__author__ = 'Michal Januszewski'
__email__ = '[email protected]'
Expand Down
5 changes: 0 additions & 5 deletions sailfish/sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,6 @@ def _prepare_symbols():
setattr(S, name, t)
S.relaxation_times.append(t)


# Commonly used aliases.
S.alias('vx', S.g0m1x)
S.alias('vy', S.g0m1y)
Expand All @@ -1059,10 +1058,6 @@ def _prepare_symbols():
S.alias('phi', S.g1m0)
S.alias('theta', S.g2m0)

S.alias('eax', S.g0eax)
S.alias('eay', S.g0eay)
S.alias('eaz', S.g0eaz)

# For incompressible models, this symbol is replaced with the average
# density, usually 1.0. For compressible models, it is the same as
# the density rho.
Expand Down
8 changes: 4 additions & 4 deletions sailfish/sym_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ def _use_pointers(str):

def _use_vectors(str):
ret = str.replace('vx', 'v0[0]').replace('vy', 'v0[1]').replace('vz', 'v0[2]')
for dist in range(1,9):
s1 = 'g%sea' % dist; s2 = 'ea%s' % dist
ret = ret.replace(s1+'x', s2+'[0]').replace(s1+'y', s2+'[1]').replace(s1+'z', s2+'[2]')
ret = ret.replace('eax', 'ea0[0]').replace('eay', 'ea0[1]').replace('eaz', 'ea0[2]')
for dist in range(0,9):
ret = ret.replace('g%seax' % dist, 'ea%s[0]' % dist)
ret = ret.replace('g%seay' % dist, 'ea%s[1]' % dist)
ret = ret.replace('g%seaz' % dist, 'ea%s[2]' % dist)

for dist in range(0, 9):
ret = ret.replace('g%sd1m0x' % dist, 'grad%s[0]' % dist)
Expand Down
18 changes: 7 additions & 11 deletions sailfish/templates/ternary_fluid.mako
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
%endif
</%def>

%if simtype == 'shan-chen':
## In the free-energy model, the relaxation time is a local quantity.
${const_var} float tau0 = ${tau}f; // relaxation time
${const_var} float tau0_inv = 1.0f / ${tau}f;
// Relaxation time for the 2nd fluid component.
%else:
// Relaxation time for the order parameter field.
%endif
// TODO(nlooije): incorporate multiple species for FE model

// Relaxation time for the 1st fluid component.
${const_var} float tau0 = ${tau}f; // relaxation time
${const_var} float tau0_inv = 1.0f / ${tau}f;

// Relaxation time for the 2nd fluid component.
${const_var} float tau1 = ${tau_phi}f;
${const_var} float tau1_inv = 1.0f / ${tau_phi}f;

Expand All @@ -43,7 +42,6 @@ ${const_var} float tau2_inv = 1.0f / ${tau_theta}f;
<%namespace file="utils.mako" import="*"/>

<%def name="init_dist_with_eq()">
%for eq, dist_name in zip([f(g, config) for f, g in zip(equilibria, grids)], ['dist1_in', 'dist2_in', 'dist3_in']):
%for local_var in eq.local_vars:
float ${cex(local_var.lhs)} = ${cex(local_var.rhs)};
Expand Down Expand Up @@ -103,8 +101,6 @@ ${kernel} void SetInitialConditions(
${init_dist_with_eq()}
}

%if simtype == 'shan-chen':
<%include file="ternary_shan_chen.mako"/>
%endif ## shan-chen

<%include file="util_kernels.mako"/>

0 comments on commit b8b28f7

Please sign in to comment.