from sympy import Symbol, ImmutableMatrix
import numpy as np
from typing import Tuple
from sympy.physics.units import Quantity
from .mvars import (
InFluxesBySymbol,
OutFluxesBySymbol,
InternalFluxesBySymbol,
TimeSymbol,
StateVariableTuple,
CompartmentalMatrix,
InputTuple,
VegetationCarbonInputScalar,
VegetationCarbonInputPartitioningTuple,
VegetationCarbonInputTuple,
VegetationCarbonCompartmentalMatrix,
NumericSimulationTimes,
NumericParameterization,
NumericStartValueArray,
NumericStartValueDict,
NumericParameterizedSmoothReservoirModel,
NumericSolutionArray,
QuantityParameterization,
QuantitySimulationTimes,
QuantityParameterizedSmoothReservoirModel,
QuantityStartValueDict,
QuantityStartValueArray,
QuantityModelRun,
QuantitySolutionArray,
StateVarUnitTuple,
)
from CompartmentalSystems.smooth_reservoir_model import SmoothReservoirModel
from CompartmentalSystems.smooth_model_run import SmoothModelRun
[docs]def smooth_reservoir_model_from_fluxes(
in_fluxes: InFluxesBySymbol,
out_fluxes: OutFluxesBySymbol,
internal_fluxes: InternalFluxesBySymbol,
time_symbol: TimeSymbol,
state_variable_tuple: StateVariableTuple,
) -> SmoothReservoirModel:
return SmoothReservoirModel.from_state_variable_indexed_fluxes(
state_vector=list(state_variable_tuple),
time_symbol=time_symbol,
input_fluxes=in_fluxes,
output_fluxes=out_fluxes,
internal_fluxes=internal_fluxes,
)
[docs]def compartmental_matrix_from_smooth_reservoir_model(
smr: SmoothReservoirModel,
) -> CompartmentalMatrix:
return CompartmentalMatrix(smr.compartmental_matrix)
# def vegetation_carbon_compartmental_matrix_from_compartmental_matrix_and_vegetation_carbon_state_variable_tuple(
# B: CompartmentalMatrix,
# svt: StateVariableTuple,
# vcsvt: VegetationCarbonStateVariableTuple
# ) ->
# return CompartmentalMatrix(smr.compartmental_matrix)
[docs]def numeric_model_run_1(
npsrm: NumericParameterizedSmoothReservoirModel,
start_values_num: NumericStartValueArray,
times_num: NumericSimulationTimes,
) -> SmoothModelRun:
return SmoothModelRun(
npsrm.srm,
npsrm.parameterization.par_dict,
start_values_num,
times_num,
npsrm.parameterization.func_dict,
)
[docs]def numeric_parameterized_smooth_reservoir_model_1(
srm: SmoothReservoirModel, para_num: NumericParameterization,
) -> NumericParameterizedSmoothReservoirModel:
return NumericParameterizedSmoothReservoirModel(srm, para_num)
[docs]def numeric_start_value_array_1(
nsvd: NumericStartValueDict,
svt: StateVariableTuple
) -> NumericStartValueArray:
tup = tuple(nsvd[k] for k in svt)
return NumericStartValueArray(tup)
[docs]def numeric_start_value_array_2(
smr: SmoothModelRun
) -> NumericStartValueArray:
tup = tuple(nsvd[k] for k in svt)
return NumericStartValueArray(smr.start_values)
[docs]def numeric_start_value_dict(
nsva: NumericStartValueArray,
svt: StateVariableTuple
) -> NumericStartValueDict:
return NumericStartValueDict({sv:nsva[i] for i,sv in enumerate(svt)})
[docs]def numeric_solution_array_1(
smr: SmoothModelRun
)->NumericSolutionArray:
return NumericSolutionArray(smr.solve())
[docs]def quantity_parameterization_1(
np: NumericParameterization,
state_var_units: StateVarUnitTuple,
time_unit: Quantity
) -> QuantityParameterization:
return QuantityParameterization(
np.par_dict,
np.func_dict,
state_var_units,
time_unit
)
[docs]def quantity_parameterized_smooth_reservoir_model_1(
srm: SmoothReservoirModel,
para_q: QuantityParameterization
) -> QuantityParameterizedSmoothReservoirModel:
return QuantityParameterizedSmoothReservoirModel(srm, para_q)
[docs]def quantity_start_value_array_1(
qsvd: QuantityStartValueDict,
svt: StateVariableTuple
) -> QuantityStartValueArray:
tup = tuple(qsvd[k] for k in svt)
return QuantityStartValueArray(tup)
[docs]def quantity_model_run_1(
qpsrm: QuantityParameterizedSmoothReservoirModel,
start_values_q: QuantityStartValueArray,
times_q: QuantitySimulationTimes,
) -> QuantityModelRun:
return QuantityModelRun(
qpsrm,
start_values_q,
times_q,
)
[docs]def quantity_solution_array_1(
qmr: QuantityModelRun
)->QuantitySolutionArray:
return QuantitySolutionArray(qmr.solve())
[docs]def smooth_reservoir_model_2(
smr: SmoothModelRun
)-> SmoothReservoirModel:
return smr.model