def preprocess_Dr(data, r, normalize=True): x = data["x"] #[xx[0] for xx in data["x"]] data, x = fields._sorted(data, x) Dt = [d[2][2] for d in data["D"]] Dn = [d[0][0] for d in data["D"]] eps = 1e-2 x = [-1., -eps, r] + x + [1000.] if normalize: Dn = [d / Dn[-1] for d in Dn] Dt = [d / Dt[-1] for d in Dt] Dn = [0., 0., eps] + Dn + [1.] Dt = [0., 0., eps] + Dt + [1.] fn = interp1d(x, Dn) ft = interp1d(x, Dt) return fn, ft
return list(B) def smootha(l): A = np.array(l) B = A[:] ker = np.array([10., 12., 15., 12., 10.]) ker = ker / np.sum(ker) n = int(ker.shape[0] / 2.) for i in range(n, A.shape[0] - n): B[i] = np.inner(A[i - n:i + n + 1], ker) return list(B) x = [z[0] for z in data["x"]] data, x = fields._sorted(data, x) eps = 5e-3 x_ = x[:] #x_.extend([1.,1.+eps,1.+2*eps,1.+3*eps]) x.extend([(x[-1] + 1.) / 2., 1., 1. + eps, 1. + 2 * eps, 1. + 3 * eps, 1. + 4 * eps, 1. + 5 * eps]) dstr = ["x", "y", "z"] Dxx = [D[0][0] for D in data["D"]] Dyy = [D[1][1] for D in data["D"]] Dzz = [D[2][2] for D in data["D"]] Dxx_ = [D[0][0] for D in data["D"]] Dyy_ = [D[1][1] for D in data["D"]] Dzz_ = [D[2][2] for D in data["D"]] Dxx.extend([0., 0., 0., 0., 0., 0., 0.]) Dyy.extend([Dyy[-1] / 2., 0., 0., 0., 0., 0., 0.]) Dzz.extend([Dzz[-1] / 2., 0., 0., 0., 0., 0., 0.])
def diffusivity_field(setup, r, ddata_r=None, ddata_z=None, boundary="dnab", poreregion="poreregion"): "interpolates diffusivity field defined on the geometry given by setup" "needs: molecule radius r, radial and vertical D profiles ddata_r, ddata_z" "the geometry needs to have subdomains poreregion and bulkfluid" if ddata_r is None: ddata_r = diff_profile_plane(r) if ddata_z is None: return diffusivity_field_simple(setup, r, ddata_r, boundary=boundary) # build 1D interpolations from data data = ddata_z z = [x[2] for x in data["x"]] data, z = fields._sorted(data, z) Dz = data["D"] fz = interp1d(z, Dz) fn, ft = preprocess_Dr(ddata_r, r) setup.prerefine(visualize=True) dist = distance_boundary_from_geo(setup.geo, boundary) VV = dolfin.VectorFunctionSpace(setup.geo.mesh, "CG", 1) normal = dolfin.project(dolfin.grad(dist), VV) phys = setup.phys D0 = phys.kT / (6. * np.pi * phys.eta * r * 1e-9) def DPore(x, i): r = dist(x) z = x[-1] Dz = float(fz(z)) n = normal(x) Dn = D0 * float(fn(r)) Dt = D0 * float(ft(r)) D = transformation(n, Dz * Dn, Dz * Dt) return D[i][i] def DBulk(x, i): r = dist(x) n = normal(x) Dn = D0 * float(fn(r)) Dt = D0 * float(ft(r)) D = transformation(n, Dn, Dt) return D[i][i] D = lambda i: { "bulkfluid": lambda x: DBulk(x, i), poreregion: lambda x: DPore(x, i) } dim = setup.geop.dim DD = [harmonic_interpolation(setup, subdomains=D(i)) for i in range(dim)] D = dolfin.Function(VV) dolfin.assign(D, DD) return dict(dist=dist, D=D)
import numpy as np import nanopores.tools.fields as fields import os import nanopores DATADIR = os.path.join(nanopores.HOME, "Dropbox", "nanopores", "fields") FIGDIR = os.path.join(nanopores.HOME, "Dropbox", "nanopores", "figures") FIGDIR = os.path.join(nanopores.HOME, "papers", "pnps-numerics", "figures") fields.set_dir(DATADIR) fields.update() #data = fields.get_fields("howorka_velo1", Nmax=1e4) data = fields.get_fields("howorka_velo3D_2") #z = [x[2] for x in data["x"]] z = [x[0] for x in data["x"]] data, z = fields._sorted(data, z) ## modify i = 0 rad = lambda x: sum(t**2 for t in x) #rad = lambda x: x[2] #v0 = [rad(x) for x in data["v0"]] #v1 = [rad(x) for x in data["v1"]] z.pop(-1) data["v0"].pop(-1) data["v1"].pop(-1) plt.plot(z, [x[0] for x in data["v0"]], "o-", color="#000099", label=r"$v_r$ (exact)")