Exemplo n.º 1
0
 def setUp(self):
     I_vl, I_vw = symbols("I_vl I_vw")
     vl, vw = symbols("vl vw")
     k_vl, k_vw = symbols("k_vl k_vw")
     self.provided_values=frozenset(
         [
             InFluxesBySymbol({vl: I_vl, vw: I_vw}),
             OutFluxesBySymbol({vl: k_vl * vl, vw: k_vw * vw}),
             InternalFluxesBySymbol({(vl, vw): k_vl * vl, (vw, vl): k_vw * vw}),
             TimeSymbol("t"),
             StateVariableTuple((vl, vw))
         ]
     )
     self.mvs=MVarSet(self.provided_values)
Exemplo n.º 2
0
])

roots_in_fluxes = {E: GPP}

roots_out_fluxes = {
    E: MR + GR,
    B_R: S_R * B_R,
}

roots_internal_fluxes = {
    (E, B_R): f_R * C_gR / (C_gR + delta_R) * eta_R * E,
    (E, C_R): f_R * delta_R / (C_gR + delta_R) * E,
    (C_R, E): S_R * C_R,
}

roots = (roots_sv_set, roots_in_fluxes, roots_out_fluxes,
         roots_internal_fluxes)

srm = SmoothReservoirModel.from_state_variable_indexed_fluxes(
    Matrix([E, B_R, C_R]), t, roots_in_fluxes, roots_out_fluxes,
    roots_internal_fluxes)

mvs = CMTVS(
    {
        InFluxesBySymbol(roots[1]),
        OutFluxesBySymbol(roots[2]),
        InternalFluxesBySymbol(roots[3]),
        TimeSymbol("t"),
        StateVariableTuple((E, B_R, C_R))
    }, bgc_md2_computers())
Exemplo n.º 3
0
from sympy import var, Symbol
from ComputabilityGraphs.CMTVS import CMTVS
from bgc_md2.helper import bgc_md2_computers
from .source_Luo import mvs

from bgc_md2.resolve.mvars import (OutFluxesBySymbol, InternalFluxesBySymbol)
mvs = CMTVS(
    {
        mvs.get_InFluxesBySymbol(),
        mvs.get_TimeSymbol(),
        mvs.get_StateVariableTuple(),
        OutFluxesBySymbol({
            dp: Symbol("k_" + str(dp) + "_to_out") * dp
            for dp in mvs.get_OutFluxesBySymbol().keys()
        }),
        InternalFluxesBySymbol(
            {(dp, rp): Symbol("k_" + str(dp) + "_to_" + str(rp)) * dp
             for dp, rp in mvs.get_InternalFluxesBySymbol().keys()})
    }, bgc_md2_computers())
Exemplo n.º 4
0
     C_nom,
     C_dom,
     C_psom,
 )),
 InFluxesBySymbol({
     #vl: I_vl, vw: I_vw
     C_leaf: NPP(t) * beta_leaf,
     C_root: NPP(t) * beta_root,
     C_wood: NPP(t) * beta_wood
 }),
 OutFluxesBySymbol({
     #vl: k_vl_o * vl, vw: k_vw_o * vw
     C_aom1: r_C_aom1_rh * C_aom1 * xi(t),
     C_aom2: r_C_aom2_rh * C_aom2 * xi(t),
     C_smb1: r_C_smb1_rh * C_smb1 * xi(t),
     C_smb2: r_C_smb2_rh * C_smb2 * xi(t),
     C_smr: r_C_smr_rh * C_smr * xi(t),
     C_nom: r_C_nom_rh * C_nom * xi(t),
     C_dom: r_C_dom_rh * C_dom * xi(t),
     C_psom: r_C_psom_rh * C_psom * xi(t),
 }),
 InternalFluxesBySymbol({
     #(vl, vw): k_vl_2_vw * vl, (vw, vl): k_vw_2_vl * vw
     (C_leaf, C_aom1):
     r_C_leaf_2_C_aom1 * C_leaf,
     (C_leaf, C_aom2):
     r_C_leaf_2_C_aom2 * C_leaf,
     (C_wood, C_aom1):
     r_C_wood_2_C_aom1 * C_wood,
     (C_wood, C_aom2):
     r_C_wood_2_C_aom2 * C_wood,
Exemplo n.º 5
0
vl, vw = symbols("vl vw")
k_vl, k_vw = symbols("k_vl k_vw")

# the keys of the internal flux dictionary are tuples (source_pool,target_pool)

# srm:SmoothReservoirModel
# srm=SmoothReservoirModel.from_state_variable_indexed_fluxes(
#     in_fluxes
#    ,out_fluxes
#    ,internal_fluxes
# )

#specialVars = {
mvs = MVarSet({
    InFluxesBySymbol({
        vl: I_vl,
        vw: I_vw
    }),
    OutFluxesBySymbol({
        vl: k_vl * vl,
        vw: k_vw * vw
    }),
    InternalFluxesBySymbol({
        (vl, vw): k_vl * vl,
        (vw, vl): k_vw * vw
    }),
    TimeSymbol("t"),
    StateVariableTuple((vl, vw))
    # ,'SmoothReservoirModel':srm
})
Exemplo n.º 6
0
func_dict={
    "I_vl": "Influx into vegetation leaf pool",
    "r_vl_o": "out flux rate of leaf pool",
}
for k in func_dict.keys():
    code=k+" = Function('{0}')".format(k)
    exec(code)

t=TimeSymbol("t")

mvs = CMTVS(
    {
        StateVariableTuple((vl, vw)),
        t,
        InFluxesBySymbol({vl: I_vl(t), vw: I_vw}),
        OutFluxesBySymbol({vl: r_vl_o(t) * vl, vw: r_vw_o * vw}),
        InternalFluxesBySymbol({(vl, vw): r_vl_2_vw * vl, (vw, vl): r_vw_2_vl * vw}),
    },

    computers=module_computers(bgc_c)
)
# -

# The last statement in the code defines a variable `mvs` which is 
# an instance of CMTVS which stands for `C`onnected`M`ulti`T`ype`V`ariable`S`et".
# It contains information in two forms. 
# 1. Variables of certain type (like InFluxesBySymbol)
# 2. a set of functions that "connect" these Variables and to other results we did not specify but which can be computed.
#
#
# Taks:
Exemplo n.º 7
0
     C_wood_litter,
     C_root_litter,
     C_soil_fast,
     C_soil_slow,
     C_soil_passive,
 )),
 InFluxesBySymbol({
     C_leaf: NPP(t) * beta_leaf,
     C_root: NPP(t) * beta_root,
     C_wood: NPP(t) * beta_wood
 }),
 OutFluxesBySymbol(
     {
         C_leaf_litter: r_C_leaf_litter_rh * C_leaf_litter * xi(t),
         C_wood_litter: r_C_wood_litter_rh * C_wood_litter * xi(t),
         C_root_litter: r_C_root_litter_rh * C_root_litter * xi(t),
         C_soil_fast: r_C_soil_fast_rh * C_soil_fast * xi(t),
         C_soil_slow: r_C_soil_slow_rh * C_soil_slow * xi(t),
         C_soil_passive: r_C_soil_passive_rh * C_soil_passive * xi(t),
     }),
 InternalFluxesBySymbol({
     (C_leaf, C_leaf_litter):
     r_C_leaf_2_C_leaf_litter * C_leaf,
     (C_wood, C_wood_litter):
     r_C_wood_2_C_wood_litter * C_wood,
     (C_root, C_root_litter):
     r_C_root_2_C_root_litter * C_root,
     (C_leaf_litter, C_soil_fast):
     r_C_leaf_litter_2_C_soil_fast * C_leaf_litter * xi(t),
     (C_leaf_litter, C_soil_slow):
     r_C_leaf_litter_2_C_soil_slow * C_leaf_litter * xi(t),
Exemplo n.º 8
0
# other + trunk
intersect = ({E: GPP, C_S: 0}, {E: MS + G_OS + G_TS, C_S: 0})

OT = hr.combine(other, trunk, {}, {}, intersect)

# complete model
intersect = ({
    E: GPP,
    C_S: 0
}, {
    E: ML + GL + MR + GR + MS + G_OS + G_TS,
    C_S: 0
})

LROT = hr.combine(LR, OT, {}, {}, intersect)

srm = SmoothReservoirModel.from_state_variable_indexed_fluxes(
    Matrix([E, B_L, C_L, B_OS, B_OH, C_S, B_TH, B_TS, C_R, B_R]), t, LROT[1],
    LROT[2], LROT[3])

mvs = CMTVS(
    {
        InFluxesBySymbol(LROT[1]),
        OutFluxesBySymbol(LROT[2]),
        InternalFluxesBySymbol(LROT[3]),
        TimeSymbol("t"),
        StateVariableTuple(
            (E, B_L, C_L, B_OS, B_OH, C_S, B_TH, B_TS, C_R, B_R))
    }, bgc_md2_computers())
Exemplo n.º 9
0
         Symbol(name): sum([Symbol(flux) for flux in val])
         for name, val in ms.external_input_structure.items()
     }
 ),
 # direct description would be
 # InFluxesBySymbol(
 #     {
 #         𝙻𝚊𝚋𝚒𝚕𝚎: 𝚐𝚙𝚙⎯𝚝𝚘⎯𝚕𝚊𝚋𝚒𝚕𝚎,
 #         𝙻𝚎𝚊𝚏: 𝚐𝚙𝚙⎯𝚝𝚘⎯𝚕𝚎𝚊𝚏,
 #         𝚁𝚘𝚘𝚝: 𝚐𝚙𝚙⎯𝚝𝚘_𝚛𝚘𝚘𝚝,
 #         𝚆𝚘𝚘𝚍: 𝚐𝚙𝚙⎯𝚝𝚘⎯𝚠𝚘𝚘𝚍
 #     }
 # ),
 OutFluxesBySymbol(
     {
         Symbol(name): sum([Symbol(flux) for flux in val])
         for name, val in ms.external_output_structure.items()
     }
 ),
 # direct description would be
 # OutFluxesBySymbol(
 #     {
 #         𝙻𝚊𝚋𝚒𝚕𝚎: 𝚏𝚒𝚛𝚎⎯𝚎𝚖⎯𝚕𝚊𝚋𝚒𝚕𝚎,
 #         𝙻𝚎𝚊𝚏: 𝚏𝚒𝚛𝚎⎯𝚎𝚖⎯𝚏𝚘𝚕𝚒𝚊𝚛,
 #         𝚁𝚘𝚘𝚝: 𝚏𝚒𝚛𝚎⎯𝚎𝚖⎯𝚛𝚘𝚘𝚝,
 #         𝚆𝚘𝚘𝚍: 𝚏𝚒𝚛𝚎⎯𝚎𝚖⎯𝚠𝚘𝚘𝚍,
 #         𝙻𝚒𝚝𝚝𝚎𝚛: 𝚏𝚒𝚛𝚎⎯𝚎𝚖⎯𝚕𝚒𝚝𝚝𝚎𝚛 + 𝚑𝚎𝚝𝚛𝚎𝚜𝚙⎯𝚕𝚒𝚝𝚝𝚎𝚛,
 #         𝚂𝚘𝚒𝚕: 𝚏𝚒𝚛𝚎⎯𝚎𝚖⎯𝚜𝚘𝚖 + 𝚑𝚎𝚝𝚛𝚎𝚜𝚙⎯𝚜𝚘𝚖
 #     }
 # ),
 InternalFluxesBySymbol(
     {
Exemplo n.º 10
0
     entryAuthorOrcid="",
     entryCreationDate="11/24/2021",
     doi="",
     further_references=BibInfo(doi="10.1016/j.agrformet.2009.05.002"),
     #  Also from PDF in Reflex experiment
     sym_dict=sym_dict),
 InFluxesBySymbol({
     C_leaf: NPP * beta_leaf,
     C_root: NPP * beta_root,
     C_wood: NPP * beta_wood
 }),
 OutFluxesBySymbol(
     {
         C_leaf_litter: k_leaf_litter_rh * C_leaf_litter * xi,
         C_wood_litter: k_wood_litter_rh * C_wood_litter * xi,
         C_root_litter: k_root_litter_rh * C_root_litter * xi,
         C_soil_fast: k_soil_fast_rh * C_soil_fast * xi,
         C_soil_slow: k_soil_slow_rh * C_soil_slow * xi,
         C_soil_passive: k_soil_passive_rh * C_soil_passive * xi,
     }),
 InternalFluxesBySymbol({
     (C_leaf, C_leaf_litter):
     k_leaf_2_leaf_litter * C_leaf,
     (C_wood, C_wood_litter):
     k_wood_2_wood_litter * C_wood,
     (C_root, C_root_litter):
     k_root_2_root_litter * C_root,
     (C_leaf_litter, C_soil_fast):
     k_leaf_litter_2_soil_fast * C_leaf_litter * xi,
     (C_leaf_litter, C_soil_slow):
     k_leaf_litter_2_soil_slow * C_leaf_litter * xi,
Exemplo n.º 11
0
    InFluxesBySymbol,
    OutFluxesBySymbol,
    InternalFluxesBySymbol,
    TimeSymbol,
    StateVariableTuple,
)
import bgc_md2.resolve.computers as bgc_c

var("I_vl I_vw vl vw k_vl k_vw")

mvs = CMTVS(
    {
        StateVariableTuple((vl, vw)),
        TimeSymbol("t"),
        InFluxesBySymbol({vl: I_vl, vw: I_vw}),
        OutFluxesBySymbol({vl: k_vl * vl, vw: k_vw * vw}),
        InternalFluxesBySymbol({(vl, vw): k_vl * vl, (vw, vl): k_vw * vw}),
    },

    computers=module_computers(bgc_c)
)
# -

# The last statement in the code defines a variable `mvs` which is 
# an instance of CMTVS which stands for `C`onnected`M`ulti`T`ype`V`ariable`S`et".
# It contains information in two forms. 
# 1. Variables of certain type (like InFluxesBySymbol)
# 2. a set of functions that "connect" these Variables and to other results we did not specify 
#    explicitly.
#
# Taks:
Exemplo n.º 12
0
    (E, C_L): f_L * delta_L/(C_gL+delta_L) * E,
    (C_L, E): S_L * C_L,
}

leaves = (
    leaves_sv_set,
    leaves_in_fluxes,
    leaves_out_fluxes,
    leaves_internal_fluxes
)

srm = SmoothReservoirModel.from_state_variable_indexed_fluxes(
    Matrix([E, B_L, C_L]),
    t,
    leaves_in_fluxes,
    leaves_out_fluxes,
    leaves_internal_fluxes
)

mvs = CMTVS(
    {
        InFluxesBySymbol(leaves[1]),
        OutFluxesBySymbol(leaves[2]),
        InternalFluxesBySymbol(leaves[3]),
        TimeSymbol("t"),
        StateVariableTuple((E, B_L, C_L))
    },
    bgc_md2_computers()
)

Exemplo n.º 13
0
trunk_in_fluxes = {E: GPP}
trunk_out_fluxes = {E: MS + G_TS}

trunk_internal_fluxes = {
    # sapwood production
    (E, C_S): f_T * delta_W / (C_gW + delta_W) * E,
    (E, B_TS): f_T * C_gW / (C_gW + delta_W) * eta_W * E,

    # trunk heartwood production
    (B_TS, B_TH): v_T * B_TS,
    (C_S, B_TH):
    v_T * 1 / C_gHW * B_TS / (B_OS + B_TS) * zeta_dw / zeta_gluc * C_S
}

trunk = (trunk_sv_set, trunk_in_fluxes, trunk_out_fluxes,
         trunk_internal_fluxes)

srm = SmoothReservoirModel.from_state_variable_indexed_fluxes(
    Matrix([E, C_S, B_TH, B_TS]), t, trunk_in_fluxes, trunk_out_fluxes,
    trunk_internal_fluxes)

mvs = CMTVS(
    {
        InFluxesBySymbol(trunk[1]),
        OutFluxesBySymbol(trunk[2]),
        InternalFluxesBySymbol(trunk[3]),
        TimeSymbol("t"),
        StateVariableTuple((E, C_S, B_TH, B_TS))
    }, bgc_md2_computers())
Exemplo n.º 14
0
}

internal_fluxes = dict()

r_S, r_L = symbols("r_S r_L")
output_fluxes = {
    WP_S: r_S * WP_S,
    WP_L: r_L * WP_L
}

t = symbols("t")
srm = SmoothReservoirModel.from_state_variable_indexed_fluxes(
    state_vector,
    t,
    input_fluxes,
    output_fluxes,
    internal_fluxes
)

mvs = CMTVS(
    {
        InFluxesBySymbol(input_fluxes),
        OutFluxesBySymbol(output_fluxes),
        InternalFluxesBySymbol(internal_fluxes),
        TimeSymbol(t.name),
        StateVariableTuple(state_vector)
    },
    bgc_md2_computers()
)

Exemplo n.º 15
0
    # sapwood production and senesence
    (E, C_S):
    f_O * delta_W / (C_gW + delta_W) * E,
    (C_S, E):
    S_O * B_OS / (B_OS + B_TS) * C_S,
    (E, B_OS):
    f_O * C_gW / (C_gW + delta_W) * eta_W * E,

    # coarse roots and branches heartwood production
    (B_OS, B_OH):
    v_O * B_OS,
    (C_S, B_OH):
    v_O * 1 / C_gHW * B_OS / (B_OS + B_TS) * zeta_dw / zeta_gluc * C_S,
}

other = (other_sv_set, other_in_fluxes, other_out_fluxes,
         other_internal_fluxes)

srm = SmoothReservoirModel.from_state_variable_indexed_fluxes(
    Matrix([E, C_S, B_OH, B_OS]), t, other_in_fluxes, other_out_fluxes,
    other_internal_fluxes)

mvs = CMTVS(
    {
        InFluxesBySymbol(other[1]),
        OutFluxesBySymbol(other[2]),
        InternalFluxesBySymbol(other[3]),
        TimeSymbol("t"),
        StateVariableTuple((E, C_S, B_OH, B_OS))
    }, bgc_md2_computers())
Exemplo n.º 16
0
    (N_NH4, N_NO3): nitr
}
mvs = CMTVS(
    {
        BibInfo(  # Bibliographical Information
            name="ACONITE",
            longName=
            "A new, simple model of ecosystem C–N cycling and interactions",
            version="1",
            entryAuthor="Verónika Ceballos-Núñez",
            entryAuthorOrcid="0000-0002-0046-1160",
            entryCreationDate="29/3/2016",
            doi="10.5194/gmd-7-2015-2014",
            sym_dict=sym_dict),
        InFluxesBySymbol(h.combine(in_fl_c, in_fl_n)),
        OutFluxesBySymbol(h.combine(out_fl_c, out_fl_n)),
        InternalFluxesBySymbol(h.combine(internal_fl_c, internal_fl_n)),
        t,  # time for the complete system
        x,  # state vector of the complete system
        xc,  # state vector of the carbon sub system
        # from which the carbon fluxes and hence
        # the CarbonCompartMentalMatrix can be derived
        # (even though in this case it is given)
        # A_c,  # the carbon compartmental matrix
        # in_fl_c, #alternatively to the CarbonCompartmentalMatrix
        # out_fl_c,#
        # internal_fl_c,
        xn,  # state vector of the nitrogen sub system
        # from which the nitrogenfluxes and hence the nitrogen compartmental
        # matrix could be derived whence the computers for extraction the
        # nitrogen fluxes from the global fluxes have been implemented
Exemplo n.º 17
0
from bgc_md2.helper import bgc_md2_computers    


from bgc_md2.resolve.mvars import (
        OutFluxesBySymbol,
        InternalFluxesBySymbol
)
mvs_F = CMTVS(
    {
        mvs.get_InFluxesBySymbol(),
        mvs.get_TimeSymbol(),
        mvs.get_StateVariableTuple(),
        OutFluxesBySymbol(
            {
                dp :
                Symbol("r_"+ str(dp))*dp
                for dp in mvs.get_OutFluxesBySymbol().keys()
            }
        ),        
        InternalFluxesBySymbol(
            {
                (dp,rp) : Symbol("r_"+ str(dp)+ "_2_" + str(rp))*dp
                for dp,rp in mvs.get_InternalFluxesBySymbol().keys()
            }
        )
    },
    bgc_md2_computers()
)

# -