Example #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)
Example #2
0
}
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
        # NitrogenInFluxesBySymbol(in_fl_n),
Example #3
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())
Example #4
0
 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,
     (C_root, C_aom1):
     r_C_root_2_C_aom1 * C_root,
     (C_root, C_aom2):
     r_C_root_2_C_aom2 * C_root,
     (C_aom1, C_smb1):
     r_C_aom1_2_C_smb1 * C_aom1 * xi(t),
     (C_aom1, C_smb2):
     r_C_aom1_2_C_smb2 * C_aom1 * xi(t),
     (C_aom1, C_dom):
     r_C_aom1_2_C_dom * C_aom1 * xi(t),
     (C_aom1, C_nom):
     r_C_aom1_2_C_nom * C_aom1 * xi(t),
     (C_aom2, C_smb1):
     r_C_aom2_2_C_smb1 * C_aom2 * xi(t),
     (C_aom2, C_smb2):
     r_C_aom2_2_C_smb2 * C_aom2 * xi(t),
     (C_aom2, C_dom):
     r_C_aom2_2_C_dom * C_aom2 * xi(t),
     (C_smb2, C_smr):
     r_C_smb2_2_C_smr * C_smb2 * xi(t),
     (C_smr, C_smb1):
     r_C_smr_2_C_smb1 * C_smr * xi(t),
     (C_dom, C_smb1):
     r_C_dom_2_C_smb1 * C_dom * xi(t),
     (C_dom, C_nom):
     r_C_dom_2_C_nom * C_dom * xi(t),
     (C_nom, C_dom):
     r_C_nom_2_C_dom * C_nom * xi(t),
     (C_nom, C_psom):
     r_C_nom_2_C_psom * C_nom * xi(t),
     (C_smb1, C_psom):
     r_C_smb1_2_C_psom * C_smb1 * xi(t),
     (C_smb1, C_nom):
     r_C_smb1_2_C_nom * C_smb1 * xi(t),
     (C_nom, C_smb1):
     r_C_nom_2_C_smb1 * C_nom * xi(t),
     (C_psom, C_smb1):
     r_C_psom_2_C_smb1 * C_psom * xi(t),
 }),
Example #5
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())
Example #6
0
    "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:
# To see what it can do with this information add a new cell an type `mvs.` and press the `tab` key `->`. This will show you the available methods, in other words what can be computed from the provided information.
Example #7
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
})
Example #8
0
mvs = CMTVS(
    {
        BibInfo(  # Bibliographical Information
            name="MIMICS",
            longName="Microbial-Mineral Carbon Stabilization",
            version="1",
            entryAuthor="Carlos Sierra",
            entryAuthorOrcid="0000-0003-0009-4169",
            entryCreationDate="14/08/2018",
            doi="10.5194/bg-11-3899-2014",
            sym_dict=sym_dict),
        TimeSymbol("t"),  # unit: "hour"
        x,  # state vector of the complete system
        #    InFluxesBySymbol({})
        #    OutFluxesBySymbol({})
        InternalFluxesBySymbol({
            (LIT_m, MIC_r): F1,
            (LIT_s, MIC_r): F2,
            (SOM_p, MIC_r): F3,
            (SOM_c, MIC_r): F4,
            (MIC_r, SOM_p): F5,
            (LIT_m, MIC_k): F6,
            (LIT_s, MIC_k): F7,
            (SOM_p, MIC_k): F8,
            (SOM_c, MIC_k): F9,
            (MIC_k, SOM_c): F10
        })
    },
    bgc_md2_computers())
Example #9
0
                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),
            (C_leaf_litter, C_soil_passive):
            r_C_leaf_litter_2_C_soil_passive * C_leaf_litter * xi(t),
            (C_wood_litter, C_soil_fast):
            r_C_wood_litter_2_C_soil_fast * C_wood_litter * xi(t),
            (C_wood_litter, C_soil_slow):
            r_C_wood_litter_2_C_soil_slow * C_wood_litter * xi(t),
            (C_wood_litter, C_soil_passive):
            r_C_wood_litter_2_C_soil_passive * C_wood_litter * xi(t),
            (C_root_litter, C_soil_fast):
            r_C_root_litter_2_C_soil_fast * C_root_litter * xi(t),
            (C_root_litter, C_soil_slow):
            r_C_root_litter_2_C_soil_slow * C_root_litter * xi(t),
            (C_root_litter, C_soil_passive):
            r_C_root_litter_2_C_soil_passive * C_root_litter * xi(t),
        }),
    },
    computers=module_computers(bgc_c))
Example #10
0
     }
 ),
 # direct description would be
 # OutFluxesBySymbol(
 #     {
 #         π™»πšŠπš‹πš’πš•πšŽ: πšπš’πš›πšŽβŽ―πšŽπš–βŽ―πš•πšŠπš‹πš’πš•πšŽ,
 #         π™»πšŽπšŠπš: πšπš’πš›πšŽβŽ―πšŽπš–βŽ―πšπš˜πš•πš’πšŠπš›,
 #         𝚁𝚘𝚘𝚝: πšπš’πš›πšŽβŽ―πšŽπš–βŽ―πš›πš˜πš˜πš,
 #         πš†πš˜πš˜πš: πšπš’πš›πšŽβŽ―πšŽπš–βŽ―πš πš˜πš˜πš,
 #         π™»πš’πšπšπšŽπš›: πšπš’πš›πšŽβŽ―πšŽπš–βŽ―πš•πš’πšπšπšŽπš› + πš‘πšŽπšπš›πšŽπšœπš™βŽ―πš•πš’πšπšπšŽπš›,
 #         πš‚πš˜πš’πš•: πšπš’πš›πšŽβŽ―πšŽπš–βŽ―πšœπš˜πš– + πš‘πšŽπšπš›πšŽπšœπš™βŽ―πšœπš˜πš–
 #     }
 # ),
 InternalFluxesBySymbol(
     {
         (Symbol(name_tup[0]),Symbol(name_tup[1])): sum([ Symbol(flux) for flux in val])
         for name_tup, val in ms.horizontal_structure.items()
     }
 ),
 # direct description would be
 # InternalFluxesBySymbol(
 #     {
 #         (π™»πšŠπš‹πš’πš•πšŽ, π™»πšŽπšŠπš): πš•πšŠπš‹πš’πš•πšŽβŽ―πšπš˜βŽ―πšπš˜πš•πš’πšŠπš›,
 #         (π™»πšŠπš‹πš’πš•πšŽ, π™»πš’πšπšπšŽπš›): πšπš’πš›πšŽβŽ―πš•πšŠπš‹πš’πš•πšŽβŽ―πšπš˜βŽ―πš•πš’πšπšπšŽπš›,
 #         (π™»πšŽπšŠπš, π™»πš’πšπšπšŽπš›): πšπš’πš›πšŽβŽ―πšπš˜πš•πš’πšŠπš›βŽ―πšπš˜βŽ―πš•πš’πšπšπšŽπš› + πš•πšŽπšŠπšβŽ―πšπš˜βŽ―πš•πš’πšπšπšŽπš›,
 #         (πš†πš˜πš˜πš, πš‚πš˜πš’πš•): πšπš’πš›πšŽβŽ―πš πš˜πš˜πšβŽ―πšπš˜βŽ―πšœπš˜πš– + πš πš˜πš˜πšβŽ―πšπš˜βŽ―πšœπš˜πš’πš•πšŒ,
 #         (𝚁𝚘𝚘𝚝, π™»πš’πšπšπšŽπš›): πšπš’πš›πšŽβŽ―πš›πš˜πš˜πšβŽ―πšπš˜βŽ―πš•πš’πšπšπšŽπš› + πš›πš˜πš˜πšβŽ―πšπš˜βŽ―πš•πš’πšπšπšŽπš›,
 #         (π™»πš’πšπšπšŽπš›, πš‚πš˜πš’πš•): πšπš’πš›πšŽβŽ―πš•πš’πšπšπšŽπš›βŽ―πšπš˜βŽ―πšœπš˜πš– + πš•πš’πšπšπšŽπš›βŽ―πšπš˜βŽ―πšœπš˜πš–
 #     }
 # ),
 t,  # time symbol
 x,  # state vector of the complete system
Example #11
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())
Example #12
0
    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:
# To see what it can do with this information add a new cell an type `mvs.` and press the `tab` key `->`. This will show you the available methods, in other words what can be computed from the provided information.
Example #13
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()
)

Example #14
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())
Example #15
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()
)

Example #16
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())