Пример #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)
Пример #2
0
 def test_vegetation_carbon_input_tuple_2(self):
     Labile = Symbol("Labile")
     Leaf = Symbol("Leaf")
     Root = Symbol("Root")
     Wood = Symbol("Wood")
     gpp_to_labile = Symbol("gpp_to_labile")
     gpp_to_leaf = Symbol("gpp_to_leaf")
     gpp_to_root = Symbol("gpp_to_root")
     gpp_to_wood = Symbol("gpp_to_wood")
     d = {
         𝙻𝚊𝚋𝚒𝚕𝚎: gpp_to_labile,
         Leaf: gpp_to_leaf,
         𝚁𝚘𝚘𝚝: gpp_to_root,
         𝚆𝚘𝚘𝚍: gpp_to_wood
     }
     u = InFluxesBySymbol(d)
     vcsv = VegetationCarbonStateVariableTuple((Labile, Leaf, Root, Wood))
     res = vegetation_carbon_input_tuple_2(u, vcsv)
     self.assertEqual(type(res), VegetationCarbonInputTuple)
Пример #3
0
    (N_soil, N_NH4): t_soilN,
    (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
Пример #4
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())
Пример #5
0
     #vw,
     C_leaf,
     C_wood,
     C_root,
     C_aom1,
     C_aom2,
     C_smb1,
     C_smb2,
     C_smr,
     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
Пример #6
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
})
Пример #7
0
 {
     t,
     StateVariableTuple((
         C_leaf,
         C_wood,
         C_root,
         C_leaf_litter,
         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):
Пример #8
0
# some we will also use some symbols for functions (which appear with an argument) 
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.
#
#
Пример #9
0
mvs = CMTVS(
    {
        BibInfo(# Bibliographical Information
           name="CARDAMOM",
           longName="?",
           version="?",
           entryAuthor="Holger Metzler",
           entryAuthorOrcid="",
           entryCreationDate="02/02/2021",
           doi="",
           #further_references=BibInfo(doi="10.5194/bg-10-2255-2013"),
           sym_dict=sym_dict
        ),
        InFluxesBySymbol(
            {
                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()
Пример #10
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())
Пример #11
0
from bgc_md2.resolve.mvars import (
    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.
#
Пример #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()
)

Пример #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())
Пример #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()
)

Пример #15
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())