kr = np.array(list(map(lambda t: rs_Kr[int(t) - 1],
                           type)))  # convert from 'per type' to 'per segment'
    kz = np.array(list(map(lambda t: rs_Kz[int(t) - 1], type)))
    #
    # 3. Root System fluxes
    #
    t3 = timer.time()
    # print("3 . Xylem fluxes")
    # age dependency
    #kr = kr * (10*time_ + 1)
    #kz = kz / (10*time_ + 1)
    soil_p2 = lambda x, y, z: soil_p(x, y, z, inf.psi, soil[-1].lowerDepth
                                     )  # J/kg

    if dirichlet == False:  # Neumann
        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]), pot_trans, seg,
                                     nodes)
        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]))
Example #2
0
    seg[c, 0] = i - 1
    seg[c, 1] = i
    c += 1
    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*")