Exemple #1
0
def diffusivity_field_simple(setup, r, ddata_bulk, boundary="poresolidb"):
    "interpolates diffusivity field defined on the geometry given by setup"

    # build 1D interpolations from data
    fn, ft = preprocess_Dr(ddata_bulk, 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 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: dict(fluid=lambda x: DBulk(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)
Exemple #2
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)
Exemple #3
0
# create random points
N = user_params(N=1000).N
R, H = domain.params["R"], domain.params["H"]
px = 2*R*np.random.random(N) - R
py = 2*R*np.random.random(N) - R
pz = H*np.random.random(N) - H/2.
points = zip(px, py, pz)

# prepare mesh containing points
domain.write_gmsh_code(h)
domain.insert_points(points, h, forbidden=["dna", "membrane"])
geo = domain.code_to_mesh()
mesh = geo.mesh

with Log("harmonic interpolation..."):
    # interpolate function from point values
    values = np.sin(np.array(points)[:,2]/5.)
    f = lambda x: np.sin(x[2]/5.)
    fexp = dolfin.Expression("sin(x[2]/5.)", domain=mesh, degree=1)

    u = harmonic_interpolation(geo, points, values,
                               dict(pore=f),
                               dict(upperb=fexp, lowerb=fexp))

with Log("plotting..."):
    dolfin.plot(mesh)
    dolfin.plot(u)
    Plotter().plot(u)
dolfin.interactive()
    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: dict(
        bulkfluid=lambda x: DBulk(x, i),
        poreregion=lambda x: DPore(x, i),
    )

    # TODO: save geo along with functions
    DD = [
        harmonic_interpolation(setup, subdomains=D(i))
        for i in range(params.dim)
    ]
    D = dolfin.Function(VV)
    dolfin.assign(D, DD)

    f.save_functions("Dpugh", params, dist=dist, D=D)
    f.update()
    plt.show()


def get_D(params):
    functions, mesh = f.get_functions("Dpugh", **params)
    D = functions["D"]
    D = dolfin.as_matrix(np.diag([D[i] for i in range(params.dim)]))
    return D