QSD-Group / QSDsan

Quantitative Sustainable Design (QSD) of sanitation and resource recovery systems.
https://qsdsan.com
Other
30 stars 12 forks source link

General `_run` for first order decay #74

Closed yalinli2 closed 1 year ago

yalinli2 commented 2 years ago

Currently almost all of the subclasses ofDecay have the following module in _run:

    def _run(self):
        waste, salt, HCl_acid = self.ins
        treated, CH4, N2O = self.outs
        treated.copy_like(waste)
        CH4.phase = N2O.phase = 'g'

        # COD decay
        COD_deg = waste.COD*waste.F_vol/1e3*self.COD_removal  # kg/hr
        treated._COD = waste.COD * (1-self.COD_removal)

        CH4_prcd = COD_deg * self.MCF_decay * self.max_CH4_emission
        CH4.imass['CH4'] = CH4_prcd

        # N decay
        N_loss = self.first_order_decay(k=self.decay_k_N, t=self.tau/365, max_decay=self.N_max_decay)
        N_loss_tot = N_loss*waste.TN/1e3*waste.F_vol
        NH3_rmd, NonNH3_rmd = \
            self.allocate_N_removal(N_loss_tot, waste.imass['NH3'])
        treated.imass['NH3'] = waste.imass['NH3'] - NH3_rmd
        treated.imass['NonNH3'] = waste.imass['NonNH3'] - NonNH3_rmd
        N2O.imass['N2O'] = N_loss_tot * self.N2O_EF_decay * 44/28

It'll be good to put this part in Decay so that any future updates can be propagated throughout, would also be good if it can be written to include a sludge effluent with consideration of the sludge moisture content

yalinli2 commented 1 year ago

Also, this class in placed under the sanunit dir but not a SanUnit, might be better to make it a Process

yalinli2 commented 1 year ago

Maybe make a Kinetics class for 0/1/2 order kinetics that can be analytically solved, but the name Kinetics is taken now... need to talk to Joy and see if we can change that to Rate or similar

yalinli2 commented 1 year ago

Also, this class in placed under the sanunit dir but not a SanUnit, might be better to make it a Process

This has been moved to processes, but it's not a Process either

yalinli2 commented 1 year ago

Maybe make a Kinetics class for 0/1/2 order kinetics that can be analytically solved, but the name Kinetics is taken now... need to talk to Joy and see if we can change that to Rate or similar

See #84

yalinli2 commented 1 year ago

This should have been completed for all public units upon https://github.com/QSD-Group/QSDsan/commit/13868fc905da6c37636aca51f5b205f88e1d1cf1, all tests for the corresponding systems can pass (except for a minor change in https://github.com/QSD-Group/EXPOsan/commit/45b59e3a9166fbd0cba96234714b312b763595ba because of more consistent account of N degradation)

yalinli2 commented 1 year ago

And also done for the private repo as well https://github.com/QSD-Group/QSDsan-private/commit/64d645186a38695208d711f22839a8f59e8e3cbf, can finally close it!