monroews / CEE4530

MIT License
4 stars 11 forks source link

Problem with CMFR model when running PFR data #120

Open rosiekrasnoff opened 5 years ago

rosiekrasnoff commented 5 years ago

The CMFR model was totally off when we were running our PFR data. This was because it was not able to estimate the number of CMFRs, so it just used 1 and then was very very off. I modified the epa function to assume 50 CMFRs instead of 1. This fixed my problem!

edit function, change solver to assume 50 CMFRs instead of 1

def Solver_CMFR_N_PFR(t_data, C_data, theta_guess, C_bar_guess): """Use non-linear least squares to fit the function Tracer_CMFR_N(t_seconds, t_bar, C_bar, N), to reactor data. Parameters

t_data : float list
    Array of times with units
C_data : float list
    Array of tracer concentration data with units
theta_guess : float
    Estimate of time spent in one CMFR with units.
C_bar_guess : float
    Estimate of average concentration with units
    (Mass of tracer)/(volume of one CMFR)
Returns
-------
tuple
    theta : float
        residence time in seconds
    C_bar : float
        average concentration with same units as C_bar_guess
    N : float
        number of CMFRS in series that best fit the data
"""
C_unitless = C_data.magnitude
C_units = str(C_bar_guess.units)
t_seconds = (t_data.to(u.s)).magnitude
# assume that a guess of 50 reactors in series is close enough to get a solution
p0 = [theta_guess.to(u.s).magnitude, C_bar_guess.magnitude,50]
popt, pcov = curve_fit(epa.Tracer_CMFR_N, t_seconds, C_unitless, p0)
Solver_theta = popt[0]*u.s
Solver_C_bar = popt[1]*u(C_units)
Solver_N = popt[2]
Reactor_results = collections.namedtuple('Reactor_results','theta C_bar N')
CMFR = Reactor_results(theta=Solver_theta, C_bar=Solver_C_bar, N=Solver_N)
return CMFR

trial5_CMFR = Solver_CMFR_N_PFR(trial5_time_data, trial5_concentration_data, trial5_theta_hydraulic, trial5_C_bar_guess)