Ejemplo n.º 1
0
    public void add_heat_constant_v(double j)
    {
        try
        {
            double new_u = internalenergy + j;
            double new_t = ThermoMath.iterate_t_given_v_verify_u(temperature, volume, new_u);

            //at this point, we have enough internal state to derive the rest
            internalenergy = new_u;
            temperature    = new_t;
            pressure       = ThermoMath.p_given_vt(volume, temperature);
            enthalpy       = ThermoMath.h_given_vt(volume, temperature);
            entropy        = ThermoMath.s_given_vt(volume, temperature);

            region = ThermoMath.region_given_pvt(pressure, volume, temperature);
            switch (region)
            {
            case 0: quality = 0;                                       break; //subcooled liquid

            case 1: quality = ThermoMath.x_given_pv(pressure, volume); break; //two-phase region

            case 2: quality = 1;                                       break; //superheated vapor
            }
        }
        catch (Exception e) {}

        clamp_state();
        visualize_state();
    }
Ejemplo n.º 2
0
    public void add_pressure_insulated(double p)
    {
        try
        {
            double new_p = pressure + p;

            switch (region)
            {
            case 0: //subcooled liquid
            case 1: //two-phase region
            {
                //AVOID THESE SCENARIOS
            }
            break;

            case 2: //superheated vapor
            {
                //default guess
                double new_t = temperature;
                double new_u = internalenergy;
                double new_v = volume;

                double k = 1.27;
                new_v = volume * Math.Pow(pressure / new_p, 1.0 / k);
                new_u = internalenergy - ((new_p * new_v - pressure * volume) / (1 - k));
                new_t = ThermoMath.iterate_t_given_p_verify_u(temperature, pressure, new_u);

                //at this point, we have enough internal state to derive the rest
                pressure       = new_p;
                volume         = new_v;
                temperature    = new_t;
                internalenergy = new_u;
                enthalpy       = ThermoMath.h_given_vt(volume, temperature);
                entropy        = ThermoMath.s_given_vt(volume, temperature);
                region         = ThermoMath.region_given_pvt(pressure, volume, temperature);
            }
            break;
            }
        }
        catch (Exception e) {}

        clamp_state();
        visualize_state();
    }
Ejemplo n.º 3
0
    public void add_pressure_uninsulated(double p)
    {
        try
        {
            double new_p = pressure + p;

            switch (region)
            {
            case 0: //subcooled liquid
            case 1: //two-phase region
            {
                //AVOID THESE SCENARIOS
                return;
            }
            break;

            case 2: //superheated vapor
            {
                //default guess
                double new_u = internalenergy;
                double new_v = volume;

                //already done!
                new_v = ThermoMath.v_given_pt(new_p, temperature);
                new_u = ThermoMath.u_given_pt(new_p, temperature);
                //at this point, we have enough internal state to derive the rest
                pressure       = new_p;
                volume         = new_v;
                internalenergy = new_u;
                enthalpy       = ThermoMath.h_given_vt(volume, temperature);
                entropy        = ThermoMath.s_given_vt(volume, temperature);
                region         = ThermoMath.region_given_pvt(pressure, volume, temperature);
            }
            break;
            }
        }
        catch (Exception e) {}

        clamp_state();
        visualize_state();
    }
Ejemplo n.º 4
0
    void reset_state()
    {
        //ensure consistent state
        pressure    = ThermoMath.p_neutral;
        temperature = ThermoMath.t_neutral;
        //from this point, the rest should be derived!
        volume         = ThermoMath.v_given_pt(pressure, temperature);
        internalenergy = ThermoMath.u_given_pt(pressure, temperature);
        enthalpy       = ThermoMath.h_given_vt(volume, temperature);
        entropy        = ThermoMath.s_given_vt(volume, temperature);
        quality        = ThermoMath.x_neutral;
        region         = ThermoMath.region_given_pvt(pressure, volume, temperature);

        prev_pressure       = -1;
        prev_temperature    = -1;
        prev_volume         = -1;
        prev_internalenergy = -1;
        prev_entropy        = -1;
        prev_enthalpy       = -1;
        prev_quality        = -1;
        prev_region         = -1;
    }