def frictionFactor(well_radius, P, h, m_dot, fluid, epsilon):

    if well_radius == None or P == None or h == None or m_dot == None or fluid == None or epsilon == None:
        return 0

    rho_fluid = FluidState.getStateFromPh(P, h, fluid).rho_kgm3
    mu = FluidState.getStateFromPh(P, h, fluid).mu_Pas

    A_c = np.pi * well_radius**2
    V = m_dot / A_c / rho_fluid

    # Relative Roughness
    rr = epsilon / (2 * well_radius)

    # Reynolds Number
    Re = rho_fluid * V * (2 * well_radius) / mu

    # Use Haaland (1983) Approximation
    c1 = -1.8 * np.log10((6.9 / Re) + (rr / 3.7)**1.11)
    return (1 / c1)**2
Beispiel #2
0
    def solve(self, initialState, T_boil_C=False, dT_pinch=False):

        T_in_C = initialState.T_C

        if not T_boil_C:
            T_boil_C = np.interp(
                T_in_C,
                self.data[self.params.opt_mode][self.params.orc_fluid][:, 0],
                self.data[self.params.opt_mode][self.params.orc_fluid][:, 1])

        if not dT_pinch:
            dT_pinch = np.interp(
                T_in_C,
                self.data[self.params.opt_mode][self.params.orc_fluid][:, 0],
                self.data[self.params.opt_mode][self.params.orc_fluid][:, 2])

        # run some checks  if T_in_C and T_boil_C are valid
        if np.isnan(T_in_C):
            raise Exception(
                'GenGeo::ORCCycleTboil:T_in_NaN - ORC input temperature is NaN!'
            )

        if np.isnan(T_boil_C):
            raise Exception(
                'GenGeo::ORCCycleTboil:T_boil_NaN - ORC boil temperature is NaN!'
            )

        if T_boil_C > FluidState.getTcrit(self.params.orc_fluid):
            raise Exception(
                'GenGeo::ORCCycleTboil:Tboil_Too_Large - Boiling temperature above critical point'
            )

        if dT_pinch <= 0:
            raise Exception(
                'GenGeo::ORCCycleTboil:dT_pinch_Negative - dT_pinch is negative!'
            )

        if T_in_C < T_boil_C + dT_pinch:
            raise Exception(
                'GenGeo::ORCCycleTboil:Tboil_Too_Large - Boiling temperature of %s is greater than input temp of %s less pinch dT of %s.'
                % (T_boil_C, T_in_C, dT_pinch))

        # only refresh T_boil_max if orc_fluid has changed from initial
        if self.params.orc_fluid != self.orc_fluid:
            self.T_boil_max = maxSubcritORCBoilTemp(self.params.orc_fluid)
            self.orc_fluid = self.params.orc_fluid
        if T_boil_C > self.T_boil_max:
            raise Exception(
                'GenGeo::ORCCycleTboil:Tboil_Too_Large - Boiling temperature of %s is greater than maximum allowed of %s.'
                % (T_boil_C, self.T_boil_max))

        T_condense_C = self.params.T_ambient_C + self.params.dT_approach

        # create empty list to compute cycle of 6 states
        state = [None] * 6

        #State 1 (Condenser -> Pump)
        #saturated liquid
        state[0] = FluidState.getStateFromTQ(T_condense_C, 0,
                                             self.params.orc_fluid)

        #State 6 (Desuperheater -> Condenser)
        #saturated vapor
        state[5] = FluidState.getStateFromTQ(state[0].T_C, 1,
                                             self.params.orc_fluid)
        # state[5].P_Pa = state[0].P_Pa

        #State 3 (Preheater -> Boiler)
        #saturated liquid
        state[2] = FluidState.getStateFromTQ(T_boil_C, 0,
                                             self.params.orc_fluid)

        #State 4 (Boiler -> Turbine)
        #saturated vapor
        state[3] = FluidState.getStateFromTQ(state[2].T_C, 1,
                                             self.params.orc_fluid)
        # state[3].P_Pa = state[2].P_Pa

        #State 5 (Turbine -> Desuperheater)
        h_5s = FluidState.getStateFromPS(state[0].P_Pa, state[3].s_JK,
                                         self.params.orc_fluid).h_Jkg
        h_5 = state[3].h_Jkg - self.params.eta_turbine_orc * (state[3].h_Jkg -
                                                              h_5s)
        state[4] = FluidState.getStateFromPh(state[0].P_Pa, h_5,
                                             self.params.orc_fluid)

        # #State 2 (Pump -> Preheater)
        h_2s = FluidState.getStateFromPS(state[2].P_Pa, state[0].s_JK,
                                         self.params.orc_fluid).h_Jkg
        h_2 = state[0].h_Jkg - (
            (state[0].h_Jkg - h_2s) / self.params.eta_pump_orc)
        state[1] = FluidState.getStateFromPh(state[2].P_Pa, h_2,
                                             self.params.orc_fluid)

        results = PowerPlantOutput()

        # #Calculate orc heat/work
        w_pump_orc = state[0].h_Jkg - state[1].h_Jkg
        q_preheater_orc = -1 * (state[1].h_Jkg - state[2].h_Jkg)
        q_boiler_orc = -1 * (state[2].h_Jkg - state[3].h_Jkg)
        w_turbine_orc = state[3].h_Jkg - state[4].h_Jkg
        q_desuperheater_orc = -1 * (state[4].h_Jkg - state[5].h_Jkg)
        q_condenser_orc = -1 * (state[5].h_Jkg - state[0].h_Jkg)

        results.dP_pump_orc = state[1].P_Pa - state[0].P_Pa
        results.P_boil = state[2].P_Pa

        # Cooling Tower Parasitic load
        dT_range = state[4].T_C - state[5].T_C
        parasiticPowerFraction = CoolingCondensingTower.parasiticPowerFraction(
            self.params.T_ambient_C, self.params.dT_approach, dT_range,
            self.params.cooling_mode)
        w_cooler_orc = q_desuperheater_orc * parasiticPowerFraction('cooling')
        w_condenser_orc = q_condenser_orc * parasiticPowerFraction(
            'condensing')

        #water (assume pressure 100 kPa above saturation)
        P_sat = FluidState.getStateFromTQ(T_in_C, 0, 'Water').P_Pa
        cp = FluidState.getStateFromPT(P_sat + 100e3, T_in_C, 'Water').cp_JK
        #Water state 11, inlet, 12, mid, 13 exit
        T_C_11 = T_in_C
        T_C_12 = T_boil_C + dT_pinch
        #mdot_ratio = mdot_orc / mdot_water
        mdot_ratio = cp * (T_C_11 - T_C_12) / q_boiler_orc
        T_C_13 = T_C_12 - mdot_ratio * q_preheater_orc / cp

        # check that T_C(13) isn't below pinch constraint
        if T_C_13 < (state[1].T_C + dT_pinch):
            # pinch constraint is here, not at 12
            # outlet is pump temp plus pinch
            T_C_13 = state[1].T_C + dT_pinch
            R = q_boiler_orc / (q_boiler_orc + q_preheater_orc)
            T_C_12 = T_C_11 - (T_C_11 - T_C_13) * R
            mdot_ratio = cp * (T_C_11 - T_C_12) / q_boiler_orc

        #Calculate water heat/work
        results.q_preheater = mdot_ratio * q_preheater_orc
        results.q_boiler = mdot_ratio * q_boiler_orc
        results.q_desuperheater = mdot_ratio * q_desuperheater_orc
        results.q_condenser = mdot_ratio * q_condenser_orc
        results.w_turbine = mdot_ratio * w_turbine_orc
        results.w_pump = mdot_ratio * w_pump_orc
        results.w_cooler = mdot_ratio * w_cooler_orc
        results.w_condenser = mdot_ratio * w_condenser_orc
        results.w_net = results.w_turbine + results.w_pump + results.w_cooler + results.w_condenser

        # Calculate temperatures
        results.dT_range_CT = state[4].T_C - state[5].T_C
        dT_A_p = T_C_13 - state[1].T_C
        dT_B_p = T_C_12 - state[2].T_C
        if dT_A_p == dT_B_p:
            results.dT_LMTD_preheater = dT_A_p
        else:
            div = dT_A_p / dT_B_p
            results.dT_LMTD_preheater = (dT_A_p - dT_B_p) / (
                math.log(abs(div)) * np.sign(div))

        dT_A_b = T_C_12 - state[2].T_C
        dT_B_b = T_C_11 - state[3].T_C
        if dT_A_b == dT_B_b:
            results.dT_LMTD_boiler = dT_A_b
        else:
            div = dT_A_b / dT_B_b
            results.dT_LMTD_boiler = (dT_A_b - dT_B_b) / (math.log(abs(div)) *
                                                          np.sign(div))

        # return temperature
        results.state = FluidState.getStateFromPT(initialState.P_Pa, T_C_13,
                                                  self.params.working_fluid)

        return results
    def solve(self):

        results = FluidSystemCO2Output()
        results.pp = PowerPlantEnergyOutput()

        # Find condensation pressure
        T_condensation = self.params.T_ambient_C + self.params.dT_approach
        P_condensation = FluidState.getStateFromTQ(T_condensation, 0, self.params.working_fluid).P_Pa + 50e3
        dP_pump = 0

        dP_downhole_threshold = 1e3
        dP_downhole = np.nan
        dP_loops = 1
        dP_solver = Solver()
        while np.isnan(dP_downhole) or np.abs(dP_downhole) >= dP_downhole_threshold:

            # Find Injection Conditions
            P_pump_inlet = P_condensation

            # Only add pump differential if positive. If negative, add as a throttle at the bottom of the injection well
            if (dP_pump > 0):
                P_pump_outlet = P_pump_inlet + dP_pump
            else:
                P_pump_outlet = P_pump_inlet

            T_pump_inlet = T_condensation
            pump_inlet_state = FluidState.getStateFromPT(P_pump_inlet, T_pump_inlet, self.params.working_fluid)

            if dP_pump > 0:
                h_pump_outletS = FluidState.getStateFromPS(P_pump_outlet, pump_inlet_state.s_JK, self.params.working_fluid).h_Jkg
                h_pump_outlet = pump_inlet_state.h_Jkg + (h_pump_outletS - pump_inlet_state.h_Jkg) / self.params.eta_pump_co2
            else:
                h_pump_outlet = pump_inlet_state.h_Jkg

            results.pp.w_pump = -1 * (h_pump_outlet - pump_inlet_state.h_Jkg)

            surface_injection_state = FluidState.getStateFromPh(P_pump_outlet, h_pump_outlet, self.params.working_fluid)

            results.injection_well    = self.injection_well.solve(surface_injection_state)

            # if dP_pump is negative, this is a throttle after the injection well
            if (dP_pump < 0):
                results.injection_well_downhole_throttle = FluidState.getStateFromPh(
                    results.injection_well.state.P_Pa + dP_pump, 
                    results.injection_well.state.h_Jkg, 
                    self.params.working_fluid)
            else:
                results.injection_well_downhole_throttle = FluidState.getStateFromPh(
                    results.injection_well.state.P_Pa, 
                    results.injection_well.state.h_Jkg, 
                    self.params.working_fluid)

            results.reservoir = self.reservoir.solve(results.injection_well_downhole_throttle)

            # find downhole pressure difference (negative means
            # overpressure
            dP_downhole = self.params.P_reservoir() - results.reservoir.state.P_Pa
            dP_pump = dP_solver.addDataAndEstimate(dP_pump, dP_downhole)
            if np.isnan(dP_pump):
                dP_pump = 0.5 * dP_downhole

            if dP_loops > 10:
                print('GenGeo::Warning::FluidSystemCO2:dP_loops is large: %s'%dP_loops)
            dP_loops += 1

        if results.reservoir.state.P_Pa >= self.params.P_reservoir_max():
            raise Exception('GenGeo::FluidSystemCO2:ExceedsMaxReservoirPressure - '
                        'Exceeds Max Reservoir Pressure of %.3f MPa!'%(self.params.P_reservoir_max()/1e6))

        results.production_well  = self.production_well.solve(results.reservoir.state)

        # Subtract surface frictional losses between production wellhead and surface plant
        ff = frictionFactor(self.params.well_radius, results.production_well.state.P_Pa, results.production_well.state.h_Jkg,
            self.params.m_dot_IP, self.params.working_fluid, self.params.epsilon)
        if self.params.has_surface_gathering_system == True:
            dP_surfacePipes = ff * self.params.well_spacing / (self.params.well_radius*2)**5 * 8 * self.params.m_dot_IP**2 / results.production_well.state.rho_kgm3 / 3.14159**2
        else:
            dP_surfacePipes = 0
        
        results.surface_plant_inlet = FluidState.getStateFromPh(
            results.production_well.state.P_Pa - dP_surfacePipes,
            results.production_well.state.h_Jkg,
            self.params.working_fluid)

        # Calculate Turbine Power
        h_turbine_outS = FluidState.getStateFromPS(P_condensation, results.surface_plant_inlet.s_JK, self.params.working_fluid).h_Jkg
        h_turbine_out = results.surface_plant_inlet.h_Jkg - self.params.eta_turbine_co2 * (results.surface_plant_inlet.h_Jkg - h_turbine_outS)

        results.pp.w_turbine = results.surface_plant_inlet.h_Jkg - h_turbine_out
        if results.pp.w_turbine < 0:
            raise Exception('GenGeo::FluidSystemCO2:TurbinePowerNegative - Turbine Power is Negative')

        # heat rejection
        h_satVapor = FluidState.getStateFromPQ(P_condensation, 1,  self.params.working_fluid).h_Jkg
        h_condensed = FluidState.getStateFromPQ(P_condensation, 0,  self.params.working_fluid).h_Jkg
        if h_turbine_out > h_satVapor:
            # desuperheating needed
            results.pp.q_cooler = h_satVapor - h_turbine_out
            results.pp.q_condenser = h_condensed - h_satVapor
            T_turbine_out = FluidState.getStateFromPh(P_condensation, h_turbine_out, self.params.working_fluid).T_C
            dT_range = T_turbine_out - T_condensation
        else:
            # no desuperheating
            results.pp.q_cooler = 0
            results.pp.q_condenser = h_condensed - h_turbine_out
            dT_range = 0

        parasiticPowerFraction = CoolingCondensingTower.parasiticPowerFraction(self.params.T_ambient_C, self.params.dT_approach, dT_range, self.params.cooling_mode)
        results.pp.w_cooler = results.pp.q_cooler * parasiticPowerFraction('cooling')
        results.pp.w_condenser = results.pp.q_condenser * parasiticPowerFraction('condensing')

        results.pp.w_net = results.pp.w_turbine + results.pp.w_pump + results.pp.w_cooler + results.pp.w_condenser

        results.pp.dP_surface = results.surface_plant_inlet.P_Pa - P_condensation
        results.pp.dP_pump = dP_pump

        results.pp.state_out = surface_injection_state

        return results
def heatExchanger(T_1_in, P_1, m_dot_1, fluid_1, T_2_in, P_2, m_dot_2, fluid_2,
                  dT_pinch):

    results = HeatExchangerResults()

    # Only tested where Temp1 < Temp2
    if T_1_in > T_2_in:
        # throw(MException('HeatExchanger:BadTemps','Temp 1 is greater than Temp 2!'));
        # No heat exchanged
        results.T_1_out = T_1_in
        results.T_2_out = T_2_in
        return results

    if m_dot_1 <= 0 or m_dot_2 <= 0:
        raise Exception(
            'GenGeo::HeatExchanger:NegativeMassFlow - Negative Massflow in Heat Exchanger'
        )

    increments = 20
    direction = np.sign(T_1_in - T_2_in)

    # Check the phase on incoming fluid
    P_crit_1 = FluidState.getPcrit(fluid_1)
    if P_1 < P_crit_1:
        T_sat_1 = FluidState.getStateFromPQ(P_1, 1, fluid_1).T_C
        if T_sat_1 == T_1_in or T_sat_1 == T_2_in:
            raise Exception(
                'GenGeo::HeatExchanger:TwoPhaseFluid - Fluid 1 enters or leaves two-phase!'
            )

    P_crit_2 = FluidState.getPcrit(fluid_2)
    if P_2 < P_crit_2:
        T_sat_2 = FluidState.getStateFromPQ(P_2, 1, fluid_2).T_C
        if T_sat_2 == T_1_in or T_sat_2 == T_2_in:
            raise Exception(
                'GenGeo::HeatExchanger:TwoPhaseFluid - Fluid 2 enters or leaves two-phase!'
            )

    h_1_in = FluidState.getStateFromPT(P_1, T_1_in, fluid_1).h_Jkg
    T_1_max = T_2_in
    h_1_max = FluidState.getStateFromPT(P_1, T_1_max, fluid_1).h_Jkg
    T_1_max_practical = T_2_in + direction * dT_pinch
    h_1_max_practical = FluidState.getStateFromPT(P_1, T_1_max_practical,
                                                  fluid_1).h_Jkg
    h_2_in = FluidState.getStateFromPT(P_2, T_2_in, fluid_2).h_Jkg
    T_2_max = T_1_in
    h_2_max = FluidState.getStateFromPT(P_2, T_2_max, fluid_2).h_Jkg
    T_2_max_practical = T_1_in - direction * dT_pinch
    h_2_max_practical = FluidState.getStateFromPT(P_2, T_2_max_practical,
                                                  fluid_2).h_Jkg

    Q_1_max = abs(m_dot_1 * (h_1_in - h_1_max))
    Q_2_max = abs(m_dot_2 * (h_2_in - h_2_max))
    Q_1_max_practical = abs(m_dot_1 * (h_1_in - h_1_max_practical))
    Q_2_max_practical = abs(m_dot_2 * (h_2_in - h_2_max_practical))

    if abs(Q_1_max) < abs(Q_2_max):
        # limitingFluid = 1;
        Q_max = Q_1_max
        Q_max_practical = Q_1_max_practical
    else:
        # limtingFluid = 2;
        Q_max = Q_2_max
        Q_max_practical = Q_2_max_practical

    results.Q_exchanged = Q_max_practical
    ddT_pinch = 1

    length = increments + 1
    results.Q = np.zeros(length)
    h_1 = np.zeros(length)
    results.T_1 = np.zeros(length)
    h_2 = np.zeros(length)
    results.T_2 = np.zeros(length)
    dT = np.zeros(length)
    UA = np.zeros(length)

    while ddT_pinch > 0.1:

        dQ = results.Q_exchanged / increments

        results.Q[0] = 0.
        h_1[0] = h_1_in
        results.T_1[0] = T_1_in
        h_2[0] = (Q_2_max - results.Q_exchanged) / m_dot_2 + h_2_max
        results.T_2[0] = FluidState.getStateFromPh(P_2, h_2[0], fluid_2).T_C
        dT[0] = direction * (results.T_1[0] - results.T_2[0])
        UA[0] = dQ / dT[0]

        for i in range(1, increments + 1):
            results.Q[i] = results.Q[i - 1] + dQ
            h_1[i] = h_1[i - 1] + dQ / m_dot_1
            h_2[i] = h_2[i - 1] + dQ / m_dot_2
            results.T_1[i] = FluidState.getStateFromPh(P_1, h_1[i],
                                                       fluid_1).T_C
            results.T_2[i] = FluidState.getStateFromPh(P_2, h_2[i],
                                                       fluid_2).T_C
            dT[i] = direction * (results.T_1[i] - results.T_2[i])
            UA[i] = dQ / dT[i]

        min_dT = min(dT)
        ddT_pinch = dT_pinch - min_dT

        # Adjust Q_exchanged
        # Use proportional error approach
        change = ddT_pinch / (T_2_in - T_1_in)
        results.Q_exchanged = (1 - change) * results.Q_exchanged

    results.dT_LMTD = results.Q_exchanged / sum(UA)
    effectiveness = results.Q_exchanged / Q_max
    results.T_1_out = results.T_1[-1]
    results.T_2_out = results.T_2[0]

    # Check the phase on leaving fluid
    if P_1 < P_crit_1:
        T_sat_1 = FluidState.getStateFromPQ(P_1, 1, fluid_1).T_C
        if T_sat_1 > T_1_in and T_sat_1 < results.T_1_out:
            print('Caution: Fluid 1 is phase changing in heat exchanger')
        if T_sat_1 == results.T_1_out:
            raise Exception(
                'GenGeo::HeatExchanger:TwoPhaseFluid - Fluid 1 leaves two-phase!'
            )

    if P_2 < P_crit_2:
        T_sat_2 = FluidState.getStateFromPQ(P_2, 1, fluid_2).T_C
        if T_sat_2 > T_2_in and T_sat_2 < results.T_2_out:
            print('Caution: Fluid 2 is phase changing in heat exchanger')
        if T_sat_2 == results.T_2_out:
            raise Exception(
                'GenGeo::HeatExchanger:TwoPhaseFluid - Fluid 2 leaves two-phase!'
            )

    return results
Beispiel #5
0
    def solve(self, initial_state):

        m_dot = self.params.m_dot_IP * self.m_dot_multiplier

        # results
        results = SemiAnalyticalWellResults(self.params.well_segments, self.params.working_fluid)

        P_f_initial = initial_state.P_Pa
        T_f_initial = initial_state.T_C
        time_seconds = self.params.time_years * ConversionConstants.secPerYear

        # set geometry
        dz = self.dz_total/self.params.well_segments             # m
        dr = self.dr_total/self.params.well_segments             # m
        dL = (dz**2 + dr**2)**0.5                       # m
        A_c = np.pi * self.params.well_radius**2        # m**2
        P_c = np.pi * 2 * self.params.well_radius       # m

        # set states
        results.T_C_f[0] = T_f_initial             # C
        results.T_C_e[0] = self.T_e_initial        # C
        results.P_Pa[0] = P_f_initial              # Pa
        results.h_Jkg[0] = FluidState.getStateFromPT(results.P_Pa[0], results.T_C_f[0], self.params.working_fluid).h_Jkg
        results.rho_kgm3[0] = FluidState.getStateFromPT(results.P_Pa[0], results.T_C_f[0], self.params.working_fluid).rho_kgm3
        results.v_ms[0] = m_dot / A_c / results.rho_kgm3[0]  #m/s

        # Calculate the Friction Factor
        # Use Colebrook-white equation for wellbore friction loss.
        # Calculate for first element and assume constant in remainder
        ff = frictionFactor(self.params.well_radius, results.P_Pa[0], results.h_Jkg[0], \
                            m_dot, self.params.working_fluid, self.params.epsilon)

        alpha_rock = self.params.k_rock/self.params.rho_rock/self.params.c_rock  #D rock
        t_d = alpha_rock*time_seconds/(self.params.well_radius**2)  #dim
        if t_d < 2.8:
            beta = ((np.pi*t_d)**-0.5 + 0.5 - 0.25*(t_d/np.pi)**0.5 + 0.125*t_d)
        else:
            beta = (2/(np.log(4*t_d)-2*0.58) - 2*0.58/(np.log(4*t_d)-2*0.58)**2)

        # loop over all well segments
        for i in range(1, self.params.well_segments+1):
            results.z_m[i] = results.z_m[i-1] + dz

            # far-field rock temp
            results.T_C_e[i] = results.T_C_e[0] - results.z_m[i] * self.params.dT_dz
            # fluid velocity
            results.v_ms[i] = m_dot / A_c / results.rho_kgm3[i-1]  #m/s

            # Calculate Pressure
            results.delta_P_loss[i] = ff * dL / ( 2 * self.params.well_radius) * \
                                            results.rho_kgm3[i-1] * \
                                            results.v_ms[i]**2. / 2.  #Pa
            results.rho_kgm3[i] = FluidState.getStateFromPh(results.P_Pa[i-1], results.h_Jkg[i-1], self.params.working_fluid).rho_kgm3
            results.P_Pa[i]     = results.P_Pa[i-1] - results.rho_kgm3[i] * \
                                        self.params.g * dz - results.delta_P_loss[i]

            # Throw exception if below saturation pressure of water at previous temperature
            if self.params.working_fluid.lower() == 'water':
                P_sat = FluidState.getStateFromTQ(results.T_C_f[i-1], 0, self.params.working_fluid).P_Pa
                if results.P_Pa[i] < P_sat:
                    raise Exception('GenGeo::SemiAnalyticalWell:BelowSaturationPressure - '
                    'Below saturation pressure of water at %s m !' %(results.z_m[i]))

            h_noHX = results.h_Jkg[i-1] - self.params.g * dz
            T_noHX = FluidState.getStateFromPh(results.P_Pa[i], h_noHX, self.params.working_fluid).T_C
            results.cp_JK[i] = FluidState.getStateFromPh(results.P_Pa[i], h_noHX, self.params.working_fluid).cp_JK

            #Find Fluid Temp
            if not self.params.useWellboreHeatLoss:
                results.T_C_f[i] = T_noHX
                results.h_Jkg[i] = h_noHX
                results.q[i] = 0.
            else:
                # See Zhang, Pan, Pruess, Finsterle (2011). A time-convolution
                # approach for modeling heat exchange between a wellbore and
                # surrounding formation. Geothermics 40, 261-266.
                x = dL * P_c * self.params.k_rock * beta / self.params.well_radius
                y = m_dot * results.cp_JK[i]
                if math.isinf(x):
                    results.T_C_f[i] = results.T_C_e[i]
                else:
                    results.T_C_f[i] = (y * T_noHX + x *results. T_C_e[i]) / (x + y)
                results.q[i] = y * (T_noHX - results.T_C_f[i])
                results.h_Jkg[i] = FluidState.getStateFromPT(results.P_Pa[i], results.T_C_f[i], self.params.working_fluid).h_Jkg
        # make sure state object is set
        results.createFinalState()

        return results
Beispiel #6
0
    def solve(self, initial_state):

        results = FluidSystemWaterOutput()

        injection_state = FluidState.getStateFromPT(initial_state.P_Pa,
                                                    initial_state.T_C,
                                                    initial_state.fluid)
        # Find necessary injection pressure
        dP_downhole = np.nan
        dP_solver = Solver()
        dP_loops = 1
        stop = False

        while np.isnan(dP_downhole) or abs(dP_downhole) > 10e3:
            results.injection_well = self.injection_well.solve(injection_state)
            results.reservoir = self.reservoir.solve(
                results.injection_well.state)

            # if already at P_system_min, stop looping
            if stop:
                break

            # find downhole pressure difference (negative means overpressure)
            dP_downhole = self.params.P_reservoir(
            ) - results.reservoir.state.P_Pa
            injection_state.P_Pa = dP_solver.addDataAndEstimate(
                injection_state.P_Pa, dP_downhole)

            if np.isnan(injection_state.P_Pa):
                injection_state.P_Pa = initial_state.P_Pa + dP_downhole

            if dP_loops > 10:
                print(
                    'GenGeo::Warning:FluidSystemWater:dP_loops is large: %s' %
                    dP_loops)
            dP_loops += 1

            # Set Limits
            if injection_state.P_Pa < self.params.P_system_min():
                # can't be below this temp or fluid will flash
                injection_state.P_Pa = self.params.P_system_min()
                # switch stop to run injection well and reservoir once more
                stop = True

        if results.reservoir.state.P_Pa >= self.params.P_reservoir_max():
            raise Exception(
                'GenGeo::FluidSystemWater:ExceedsMaxReservoirPressure - '
                'Exceeds Max Reservoir Pressure of %.3f MPa!' %
                (self.params.P_reservoir_max() / 1e6))

        # Production Well (Lower, to production pump)
        results.production_well1 = self.production_well1.solve(
            results.reservoir.state)
        # Upper half of production well
        results.pump = self.pump.solve(results.production_well1.state,
                                       injection_state.P_Pa)

        # Subtract surface frictional losses between production wellhead and surface plant
        ff = frictionFactor(self.params.well_radius,
                            results.pump.well.state.P_Pa,
                            results.pump.well.state.h_Jkg,
                            self.params.m_dot_IP, self.params.working_fluid,
                            self.params.epsilon)
        if self.params.has_surface_gathering_system == True:
            dP_surfacePipes = ff * self.params.well_spacing / (
                self.params.well_radius * 2
            )**5 * 8 * self.params.m_dot_IP**2 / results.pump.well.state.rho_kgm3 / np.pi**2
        else:
            dP_surfacePipes = 0

        results.surface_plant_inlet = FluidState.getStateFromPh(
            results.pump.well.state.P_Pa - dP_surfacePipes,
            results.pump.well.state.h_Jkg, self.params.working_fluid)

        results.pp = self.pp.solve(results.surface_plant_inlet)
        return results
    def solve(self, initialState, P_boil_Pa=False):

        T_in_C = initialState.T_C

        if not P_boil_Pa:
            P_boil_Pa = np.interp(T_in_C, self.data[:, 0], self.data[:, 1])
        # Critical point of R245fa
        # if Pboil is below critical, throw error
        if P_boil_Pa < FluidState.getPcrit(self.params.orc_fluid):
            raise Exception(
                'GenGeo::ORCCycleSupercritPboil:lowBoilingPressure - Boiling Pressure Below Critical Pressure'
            )
        # The line of minimum entropy to keep the fluid vapor in turbine is
        # entropy at saturated vapor at 125C. So inlet temp must provide this
        # minimum entropy.
        s_min = FluidState.getStateFromTQ(125., 1, self.params.orc_fluid).s_JK
        T_min = FluidState.getStateFromPS(P_boil_Pa, s_min,
                                          self.params.orc_fluid).T_C
        if (T_in_C - self.params.dT_pinch) < T_min:
            raise Exception(
                'GenGeo::ORCCycleSupercritPboil:lowInletTemp - Inlet Temp below %.1f C for Supercritical Fluid'
                % (T_min + self.params.dT_pinch))

        T_condense_C = self.params.T_ambient_C + self.params.dT_approach

        # create empty list to compute cycle of 7 states
        state = [None] * 7

        #State 1 (Condenser -> Pump)
        #saturated liquid
        state[0] = FluidState.getStateFromTQ(T_condense_C, 0,
                                             self.params.orc_fluid)

        # State 7 (Desuperheater -> Condenser)
        # saturated vapor
        state[6] = FluidState.getStateFromTQ(state[0].T_C, 1,
                                             self.params.orc_fluid)

        # State 2 (Pump -> Recuperator)
        h_2s = FluidState.getStateFromPS(P_boil_Pa, state[0].s_JK,
                                         self.params.orc_fluid).h_Jkg
        h2 = state[0].h_Jkg - (
            (state[0].h_Jkg - h_2s) / self.params.eta_pump_orc)
        state[1] = FluidState.getStateFromPh(P_boil_Pa, h2,
                                             self.params.orc_fluid)

        # water (assume pressure 100 kPa above saturation)
        P_water = FluidState.getStateFromTQ(T_in_C, 0, 'Water').P_Pa + 100e3

        # Guess orc_in fluid is state[1].T_C
        state[2] = FluidState.getStateFromPT(state[1].P_Pa, state[1].T_C,
                                             self.params.orc_fluid)
        # Water in temp is T_in_C
        T_C_11 = T_in_C
        P_4 = state[1].P_Pa

        # initialize state 2 with pressure state 2 and dummy temperature
        state[3] = FluidState.getStateFromPT(P_4, 15., self.params.orc_fluid)

        # initialize state 3 with pressure state 1 and dummy enthalpy
        state[4] = FluidState.getStateFromPh(state[0].P_Pa, 1e4,
                                             self.params.orc_fluid)

        # initialize state 6 with pressure state 1 and dummy temperature
        state[5] = FluidState.getStateFromPT(state[0].P_Pa, 15.,
                                             self.params.orc_fluid)

        results = PowerPlantOutput()

        dT = 1
        while abs(dT) >= 1:
            # State 4 (Boiler -> Turbine)
            # Input orc/geo heat exchanger
            opt_heatExchanger_results = heatExchangerOptMdot(
                state[2].T_C, P_4, self.params.orc_fluid, T_C_11, P_water,
                'Water', self.params.dT_pinch, T_min)
            # state[3] = FluidStateFromPT(P_4, opt_heatExchanger_results.T_1_out, self.params.orc_fluid)
            state[3].T_C = opt_heatExchanger_results.T_1_out

            #State 5 (Turbine -> Recuperator)
            h_5s = FluidState.getStateFromPS(state[0].P_Pa, state[3].s_JK,
                                             self.params.orc_fluid).h_Jkg
            h_5 = state[3].h_Jkg - self.params.eta_turbine_orc * (
                state[3].h_Jkg - h_5s)
            state[4].h_Jkg = h_5
            # state[4] =  FluidStateFromPh(state[0].P_Pa(), h_5, self.params.orc_fluid)

            # State 3 (Recuperator -> Boiler)
            # State 6 (Recuperator -> Desuperheater)
            # Assume m_dot for each fluid is 1, then output is specific heat
            # exchange
            heatExchanger_results = heatExchanger(state[1].T_C, state[1].P_Pa,
                                                  1, self.params.orc_fluid,
                                                  state[4].T_C, state[0].P_Pa,
                                                  1, self.params.orc_fluid,
                                                  self.params.dT_pinch)

            # state[2] = FluidStateFromPT(state[2].P_Pa, state[2].T_C, self.params.orc_fluid)
            # state[5] = FluidStateFromPT(state[0].P_Pa, heatExchanger_results.T_2_out, self.params.orc_fluid)
            state[5].T_C = heatExchanger_results.T_2_out

            dT = state[2].T_C - heatExchanger_results.T_1_out
            state[2].T_C = heatExchanger_results.T_1_out

        #Calculate orc heat/work
        w_pump_orc = state[0].h_Jkg - state[1].h_Jkg
        q_boiler_orc = -1 * (state[2].h_Jkg - state[3].h_Jkg)
        w_turbine_orc = state[3].h_Jkg - state[4].h_Jkg
        q_desuperheater_orc = -1 * (state[5].h_Jkg - state[6].h_Jkg)
        q_condenser_orc = -1 * (state[6].h_Jkg - state[0].h_Jkg)

        # Cooling Tower Parasitic load
        results.dT_range_CT = state[5].T_C - state[6].T_C
        parasiticPowerFraction = CoolingCondensingTower.parasiticPowerFraction(
            self.params.T_ambient_C, self.params.dT_approach,
            results.dT_range_CT, self.params.cooling_mode)
        w_cooler_orc = q_desuperheater_orc * parasiticPowerFraction('cooling')
        w_condenser_orc = q_condenser_orc * parasiticPowerFraction(
            'condensing')

        #Calculate water heat/work
        results.w_pump = opt_heatExchanger_results.mdot_ratio * w_pump_orc
        results.q_boiler = opt_heatExchanger_results.mdot_ratio * q_boiler_orc
        results.w_turbine = opt_heatExchanger_results.mdot_ratio * w_turbine_orc
        results.q_recuperator = opt_heatExchanger_results.mdot_ratio * heatExchanger_results.Q_exchanged
        results.q_desuperheater = opt_heatExchanger_results.mdot_ratio * q_desuperheater_orc
        results.q_condenser = opt_heatExchanger_results.mdot_ratio * q_condenser_orc
        results.w_cooler = opt_heatExchanger_results.mdot_ratio * w_cooler_orc
        results.w_condenser = opt_heatExchanger_results.mdot_ratio * w_condenser_orc

        results.w_net = results.w_turbine + results.w_pump + results.w_cooler + results.w_condenser

        results.end_T_C = opt_heatExchanger_results.T_2_out
        results.dT_LMTD_boiler = opt_heatExchanger_results.dT_LMTD
        results.dT_LMTD_recuperator = heatExchanger_results.dT_LMTD

        # return temperature
        results.state = FluidState.getStateFromPT(
            initialState.P_Pa, opt_heatExchanger_results.T_2_out,
            self.params.working_fluid)

        return results