コード例 #1
0
    else:
        return tuple(functions)


def lambda_to_S1(f, mesh, dim=1):
    V = dolfin.FunctionSpace(mesh, "CG", 1)
    if dim > 1:
        V = dolfin.MixedFunctionSpace([V] * dim)
    f1 = dolfin.Function(V)
    value_shape = () if dim == 1 else (dim, )

    class expr(dolfin.Expression):
        def eval(self, value, x):
            value[:] = f(x)

        def value_shape(self):
            return value_shape

    f1.interpolate(expr())
    return f1


if __name__ == "__main__":
    from plot_forcefield import porestreamlines, plt
    F = forcefieldS1(implicit=False, **default)
    Fimp = forcefieldS1(implicit=True, **default)
    porestreamlines(Howorka.polygon(), 6., 8., F=F)  #, Fimp=Fimp)
    fig = plt.figure("F")
    fig.axes[1].set_ylabel("force [N]")
    nanopores.showplots()
コード例 #2
0
ファイル: MLSC.py プロジェクト: jhwnkim/nanopores
    legend(loc='best')

# --- create interpolation for different h and orders ---
orders = range(1, maxorder+1)
samples = []
interpolands = []

for order in orders:
    print "\n-- order = %s --" %order
    u, N = interpolate(h=h, order=order)
    samples.append(N)
    interpolands.append(u)

dolfin.plot(u, key="u", title="interpolated potential, order %s" %order)
ulast = interpolands.pop()
Nlast = samples.pop()

def err(uh):
    return errornorm(ulast, uh, "H1", degree_rise=0)/norm(ulast, "H1")

errors = [err(uh) for uh in interpolands]

label = "|Iluh - I%duh|/|I%duh|" %(maxorder, maxorder)
hplot(label, samples, errors, xlab="# samples M", ylab="relative interpolation error", hstr="M", fit=True)

list_timings()
#saveplots("mlsc", meta=PARAMS)
showplots()
interactive()

コード例 #3
0
ファイル: test_pugh.py プロジェクト: jhwnkim/nanopores
    #        v, cp, cm = pnps.functions["pnp"].split()
    #    else:
    #        v = pnps.functions["poisson"]
    nano.plot_cross(v, mesh2D, title="potential", key="u")
    nano.plot_cross(cm, mesh2D, title="negative ions", key="cm")
    #dolfin.interactive()
    #u = pnps.functions["stokes"].sub(0)
    #nano.plot_cross_vector(u, mesh2D, title="u", key="uu")
    print "v0 =", v([0., 0., -25.])

print "CPU time (solve): %.3g s" % (dolfin.toc(), )

print pnps.evaluate(phys.CurrentPNPS)
print pnps.evaluate(phys.ForcesPNPS)

# visualize
v, cp, cm, u, p = pnps.solutions()
#nano.plot_cross(v, mesh2D, title="potential")
nano.plot_cross(cm, mesh2D, title="cm")
nano.plot_cross(cp, mesh2D, title="cp")
nano.plot_cross(p, mesh2D, title="p")
nano.plot_cross_vector(u, mesh2D, title="u")

#if not solverp.cheapest:
#    pb.estimators["rep"].plot()
#    pb.estimators["err"].plot(rate=-2./3., fig=False)

#pnps.visualize("pore")
nano.showplots()
dolfin.interactive()