def __init__(self, params=None, **kwargs): super(ChemostatSimple, self).__init__(**kwargs) if params == None: params = AttributeDict(kwargs) # Initialize update progress function self.updateProgress = params.updateProgress # Initialize parameters self.m = params.m self.K = params.K self.S_in = params.S_in self.X_in = params.X_in self.gamma = params.gamma self.D_vals = params.D_vals # Create state vector and derivative vector stateVarNames = ['S', 'X'] self.y = NamedStateVector(stateVarNames) self.yRes = NamedStateVector(stateVarNames) self.yDot = NamedStateVector(stateVarNames) # Initialize data storage self.resultStorage = ResultStorage(filePath=dataStorageFilePath, datasetPath=dataStorageDatasetPath) if (kwargs.get('initDataStorage', True)): self.resultStorage.initializeWriting(varList=['t'] + stateVarNames + ['D'], chunkSize=1e4) # Register time event (changed of D) D_val = self.D_vals[0] self.D = D_val[1] tChangedD = D_val[0] for i in range(len(self.D_vals) - 1): self.D_val = self.D_vals[i + 1] self.timeEventRegistry.add( ChemostatSimpleTimeEvent(t=tChangedD, newValue_D=self.D_val[1])) tChangedD += self.D_val[0] # Set initial values of the states self.y.S = params.S0 self.y.X = params.X0 # Set all the initial state values self.y0 = self.y.get(copy=True) # Set the initial flags self.sw0 = [True]
def __init__(self, params=None, **kwargs): """ #params.reactions = [reactionEquation, rateConstants] #params.species = [speciesVariable, initialValue] """ super(BiochemicalReactions, self).__init__(**kwargs) if params == None: params = AttributeDict(kwargs) # Initialize update progress function self.updateProgress = params.updateProgress # Get the species variables Xs = [X1, X2, ..., Xn] and their initial values self.Xs = np.empty(len(params.species), dtype=(np.str_, 256)) self.X0s = np.zeros(len(params.species)) for i, itSpecies in enumerate(params.species): self.Xs[i] = itSpecies[0] self.X0s[i] = itSpecies[1] # Get the reactions = [[left Xs, right Xs, k, ss, rs, f], ...], where: # left Xs - the species variables of reactants (i.e. the species variables of the left parts of the reactions) # rigth Xs - the species variables of products (i.e. the species variables of the right parts of the reactions) # k - the rate constant of the reaction # ss - the stoichiometric coefficients of reactants (e.g. [0,1,1,0,...,1]) # rs - the stoichiometric coefficients of products (e.g. [1,0,...,0]) # f - the fluxs (e.g. k*X2*X3*...*Xn) self.reactions = self.readReactions(params.reactions, self.Xs) #for reaction in self.reactions: print reaction # Create a vector with state variable names stateVarNames = list(self.Xs) # Initialize data storage self.resultStorage = ResultStorage(filePath=dataStorageFilePath, datasetPath=dataStorageDatasetPath) if (kwargs.get('initDataStorage', True)): self.resultStorage.initializeWriting(varList=['t'] + stateVarNames, chunkSize=1e4) # Set the initial state values self.y0 = self.X0s # Set the initial flags self.sw0 = [True]
def __init__(self, webModel, paramsRH2, concentrsRH2, paramsRCH4, concentrsRCH4, **kwargs): super(ADM1H2CH4Bioreactors, self).__init__(**kwargs) # Initialize update progress function self.updateProgress = webModel.updateProgress # Initialize parameters self.paramsRH2 = paramsRH2 self.paramsRCH4 = paramsRCH4 # Initialize concentrations self.concentrsRH2 = concentrsRH2 self.concentrsRCH4 = concentrsRCH4 # Create state vector and derivative vector stateVarNames = [ 'S_su_RH2', 'S_aa_RH2', 'S_fa_RH2', 'S_ac_RH2', 'X_c_RH2', 'X_ch_RH2', 'X_pr_RH2', 'X_li_RH2', 'X_suaa_RH2', 'X_fa_RH2', 'intQ_h2_RH2', 'S_ac_RCH4', 'X_ac_RCH4', 'intQ_ch4_RCH4' ] self.y = NamedStateVector(stateVarNames) self.yRes = NamedStateVector(stateVarNames) self.yDot = NamedStateVector(stateVarNames) # Initialize data storage self.resultStorage = ResultStorage(filePath=dataStorageFilePath, datasetPath=dataStorageDatasetPath) if (kwargs.get('initDataStorage', True)): self.resultStorage.initializeWriting( varList=['time'] + stateVarNames + ['Q_h2_RH2', 'Q_ch4_RCH4', 'D_RH2', 'D_RCH4'], chunkSize=1e4) # Register time event (changed of D) tChangedD = paramsRH2.D_liq_arr[0][0] self.D_RH2 = paramsRH2.D_liq_arr[0][1] self.D_RCH4 = self.D_RH2 / paramsRCH4.V_liq_RCH4_del_V_liq_RH2 for i in range(len(paramsRH2.D_liq_arr) - 1): self.timeEventRegistry.add( ADM1TimeEvent(t=tChangedD, newValue_D=paramsRH2.D_liq_arr[i + 1][1])) tChangedD += paramsRH2.D_liq_arr[i + 1][0] # Set initial values of the states self.y.S_su_RH2 = concentrsRH2.S_su_0 self.y.S_aa_RH2 = concentrsRH2.S_aa_0 self.y.S_fa_RH2 = concentrsRH2.S_fa_0 self.y.S_ac_RH2 = concentrsRH2.S_ac_0 self.y.X_c_RH2 = concentrsRH2.X_c_0 self.y.X_ch_RH2 = concentrsRH2.X_ch_0 self.y.X_pr_RH2 = concentrsRH2.X_pr_0 self.y.X_li_RH2 = concentrsRH2.X_li_0 self.y.X_suaa_RH2 = concentrsRH2.X_suaa_0 self.y.X_fa_RH2 = concentrsRH2.X_fa_0 self.y.intQ_h2_RH2 = 0.0 self.Q_h2_RH2 = 0.0 self.y.S_ac_RCH4 = concentrsRCH4.S_ac_0 self.y.X_ac_RCH4 = concentrsRCH4.X_ac_0 self.y.intQ_ch4_RCH4 = 0.0 self.Q_ch4_RCH4 = 0.0 # Set all the initial state values self.y0 = self.y.get(copy=True) # Set the initial flags self.sw0 = [True]