Exemple #1
0
    nodes[i, :] = [0., 0., -i * L / (nnz - 1)]
    z_[i] = -i * L / (nnz - 1)

# from constant to per segment
kr_ = [kr] * 2 * (nnz - 1)
kz_ = [kz] * 2 * (nnz - 1)
a_ = [a] * 2 * (nnz - 1)

# call back function for soil potential
soil = lambda x, y, z: p_s

# calculate fluxes within the root system
Q, b = xylem_flux.linear_system(seg, nodes, a_, kr_, kz_, rho, g, soil)  #

# Q, b = xylem_flux.bc_dirichlet(Q, b, np.array([0,nnz-1]), np.array([p0,pL]))
Q, b = xylem_flux.bc_dirichlet(Q, b, np.array([0]),
                               np.array([p0]))  # dirichlet top
Q, b = xylem_flux.bc_neumann(Q, b, [nnz - 1], [0])  # neumann tip
# plt.spy(Q)
# plt.show()

start = timeit.default_timer()
x = LA.spsolve(Q, b, use_umfpack=True)  # direct
stop = timeit.default_timer()
# print ("linear system solved in", stop - start, " s")

# plot results
plt.plot(list(map(toHead, x)), z_, "r*")
plt.plot(pr, za_)
plt.xlabel("Xylem pressure (cm)")
plt.ylabel("Depth (m)")
plt.show()
Exemple #2
0
        Q, b = xylem_flux.linear_system(seg, nodes, radius, kr, kz, rho, g,
                                        soil_p2)
        Q, b = xylem_flux.bc_neumann(Q, b, np.array([0]),
                                     np.array([pot_trans]))
        x = LA.spsolve(Q, b)  # direct
        eff_trans = xylem_flux.axial_flux0(
            x, seg, nodes, kz, rho, g)  # verify that eff_trans == pot_trans
        print(
            "using neumann ( Effective Transpiration = " + str(eff_trans) +
            " m^3 s^-1)", "top potential", x[0])

    if dirichlet or (x[0] < top_pot):
        Q, b = xylem_flux.linear_system(seg, nodes, radius, kr, kz, rho, g,
                                        soil_p2)
        dirichlet = True
        Q, b = xylem_flux.bc_dirichlet(Q, b, np.array([0]),
                                       np.array([top_pot]))
        x = LA.spsolve(Q, b)  # direct
        eff_trans = xylem_flux.axial_flux0(x, seg, nodes, kz, rho, g)
        dirichlet = eff_trans < pot_trans
        print("using dirichlet ( Effective Transpiration = " + str(eff_trans) +
              " m^3 s^-1)")

    radial_flux = xylem_flux.radial_flux(
        x, seg, nodes, radius, kr, soil_p2)  # used to calculate the sink term

    #
    # 4. Sink term
    #
    t4 = timer.time()
    sink = np.zeros(inf.n)
Exemple #3
0
#
# create linear system
#
Q, b = xylem_flux.linear_system(seg, nodes, radius, kr, kz, rho, g, soil_p)

#
# apply BC
#
n0 = np.array([0])  # node indices
seg0 = np.array([0])  # segment indices
potT = np.array([-5.79e-4])  # potential Transpiration
topP = np.array([-1500])  # top potential (J/kg)

# Q, b = xylem_flux.bc_neumann(Q, b, seg0, potT, seg, nodes) # Neumann
Q, b = xylem_flux.bc_dirichlet(Q, b, n0, topP)  # Dirichlet

#
# solve LS
#
t = time.time()
print("solve")
# x0 = d*np.ones(Q.shape[0]) # empirically proofen to be the best
# x, info = LA.cg(Q,b,x0=x0, tol=1e-12)  # tested with CG, CGS, GMRES, BICG. CG by far the best
x = LA.spsolve(Q, b)  # direct
print("fin")
# print("CG: " + str(time.time()-t) +" sec" )
print("spsolve: " + str(time.time() - t) + " sec")

#
# output