from ticktack import Box, Flow, CarbonBoxModel, save_model

# ------------- Guttler15 Model ------------- #
SS = Box("Sedimentary Sink", 378000)
Sw = Box("Surface Water", 900)
Sb = Box("Surface Biota", 3)
Idw = Box("Intermediate & Deep water", 37800)
Slb = Box("Short-lived biota", 110)
Llb = Box("Long-lived Biota", 450)
L = Box("Litter", 300)
S = Box("Soil", 1350)
P = Box("Peat", 500)
Sp = Box("Stratosphere", 88.5, production_coefficient=0.7)
Tp = Box("Troposphere", 501.5, production_coefficient=0.3)

f1 = Flow(SS, Tp, 0.7)
f2 = Flow(Sp, Tp, 45)
f3 = Flow(Tp, Sp, 45)
f4 = Flow(Tp, Sw, 60.5)
f5 = Flow(Sw, Tp, 61)
f6 = Flow(Sw, Sb, 40)
f7 = Flow(Sb, Sw, 36)
f8 = Flow(Sb, Idw, 4)
f9 = Flow(Idw, Sw, 42)
f10 = Flow(Sw, Idw, 38.2)
f11 = Flow(Sw, SS, 0.3)
f12 = Flow(Idw, SS, 0.2)
f13 = Flow(Tp, Slb, 115)
f14 = Flow(Slb, Tp, 60)
f15 = Flow(Slb, Llb, 15)
f16 = Flow(Llb, L, 15)
f17 = Flow(Slb, L, 40)
f18 = Flow(L, S, 3)
f19 = Flow(L, P, 1)
f20 = Flow(L, Sw, 1)
f21 = Flow(L, Tp, 50)
f22 = Flow(S, Tp, 3)
f23 = Flow(P, Tp, 0.8)
f24 = Flow(P, SS, 0.2)
CBM = CarbonBoxModel(production_rate_units='atoms/cm^2/s')
to_add = [Sp, Tp, Sw, Sb, Idw, Slb, Llb, L, S, P, SS]
CBM.add_nodes(to_add)
CBM.add_edges([f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20,
               f21, f22, f23, f24])
CBM.compile()
save_model(CBM, 'data/Guttler15.hd5')


# ------------- Brehm21 Model ------------- #
SSS = Box("Sedimentary Sink", 189000, hemisphere='south')
SwS = Box("Surface Water", 540,  hemisphere='south')
SbS = Box("Surface Biota", 1.8,  hemisphere='south')
IdwS = Box("Intermediate and Deep water", 22680, hemisphere='south')
SlbS = Box("Short-lived biota", 33, hemisphere='south')
LlbS = Box("Long-lived Biota", 135, hemisphere='south')
LS = Box("Litter", 90, hemisphere='south')
SoS = Box("Soil", 405, hemisphere='south')
PS = Box("Peat", 150, hemisphere='south')
SpS = Box("Stratosphere", 44.5, production_coefficient=0.7*0.5, hemisphere='south')
TpS = Box("Troposphere", 250.5, production_coefficient=0.3*0.5, hemisphere='south')
SSN = Box("Sedimentary Sink", 189000, hemisphere='north')
SwN = Box("Surface Water", 360,hemisphere='north')
SbN = Box("Surface Biota", 1.2,hemisphere='north')
IdwN = Box("Intermediate & Deep water", 15120,hemisphere='north')
SlbN = Box("Short-lived biota", 77,hemisphere='north')
LlbN = Box("Long-lived Biota", 315,hemisphere='north')
LN = Box("Litter", 210,hemisphere='north')
SoN = Box("Soil", 945,hemisphere='north')
PN = Box("Peat", 350,hemisphere='north')
SpN = Box("Stratosphere", 44.5, production_coefficient=0.7*0.5,hemisphere='north')
TpN = Box("Troposphere", 250.5, production_coefficient=0.3*0.5,hemisphere='north')

f1 = Flow(SpS, TpS, 22.5)
f2 = Flow(TpS, SpS, 22.5)
f3 = Flow(TpS, SlbS, 34.5)
f4 = Flow(SlbS, TpS, 18)
f5 = Flow(TpS, SwS, 36.6)
f6 = Flow(SwS, TpS, 36.6)
f7 = Flow(SlbS, LlbS, 4.5)
f8 = Flow(LlbS, LS, 4.5)
f9 = Flow(SlbS, LS, 12)
f10 = Flow(LS, TpS, 15)
f11 = Flow(LS, SwS, 0.3)
f12 = Flow(LS, PS, 0.3)
f13 = Flow(LS, SoS, 0.9)
f14 = Flow(PS, TpS, 0.24)
f15 = Flow(PS, SSS, 0.06)
f16 = Flow(SoS, TpS, 0.9)
f17 = Flow(SwS, SSS, 0.18)
f18 = Flow(IdwS, SSS, 0.12)
f19 = Flow(SwS, SbS, 22.6)
f20 = Flow(SwS, IdwS, 37.92)
f21 = Flow(SwS, SwN, 13)
f22 = Flow(SbS, SwS, 20.2)
f23 = Flow(SbS, IdwS, 2.4)
f24 = Flow(IdwS, SwS, 43.2)
f25 = Flow(IdwS, IdwN, 15.12)
f26 = Flow(SSS, TpS, 0.36)
f27 = Flow(SpS, SpN, 44.1)
f28 = Flow(TpS, TpN, 71)
f29 = Flow(SpN, SpS, 44.1)
f30 = Flow(TpN, TpS, 71)
f31 = Flow(SpN, TpN, 22.5)
f32 = Flow(TpN, SpN, 22.5)
f33 = Flow(TpN, SwN, 24.4)
f34 = Flow(TpN, SlbN, 80.5)
f35 = Flow(SwN, TpN, 24.89)
f36 = Flow(SwN, SwS, 10)
f37 = Flow(SwN, SbN, 16)
f38 = Flow(SwN, IdwN, 28.29)
f39 = Flow(SlbN, TpN, 42)
f40 = Flow(SlbN, LlbN, 10.5)
f41 = Flow(SlbN, LN, 28)
f42 = Flow(LlbN, LN, 10.5)
f43 = Flow(SbN, SwN, 14.4)
f44 = Flow(SbN, IdwN, 1.6)
f45 = Flow(SwN, SSN, 0.12)
f46 = Flow(IdwN, SwN, 26.8)
f47 = Flow(IdwN, SSN, 0.09)
f48 = Flow(IdwN, IdwS, 18.12)
f49 = Flow(LN, SwN, 0.7)
f50 = Flow(LN, SoN, 2.1)
f51 = Flow(LN, TpN, 35)
f52 = Flow(LN, PN, 0.7)
f53 = Flow(SoN, TpN, 2.1)
f54 = Flow(PN, TpN, 0.56)
f55 = Flow(PN, SSN, 0.14)
f56 = Flow(SSN, TpN, 0.35)
CBM = CarbonBoxModel()
to_add = [SpS, TpS, SwS, SbS, IdwS, SlbS, LlbS, LS, SoS,
          PS, SSS, SpN, TpN, SwN, SbN, IdwN, SlbN, LlbN, LN, SoN, PN, SSN]
CBM.add_nodes(to_add)
CBM.add_edges([f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20,
               f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40,
               f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56])
CBM.compile()
save_model(CBM, 'data/Brehm21.hd5')


# ------------- Buntgen18 Model ------------- #
SSS = Box("Sedimentary Sink", 189000, hemisphere='south')
SwS = Box("Surface Water", 540, hemisphere='south')
SbS = Box("Surface Biota", 1.8, hemisphere='south')
IdwS = Box("Intermediate and Deep water", 22680, hemisphere='south')
SlbS = Box("Short-lived biota", 33, hemisphere='south')
LlbS = Box("Long-lived Biota", 135, hemisphere='south')
LS = Box("Litter", 90, hemisphere='south')
SoS = Box("Soil", 405, hemisphere='south')
PS = Box("Peat", 150, hemisphere='south')
SpS = Box("Stratosphere", 44.5, production_coefficient=0.7*0.5, hemisphere='south')
TpS = Box("Troposphere", 250.5, production_coefficient=0.3*0.5, hemisphere='south')
SSN = Box("Sedimentary Sink", 189000, hemisphere='north')
SwN = Box("Surface Water", 360, hemisphere='north')
SbN = Box("Surface Biota", 1.2, hemisphere='north')
IdwN = Box("Intermediate & Deep water", 15120, hemisphere='north')
SlbN = Box("Short-lived biota", 77, hemisphere='north')
LlbN = Box("Long-lived Biota", 315, hemisphere='north')
LN = Box("Litter", 210, hemisphere='north')
SoN = Box("Soil", 945, hemisphere='north')
PN = Box("Peat", 350, hemisphere='north')
SpN = Box("Stratosphere", 44.5, production_coefficient=0.7*0.5, hemisphere='north')
TpN = Box("Troposphere", 250.5, production_coefficient=0.3*0.5, hemisphere='north')

f1 = Flow(SpS, TpS, 23.8)
f2 = Flow(TpS, SpS, 23.8)
f3 = Flow(TpS, SlbS, 35.36)
f4 = Flow(SlbS, TpS, 18.86)
f5 = Flow(TpS, SwS, 38.25)
f6 = Flow(SwS, TpS, 38.25)
f7 = Flow(SlbS, LlbS, 4.5)
f8 = Flow(LlbS, LS, 4.5)
f9 = Flow(SlbS, LS, 12)
f10 = Flow(LS, TpS, 15)
f11 = Flow(LS, SwS, 0.3)
f12 = Flow(LS, PS, 0.3)
f13 = Flow(LS, SoS, 0.9)
f14 = Flow(PS, TpS, 0.24)
f15 = Flow(PS, SSS, 0.06)
f16 = Flow(SoS, TpS, 0.9)
f17 = Flow(SwS, SSS, 0.18)
f18 = Flow(IdwS, SSS, 0.12)
f19 = Flow(SwS, SbS, 22.6)
f20 = Flow(SwS, IdwS, 8.52)
f21 = Flow(SwS, SwN, 28.8)
f22 = Flow(SbS, SwS, 20.2)
f23 = Flow(SbS, IdwS, 2.4)
f24 = Flow(IdwS, SwS, 39.6)
f25 = Flow(IdwS, IdwN, 0.72)
f26 = Flow(SSS, TpS, 0.36)
f27 = Flow(SpS, SpN, 22.25)
f28 = Flow(TpS, TpN, 71.6)
f29 = Flow(SpN, SpS, 22.25)
f30 = Flow(TpN, TpS, 71.6)
f31 = Flow(SpN, TpN, 23.8)
f32 = Flow(TpN, SpN, 23.8)
f33 = Flow(TpN, SwN, 29.16)
f34 = Flow(TpN, SlbN, 80.51)
f35 = Flow(SwN, TpN, 29.65)
f36 = Flow(SwN, SwS, 0)
f37 = Flow(SwN, SbN, 16)
f38 = Flow(SwN, IdwN, 49.69)
f39 = Flow(SlbN, TpN, 42.01)
f40 = Flow(SlbN, LlbN, 10.5)
f41 = Flow(SlbN, LN, 28)
f42 = Flow(LlbN, LN, 10.5)
f43 = Flow(SbN, SwN, 14.4)
f44 = Flow(SbN, IdwN, 1.6)
f45 = Flow(SwN, SSN, 0.12)
f46 = Flow(IdwN, SwN, 22.4)
f47 = Flow(IdwN, SSN, 0.09)
f48 = Flow(IdwN, IdwS, 29.52)
f49 = Flow(LN, SwN, 0.7)
f50 = Flow(LN, SoN, 2.1)
f51 = Flow(LN, TpN, 35)
f52 = Flow(LN, PN, 0.7)
f53 = Flow(SoN, TpN, 2.1)
f54 = Flow(PN, TpN, 0.56)
f55 = Flow(PN, SSN, 0.14)
f56 = Flow(SSN, TpN, 0.35)
CBM = CarbonBoxModel()
to_add = [SpS, TpS, SwS, SbS, IdwS, SlbS, LlbS, LS, SoS,
          PS, SSS, SpN, TpN, SwN, SbN, IdwN, SlbN, LlbN, LN, SoN, PN, SSN]
CBM.add_nodes(to_add)
CBM.add_edges([f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20,
               f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40,
               f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56])
CBM.compile()
save_model(CBM, 'data/Buntgen18.hd5')


# ------------- Miyake17 Model ------------- #
strat = Box('Stratosphere', 112.5, 0.7)
trop = Box('Troposphere', 637.5, 0.3)
MS = Box("Marine surface", 900)
Bio = Box("Biosphere", 1600)
f1 = Flow(strat, trop, 1 / 2)
f2 = Flow(trop, MS, 1 / 11)
f3 = Flow(trop, Bio, 1 / 23)
CBM = CarbonBoxModel(flow_rate_units='1/yr')
CBM.add_nodes([strat, trop, MS, Bio])
CBM.add_edges([f1, f2, f3])
CBM.compile()
save_model(CBM, 'data/Miyake17.hd5')