示例#1
0
 protected AbstractNode(AbstractState state, AbstractState target, AbstractNode Parent, AbstractAction action)
 {
     this.State = state;
     this.Target = target;
     this.Parent = Parent;
     this.Action = action;
 }
示例#2
0
        public TileHandler(AbstractState state)
        {
            this._state = state;

            int ySize = this._state.Form.Height / TileHandler.TILE_HEIGHT;
            int xSize = this._state.Form.Width / TileHandler.TILE_WIDTH;

            this.Map = new Tile[xSize, ySize];
        }
示例#3
0
 /**
  * This method registers a state in the handler's internal list.
  */
 public void addState(AbstractState state)
 {
     lock(this._lockObj) {
         state.Location = new System.Drawing.Point (0, 0);
         state.Size = this._form.Size;
         state.Form = this._form;
         this._states.Add(state);
     }
 }
示例#4
0
文件: Player.cs 项目: Railec/SE1cKBS
        public override void CheckCollision(AbstractState state)
        {
            base.CheckCollision (state);

            //Entity collision
            RectangleF pyRectF = new RectangleF(this.posVector.x+(this.Sprite.Image.Width*0.25f), this.posVector.y, (this.Sprite.Image.Width*0.5f), this.Sprite.Image.Height);
            RectangleF pxRectF = new RectangleF(this.posVector.x, this.posVector.y+(this.Sprite.Image.Height*0.25f), this.Sprite.Image.Width, (this.Sprite.Image.Height*0.5f));

            List<Entity> list = ((GameState)state).GetEntityHandler().GetEntitiesBy(delegate(Entity ent) {
                if(ent.Equals(this) || !ent.GetCollidable()) return false;

                Rectangle eRect = new Rectangle((int)Math.Floor(ent.posVector.x), (int)Math.Floor(ent.posVector.y), ent.Sprite.Image.Width, ent.Sprite.Image.Height);
                Rectangle oRect = new Rectangle((int)Math.Floor(this.posVector.x), (int)Math.Floor(this.posVector.y), this.Sprite.Image.Width, this.Sprite.Image.Height);
                if(eRect.IntersectsWith(oRect)) {
                    return true;
                }
                return false;
            });

            foreach(Entity e in list) {
                RectangleF ttrect = new RectangleF(e.posVector.x, e.posVector.y, e.Sprite.Image.Width, (e.Sprite.Image.Height*0.25f));
                RectangleF trrect = new RectangleF(e.posVector.x, e.posVector.y+(e.Sprite.Image.Height*0.25f), (e.Sprite.Image.Width*0.25f), (e.Sprite.Image.Height*0.5f));
                RectangleF tbrect = new RectangleF(e.posVector.x, e.posVector.y+(e.Sprite.Image.Height*0.75f), e.Sprite.Image.Width, (e.Sprite.Image.Height*0.25f));
                RectangleF tlrect = new RectangleF(e.posVector.x+(e.Sprite.Image.Width*0.75f), e.posVector.y+(e.Sprite.Image.Height*0.25f), (e.Sprite.Image.Width*0.25f), (e.Sprite.Image.Height*0.5f));

                byte collide = 0;
                if(movVector.y >= 0 && pyRectF.IntersectsWith(ttrect)) {
                    collide |= 1;
                } else if(movVector.y <= 0 && pyRectF.IntersectsWith(tbrect)) {
                    collide |= 2;
                }

                if(movVector.x > 0 && pxRectF.IntersectsWith(trrect)) {
                    collide |= 4;
                } else if(movVector.x < 0 && pxRectF.IntersectsWith(tlrect)) {
                    collide |= 8;
                }

                if(e.OnCollision(this, collide)) {
                    if((collide & 1) != 0) {
                        this._airborne = false;
                        this.SetMovement(this.movVector.x, 0);
                        this.SetPosition(this.posVector.x, e.posVector.y-this.Sprite.Image.Height);
                    } else if((collide & 2) != 0) {
                        this.SetMovement(this.movVector.x, 0);
                        this.SetPosition(this.posVector.x, e.posVector.y+e.Sprite.Image.Height);
                    }
                    if((collide & 4) != 0) {
                        this.SetPosition(e.posVector.x-this.Sprite.Image.Width, this.posVector.y);
                    } else if((collide & 8) != 0) {
                        this.SetPosition(e.posVector.x+e.Sprite.Image.Width, this.posVector.y);
                    }
                }
            }
        }
示例#5
0
    /// <summary>
    /// Sets the given state as the default & current state. When creating a state machine the
    /// initial state should be added with this method.
    /// </summary>
    /// <param name="state">Default state.</param>
    public virtual void AddDefaultState(AbstractState state)
    {
        // Add the passed state into the Dictionary.
        AddState(state);

        // Set the state as the default state to transition to upon call to Reset.
        defaultStateId = state.ID;

        // Set this state as the current state.
        Transition(state.ID);
    }
示例#6
0
        /**
         * This is the constructor for the StateHandler.
         * In it a new state handler will register its parent form and it will create a new Timer.
         * The Timer is used to update the current active state every 10ms.
         */
        public StateHandler(Form form)
        {
            this._form = form;
            this._active = null;
            this._states = new List<AbstractState> ();

            this._updateTimer = new System.Timers.Timer(10);
            this._updateTimer.Elapsed += new ElapsedEventHandler(this.updateActiveState);
            this._updateTimer.SynchronizingObject = this._form;
            this._updateTimer.Start();
        }
示例#7
0
        /**
         * This method activates a new state.
         * It will deactivate the current active state.
         * The name argument that is passed should match the Name propery of a registered state.
         * It will call the Show() method on the new state as well as its Construct() method.
         */
        public void activateState(string name)
        {
            deactivateState();
            lock(this._lockObj) {
                foreach(AbstractState a in _states) {
                    if(a.Name == name) {
                        this._active = a;

                        this._form.Controls.Add(this._active);
                        this._active.Construct();
                        this._active.Show();
                        this._form.Focus();
                        break;
                    }
                }
            }
        }
示例#8
0
    public Agent(int _id, int lifespan, AbstractState[] _states, Tile _currentTile)
    {
        id = _id;
        states = _states;

        //Attributes Update
        attributes = new Dictionary<string, int> ();
        attributes.Add (Map.Lifespan, lifespan);

        foreach (AbstractState state in states) {
            if(state.AttributesRequired!=null){
                foreach(string requirement in state.AttributesRequired){
                    attributes[requirement] = Map.STARTING_ATTRIBUTE_VALUE;
                }
            }
        }

        MAX_LIFESPAN = lifespan;
        currentTile = _currentTile;
    }
示例#9
0
文件: Player.cs 项目: Railec/SE1cKBS
        public override void Update(AbstractState state, float interval)
        {
            base.Update(state, interval);

            if (this.IsAnimated()) {
                if (this._animationStage == 3 && this.left == true) {
                    this._animationStage = -1;
                }
                if (this._animationStage == 7 && this.right == true) {
                    this._animationStage = 3;
                }
            }
            if(this.movVector.x != 0 || this.movVector.y != 0) {
                this.SetPosition(this.posVector.x + this.movVector.x, this.posVector.y + this.movVector.y);
            }
            if (this.posVector.y + this.Sprite.Image.Height + 20 > state.Form.ClientSize.Height)
            {
                this.Alive = false;
            }
        }
示例#10
0
 public InferenceNode(AbstractNode parent, AbstractState target, AbstractState state, AbstractAction action)
     : base(state, target, parent, action)
 {
     this.PathCost = this.Parent.PathCost + 1;
     this.EstimatedTotalPathCost = this.State.Clause.Count;
 }
示例#11
0
 public survivorAI()
 {
     State = new StandByState (this);
 }
示例#12
0
 public void Initialize(ref AbstractState state)
 {
     StateSelected = state;
     Init();
 }
示例#13
0
        public static CalcResult ElementCalc3(string fluid, double l, double Aa_fin, double Aa_tube, double A_r_cs, double Ar, Geometry geo, double tai,
                                              double RHi, double tri, double pri, double hri, double mr, double g, double ma, double ha, double haw,
                                              double eta_surface, double zh, double zdp, int hexType, double thickness, double conductivity, double Pwater, AbstractState coolprop, double[,] SourceTableData)
        {
            Model.HumidAirProp humidairprop = new Model.HumidAirProp();

            RHi = RHi > 1 ? 1 : RHi;
            double     dh         = geo.Di;
            double     Q          = 0;
            double     Tout_a     = 0;
            double     Q_sensible = 0;
            double     r_metal    = thickness / conductivity / Ar;
            CalcResult res        = new CalcResult();

            coolprop.update(input_pairs.HmassP_INPUTS, hri * 1000, (fluid == "Water" ? Pwater : pri) * 1000);
            double mu_r = coolprop.viscosity();
            //double mu_r = CoolProp.PropsSI("V", "H", hri * 1000, "P", (fluid == "Water" ? Pwater : pri) * 1000, fluid);
            double k_r = coolprop.conductivity();
            //double k_r = CoolProp.PropsSI("L", "H", hri * 1000, "P", (fluid == "Water" ? Pwater : pri) * 1000, fluid);
            double rho_r = coolprop.rhomass();
            //double rho_r = CoolProp.PropsSI("D", "H", hri * 1000, "P", (fluid == "Water" ? Pwater : pri) * 1000, fluid);
            double cp_r = coolprop.cpmass();
            //double cp_r = CoolProp.PropsSI("C", "H", hri * 1000, "P", (fluid == "Water" ? Pwater : pri) * 1000, fluid);

            double Pr_r = cp_r * mu_r / k_r;

            res.Vel_r = g / rho_r;
            double Re_r    = rho_r * res.Vel_r * dh / mu_r;
            double fh      = RefrigerantSPHTC.ff_CHURCHILL(Re_r);
            double Nusselt = RefrigerantSPHTC.NU_GNIELINSKI(Re_r, Pr_r, fh);

            res.href = Nusselt * k_r / dh * zh;
            double cp_da = 1.0;

            cp_da = (hexType == 0 ? 1.027 : 1.02) * 1000;
            double Tin_a = tai;
            double Tin_r = tri;

            //double cp_da0 = CoolProp.HAPropsSI("C", "T", Tin_a + 273.15, "P", 101325, "R", RHi);
            //cp_da = 1005.1458551 + 0.1541627 * Tin_a + 4.3454442 * RHi - 0.0090904 * Math.Pow(Tin_a, 2) - 0.3409659 * Math.Pow(RHi, 2) - 0.0007819 * Tin_a * RHi + 0.0001851 * Math.Pow(Tin_a, 3) + 0.0049274 * Math.Pow(RHi, 3) + 0.0476513 * Tin_a * Math.Pow(RHi, 2) + 0.020268209 * Math.Pow(Tin_a, 2) * RHi;
            cp_da = humidairprop.Cp(Tin_a, RHi, SourceTableData);

            double h_r        = res.href;
            double k_fin      = 237;
            double Fthickness = geo.Fthickness;
            double Pt         = geo.Pt;
            double Pr         = geo.Pr;
            double Do         = geo.Do;

            //double h_fin = (Pt - Do) / 2;
            //double dc = Do + 2 * Fthickness;
            //double df = Math.Pow(4 / Math.PI * Pt * Pr, 0.5);
            //double eta_a = 1 / (1 + ha * Math.Pow(df - dc, 2) * Math.Pow(df, 0.5) / 6 / Fthickness / k_fin / Math.Pow(dc, 0.5));
            //double m = Math.Sqrt(2 * ha / (k_fin * Fthickness));
            //double eta_a= Math.Tanh(m * h_fin) / (m * h_fin);// may cause error
            //double eta_dry = eta_surface;

            double r_eta = Do / 2;
            double XD    = Math.Pow((Pr * Pr + Pt * Pt / 4), 0.5) / 2;
            double XT    = Pt / 2;
            double rf_r  = 1.27 * XT / r_eta * Math.Pow((XD / XT - 0.3), 0.5);
            double m     = Math.Pow((2 * ha / k_fin / Fthickness), 0.5);
            double fai   = (rf_r - 1) * (1 + (0.3 + Math.Pow((m * r_eta * (rf_r - r_eta) / 2.5), (1.5 - 1 / 12 * rf_r)) * (0.26 * Math.Pow(rf_r, 0.3) - 0.3)) * Math.Log(rf_r));
            double eta_0 = Math.Tanh(m * r_eta * fai) / m / r_eta / fai * Math.Cos(0.1 * m * r_eta * fai);
            double eta_a = (eta_0 * Aa_fin + Aa_tube) / (Aa_fin + Aa_tube);

            double UA_i        = h_r * Ar;
            double UA_o        = eta_a * (Aa_fin + Aa_tube) * ha;
            double Ntu_i       = UA_i / (mr * cp_r);
            double Ntu_o       = UA_o / (ma * cp_da);
            double UA          = 1 / (1 / (UA_i) + 1 / (UA_o) + r_metal);
            double Cmin        = Math.Min(cp_r * mr, cp_da * ma);
            double Cmax        = Math.Max(cp_r * mr, cp_da * ma);
            double C_star      = Cmin / Cmax;
            double Ntu_dry     = UA / Cmin;
            double epsilon_dry = (1 - Math.Exp(-Ntu_dry * (1 - C_star))) / (1 - C_star * Math.Exp(-Ntu_dry * (1 - C_star)));
            double Q_dry       = epsilon_dry * Cmin * (Tin_a - Tin_r) * Math.Pow(-1, hexType);//need to be modified//所以蒸发器算不出Q
            double Tout_a_dry  = Tin_a - Q_dry / (ma * cp_da) * Math.Pow(-1, hexType);
            double Tout_r      = Tin_r + Q_dry / (mr * cp_r) * Math.Pow(-1, hexType);
            double Tout_s      = (UA_o * Tout_a_dry + UA_i * Tin_r) / (UA_o + UA_i);
            double Tin_s       = (UA_o * Tin_a + UA_i * Tout_r) / (UA_o + UA_i);
            double Tout_r_dry  = Tout_r;
            double f_dry       = 1.0;
            //double omega_in0 = CoolProp.HAPropsSI("W", "T", Tin_a + 273.15, "P", 101325, "R", RHi);
            //double omega_in = (-0.0682340 + 0.0292341 * Tin_a + 4.1604535 * RHi - 0.0025985 * Math.Pow(Tin_a, 2) - 0.0769009 * Math.Pow(RHi, 2) + 0.1246489 * Tin_a * RHi + 6.008 * Math.Pow(10, -5) * Math.Pow(Tin_a, 3) - 0.0006775 * Math.Pow(RHi, 3) + 0.0267183 * Tin_a * Math.Pow(RHi, 2) + 0.019904969 * Math.Pow(Tin_a, 2) * RHi) / 1000;
            double omega_in = humidairprop.O(Tin_a, RHi, SourceTableData);

            //double omega_out = omega_in;
            double hin_a = 0;

            if (hexType == 0 && tri < tai)
            {
                bool isFullyWet = true;
                //double hin_a0 = CoolProp.HAPropsSI("H", "T", Tin_a + 273.15, "P", 101325, "R", RHi);
                //hin_a = -244.2924077 + 1135.8711 * Tin_a + 10101.404 * RHi - 12.968219 * Math.Pow(Tin_a, 2) - 11.356807 * Math.Pow(RHi, 2) + 357.25464 * Tin_a * RHi + 0.3178346 * Math.Pow(Tin_a, 3) - 0.0024329 * Math.Pow(RHi, 3) + 44.100799 * Tin_a * Math.Pow(RHi, 2) + 50.31444812 * Math.Pow(Tin_a, 2) * RHi;
                hin_a = humidairprop.H(Tin_a, "R", RHi, SourceTableData);

                double hout_a = hin_a - Q_dry / ma * Math.Pow(-1, hexType);

                //double Tdp0 = CoolProp.HAPropsSI("D", "T", Tin_a + 273.15, "P", 101325, "R", RHi) - 273.15;
                //double Tdp = -273.15 + 241.0212518 + 0.5718833 * tai + 84.99553 * RHi + 0.002691 * Math.Pow(tai, 2) - 95.003186 * Math.Pow(RHi, 2) + 0.7135779 * tai * RHi - 2.691 / Math.Pow(10, 5) * Math.Pow(tai, 3) + 42.58183 * Math.Pow(RHi, 3) - 0.3227474 * tai * Math.Pow(RHi, 2) - 0.000884612 * Math.Pow(tai, 2) * RHi;
                double Tdp = humidairprop.Tdp(Tin_a, RHi, SourceTableData);

                //***delete***//
                //res.RHout = CoolProp.HAPropsSI("R", "T", Tout_a_dry + 273.15, "P", 101325, "W", omega_out);
                //res.RHout = 0.0215344 - 0.0059467 * Tout_a_dry + 0.2386894 * (omega_out * 1000) + 0.0004378 * Math.Pow(Tout_a_dry, 2) + 0.0004635 * Math.Pow((omega_out * 1000), 2) - 0.0125912 * Tout_a_dry * (omega_out * 1000) - 9.134 * Math.Pow(10, -6) * Math.Pow(Tout_a_dry, 3) + 1.696 * Math.Pow(10, -6) * Math.Pow((omega_out * 1000), 3) - 2.214 * Math.Pow(10, -5) * Tout_a_dry * Math.Pow((omega_out * 1000), 2) + 0.000200865 * Math.Pow(Tout_a_dry, 2) * (omega_out * 1000);
                //***delete***//

                //res.RHout = CoolProp.HAPropsSI("R", "T", Tout_a_dry + 273.15, "P", 101325, "H", hout_a);
                //double resRHout0 = CoolProp.HAPropsSI("R", "T", Tout_a_dry + 273.15, "P", 101325, "H", hout_a);
                //res.RHout = 0.0259124 - 0.0996818 * Tout_a_dry + 0.0934877 * (hout_a / 1000) + 0.0040018 * Math.Pow(Tout_a_dry, 2) - 0.0003662 * Math.Pow((hout_a / 1000), 2) - 0.0034077 * Tout_a_dry * (hout_a / 1000) - 1.76447 * Math.Pow(10, -5) * Math.Pow(Tout_a_dry, 3) - 2.74524 * Math.Pow(10, -6) * Math.Pow((hout_a / 1000), 3) + 2.99291 * Math.Pow(10, -5) * Tout_a_dry * Math.Pow((hout_a / 1000), 2) - 9.56644 * Math.Pow(10, -6) * Math.Pow(Tout_a_dry, 2) * (hout_a / 1000);
                //double Tdp_out0 = CoolProp.HAPropsSI("T", "H", hout_a, "P", 101325, "R", 1.0) - 273.15;//@@@@@@@@@@@@@@@@@@@@@@@@@@
                double Tdp_out = humidairprop.Ts(hout_a / 1000, SourceTableData);
                res.RHout = humidairprop.RHI(Tout_a_dry, Tdp_out, SourceTableData);
                Tout_a    = Tout_a_dry;
                Q         = Q_dry;
                if (Tin_s < Tdp)
                {
                    isFullyWet = true;
                }
                else
                {
                    isFullyWet = false;
                }
                if (Tout_s < Tdp | isFullyWet == true)
                {
                    double x1 = Tin_r + 0.001;
                    double x2 = Tin_a - 0.001;
                    double eps = 1e-8;
                    int    iter = 1;
                    double change = 999;
                    double y1 = 0, y2 = 0, x3 = 0;
                    double m_star = 0, epsilon_wet = 0, h_s_w_i = 0, h_s_w_o = 0, h_s_s_e = 0, T_s_e = 0, h_a_x = 0, T_a_x = 0;
                    double Q_wet = 0, Ntu_owet = 0, mdot_min = 0;
                    double Ntu_wet = 0;
                    while ((iter <= 3 | change > eps) && iter < 100)
                    {
                        if (iter == 1)
                        {
                            Tout_r = x1;
                        }
                        if (iter > 1)
                        {
                            Tout_r = x2;
                        }
                        double Tout_r_start = Tout_r;
                        //double h_s_w_i0 = CoolProp.HAPropsSI("H", "T", Tin_r + 273.15, "P", 101325, "R", 1.0);
                        //h_s_w_i = 58.732687 * Math.Pow(Tin_r + 273.15, 2) - 30921.970577 * (Tin_r + 273.15) + 4075493.951473;
                        h_s_w_i = humidairprop.H(Tin_r, "R", 1, SourceTableData);
                        ///////
                        //double h10 = 58.732687 * Math.Pow((Tin_r + Tout_r) / 2 + 273.15 + 0.01, 2) - 30921.970577 * ((Tin_r + Tout_r) / 2 + 273.15 + 0.01) + 4075493.951473;
                        double h1 = humidairprop.H((Tin_r + Tout_r) / 2 + 0.01, "R", 1, SourceTableData);
                        //double h20 = 58.732687 * Math.Pow((Tin_r + Tout_r) / 2 + 273.15, 2) - 30921.970577 * ((Tin_r + Tout_r) / 2 + 273.15 ) + 4075493.951473;
                        double h2  = humidairprop.H((Tin_r + Tout_r) / 2, "R", 1, SourceTableData);
                        double c_s = (h1 - h2) / 0.01;
                        //double c_s = (CoolProp.HAPropsSI("H", "T", (Tin_r + Tout_r) / 2 + 273.15 + 0.01, "P", 101325, "R", 1) - CoolProp.HAPropsSI("H", "T", (Tin_r + Tout_r) / 2 + 273.15, "P", 101325, "R", 1)) / 0.01;

                        //double c_s = 2500;
                        //m = Math.Sqrt(2 * ha*c_s/cp_da / (k_fin * Fthickness));
                        //eta_a= Math.Tanh(m * h_fin) / (m * h_fin);// may cause error
                        //double m_star=ma/(mr*(cp_r/c_s));
                        //eta_a = eta_a * c_s / cp_da;
                        m     = Math.Pow((2 * haw / k_fin / Fthickness), 0.5);
                        fai   = (rf_r - 1) * (1 + (0.3 + Math.Pow((m * r_eta * (rf_r - r_eta) / 2.5), (1.5 - 1 / 12 * rf_r)) * (0.26 * Math.Pow(rf_r, 0.3) - 0.3)) * Math.Log(rf_r));
                        eta_0 = Math.Tanh(m * r_eta * fai) / m / r_eta / fai * Math.Cos(0.1 * m * r_eta * fai);
                        double eta_wet = (eta_0 * Aa_fin + Aa_tube) / (Aa_fin + Aa_tube);
                        Ntu_owet = (eta_0 * Aa_fin + Aa_tube) * haw / (ma * cp_da);//zzc
                        m_star   = Math.Min(cp_r * mr / c_s, ma) / Math.Max(cp_r * mr / c_s, ma);
                        mdot_min = Math.Min(cp_r * mr / c_s, ma);
                        Ntu_wet  = Ntu_owet / (1 + m_star * (Ntu_owet / Ntu_i));//zzc
                        if (cp_r * mr > c_s * ma)
                        {
                            Ntu_wet = Ntu_owet / (1 + m_star * (Ntu_owet / Ntu_i));//zzc
                        }
                        else
                        {
                            Ntu_wet = Ntu_i / (1 + m_star * (Ntu_i / Ntu_owet));
                        }
                        epsilon_wet = ((1 - Math.Exp(-Ntu_wet * (1 - m_star))) / (1 - m_star * Math.Exp(-Ntu_wet * (1 - m_star))));
                        Q_wet       = epsilon_wet * mdot_min * (hin_a - h_s_w_i);
                        hout_a      = hin_a - Q_wet / ma;
                        Tout_r      = Tin_r + ma / (mr * cp_r) * (hin_a - hout_a);

                        //double h_s_w_o0 = CoolProp.HAPropsSI("H", "T", Tout_r + 273.15, "P", 101325, "R", 1.0);
                        //h_s_w_o = 58.732687 * Math.Pow(Tout_r + 273.15, 2) - 30921.970577 * (Tout_r + 273.15) + 4075493.951473;
                        h_s_w_o = humidairprop.H(Tout_r, "R", 1, SourceTableData);

                        //double UA_star = 1 / (cp_da / (eta_a * Aa_fin + Aa_tube) / haw + CoolProp.HAPropsSI("C", "T", (Tin_a + Tout_r) / 2.0 + 273.15, "P", 101325, "R", 1) / h_r / Ar);//zzc
                        double UA_star = 1 / (cp_da / (eta_a * Aa_fin + Aa_tube) / haw + c_s / h_r / Ar); //zzc
                        Tin_s   = Tout_r + UA_star / h_r / Ar * (hin_a - h_s_w_o);
                        h_s_s_e = hin_a + (hout_a - hin_a) / (1 - Math.Exp(-Ntu_owet));                   //zzc

                        //double T_s_e0 = CoolProp.HAPropsSI("T", "H", h_s_s_e, "P", 101325, "R", 1.0) - 273.15;
                        //T_s_e = -273.15 - 1.96 * Math.Pow(10, -3) * Math.Pow(h_s_s_e / 1000, 2) + 0.5357597 * h_s_s_e / 1000 + 268.871551;
                        T_s_e = humidairprop.Ts(h_s_s_e, SourceTableData);

                        Tout_a     = T_s_e + (Tin_a - T_s_e) * Math.Exp(-Ntu_owet);//zzc
                        Q_sensible = ma * cp_da * (Tin_a - Tout_a);
                        double errorToutr = Tout_r - Tout_r_start;
                        if (iter == 1)
                        {
                            y1 = errorToutr;
                        }
                        if (iter > 1)
                        {
                            y2     = errorToutr;
                            x3     = x2 - y2 / (y2 - y1) * (x2 - x1);
                            change = Math.Abs(y2 / (y2 - y1) * (x2 - x1));
                            y1     = y2;
                            x1     = x2;
                            x2     = x3;
                        }
                        iter++;
                    }
                    //if (iter > 500)
                    //    Q = Q_dry;
                    double Tout_r_wet = Tout_r;
                    f_dry = 0.0;
                    if ((Tin_s > Tdp) && isFullyWet == false)
                    {
                        double iter1        = 1;
                        double error        = 1;
                        double Tout_r_guess = 0;
                        x1  = 0.0001;
                        x2  = 0.9999;
                        eps = 1e-8;
                        while ((iter1 <= 3 | change > eps) && iter < 100)
                        {
                            if (iter1 == 1)
                            {
                                f_dry = x1;
                            }
                            if (iter1 > 1)
                            {
                                f_dry = x2;
                            }
                            double K    = Ntu_dry * (1.0 - C_star);
                            double expk = Math.Exp(-K * f_dry);
                            if (cp_da * ma < cp_r * mr)
                            {
                                Tout_r_guess = (Tdp + C_star * (Tin_a - Tdp) - expk * (1 - K / Ntu_o) * Tin_a) / (1 - expk * (1 - K / Ntu_o));//zzc
                            }
                            else
                            {
                                Tout_r_guess = (expk * (Tin_a + (C_star - 1) * Tdp) - C_star * (1 + K / Ntu_o) * Tin_a) / (expk * C_star - C_star * (1 + K / Ntu_o));//zzc
                            }
                            epsilon_dry = ((1 - Math.Exp(-f_dry * Ntu_dry * (1 - C_star))) / (1 - C_star * Math.Exp(-f_dry * Ntu_dry * (1 - C_star))));
                            epsilon_wet = ((1 - Math.Exp(-(1 - f_dry) * Ntu_wet * (1 - m_star))) / (1 - m_star * Math.Exp(-(1 - f_dry) * Ntu_wet * (1 - m_star))));
                            double T_w_x = (Tin_r + (mdot_min) / (cp_r * mr) * epsilon_wet * (hin_a - h_s_w_i - epsilon_dry * Cmin / ma * Tin_a)) / (1 - (Cmin * mdot_min) / (cp_r * mr * ma) * epsilon_wet * epsilon_dry);
                            T_a_x  = Tin_a - epsilon_dry * Cmin * (Tin_a - T_w_x) / (ma * cp_da);
                            h_a_x  = hin_a - cp_da * (Tin_a - T_a_x);
                            Tout_r = (Cmin) / (cp_r * mr) * epsilon_dry * Tin_a + (1 - (Cmin) / (cp_r * mr) * epsilon_dry) * T_w_x;
                            error  = Tout_r - Tout_r_guess;
                            if (iter1 > 500)
                            {
                                Q = Q_dry;
                            }
                            if (iter1 == 1)
                            {
                                y1 = error;
                            }
                            if (iter1 > 1)
                            {
                                y2     = error;
                                x3     = x2 - y2 / (y2 - y1) * (x2 - x1);
                                change = Math.Abs(y2 / (y2 - y1) * (x2 - x1));
                                y1     = y2;
                                x1     = x2;
                                x2     = x3;
                            }
                            iter1++;
                        }
                        //if (iter1 > 500)
                        //    Q = Q_dry;
                        Q       = mr * cp_r * (Tout_r - Tin_r);
                        hout_a  = hin_a - Q / ma;
                        h_s_s_e = h_a_x + (hout_a - h_a_x) / (1 - Math.Exp(-(1 - f_dry) * Ntu_owet));//zzc
                        //double T_s_e0 = CoolProp.HAPropsSI("T", "H", h_s_s_e, "P", 101325, "R", 1.0) - 273.15;////////////////
                        //T_s_e = -273.15 - 1.96 * Math.Pow(10, -3) * Math.Pow(h_s_s_e / 1000, 2) + 0.5357597 * h_s_s_e / 1000 + 268.871551;
                        T_s_e      = humidairprop.Ts(h_s_s_e, SourceTableData);
                        Tout_a     = T_s_e + (T_a_x - T_s_e) * Math.Exp(-(1 - f_dry) * Ntu_owet);//zzc
                        Q_sensible = ma * cp_da * (Tin_a - Tout_a);
                    }
                    else
                    {
                        Q = Q_wet;
                    }
                    //res.RHout = CoolProp.HAPropsSI("R", "T", Tout_a + 273.15, "P", 101325, "H", hout_a);
                    //double  resRHout1 = CoolProp.HAPropsSI("R", "T", Tout_a + 273.15, "P", 101325, "H", hout_a);
                    //res.RHout = 0.0259124 - 0.0996818 * Tout_a + 0.0934877 * (hout_a / 1000) + 0.0040018 * Math.Pow(Tout_a, 2) - 0.0003662 * Math.Pow((hout_a / 1000), 2) - 0.0034077 * Tout_a * (hout_a / 1000) - 1.76447 * Math.Pow(10, -5) * Math.Pow(Tout_a, 3) - 2.74524 * Math.Pow(10, -6) * Math.Pow((hout_a / 1000), 3) + 2.99291 * Math.Pow(10, -5) * Tout_a * Math.Pow((hout_a / 1000), 2) - 9.56644 * Math.Pow(10, -6) * Math.Pow(Tout_a, 2) * (hout_a / 1000);
                    Tdp_out   = humidairprop.Ts(hout_a, SourceTableData);
                    res.RHout = humidairprop.RHI(Tout_a, Tdp_out, SourceTableData);
                    if (res.RHout > 1)
                    {
                        //res.RHout = 1;
                        //double Tout_a0 = CoolProp.HAPropsSI("T", "H", hout_a, "P", 101325, "R", 1)-273.15;
                        //Tout_a = -273.15 - 1.96 * Math.Pow(10, -3) * Math.Pow(hout_a / 1000, 2) + 0.5357597 * hout_a / 1000 + 268.871551;
                        //Tdp_out0 = CoolProp.HAPropsSI("T", "H", hout_a, "P", 101325, "R", 1.0) - 273.15;//@@@
                        Tout_a     = humidairprop.Ts(hout_a, SourceTableData);
                        Q_sensible = ma * cp_da * (Tin_a - Tout_a);
                    }
                }
            }
            else
            {
                Tout_a     = Tout_a_dry;
                Q          = Q_dry;
                Q_sensible = Q_dry;

                double hout_a = hin_a - Q / ma * Math.Pow(-1, hexType);

                //***delete***//
                //res.RHout = CoolProp.HAPropsSI("R", "T", Tout_a + 273.15, "P", 101325, "W", omega_out);
                //res.RHout = 0.0215344 - 0.0059467 * Tout_a + 0.2386894 * (omega_out * 1000) + 0.0004378 * Math.Pow(Tout_a, 2) + 0.0004635 * Math.Pow((omega_out * 1000), 2) - 0.0125912 * Tout_a * (omega_out * 1000) - 9.134 * Math.Pow(10, -6) * Math.Pow(Tout_a, 3) + 1.696 * Math.Pow(10, -6) * Math.Pow((omega_out * 1000), 3) - 2.214 * Math.Pow(10, -5) * Tout_a * Math.Pow((omega_out * 1000), 2) + 0.000200865 * Math.Pow(Tout_a, 2) * (omega_out * 1000);
                //***delete***//

                //res.RHout = CoolProp.HAPropsSI("R", "T", Tout_a + 273.15, "P", 101325, "H", hout_a);
                //double resRHout0 = CoolProp.HAPropsSI("R", "T", Tout_a + 273.15, "P", 101325, "H", hout_a);
                //res.RHout = 0.0259124 - 0.0996818 * Tout_a + 0.0934877 * (hout_a / 1000) + 0.0040018 * Math.Pow(Tout_a, 2) - 0.0003662 * Math.Pow((hout_a / 1000), 2) - 0.0034077 * Tout_a * (hout_a / 1000) - 1.76447 * Math.Pow(10, -5) * Math.Pow(Tout_a, 3) - 2.74524 * Math.Pow(10, -6) * Math.Pow((hout_a / 1000), 3) + 2.99291 * Math.Pow(10, -5) * Tout_a * Math.Pow((hout_a / 1000), 2) - 9.56644 * Math.Pow(10, -6) * Math.Pow(Tout_a, 2) * (hout_a / 1000);
                //double Tdp_out0 = CoolProp.HAPropsSI("T", "H", hout_a, "P", 101325, "R", 1.0) - 273.15;//@@@
                double Tdp_out = humidairprop.Ts(hout_a, SourceTableData);
                res.RHout = humidairprop.RHI(Tout_a, Tdp_out, SourceTableData);
            }
            res.Tao = Tout_a;
            res.Tro = Tout_r;
            res.Q   = Q / 1000;
            //res.hro = (hri + Math.Pow(-1, hexType) * res.Q / mr);
            double f_sp = RefrigerantSPDP.ff_Friction(Re_r);

            res.DP  = zdp * f_sp * l / dh * Math.Pow(g, 2.0) / rho_r / 2000;
            res.Pro = fluid == "Water" ? pri : pri - res.DP;
            if (res.Pro < 0)
            {
                res.Pro = -10000000; return(res);
            }
            res.hro  = hri + Math.Pow(-1, hexType) * res.Q / mr;
            res.R_1a = 1 / ((eta_0 * Aa_fin + Aa_tube) * ha);
            res.R_1r = 1 / (res.href * Ar);
            res.R_1  = res.R_1a + res.R_1r + r_metal;
            if (fluid != "Water")
            {
                coolprop.update(input_pairs.HmassP_INPUTS, res.hro * 1000, res.Pro * 1000);
                res.Tro = coolprop.T() - 273.15;
                //res.Tro = CoolProp.PropsSI("T", "P", res.Pro * 1000, "H", res.hro * 1000, fluid) - 273.15;
            }

            return(res);
        }
示例#14
0
 /// <summary>
 /// Transitions from one state to another. Should only ever be called
 /// from the state machine's update function.
 /// </summary>
 /// <param name="id">ID mapped to the state in the Dictionary.</param>
 protected void Transition(int id)
 {
     // Call current state's Exit method. Base case: Initial transition.
     if (currentState != null) currentState.Exit();
     // Set current state to state mapped to the given key.
     currentState = states[id];
     // Call the new current state's Enter method.
     currentState.Enter();
 }
示例#15
0
    private void initStateMachine()
    {
        m_stateMachine = new StateMachineBuilder().
                         State(CSTATE_Idle)
                         .Enter(state =>
        {
        })
                         .Condition(() => InputManager.GetAxis("Horizontal") > 0f, state => m_stateMachine.ChangeState(CSTATE_MoveRight))
                         .Condition(() => InputManager.GetAxis("Horizontal") < 0f, state => m_stateMachine.ChangeState(CSTATE_MoveLeft))
                         .Condition(() => InputManager.GetAxis("Vertical") > 0f, state => m_stateMachine.ChangeState(CSTATE_MoveUp))
                         .Condition(() => InputManager.GetAxis("Vertical") < 0f, state => m_stateMachine.ChangeState(CSTATE_MoveDown))
                         .End().
                         State(CSTATE_MoveLeft)
                         .Enter(state =>
        {
            m_actionAnimator.Play(CSTATE_MoveLeft);
        })
                         .Update((state, dt) =>
        {
            m_moveController.Move(InputManager.GetAxis("Horizontal"), InputManager.GetAxis("Vertical"));
        })
                         .Condition(() => InputManager.GetAxis("Horizontal") == 0f, state => m_stateMachine.ChangeState(CSTATE_Idle))
                         .Condition(() => InputManager.GetAxis("Horizontal") > 0f, state => m_stateMachine.ChangeState(CSTATE_MoveRight))
                         .End().
                         State(CSTATE_MoveRight)
                         .Enter(state =>
        {
            m_actionAnimator.Play(CSTATE_MoveRight);
        })
                         .Update((state, dt) =>
        {
            m_moveController.Move(InputManager.GetAxis("Horizontal"), InputManager.GetAxis("Vertical"));
        })
                         .Condition(() => InputManager.GetAxis("Horizontal") == 0f, state => m_stateMachine.ChangeState(CSTATE_Idle))
                         .Condition(() => InputManager.GetAxis("Horizontal") < 0f, state => m_stateMachine.ChangeState(CSTATE_MoveLeft))
                         .End().
                         State(CSTATE_MoveUp)
                         .Enter(state =>
        {
            m_actionAnimator.Play(CSTATE_MoveUp);
        })
                         .Update((state, dt) =>
        {
            m_moveController.Move(0f, InputManager.GetAxis("Vertical"));
        })
                         .Condition(() => InputManager.GetAxis("Vertical") == 0f, state => m_stateMachine.ChangeState(CSTATE_Idle))
                         .End().
                         State(CSTATE_MoveDown)
                         .Enter(state =>
        {
            m_actionAnimator.Play(CSTATE_MoveDown);
        })
                         .Update((state, dt) =>
        {
            m_moveController.Move(0f, InputManager.GetAxis("Vertical"));
        })
                         .Condition(() => InputManager.GetAxis("Vertical") == 0f, state => m_stateMachine.ChangeState(CSTATE_Idle))
                         .End()
                         .Build() as AbstractState;

        m_stateMachine.PushState(CSTATE_MoveRight);
    }
示例#16
0
 public void UpdateAbstractState(AbstractState newState)
 {
     // Do Something special for statechange
     currentState = newState.Name;
 }
示例#17
0
 public Equippable()
 {
     Stats = new Attribute();
     State = new AbstractState();
 }
示例#18
0
 protected override void StateResumed(AbstractState previousState)
 {
     this.StateStarted();
 }
示例#19
0
 public AbstractAbility()
 {
     State = new AbstractState();
 }
示例#20
0
        public static CalcResult CircuitCalc(int index, CirArr[] cirArr, CircuitNumber CircuitInfo, int Nrow, int[] Ntube, int Nelement, string fluid,
                                             double l, Geometry geo, double[, ,] ta, double[, ,] RH, double tri, double pri, double hri, double mr, double[,] ma, double[,] ha, double[,] haw,
                                             double eta_surface, double zh, double zdp, int hexType, double thickness, double conductivity, double Pwater, CapiliaryInput cap_inlet, CapiliaryInput cap_outlet, AbstractState coolprop, double[,] SourceTableData)
        {
            #region 算进口毛细管
            //调用毛细管守恒方程模型
            ///
            double          DP_cap     = 0;
            int             N          = 1;
            Capiliary_res[] res_cap_in = new Capiliary_res[N];
            if (cap_inlet.d_cap[index] == 0 && cap_inlet.lenth_cap[index] == 0)
            {
                pri = pri;
                hri = hri;
                tri = tri;
            }
            else
            {
                for (int i = 0; i < N; i++)
                {
                    res_cap_in[i] = Capiliary.CapiliaryCalc(index, fluid, cap_inlet.d_cap[index], cap_inlet.lenth_cap[index] / N, tri, pri, hri, mr, Pwater, hexType, coolprop, SourceTableData);
                    pri           = res_cap_in[i].pro;
                    hri           = res_cap_in[i].hro;
                    tri           = res_cap_in[i].tro;
                    DP_cap       += res_cap_in[i].DP_cap;
                }
            }
            #endregion

            #region 算流路
            ///
            //******蒸发器毛细管******//

            int N_tube = Ntube[0];
            //int Ncir = CircuitInfo.number[0];
            int          Ncir      = CircuitInfo.TubeofCir.Length;
            int[]        TubeofCir = CircuitInfo.TubeofCir;
            CalcResult   res_cir   = new CalcResult();
            CalcResult[] r         = new CalcResult[TubeofCir[index]];

            int iRow  = 0;
            int iTube = 0;

            double[] tai = new double[Nelement];
            double[] RHi = new double[Nelement];
            double[, ,] taout_calc  = new double[Nelement, N_tube, Nrow];
            double[, ,] RHout_calc  = new double[Nelement, N_tube, Nrow];
            double[,] Q_detail      = new double[N_tube, Nrow];//detail output
            double[,] DP_detail     = new double[N_tube, Nrow];
            double[,] Tri_detail    = new double[N_tube, Nrow];
            double[,] Pri_detail    = new double[N_tube, Nrow];
            double[,] hri_detail    = new double[N_tube, Nrow];
            double[,] Tro_detail    = new double[N_tube, Nrow];
            double[,] Pro_detail    = new double[N_tube, Nrow];
            double[,] hro_detail    = new double[N_tube, Nrow];//
            double[,] href_detail   = new double[N_tube, Nrow];
            double[,] mr_detail     = new double[N_tube, Nrow];
            double[,] charge_detail = new double[N_tube, Nrow];
            double   Ar       = 0;
            double   Aa       = 0;
            double   Aa_tube  = 0;
            double   Aa_fin   = 0;
            double   Ar_cs    = 0;
            double   pri_tube = 0;
            double   tri_tube = 0;
            double   hri_tube = 0;
            double[] ma_tube  = new double[Nelement];
            double[] ha_tube  = new double[Nelement];
            double[] haw_tube = new double[Nelement];
            int      index2   = 0;

            CheckAir airConverge = new CheckAir();
            int      iter        = 0;
            //ma = ma / (N_tube*Nelement); //air flow distribution to be considered

            if (index == 0)
            {
                index2 = 0;
            }
            else
            {
                for (int i = 1; i <= index; i++)
                {
                    index2 += TubeofCir[i - 1];
                }
            }
            //do
            //{
            pri_tube   = pri;
            tri_tube   = tri;
            hri_tube   = hri;
            res_cir.DP = 0;
            // res_cir.Tao += r.Tao;
            res_cir.Q     = 0;
            res_cir.M     = 0;
            res_cir.Tro   = 0;
            res_cir.Pro   = 0;
            res_cir.hro   = 0;
            res_cir.x_o   = 0;
            res_cir.Vel_r = 0;
            res_cir.href  = 0;
            res_cir.R_1   = 0;
            res_cir.R_1a  = 0;
            res_cir.R_1r  = 0;
            res_cir.mr    = 0;
            for (int i = 0; i < TubeofCir[index]; i++)     //to be updated //Nrow * N_tube
            {
                //index2 = index == 1 ? 0 : (index - 1) * TubeofCir[index - 1 - 1];
                iRow  = cirArr[i + index2].iRow;
                iTube = cirArr[i + index2].iTube;

                Ar      = geo.ElementArea[iTube, iRow].A_r;
                Aa      = geo.ElementArea[iTube, iRow].A_a;
                Aa_tube = geo.ElementArea[iTube, iRow].Aa_tube;
                Aa_fin  = geo.ElementArea[iTube, iRow].Aa_fin;
                Ar_cs   = geo.ElementArea[iTube, iRow].A_r_cs;
                //tai=ta[,iTube,iRow];
                for (int j = 0; j < Nelement; j++)
                {
                    tai[j]      = ta[j, iTube, iRow];
                    RHi[j]      = RH[j, iTube, iRow];
                    ma_tube[j]  = ma[iTube, j];
                    ha_tube[j]  = ha[iTube, j];
                    haw_tube[j] = haw[iTube, j];
                }

                r[i] = Tube.TubeCalc(Nelement, fluid, l, Aa_fin, Aa_tube, Ar_cs, Ar, geo, tai, RHi, tri_tube, pri_tube, hri_tube,
                                     mr, ma_tube, ha_tube, haw_tube, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, coolprop, SourceTableData);
                if (r[i].Pro < 0)
                {
                    res_cir.Pro = -10000000; return(res_cir);
                }

                /*if (Airdirection == "顺流")
                 * {
                 *  for (int j = 0; j < Nelement; j++)
                 *  {
                 *      taout_calc[j, iTube, iRow] = r[i].Tao;
                 *      RHout_calc[j, iTube, iRow] = r[i].RHout;
                 *      ta[j, iTube, iRow+1] = r[i].Tao;
                 *      RH[j, iTube, iRow+1] = r[i].RHout;
                 *  }
                 * }
                 * else//Counter
                 * {
                 *  for(int j=0;j<Nelement;j++)
                 *  {
                 *      taout_calc[j, iTube, iRow] =r[i].Tao_Detail[0, 0, j];
                 *      RHout_calc[j, iTube, iRow] = r[i].RHout;
                 *  }
                 * }*/

                for (int j = 0; j < Nelement; j++)
                {
                    taout_calc[j, iTube, iRow] = r[i].Tao_Detail[0, 0, j];
                    RHout_calc[j, iTube, iRow] = r[i].RHout;
                }



                Tri_detail[iTube, iRow] = tri_tube;
                Pri_detail[iTube, iRow] = pri_tube;
                hri_detail[iTube, iRow] = hri_tube;
                tri_tube    = r[i].Tro;
                pri_tube    = r[i].Pro;
                hri_tube    = r[i].hro;
                res_cir.DP += r[i].DP;
                // res_cir.Tao += r.Tao;
                res_cir.Q             += r[i].Q;
                Q_detail[iTube, iRow]  = r[i].Q;   //detail output
                DP_detail[iTube, iRow] = r[i].DP;

                Tro_detail[iTube, iRow]    = r[i].Tro;
                Pro_detail[iTube, iRow]    = r[i].Pro;
                hro_detail[iTube, iRow]    = r[i].hro;
                href_detail[iTube, iRow]   = r[i].href;
                mr_detail[iTube, iRow]     = mr;
                charge_detail[iTube, iRow] = r[i].M;
                res_cir.M    += r[i].M;
                res_cir.Tro   = r[i].Tro;
                res_cir.Pro   = r[i].Pro;
                res_cir.hro   = r[i].hro;
                res_cir.x_o   = r[i].x_o;
                res_cir.Vel_r = r[i].Vel_r;
                res_cir.href += r[i].href;
                res_cir.R_1  += r[i].R_1;
                res_cir.R_1a += r[i].R_1a;
                res_cir.R_1r += r[i].R_1r;
                res_cir.Tri   = r[i].Tri;
                res_cir.x_i   = r[i].x_i;
            }

            /*
             *  if (Airdirection == "顺流")
             *      airConverge.flag = true;
             *  else//Counter
             *  {
             *      airConverge = CheckAirConvergeforCircuits.CheckAirConverge(Nrow, N_tube, Nelement, ta, RH, taout_calc, RHout_calc);
             *      ta = airConverge.ta;
             *      RH = airConverge.RH;
             *      iter++;
             *  }
             * } while (!airConverge.flag && iter < 100);
             */

            //if (iter >= 100)
            //{
            //    throw new Exception("iter for AirConverge > 100.");
            //}
            res_cir.mr         = mr;
            res_cir.Tao_Detail = taout_calc;
            res_cir.RHo_Detail = RHout_calc;

            //res_cir.Tao = res_cir.Tao / Nelement;
            res_cir.href        = res_cir.href / TubeofCir[index];
            res_cir.R_1         = res_cir.R_1 / TubeofCir[index];
            res_cir.R_1a        = res_cir.R_1a / TubeofCir[index];
            res_cir.R_1r        = res_cir.R_1r / TubeofCir[index];
            res_cir.Q_detail    = Q_detail;//detail output
            res_cir.DP_detail   = DP_detail;
            res_cir.Tri_detail  = Tri_detail;
            res_cir.Pri_detail  = Pri_detail;
            res_cir.hri_detail  = hri_detail;
            res_cir.Tro_detail  = Tro_detail;
            res_cir.Pro_detail  = Pro_detail;
            res_cir.hro_detail  = hro_detail;
            res_cir.href_detail = href_detail;
            res_cir.mr_detail   = mr_detail;

            #endregion

            #region 算出口毛细管
            //调用毛细管守恒方程模型  ----需要校核,调整----
            ///
            N = 1;
            Capiliary_res[] res_cap_out = new Capiliary_res[N];
            //double DP_cap = 0;
            if (cap_outlet.d_cap[index] == 0 && cap_outlet.lenth_cap[index] == 0)
            {
                pri = pri;
                hri = hri;
                tri = tri;
            }
            else
            {
                for (int i = 0; i < N; i++)
                {
                    res_cap_out[i] = Capiliary.CapiliaryCalc(index, fluid, cap_outlet.d_cap[index], cap_outlet.lenth_cap[index] / N, res_cir.Tro, res_cir.Pro, res_cir.hro, mr, Pwater, hexType, coolprop, SourceTableData);
                    res_cir.Pro    = res_cap_out[i].pro;
                    res_cir.hro    = res_cap_out[i].hro;
                    res_cir.Tro    = res_cap_out[i].tro;
                    DP_cap        += res_cap_out[i].DP_cap;
                }
            }
            #endregion

            //增加毛细管模型的单流路总压降
            res_cir.DP     = res_cir.DP + DP_cap;
            res_cir.DP_cap = DP_cap;


            res_cir.charge_detail = charge_detail;

            return(res_cir);
        }
示例#21
0
 // Start is called before the first frame update
 void Start()
 {
     sound     = GetComponent <ControllerSound>();
     state     = new IdleState(this);
     rigidbody = GetComponent <Rigidbody>();
 }
示例#22
0
        /// <summary>
        /// インスタンスを初期化します。初期値はそれぞれ下記となります。
        /// <list type="bullet">
        ///   <item>
        ///     <description><see cref="AreaCode"/> (地域コード): 900 (地域未設定)</description>
        ///   </item>
        ///   <item>
        ///     <description><see cref="MaxConnections"/> (最大接続数): 4</description>
        ///   </item>
        /// </list>
        /// </summary>
        public MediatorContext()
        {
            clientContext       = new ClientContext();
            peerContext         = new Context();
            maintainTimer       = new MaintainTimer(this, clientContext);
            userquakeAggregator = new Aggregator();
            state = new DisconnectedState();

            Verification   = true;
            AreaCode       = 900;
            MaxConnections = 4;
            IsPortOpen     = false;
            UseUPnP        = false;

            clientContext.PeerConfig          = this;
            clientContext.PeerConnector       = peerContext;
            clientContext.PeerState           = this;
            clientContext.StateChanged       += ClientContext_StateChanged;
            clientContext.OperationCompleted += ClientContext_OperationCompleted;

            peerContext.PeerConfig          = this;
            peerContext.PeerState           = this;
            peerContext.ConnectionsChanged += (s, e) => { ConnectionsChanged(s, e); };
            peerContext.OnUserquake        += (s, e) => { if (!Verification || e.IsValid)
                                                          {
                                                              OnUserquake(s, e);
                                                          }
            };
            peerContext.OnTsunami += (s, e) => { if (!Verification || e.IsValid)
                                                 {
                                                     OnTsunami(s, e);
                                                 }
            };
            peerContext.OnEarthquake += (s, e) => { if (!Verification || e.IsValid)
                                                    {
                                                        OnEarthquake(s, e);
                                                    }
            };
            peerContext.OnEEWTest += (s, e) => { if (!Verification || e.IsValid)
                                                 {
                                                     OnEEWTest(s, e);
                                                 }
            };
#if RAISE_RAW_DATA_EVENT
            peerContext.OnData += (s, e) => { OnData(s, e); };
#endif

            maintainTimer.RequireConnect            += MaintainTimer_RequireConnect;
            maintainTimer.RequireMaintain           += MaintainTimer_RequireMaintain;
            maintainTimer.RequireDisconnect         += MaintainTimer_RequireDisconnect;
            maintainTimer.RequireDisconnectAllPeers += MaintainTimer_RequireDisconnectAllPeers;

            OnUserquake += (s, e) => {
                if (areaPeerDictionary != null)
                {
                    userquakeAggregator.AddUserquake(e.ReceivedAt, e.AreaCode, new Dictionary <string, int>(areaPeerDictionary));
                }
            };
            userquakeAggregator.OnNew    += (s, e) => { OnNewUserquakeEvaluation(this, e); };
            userquakeAggregator.OnUpdate += (s, e) => { OnUpdateUserquakeEvaluation(this, e); };
        }
示例#23
0
        private void ToucheDown(Object o, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.D2)
            {
                viewState = new ViewPerspectiveState();
                FonctionsNatives.changeToPerspective();
            }

            if (e.KeyCode == Keys.D1)
            {
                viewState = new ViewOrthoState();
                FonctionsNatives.changeToOrtho();
            }

            if (e.KeyValue == (char)Keys.Subtract || (e.KeyValue == (char)Keys.OemMinus))
            {
                FonctionsNatives.zoomOut();
            }

            if (e.KeyValue == (char)Keys.Add || (e.KeyValue == (char)Keys.Oemplus && e.Modifiers == Keys.Shift))
            {
                FonctionsNatives.zoomIn();
            }
            if (viewState is ViewOrthoState)
            {
                if (e.KeyValue == (char)Keys.Up)
                {
                    FonctionsNatives.translater(0, 1);
                }

                if (e.KeyValue == (char)Keys.Left)
                {
                    FonctionsNatives.translater(-1, 0);
                }

                if (e.KeyValue == (char)Keys.Down)
                {
                    FonctionsNatives.translater(0, -1);
                }

                if (e.KeyValue == (char)Keys.Right)
                {
                    FonctionsNatives.translater(1, 0);
                }
            }
            if (viewState is ViewPerspectiveState)
            {
                if (e.KeyValue == (char)Keys.Up)
                {
                    FonctionsNatives.rotaterXY(0, 0.05);
                }

                if (e.KeyValue == (char)Keys.Left)
                {
                    FonctionsNatives.rotaterXY(0.05, 0);
                }

                if (e.KeyValue == (char)Keys.Down)
                {
                    FonctionsNatives.rotaterXY(0, -0.05);
                }

                if (e.KeyValue == (char)Keys.Right)
                {
                    FonctionsNatives.rotaterXY(-0.05, 0);
                }
            }

            if (e.KeyValue == (char)Keys.Escape && pause == false)
            {
                pause = true;
                menuStrip1.Show();
                e.Handled = true;
                FonctionsNatives.pauserSon();
            }
            if (e.KeyValue == (char)Keys.Escape && pause == true && e.Handled == false)
            {
                pause = false;
                menuStrip1.Hide();
                e.Handled = true;
                FonctionsNatives.pauserSon();
            }


            if (e.KeyCode == touches[0] && !PGJ1isPressed)
            {
                FonctionsNatives.animerPaletteGJ1(true);

                PGJ1isPressed = true;
            }

            if (e.KeyCode == touches[1] && !PDJ1isPressed)
            {
                FonctionsNatives.animerPaletteDJ1(true);

                PDJ1isPressed = true;
            }


            if (e.KeyCode == touches[2] && !PGJ2isPressed && configSimple_.estMultiplayer_ && !configSimple_.joueurVirtuel_)
            {
                FonctionsNatives.animerPaletteGJ2(true);

                PGJ2isPressed = true;
            }


            if (e.KeyCode == touches[3] && !PDJ2isPressed && configSimple_.estMultiplayer_ && !configSimple_.joueurVirtuel_)
            {
                FonctionsNatives.animerPaletteDJ2(true);

                PDJ2isPressed = true;
            }


            if (e.KeyCode == touches[4] && !ressortPressed)
            {
                FonctionsNatives.animerRessort(true);
                ressortPressed = true;
            }
        }
示例#24
0
 private void orbiteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     viewState = new ViewOrthoState();
     FonctionsNatives.changeToOrtho();
 }
示例#25
0
        public void TestMethod1()
        {
            var            geoInput = new GeometryInput();
            var            refInput = new RefStateInput();
            var            airInput = new AirStateInput();
            CapiliaryInput capInput = new CapiliaryInput();

            //ref input
            refInput.FluidName = "R32";
            AbstractState coolprop = AbstractState.factory("HEOS", refInput.FluidName);

            //*************if input SC or Sh, Massflowrate is the initial input***************
            refInput.Massflowrate = 0.02161311486;//0.02 //kg/s
            refInput.zh           = 1.6;
            refInput.zdp          = 4;
            airInput.za           = 1;
            airInput.zdpa         = 1.0;

            //for condenser
            refInput.tc  = 45;
            refInput.tri = 80;
            //refInput.tc = 40;
            //refInput.tri = 70;

            //for evaporator
            refInput.te = 6.92842345;//12
            //refInput.P_exv = CoolProp.PropsSI("P", "T", refInput.tc + 273.15, "Q", 0, refInput.FluidName) / 1000;
            coolprop.update(input_pairs.QT_INPUTS, 0, refInput.tc + 273.15);
            refInput.P_exv = coolprop.p() / 1000;
            refInput.T_exv = refInput.tc - 8;
            refInput.H_exv = 272;

            //air input
            airInput.Volumetricflowrate = 0.23; //m3/s
            airInput.tai = 27;                  //24.85
            airInput.RHi = 0.47;

            //airInput.ha = 80;

            //geo input
            //mm
            geoInput.Pt         = 21;
            geoInput.Pr         = 13.37;
            geoInput.Di         = 6.89;
            geoInput.Do         = 7.35;
            geoInput.L          = 653;
            geoInput.FPI        = 21;
            geoInput.Fthickness = 0.095;
            geoInput.Nrow       = 2;
            geoInput.Ntube      = 15;
            geoInput.CirNum     = 2;

            //初始化湿空气数组
            double[,] HumidSourceData = Model.HumidAirSourceData.InitializeSourceTableData();
            DateTime Time1 = DateTime.Now;
            //var rr = Main.main_condenser_py(refInput, airInput, geoInput, capInput, coolprop, Model.HumidAirSourceData.SourceTableData);
            //var r = Main.main_evaporator_py(refInput, airInput, geoInput, capInput, coolprop, HumidAirSourceData.SourceTableData);
            var rr = Main.main_condenser_py(refInput, airInput, geoInput, HumidSourceData);
            var r  = Main.main_evaporator_py(refInput, airInput, geoInput, HumidSourceData);

            //for (int i=0;i<5;i++)
            //r = Main.main_evaporator_py(refInput, airInput, geoInput, capInput);

            //DateTime Time2 = DateTime.Now;
            //double time01 = (Time2 - Time1).TotalSeconds;

            //using (StreamWriter wr = File.AppendText(@"D:\QQQ.txt"))
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        refInput.H_exv = 270 + i;
            //        var r = Main.main_evaporator_py(refInput, airInput, geoInput, HumidSourceData);
            //        wr.WriteLine("{0}", r.Q);
            //    }
            //}

            //using (StreamWriter wr = File.AppendText(@"D:\QQQ.txt"))
            //{
            //    for (int i = 0; i < 15; i++)
            //    {
            //        for (int j = 0; j < 2;j++ )
            //        {
            //            wr.WriteLine("{0}", r.Q_detail[i,j]);
            //        }
            //    }
            //}

            //double Tsc_set = 5;
            //double Tsh_set = 5;
            //var rr = Main.main_condenser_inputSC_py(Tsc_set, refInput, airInput, geoInput, capInput, coolprop);
            //var rrr = Main.main_evaporator_inputSH_py(Tsh_set, refInput, airInput, geoInput, capInput, coolprop);
            DateTime Time2  = DateTime.Now;
            double   time01 = (Time2 - Time1).TotalSeconds;
        }
 public AbstractNode Resolve(AbstractNode parent, AbstractAction action, AbstractState targetState)
 {
     return new RouteFindingNode(parent, action, action.EndState as RouteFindingState, targetState as RouteFindingState);
 }
示例#27
0
 public InferenceAction(AbstractState startState, AbstractState endState)
     : base(startState, endState)
 {
 }
示例#28
0
 /// <summary>
 /// Adds the given state to the machine.
 /// </summary>
 /// <param name="state">State being added to the machine.</param>
 public virtual void AddState(AbstractState state)
 {
     states.Add(state.ID, state);
 }
示例#29
0
        //Start
        public static CalcResult SlabCalc(int[,] CirArrange, CircuitNumber CircuitInfo, int Nrow, int[] Ntube, int Nelement, string fluid, //double Npass, int[] N_tubes_pass,
                                          double l, Geometry geo, double[, ,] ta, double[, ,] RH, double te, double pe, double hri, double mr, double[,] ma, double[,] ha, double[,] haw,
                                          double eta_surface, double zh, double zdp, int hexType, double thickness, double conductivity, double Pwater, int AirFlowDirection, List <NodeInfo> Nodes, int N_Node, CapiliaryInput cap_inlet, CapiliaryInput cap_outlet, AbstractState coolprop, double[,] SourceTableData)
        {
            double tri         = te; //Refrigerant.SATP(fluid, composition, pri, 1).Temperature - 273.15;
            double pri         = pe;
            double te_calc_org = 0;
            int    N_tube      = Ntube[0];

            CirArr[]     cirArr       = new CirArr[Nrow * N_tube];
            CirArrforAir cirArrforAir = new CirArrforAir();

            cirArrforAir = CirArrangement.ReadCirArr(CirArrange, CircuitInfo, Nrow, Ntube, AirFlowDirection);
            cirArr       = cirArrforAir.CirArr;
            CheckAir   airConverge  = new CheckAir();
            CheckDP    dPconverge   = new CheckDP();
            CheckPri   priconverge  = new CheckPri();
            int        iterforAir   = 0;
            int        iterforDP    = 0;
            int        iterforPri   = 0;
            CalcResult r            = new CalcResult();
            CalcResult res_slab     = new CalcResult();
            int        N_cir        = CircuitInfo.TubeofCir.Length;
            int        N_tube_total = CircuitInfo.TubeofCir.Sum();

            CalcResult[] res_cir = new CalcResult[N_cir];
            double[, ,] taout_calc  = new double[Nelement, N_tube, Nrow];
            double[, ,] RHout_calc  = new double[Nelement, N_tube, Nrow];
            double[,] Q_detail      = new double[N_tube, Nrow];//detail output
            double[,] DP_detail     = new double[N_tube, Nrow];
            double[,] Tri_detail    = new double[N_tube, Nrow];
            double[,] Pri_detail    = new double[N_tube, Nrow];
            double[,] hri_detail    = new double[N_tube, Nrow];
            double[,] Tro_detail    = new double[N_tube, Nrow];
            double[,] Pro_detail    = new double[N_tube, Nrow];
            double[,] hro_detail    = new double[N_tube, Nrow];//
            double[,] href_detail   = new double[N_tube, Nrow];
            double[,] mr_detail     = new double[N_tube, Nrow];
            double[,] charge_detail = new double[N_tube, Nrow];
            int  index_Node      = 0;
            int  index_couple    = 0;
            int  index_last_Node = 0;
            bool index_end       = false;

            int[]  index_status     = new int[N_Node];
            int[]  index_FullStatus = new int[N_Node];
            int[]  index_DP         = new int[N_Node];//
            double mri_cal          = 0;
            double pri_cal          = 0;
            double hri_cal          = 0;
            double tri_cal          = 0;
            int    index_cir        = 0;
            double te_calc;

            do                    //Pri iteration
            {
                if (hexType == 0) // need to be under pri iteration
                {
                    tri = CoolProp.PropsSI("T", "P", pri * 1000, "Q", 0, fluid) - 273.15;
                }
                else
                {
                    te = CoolProp.PropsSI("T", "P", pri * 1000, "Q", 0, fluid) - 273.15;
                }

                int iiii = 0;
                do//Air iteration
                {
                    //Node[] Nodes=new Node[N_node];
                    //Nodes[0]=First Node;
                    for (int i = 0; i < N_Node; i++)
                    {
                        index_FullStatus[i] = Math.Max(Nodes[i].N_in, Nodes[i].N_out);
                        index_status[i]     = 0;
                    }

                    index_Node = SearchNode.FindNextNode(-1, 0, Nodes, N_Node); //Find the first node
                    index_status[index_Node] = 0;                               //initial status
                    //index_FullStatus[index_Node]=Nodes[index_Node].N_out;
                    //index_DP[index_Node] = 0;
                    index_end = false;
                    for (int i = 0; i < 1000; i++)            //for DP converge
                    {
                        if (Nodes[index_Node].inlet[0] == -1) //First Node(diverse)
                        {
                            Nodes[index_Node].mri[0] = mr;
                            Nodes[index_Node].pri[0] = pri;
                            Nodes[index_Node].hri[0] = hri;
                            Nodes[index_Node].tri[0] = tri;
                            //index_cir=Node[index].out[i];//?
                        }
                        if (Nodes[index_Node].type == 'D' || Nodes[index_Node].type == 'S') //Diverse Node Distribution
                        {
                            if (index_DP[index_Node] == 0)                                  //first time calculation
                            {
                                Nodes[index_Node].mro[index_status[index_Node]] = Nodes[index_Node].mri[0] / Nodes[index_Node].N_out;
                            }
                            else
                            {
                                Nodes[index_Node].mro[index_status[index_Node]] = Nodes[index_Node].mri[0] * Nodes[index_Node].mr_ratio[index_status[index_Node]];
                            }
                            Nodes[index_Node].pro[index_status[index_Node]] = Nodes[index_Node].pri[0];
                            Nodes[index_Node].tro[index_status[index_Node]] = Nodes[index_Node].tri[0];
                            Nodes[index_Node].hro[index_status[index_Node]] = Nodes[index_Node].hri[0];
                            if (Nodes[index_Node].outType[index_status[index_Node]] == 0)//0:out is Node,1:out is Circuit
                            {
                                index_last_Node          = index_Node;
                                index_Node               = SearchNode.FindNextNode(index_Node, index_status[index_Node], Nodes, N_Node);//find node
                                Nodes[index_Node].pri[0] = Nodes[index_last_Node].pro[index_status[index_last_Node]];
                                Nodes[index_Node].tri[0] = Nodes[index_last_Node].tro[index_status[index_last_Node]];
                                Nodes[index_Node].hri[0] = Nodes[index_last_Node].hro[index_status[index_last_Node]];
                                Nodes[index_Node].mri[0] = Nodes[index_last_Node].mro[index_status[index_last_Node]];
                                index_status[index_Node] = 0;
                                //i_end=Nodes[index_Node].N_out;
                                continue;
                            }
                            else//out is Circuit
                            {
                                mri_cal   = Nodes[index_Node].mro[index_status[index_Node]];
                                pri_cal   = Nodes[index_Node].pro[index_status[index_Node]];
                                tri_cal   = Nodes[index_Node].tro[index_status[index_Node]];
                                hri_cal   = Nodes[index_Node].hro[index_status[index_Node]];
                                index_cir = Nodes[index_Node].outlet[index_status[index_Node]];
                            }
                        }
                        else if (Nodes[index_Node].type == 'C')//Converge Node
                        {
                            mri_cal   = Nodes[index_Node].mro[0];
                            pri_cal   = Nodes[index_Node].pro[0];
                            hri_cal   = Nodes[index_Node].hro[0];
                            tri_cal   = Nodes[index_Node].tro[0];
                            index_cir = Nodes[index_Node].outlet[0];
                        }

                        //index_status[index_Node]=i;//status
                        r = Circuit.CircuitCalc(index_cir, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, l, geo, ta, RH,
                                                tri_cal, pri_cal, hri_cal, mri_cal, ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, cap_inlet, cap_outlet, coolprop, SourceTableData);

                        res_cir[index_cir] = r;
                        if (r.Pro < 0)
                        {
                            res_slab.Pro = -10000000; return(res_slab);
                        }
                        for (int aa = 0; aa < Nrow; aa++)// detail result print
                        {
                            for (int bb = 0; bb < N_tube; bb++)
                            {
                                Q_detail[bb, aa]      = r.Q_detail[bb, aa] == 0 ? Q_detail[bb, aa] : r.Q_detail[bb, aa];
                                DP_detail[bb, aa]     = r.DP_detail[bb, aa] == 0 ? DP_detail[bb, aa] : r.DP_detail[bb, aa];
                                Pri_detail[bb, aa]    = r.Pri_detail[bb, aa] == 0 ? Pri_detail[bb, aa] : r.Pri_detail[bb, aa];
                                Tri_detail[bb, aa]    = r.Tri_detail[bb, aa] == 0 ? Tri_detail[bb, aa] : r.Tri_detail[bb, aa];
                                hri_detail[bb, aa]    = r.hri_detail[bb, aa] == 0 ? hri_detail[bb, aa] : r.hri_detail[bb, aa];
                                Pro_detail[bb, aa]    = r.Pro_detail[bb, aa] == 0 ? Pro_detail[bb, aa] : r.Pro_detail[bb, aa];
                                Tro_detail[bb, aa]    = r.Tro_detail[bb, aa] == 0 ? Tro_detail[bb, aa] : r.Tro_detail[bb, aa];
                                hro_detail[bb, aa]    = r.hro_detail[bb, aa] == 0 ? hro_detail[bb, aa] : r.hro_detail[bb, aa];
                                href_detail[bb, aa]   = r.href_detail[bb, aa] == 0 ? href_detail[bb, aa] : r.href_detail[bb, aa];
                                mr_detail[bb, aa]     = r.mr_detail[bb, aa] == 0 ? mr_detail[bb, aa] : r.mr_detail[bb, aa];
                                charge_detail[bb, aa] = r.charge_detail[bb, aa] == 0 ? charge_detail[bb, aa] : r.charge_detail[bb, aa];
                                for (int cc = 0; cc < Nelement; cc++)
                                {
                                    taout_calc[cc, bb, aa] = r.Tao_Detail[cc, bb, aa] == 0 ? taout_calc[cc, bb, aa] : r.Tao_Detail[cc, bb, aa];
                                    RHout_calc[cc, bb, aa] = r.RHo_Detail[cc, bb, aa] == 0 ? RHout_calc[cc, bb, aa] : r.RHo_Detail[cc, bb, aa];
                                }
                            }
                        }
                        index_Node = SearchNode.FindNextNode(index_Node, index_status[index_Node], Nodes, N_Node); //Find Next Node

                        if (Nodes[index_Node].type == 'D')                                                         //Diverse Node cal
                        {
                            index_status[index_Node] = 0;
                            //i_end=Nodes[index_Node].N_out;
                            Nodes[index_Node].pri[0] = r.Pro;
                            Nodes[index_Node].tri[0] = r.Tro;
                            Nodes[index_Node].hri[0] = r.hro;
                            Nodes[index_Node].mri[0] = r.mr;
                            continue;
                        }
                        else if (Nodes[index_Node].type == 'C')//Converge Node cal
                        {
                            for (int ii = 0; ii < N_Node; ii++)
                            {
                                if (Nodes[ii].couple == Nodes[index_Node].couple && ii != index_Node)
                                {
                                    index_couple = ii;
                                    break;
                                }
                            }//Find the Couple Node
                            Nodes[index_Node].pri[index_status[index_couple]] = r.Pro;
                            Nodes[index_Node].tri[index_status[index_couple]] = r.Tro;
                            Nodes[index_Node].hri[index_status[index_couple]] = r.hro;
                            Nodes[index_Node].mri[index_status[index_couple]] = r.mr;
                            for (int k = 0; k < 100; k++)
                            {
                                if (index_status[index_couple] < index_FullStatus[index_couple] - 1)//continue
                                {
                                    index_Node = index_couple;
                                    index_status[index_Node]++;
                                    //i_end=Nodes[index_couple].N_out;
                                    break;
                                }
                                else if (index_status[index_couple] == index_FullStatus[index_couple] - 1)//dp converge calculation
                                {
                                    //DPconverge=DPConverge(Nodes[index_Node].mri,Nodes[index_Node].pri);
                                    dPconverge = CheckDPforCircuits.CheckDPConverge2(hexType, iterforPri, Nodes[index_Node].mri, Nodes[index_Node].pri, Nodes[index_couple].pri[0], index_FullStatus[index_couple]);
                                    iterforDP++;
                                    if (dPconverge.flag == false)//need to be modified
                                    {
                                        Nodes[index_couple].mro      = dPconverge.mr;
                                        Nodes[index_couple].mr_ratio = dPconverge.mr_ratio;
                                        index_DP[index_couple]++;
                                        index_Node = index_couple;
                                        index_status[index_Node] = 0;
                                        //i_end=Nodes[index_Node].N_out;
                                        break;
                                    }
                                    else if (dPconverge.flag == true)
                                    {
                                        index_DP[index_couple]       = 1;
                                        Nodes[index_couple].mr_ratio = dPconverge.mr_ratio;
                                        double mr_sum  = 0;
                                        double tro_ave = 0;
                                        double hro_ave = 0;
                                        for (int ii = 0; ii < index_FullStatus[index_couple]; ii++)
                                        {
                                            mr_sum += Nodes[index_Node].mri[ii];
                                        }
                                        for (int ii = 0; ii < index_FullStatus[index_couple]; ii++)
                                        {
                                            tro_ave += Nodes[index_Node].mri[ii] * Nodes[index_Node].tri[ii];
                                            hro_ave += Nodes[index_Node].mri[ii] * Nodes[index_Node].hri[ii];
                                        }
                                        Nodes[index_Node].mro[0] = mr_sum;
                                        Nodes[index_Node].tro[0] = tro_ave / mr_sum;
                                        Nodes[index_Node].hro[0] = hro_ave / mr_sum;
                                        Nodes[index_Node].pro[0] = Nodes[index_Node].pri[0];
                                        if (Nodes[index_Node].outType[0] == 0)//0:out is Node
                                        {
                                            index_last_Node = index_Node;
                                            index_Node      = SearchNode.FindNextNode(index_Node, 0, Nodes, N_Node);
                                            if (Nodes[index_Node].type == 'C')
                                            {
                                                for (int ii = 0; ii < N_Node; ii++)
                                                {
                                                    if (Nodes[ii].couple == Nodes[index_Node].couple && ii != index_Node)
                                                    {
                                                        index_couple = ii;
                                                        break;
                                                    }
                                                }//Find the Couple Node
                                                Nodes[index_Node].pri[index_status[index_couple]] = Nodes[index_last_Node].pro[0];
                                                Nodes[index_Node].tri[index_status[index_couple]] = Nodes[index_last_Node].tro[0];
                                                Nodes[index_Node].hri[index_status[index_couple]] = Nodes[index_last_Node].hro[0];
                                                Nodes[index_Node].mri[index_status[index_couple]] = Nodes[index_last_Node].mro[0];
                                                continue;
                                            }
                                            else if (Nodes[index_Node].type == 'D')
                                            {
                                                index_status[index_Node] = 0;
                                                Nodes[index_Node].mri[0] = Nodes[index_last_Node].mro[0];
                                                Nodes[index_Node].tri[0] = Nodes[index_last_Node].tro[0];
                                                Nodes[index_Node].hri[0] = Nodes[index_last_Node].hro[0];
                                                Nodes[index_Node].pri[0] = Nodes[index_last_Node].pro[0];
                                                break;
                                            }
                                        }
                                        else if (Nodes[index_Node].outType[0] == -1)
                                        {
                                            index_end = true;
                                            break;
                                        }
                                        else//out is Circuit
                                        {
                                            break;
                                        }
                                        continue;
                                    }
                                } //end if
                            }     //end for
                            if (index_end == true)
                            {
                                break;
                            }
                        }
                        else if (Nodes[index_Node].type == 'E')//for 1 out case
                        {
                            Nodes[index_Node].pri[0] = r.Pro;
                            Nodes[index_Node].tri[0] = r.Tro;
                            Nodes[index_Node].hri[0] = r.hro;
                            Nodes[index_Node].mro[0] = r.mr;
                            Nodes[index_Node].pro[0] = r.Pro;
                            Nodes[index_Node].tro[0] = r.Tro;
                            Nodes[index_Node].hro[0] = r.hro;
                            Nodes[index_Node].mro[0] = r.mr;
                            break;
                        }
                    }//end out for
                    airConverge = CheckAirConvergeforCircuits.CheckAirConverge2(cirArrforAir.TotalDirection, Nrow, N_tube, Nelement, ta, RH, taout_calc, RHout_calc); //taout_calc, RHout_calc
                    ta          = airConverge.ta;
                    RH          = airConverge.RH;
                    iterforAir++;
                } while (airConverge.flag == false && iterforAir < 50);
                if (hexType == 0)
                {
                    te_calc     = CoolProp.PropsSI("T", "P", Nodes[index_Node].pro[0] * 1000, "Q", 0, fluid);
                    priconverge = CheckPin.CheckPriConverge(te, te_calc - 273.15, te_calc_org - 273.15, pri, pe, Nodes[index_Node].pro[0]); //res_slab.Pro
                    iterforPri++;
                    pri         = priconverge.pri;
                    te_calc_org = te_calc;
                    if (priconverge.flag && iterforPri == 1)
                    {
                        priconverge.flag = false; //to avoid not even iterate but converge by chance
                    }
                }
            } while (priconverge.flag == false && iterforPri < 20);
            //result print
            if (iterforDP >= 200)
            {
                return(res_slab);

                throw new Exception("iter for DPConverge > 200.");
            }
            if (iterforPri >= 50)
            {
                return(res_slab);

                throw new Exception("iter for Pri > 50.");
            }
            #region result print
            for (int i = 0; i < N_cir; i++)
            {
                res_slab.R_1  += res_cir[i].R_1 * CircuitInfo.TubeofCir[i];
                res_slab.R_1a += res_cir[i].R_1a * CircuitInfo.TubeofCir[i];
                res_slab.R_1r += res_cir[i].R_1r * CircuitInfo.TubeofCir[i];
            }
            for (int j = 0; j < N_tube; j++)//detail output
            {
                for (int k = 0; k < Nrow; k++)
                {
                    res_slab.Q    += Q_detail[j, k];
                    res_slab.M    += charge_detail[j, k];
                    res_slab.href += href_detail[j, k];
                }
            }
            res_slab.hro        = Nodes[index_Node].hro[0];
            res_slab.Pro        = Nodes[index_Node].pro[0];
            res_slab.Pri        = pri;
            res_slab.Tri        = tri;
            res_slab.hri        = hri;
            res_slab.mr         = mr;
            res_slab.DP         = pri - res_slab.Pro;
            res_slab.Tao_Detail = ta;
            res_slab.RHo_Detail = RH;
            res_slab.href       = res_slab.href / N_tube_total;
            for (int i = 0; i < ha.GetLength(0); i++)
            {
                for (int j = 0; j < ha.GetLength(1); j++)
                {
                    res_slab.ha += ha[i, j];
                }
            }
            res_slab.ha   = res_slab.ha / ha.Length;
            res_slab.R_1  = res_slab.R_1 / N_tube_total;
            res_slab.R_1a = res_slab.R_1a / N_tube_total;
            res_slab.R_1r = res_slab.R_1r / N_tube_total;
            te_calc       = CoolProp.PropsSI("T", "P", res_slab.Pro * 1000, "Q", 0, fluid) - 273.15;
            double densityLo = CoolProp.PropsSI("D", "T", te_calc + 273.15, "Q", 0, fluid);
            double densityVo = CoolProp.PropsSI("D", "T", te_calc + 273.15, "Q", 1, fluid);
            double hlo       = CoolProp.PropsSI("H", "T", te_calc + 273.15, "D", densityLo, fluid) / 1000;
            double hvo       = CoolProp.PropsSI("H", "T", te_calc + 273.15, "D", densityVo, fluid) / 1000;
            res_slab.x_o = (res_slab.hro - hlo) / (hvo - hlo);
            double hli = CoolProp.PropsSI("H", "P", pri * 1000, "Q", 0, fluid) / 1000;
            double hvi = CoolProp.PropsSI("H", "P", pri * 1000, "Q", 1, fluid) / 1000;
            res_slab.x_i = (res_slab.hri - hli) / (hvi - hli);
            res_slab.Tro = CoolProp.PropsSI("T", "P", res_slab.Pro * 1000, "H", res_slab.hro * 1000, fluid) - 273.15;
            for (int j = 0; j < N_tube; j++)
            {
                for (int i = 0; i < Nelement; i++)
                {
                    res_slab.Tao   += res_slab.Tao_Detail[i, j, Nrow];
                    res_slab.RHout += res_slab.RHo_Detail[i, j, Nrow];
                }
            }

            res_slab.Tao      = res_slab.Tao / (N_tube * Nelement);
            res_slab.RHout    = res_slab.RHout / (N_tube * Nelement);
            res_slab.Ra_ratio = res_slab.R_1a / res_slab.R_1;
            for (int i = 0; i < ma.GetLength(0); i++)
            {
                for (int j = 0; j < ma.GetLength(1); j++)
                {
                    res_slab.ma += ma[i, j];
                }
            }
            res_slab.Va            = res_slab.ma / 1.2 * 3600;
            res_slab.Q_detail      = Q_detail;//detail output
            res_slab.DP_detail     = DP_detail;
            res_slab.Tri_detail    = Tri_detail;
            res_slab.Pri_detail    = Pri_detail;
            res_slab.hri_detail    = hri_detail;
            res_slab.Tro_detail    = Tro_detail;
            res_slab.Pro_detail    = Pro_detail;
            res_slab.hro_detail    = hro_detail;
            res_slab.href_detail   = href_detail;
            res_slab.mr_detail     = mr_detail;
            res_slab.Aa            = geo.TotalArea.A_a;
            res_slab.Ar            = geo.TotalArea.A_r;
            res_slab.AHx           = geo.TotalArea.A_hx;
            res_slab.N_row         = Nrow;
            res_slab.tube_row      = N_tube;
            res_slab.charge_detail = charge_detail;
            #endregion
            return(res_slab);
        } //end function
示例#30
0
        public static CalcResult TubeCalc(int Nelement, string fluid,
                                          double l, double Aa_fin, double Aa_tube, double A_r_cs, double Ar, Geometry geo, double[] tai,
                                          double[] RHi, double tri, double pri, double hri, double mr, double[] ma, double[] ha, double[] haw,
                                          double eta_surface, double zh, double zdp, int hexType, double thickness, double conductivity, double Pwater, AbstractState coolprop, double[,] SourceTableData)
        {
            double g = mr / A_r_cs;

            CalcResult res_tube = new CalcResult();

            res_tube.Tao_Detail = new double[1, 1, Nelement];
            CalcResult[] r = new CalcResult[Nelement];
            for (int i = 0; i < Nelement; i++)
            {
                r[i] = Element.ElementCal(fluid, l / Nelement, Aa_fin, Aa_tube, A_r_cs, Ar, geo,
                                          tai[i], RHi[i], tri, pri, hri, mr, g, ma[i], ha[i], haw[i], eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, coolprop, SourceTableData);//elementtest

                //SP/TP Smooth
                if ((r[i].x_i > 1 && r[i].x_o < 1) || (r[i].x_i > 0 && r[i].x_o < 0) || (r[i].x_i < 0 && r[i].x_o > 0) || (r[i].x_i < 1 && r[i].x_o > 1))
                {
                    int N_sub = 20;
                    r[i] = new CalcResult();
                    CalcResult[] r_sub   = new CalcResult[N_sub];
                    double       tri_sub = new double();
                    double       pri_sub = new double();
                    double       hri_sub = new double();
                    tri_sub = tri;
                    pri_sub = pri;
                    hri_sub = hri;
                    for (int j = 0; j < N_sub; j++)
                    {
                        r_sub[j] = Element.ElementCal(fluid, l / Nelement / N_sub, Aa_fin / N_sub, Aa_tube / N_sub, A_r_cs, Ar / N_sub, geo,
                                                      tai[i], RHi[i], tri_sub, pri_sub, hri_sub, mr, g, ma[i] / N_sub, ha[i], haw[i], eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, coolprop, SourceTableData);
                        pri_sub = r_sub[j].Pro;
                        hri_sub = r_sub[j].hro;
                        tri_sub = r_sub[j].Tro;

                        r[i].Tao   += r_sub[j].Tao;
                        r[i].RHout += r_sub[j].RHout;
                        r[i].DP    += r_sub[j].DP;
                        r[i].Q     += r_sub[j].Q;
                        r[i].M     += r_sub[j].M;
                        r[i].href  += r_sub[j].href;
                        r[i].R_1   += r_sub[j].R_1;
                        r[i].R_1a  += r_sub[j].R_1a;
                        r[i].R_1r  += r_sub[j].R_1r;
                    }
                    r[i].Tao   = r[i].Tao / N_sub;
                    r[i].RHout = r[i].RHout / N_sub;
                    r[i].href  = r[i].href / N_sub;
                    r[i].R_1   = r[i].R_1 / N_sub;
                    r[i].R_1a  = r[i].R_1a / N_sub;
                    r[i].R_1r  = r[i].R_1r / N_sub;
                    r[i].Pro   = r_sub[N_sub - 1].Pro;
                    r[i].hro   = r_sub[N_sub - 1].hro;
                    r[i].Tro   = r_sub[N_sub - 1].Tro;
                    r[i].x_o   = r_sub[N_sub - 1].x_o;
                    r[i].Vel_r = r_sub[N_sub - 1].Vel_r;
                    r[i].x_i   = r_sub[0].x_i;
                    r[i].Tri   = r_sub[0].Tri;
                }

                if (r[i].Pro < 0)
                {
                    res_tube.Pro = -10000000; return(res_tube);
                }
                pri = r[i].Pro;
                hri = r[i].hro;
                tri = r[i].Tro;
                res_tube.Tao_Detail[0, 0, i] = r[i].Tao;
                res_tube.Tao   += r[i].Tao;
                res_tube.RHout += r[i].RHout;
                res_tube.DP    += r[i].DP;
                res_tube.Q     += r[i].Q;
                res_tube.M     += r[i].M;
                res_tube.href  += r[i].href;
                res_tube.R_1   += r[i].R_1;
                res_tube.R_1a  += r[i].R_1a;
                res_tube.R_1r  += r[i].R_1r;
            }
            res_tube.Tao   = res_tube.Tao / Nelement;
            res_tube.RHout = res_tube.RHout / Nelement;
            res_tube.href  = res_tube.href / Nelement;
            res_tube.R_1   = res_tube.R_1 / Nelement;
            res_tube.R_1a  = res_tube.R_1a / Nelement;
            res_tube.R_1r  = res_tube.R_1r / Nelement;
            res_tube.Tro   = r[Nelement - 1].Tro;
            res_tube.Pro   = r[Nelement - 1].Pro;
            res_tube.hro   = r[Nelement - 1].hro;
            res_tube.x_o   = r[Nelement - 1].x_o;
            res_tube.Vel_r = r[Nelement - 1].Vel_r;
            res_tube.Tri   = r[0].Tri;
            res_tube.x_i   = r[0].x_i;
            return(res_tube);
        }
示例#31
0
        static void Main(string[] args)
        {
            AbstractState State = AbstractState.factory("HEOS", "Water");

            State.update(input_pairs.PT_INPUTS, 1e5, 300);
            double hmol = State.hmolar();

            Console.Write("Hmol: " + hmol + " J/kg" + "\n");

            double T, h, p, D;

            //Console.Write("CoolProp version: " + CoolProp.get_global_param_string("version") + "\n");
            //Console.Write("CoolProp gitrevision: " + CoolProp.get_global_param_string("gitrevision") + "\n");
            //Console.Write("CoolProp fluids: " + CoolProp.get_global_param_string("FluidsList") + "\n");

            Console.Write(" " + "\n");
            Console.Write("************ USING EOS *************" + "\n");
            Console.Write(" " + "\n");
            Console.Write("FLUID STATE INDEPENDENT INPUTS" + "\n");
            //Console.Write("Critical Density Propane: " + CoolProp.Props1SI("Propane", "rhocrit") + " kg/m^3" + "\n");
            Console.Write("TWO PHASE INPUTS (Pressure)" + "\n");
            Console.Write("Density of saturated liquid Propane at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "Propane") + " kg/m^3" + "\n");
            Console.Write("Density of saturated vapor R290 at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 1, "R290") + " kg/m^3" + "\n");
            Console.Write("TWO PHASE INPUTS (Temperature)" + "\n");
            Console.Write("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "Propane") + " kg/m^3" + "\n");
            Console.Write("Density of saturated vapor R290 at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 1, "R290") + " kg/m^3" + "\n");
            Console.Write("SINGLE PHASE CYCLE (propane)" + "\n");
            p = CoolProp.PropsSI("P", "T", 300, "D", 1, "Propane");
            h = CoolProp.PropsSI("H", "T", 300, "D", 1, "Propane");
            Console.Write("T,D -> P,H " + 300 + "," + 1 + " --> " + p + "," + h + "\n");
            T = CoolProp.PropsSI("T", "P", p, "H", h, "Propane");
            D = CoolProp.PropsSI("D", "P", p, "H", h, "Propane");
            Console.Write("P,H -> T,D " + p + "," + h + " --> " + T + "," + D + "\n");

            //~ Console.Write(" " + "\n");
            //~ Console.Write("************ USING TTSE ***************" + "\n");
            //~ Console.Write(" " + "\n");
            //~ //CoolProp.enable_TTSE_LUT("Propane");
            //~ Console.Write("TWO PHASE INPUTS (Pressure)" + "\n");
            //~ Console.Write("Density of saturated liquid Propane at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "Propane") + " kg/m^3" + "\n");
            //~ Console.Write("Density of saturated vapor R290 at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 1, "R290") + " kg/m^3" + "\n");
            //~ Console.Write("TWO PHASE INPUTS (Temperature)" + "\n");
            //~ Console.Write("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "Propane") + " kg/m^3" + "\n");
            //~ Console.Write("Density of saturated vapor R290 at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 1, "R290") + " kg/m^3" + "\n");
            //~ Console.Write("SINGLE PHASE CYCLE (propane)" + "\n");
            //~ p = CoolProp.PropsSI("P", "T", 300, "D", 1, "Propane");
            //~ h = CoolProp.PropsSI("H", "T", 300, "D", 1, "Propane");
            //~ Console.Write("T,D -> P,H " + 300 + ","+ 1+ " --> " + p + "," + h + "\n");
            //~ T = CoolProp.PropsSI("T", "P", p, "H", h, "Propane");
            //~ D = CoolProp.PropsSI("D", "P", p, "H", h, "Propane");
            //~ Console.Write("P,H -> T,D " + p + "," + h + " --> " + T + "," + D + "\n");
            //CoolProp.disable_TTSE_LUT("Propane");

            try
            {
                Console.Write(" " + "\n");
                Console.Write("************ USING REFPROP ***************" + "\n");
                Console.Write(" " + "\n");
                Console.Write("TWO PHASE INPUTS (Pressure)" + "\n");
                Console.Write("Density of saturated liquid Propane at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "REFPROP::Propane") + " kg/m^3" + "\n");
                Console.Write("TWO PHASE INPUTS (Temperature)" + "\n");
                Console.Write("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "REFPROP::Propane") + " kg/m^3" + "\n");
                Console.Write("SINGLE PHASE CYCLE (propane)" + "\n");
                p = CoolProp.PropsSI("P", "T", 300, "D", 1, "REFPROP::Propane");
                h = CoolProp.PropsSI("H", "T", 300, "D", 1, "REFPROP::Propane");
                Console.Write("T,D -> P,H " + 300 + "," + 1 + " --> " + p + "," + h + "\n");
                T = CoolProp.PropsSI("T", "P", p, "H", h, "REFPROP::Propane");
                D = CoolProp.PropsSI("D", "P", p, "H", h, "REFPROP::Propane");
                Console.Write("P,H -> T,D " + p + "," + h + " --> " + T + "," + D + "\n");
            }
            catch
            {
                Console.Write(" " + "\n");
                Console.Write("************ CANT USE REFPROP ************" + "\n");
                Console.Write(" " + "\n");
            }

            Console.Write(" " + "\n");
            Console.Write("************ BRINES AND SECONDARY WORKING FLUIDS *************" + "\n");
            Console.Write(" " + "\n");
            Console.Write("Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa: " + CoolProp.PropsSI("D", "T", 300, "P", 101325, "INCOMP::MEG-50%") + " kg/m^3" + "\n");
            Console.Write("Viscosity of Therminol D12 at 350 K, 101325 kPa: " + CoolProp.PropsSI("V", "T", 350, "P", 101325, "INCOMP::TD12") + " Pa-s" + "\n");

            Console.Write(" " + "\n");
            Console.Write("************ HUMID AIR PROPERTIES *************" + "\n");
            Console.Write(" " + "\n");
            //Console.Write("Humidity ratio of 50% rel. hum. air at 300 K, 101.325 kPa: " + CoolProp.HAProps("W", "T", 300, "P", 101.325, "R", 0.5) + " kg_w/kg_da" + "\n");
            //Console.Write("Relative humidity from last calculation: " + CoolProp.HAProps("R", "T", 300, "P", 101.325, "W", CoolProp.HAProps("W", "T", 300, "P", 101.325, "R", 0.5)) + "(fractional)" + "\n");

            //Console.Write("Enter to quit");
            //Console.ReadLine();
        }
示例#32
0
        public void addState(string stateName, string p1, string p2, string p3, float precision, float grados, string stateType, int posState1, int posState2)
        {
            AbstractState aS = makeState(stateName, p1, p2, p3, precision, grados, stateType, posState1, posState2);

            myStates.Add(aS);
        }
示例#33
0
 // Evento disparado cuando se comienza a editar una celda
 private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
 {
     currentStateEditing = myStates[e.RowIndex];
 }
示例#34
0
    // Update is called once per frame
    void Update()
    {
        base.Update ();
        this.State = State.Update ();
        /*if(time==0){
            //GameObject zombie1 = GameObject.FindGameObjectWithTag("zombie");
            zombie zombie = zombie1.GetComponent(typeof(zombie)) as zombie;
            print (zombie.decayTime);
            zombie1 = zombie.gameObject;
            angle = GetAngle (transform.position.x, transform.position.y, zombie1.transform.position.x, zombie1.transform.position.y);
            transform.localEulerAngles = new Vector3 (0, 0, transform.rotation.z + angle);
            zombie.isDead = true;
            zombie.setDT(Time.time+1);
            zombie.gameObject.tag = "Untagged";
            zombie.gameObject.transform.renderer.material.color = Color.gray;
            doBulletEffect(zombie1.transform);
        }*/
        if(Time.time-time>=1.2f&&time!=0&&time!=-1){
            for(int i =0; i<5;i++)
                Destroy(effect[i]);
            time = -1;
            bEffect = false;

        }
        if(bEffect){
            Vector3[] eP = new Vector3[5];
            for(int i =0; i<5;i++)
                eP[i] = effect[i].transform.position;
            effect[0].transform.position = Vector3.MoveTowards(effect[0].transform.position, new Vector3(eP[0].x+1f,eP[0].y,-5), 2.5f * Time.deltaTime);
            effect[1].transform.position = Vector3.MoveTowards(effect[1].transform.position, new Vector3(eP[1].x-1f,eP[1].y,-5), 3f * Time.deltaTime);
            effect[2].transform.position = Vector3.MoveTowards(effect[2].transform.position, new Vector3(eP[2].x,eP[2].y+1f,-5), 4f * Time.deltaTime);
            effect[3].transform.position = Vector3.MoveTowards(effect[3].transform.position, new Vector3(eP[3].x,eP[3].y-1f,-5), 5f * Time.deltaTime);
            effect[4].transform.position = Vector3.MoveTowards(effect[4].transform.position, new Vector3(eP[4].x+1f,eP[4].y+1f,-5), 0.5f * Time.deltaTime);
        }
    }
示例#35
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AbstractState obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
示例#36
0
 public StateContext()
 {
     Current = new State1();
 }
示例#37
0
        private async Task <InitResult> DoInit(InitParameter parameter, string code)
        {
            var    config = new Mediator.Config(parameter.ModuleConfig);
            string libs   = config.GetOptionalString("csharp-libraries", "");
            bool   cache  = config.GetOptionalBool("csharp-cache-scripts", true);

            string[] assemblies = libs
                                  .Split(new char[] { ';', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
                                  .Select(s => s.Trim())
                                  .ToArray();

            string[] absoluteAssemblies = assemblies.Select(d => Path.GetFullPath(d)).ToArray();
            foreach (string assembly in absoluteAssemblies)
            {
                if (!File.Exists(assembly))
                {
                    throw new Exception($"csharp-library does not exist: {assembly}");
                }
            }

            absoluteAssemblies = absoluteAssemblies.Select(assembly => {
                if (assembly.ToLowerInvariant().EndsWith(".cs"))
                {
                    CompileResult compileRes = CompileLib.CSharpFile2Assembly(assembly);
                    Print(compileRes, assembly);
                    return(compileRes.AssemblyFileName);
                }
                return(assembly);
            }).ToArray();

            var referencedAssemblies = new List <Assembly>();

            foreach (string assembly in absoluteAssemblies)
            {
                try {
                    Assembly ass = Assembly.LoadFrom(assembly);
                    referencedAssemblies.Add(ass);
                }
                catch (Exception exp) {
                    throw new Exception($"Failed to load csharp-library {assembly}: {exp.Message}");
                }
            }

            CodeToObjectBase objMaker;

            if (cache)
            {
                objMaker = new CodeToObjectCompile();
            }
            else
            {
                objMaker = new CodeToObjectScripting();
            }

            object obj = await objMaker.MakeObjectFromCode(parameter.Calculation.Name, code, referencedAssemblies);

            inputs  = GetIdentifiableMembers <InputBase>(obj, "", recursive: false).ToArray();
            outputs = GetIdentifiableMembers <OutputBase>(obj, "", recursive: false).ToArray();
            states  = GetIdentifiableMembers <AbstractState>(obj, "", recursive: true).ToArray();

            var eventProviders = GetMembers <EventProvider>(obj, recursive: true);

            foreach (EventProvider provider in eventProviders)
            {
                provider.EventSinkRef = this;
            }

            Type type = obj.GetType();

            MethodInfo[] methods =
                type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)
                .Where(m => m.Name == "Step" && IsStepSignature(m))
                .ToArray();

            if (methods.Length == 0)
            {
                throw new Exception("No Step(Timestamp t, TimeSpan dt) method found.");
            }
            MethodInfo step = methods[0];

            stepAction = (Action <Timestamp, Duration>)step.CreateDelegate(typeof(Action <Timestamp, Duration>), obj);

            foreach (StateValue v in parameter.LastState)
            {
                AbstractState state = states.FirstOrDefault(s => s.ID == v.StateID);
                if (state != null)
                {
                    state.SetValueFromDataValue(v.Value);
                }
            }

            return(new InitResult()
            {
                Inputs = inputs.Select(MakeInputDef).ToArray(),
                Outputs = outputs.Select(MakeOutputDef).ToArray(),
                States = states.Select(MakeStateDef).ToArray(),
                ExternalStatePersistence = true
            });
        }
示例#38
0
 public InferenceNode(AbstractState startState, AbstractState targetState)
     : base(startState, targetState, null, null)
 {
     this.PathCost = 0;
     this.EstimatedTotalPathCost = this.PathCost + this.State.Clause.Count;
 }
示例#39
0
 public GoBaseAI(survivorAI surviror, AbstractState parent)
     : base(surviror)
 {
     this.Parent = parent;
     startSearch = Time.fixedTime;
     this.survivorAI.doSearch(20.0f, 13.0f);
 }
示例#40
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AbstractState obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
示例#41
0
        /**
         * This method deactivates the current active state.
         * It will call the Hide() method on it as well as the state's Destruct() method.
         */
        public void deactivateState()
        {
            if (this._active == null) return;

            lock(this._lockObj) {
                this._form.Controls.Remove (this._active);
                this._active.Hide ();
                this._active.Destruct();
                this._active = null;
            }
        }
示例#42
0
 internal static HandleRef getCPtr(AbstractState obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
示例#43
0
 public Context(AbstractState state)
 {
     State = state;
 }
示例#44
0
 public State()
 {
     Data = new AbstractState();
 }
示例#45
0
 private void Start()
 {
     _game.Init(this);
     AbstractState.Init(this, DefaultState.instance);
 }
示例#46
0
 private void orthographiqueToolStripMenuItem_Click(object sender, EventArgs e)
 {
     viewState = new ViewPerspectiveState();
     FonctionsNatives.changeToPerspective();
 }
示例#47
0
 public void AddState(string stateName, AbstractState state)
 {
     Debug.Assert(Exists(stateName) == false);
     _states.Add(stateName, state);
 }
 /// <summary>
 /// 初始化异步读写锁
 /// </summary>
 public AsyncReaderWriterLock()
 {
     m_currentState = new NoneState(this);
 }
示例#49
0
 public void ChangeState(string stateName)
 {
     Debug.Assert(Exists(stateName));
     _currentState = _states[stateName];
 }
示例#50
0
        public static CalcResult SlabCalc(int[,] CirArrange, CircuitNumber CircuitInfo, int Nrow, int[] Ntube, int Nelement, string fluid, //double Npass, int[] N_tubes_pass,
                                          double l, Geometry geo, double[, ,] ta, double[, ,] RH,
                                          double te, double pe, double hri, double mr, double[,] ma, double[,] ha, double[,] haw,
                                          double eta_surface, double zh, double zdp, int hexType, double thickness, double conductivity, double Pwater, string Airdirection, CapiliaryInput cap_inlet, CapiliaryInput cap_outlet, AbstractState coolprop, double[,] SourceTableData)

        {
            //------->
            // R2   R1

            // [11   1] <====
            // [12   2] <====
            //          <==== Air
            // [13   3] <====
            // [14   4] <====
            // [15   5]  <====
            // [16   6] <====
            // [17   7] <====
            // [18   8]  <====
            // [19   9] <====
            // [20  10] <====

            //  Ncir=1, 11in, 20->10 1out


            // [19 - 17 - 15 - 13   11   9   7   5   3   1] <====Air
            // [20 - 18 - 16 - 14   12   10  8   6   4   2] <====Air
            //  Ncir=1, 20in, 20->19 1out

            // CirArrange = new int[,] { { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 } };
            // Nrow=2
            // Ncir=2
            //AbstractState coolprop = AbstractState.factory("HEOS", fluid);

            double[] Q1    = new double[50];
            double   tri   = te; //Refrigerant.SATP(fluid, composition, pri, 1).Temperature - 273.15;
            double   pri   = pe;
            int      Nciri = CircuitInfo.number[0];
            int      Nciro = CircuitInfo.number[1];
            int      Ncir  = (Nciri == Nciro ? Nciri : Nciri + Nciro);

            int    N_tube       = Ntube[0];
            int    N_tube_total = 0;
            int    iRow         = 0;
            int    iTube_o      = 0;
            int    iTube_n      = 0;
            int    index_o      = 0;
            int    index_n      = 0;
            double te_calc_org  = 0;

            CirArr[]     cirArr       = new CirArr[Nrow * N_tube];
            CirArrforAir cirArrforAir = new CirArrforAir();

            cirArrforAir = CirArrangement.ReadCirArr(CirArrange, CircuitInfo, Nrow, Ntube, 0);
            cirArr       = cirArrforAir.CirArr;

            CalcResult res_slab = new CalcResult();

            double[]        pri_cir      = new double[Ncir]; //[element, tube, row]
            double[]        hri_cir      = new double[Ncir];
            double[]        tri_cir      = new double[Ncir];
            double[]        mr_ciri      = new double[Nciri];
            List <double[]> mr_ciri_base = new List <double[]>();

            double[] mr_ciro         = new double[Nciro];
            int[]    Ngroupin        = new int[Nciro];
            int      index           = 0;
            int      restartDP_index = 0;
            int      N_tube2         = 0;

            int[] index_cir          = new int[Ncir];
            int   index_mr_ciri_base = 0;

            CalcResult[] r        = new CalcResult[Ncir];
            CalcResult[] r1       = new CalcResult[Ncir];
            CalcResult[] r2       = new CalcResult[Ncir]; //for NinMout only
            CalcResult[] res_cir2 = new CalcResult[Nciro + 1];
            CalcResult[] res_type = new CalcResult[Nciri + 1];

            double[,] Q_detail      = new double[N_tube, Nrow];//detail output
            double[,] DP_detail     = new double[N_tube, Nrow];
            double[,] Tri_detail    = new double[N_tube, Nrow];
            double[,] Pri_detail    = new double[N_tube, Nrow];
            double[,] hri_detail    = new double[N_tube, Nrow];
            double[,] Tro_detail    = new double[N_tube, Nrow];
            double[,] Pro_detail    = new double[N_tube, Nrow];
            double[,] hro_detail    = new double[N_tube, Nrow];
            double[,] href_detail   = new double[N_tube, Nrow];
            double[,] mr_detail     = new double[N_tube, Nrow];
            double[,] charge_detail = new double[N_tube, Nrow];

            int flag_ciro  = 0;
            int Ncir_forDP = 0;

            double[] mr_forDP = new double[Nciri];
            int      k;
            double   te_calc = 0;

            CheckAir airConverge = new CheckAir();
            CheckDP  dPconverge  = new CheckDP();
            CheckPri priconverge = new CheckPri();

            for (int i = 0; i < Nrow; i++)
            {
                N_tube_total += Ntube[i];
            }
            for (int i = 0; i < Nciro; i++)
            {
                mr_ciro[i] = mr / Nciro;
            }

            bool index_outbig;

            if (CircuitInfo.UnequalCir == null || CircuitInfo.UnequalCir[0] > 0)
            {
                index_outbig = false;
            }
            else
            {
                index_outbig = true;
            }

            if (CircuitInfo.UnequalCir != null)
            {
                for (int j = 0; j < Nciro; j++)
                {
                    for (int i = 0; i < Ncir; i++)
                    {
                        if (CircuitInfo.UnequalCir[i] == Nciri + 1 + j)
                        {
                            Ngroupin[j]++;
                        }
                    }
                    //for (int i = 0; i < Nciri; i++) mr_ciri[i] = mr_ciro[j] / Ngroupin[j];
                }
            }
            int    iterforAir = 0;
            int    iterforDP  = 0;
            int    iterforPri = 0;
            double pri_1      = 0;
            double pri_2      = 0;
            double pri_3      = 0;
            double pri_4      = 0;

            double tri1 = 0;
            double te1  = 0;

            double iterforDP_ciri = 0;
            double iterforDP_ciro = 0;

            //Starting properties
            iterforDP_ciro = 0;
            double[] mr_forDP_o_4 = new double[Nciri];
            double[] mr_forDP_o_3 = new double[Nciri];
            double[] mr_forDP_o_2 = new double[Nciri];
            double[] mr_forDP_o_1 = new double[Nciri];
            do
            {
                #region //AirConverge
                do
                {
                    //iterforDP = 0;
                    r        = new CalcResult[Ncir];
                    r1       = new CalcResult[Ncir];
                    res_cir2 = new CalcResult[Nciro + 1];


                    flag_ciro = (index_outbig ? 1 : 0);
                    //tri = tri;
                    //制冷制热模块计算切换
                    if (hexType == 0)
                    {
                        coolprop.update(input_pairs.PQ_INPUTS, pri * 1000, 0);
                        tri = coolprop.T() - 273.15;
                        tri = CoolProp.PropsSI("T", "P", pri * 1000, "Q", 0, fluid) - 273.15;
                        int a = 1;
                    }
                    else
                    {
                        coolprop.update(input_pairs.PQ_INPUTS, pri * 1000, 0);
                        te = coolprop.T() - 273.15;
                        te = CoolProp.PropsSI("T", "P", pri * 1000, "Q", 0, fluid) - 273.15;
                        int a = 1;
                    }

                    for (int j = 0; j < (flag_ciro == 1 ? (index_outbig ? Nciri + 1 : 1) : Nciro + 1); j++)
                    {
                        if (j >= Nciro)
                        {
                            j         = j - Nciro; //for Nciro
                            flag_ciro = (index_outbig ? 0 : 1);
                        }
                        if (j == 1 && index_outbig && index == 0)
                        {
                            j         = j - 1;
                            flag_ciro = 0;
                        }

                        index          = 0;
                        iterforDP_ciri = 0;
                        double[] mr_forDP_4 = new double[Nciri];
                        double[] mr_forDP_3 = new double[Nciri];
                        double[] mr_forDP_2 = new double[Nciri];
                        double[] mr_forDP_1 = new double[Nciri];

                        double [] mr0_forDP = new double[5];
                        #region //DPConverge
                        do
                        {
                            res_type = new CalcResult[Nciri + 1];
                            k        = 0;
                            if (!index_outbig)
                            {
                                for (int i = 0; i < (flag_ciro == 1 ? Nciro : (Nciri == Nciro ? Ncir : Ncir - Nciro)); i++)
                                {
                                    if (flag_ciro == 1)
                                    {
                                        pri_cir[i + Ncir - Nciro] = res_cir2[i].Pro;
                                        hri_cir[i + Ncir - Nciro] = res_cir2[i].hro;
                                        tri_cir[i + Ncir - Nciro] = res_cir2[i].Tro;
                                    }
                                    else
                                    {
                                        pri_cir[i] = pri;
                                        hri_cir[i] = hri;
                                        tri_cir[i] = tri;
                                    }
                                }
                            }
                            else
                            {
                                for (int i = 0; i < (flag_ciro == 1 ? Nciro : Ncir); i++)
                                {
                                    if (flag_ciro == 1)
                                    {
                                        pri_cir[i] = pri;
                                        hri_cir[i] = hri;
                                        tri_cir[i] = tri;
                                    }
                                    else
                                    {
                                        if (CircuitInfo.UnequalCir[i] == Nciri + 1 + j)
                                        {
                                            pri_cir[i] = r2[j].Pro;
                                            hri_cir[i] = r2[j].hro;
                                            tri_cir[i] = r2[j].Tro;
                                        }
                                    }
                                }
                            }
                            for (int i = 0; i < Ncir; i++)
                            {
                                if (flag_ciro == 1)
                                {
                                    //汇管计算
                                    if (CircuitInfo.UnequalCir[i] <= 0)
                                    {
                                        //for (int i = 0; i < Ncir; i++)

                                        //r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, dh, l, geo.element, ta, RH,
                                        //   tri_cir[i], pri_cir[i], hri_cir[i], mr_ciro[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, Airdirection, d_cap, lenth_cap);

                                        r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, l, geo, ta, RH,
                                                                   tri_cir[i], pri_cir[i], hri_cir[i], mr_ciro[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, cap_inlet, cap_outlet, coolprop, SourceTableData);

                                        if (r[i].Pro < 0)
                                        {
                                            res_slab.Pro = -10000000; return(res_slab);
                                        }
                                        r1[k] = r[i].ShallowCopy();
                                        r2[k] = r[i].ShallowCopy();
                                        if (!index_outbig)
                                        {
                                            r1[k].DP += res_cir2[k].DP;
                                        }

                                        index_cir[k] = i;
                                        k++;
                                        Ncir_forDP = Nciro;
                                        mr_forDP   = (double[])mr_ciro.Clone(); // mr_forDP = mr_ciro
                                        if (k == Nciro)
                                        {
                                            break;
                                        }
                                    }
                                }
                                else if (Nciri == Nciro || CircuitInfo.UnequalCir[i] == Nciri + 1 + j)
                                {
                                    //均匀流路计算和不均匀流路开始部分(独立管)计算
                                    if (index == 0)
                                    {
                                        if (Nciri == Nciro && iterforPri == 0)
                                        {
                                            mr_ciro.CopyTo(mr_ciri, 0);
                                        }
                                        else if (Nciri != Nciro)
                                        {
                                            if (restartDP_index == 1 || !priconverge.flag)
                                            {
                                                var mm = mr_ciri_base[j].Sum();
                                                //foreach (var item in mr_ciri_base[j])
                                                //mm += item;
                                                mr_ciri[k] = mr_ciri_base[j][k] * mr_ciro[j] / mm;//(mr / Nciro);
                                            }
                                            else
                                            {
                                                mr_ciri[k] = mr_ciro[j] / Ngroupin[j];
                                            }
                                        }
                                    }
                                    //else mr_ciri_base.CopyTo(mr_ciri[k], 0);

                                    //for (int i = 0; i < Ncir; i++)

                                    //首次流路计算
                                    if (CircuitInfo.CirType != null && CircuitInfo.CirType.flag == true)
                                    {
                                        bool circuit_cap = false;
                                        //if (d_cap[index] == 0 && lenth_cap[index] == 0) circuit_cap = true;
                                        if ((CircuitInfo.CirType.flag == true) && (CircuitInfo.CirType.type[i, 0] == 0) && (res_type[CircuitInfo.CirType.type[i, 1]] != null && circuit_cap))
                                        {
                                            //r[i] = res_type[CircuitInfo.CirType.type[i, 1]];
                                            r[i]               = new CalcResult();
                                            r[i].DP            = res_type[CircuitInfo.CirType.type[i, 1]].DP;
                                            r[i].DP_cap        = res_type[CircuitInfo.CirType.type[i, 1]].DP_cap;
                                            r[i].href          = res_type[CircuitInfo.CirType.type[i, 1]].href;
                                            r[i].hro           = res_type[CircuitInfo.CirType.type[i, 1]].hro;
                                            r[i].M             = res_type[CircuitInfo.CirType.type[i, 1]].M;
                                            r[i].Pro           = res_type[CircuitInfo.CirType.type[i, 1]].Pro;
                                            r[i].Q             = res_type[CircuitInfo.CirType.type[i, 1]].Q;
                                            r[i].R_1           = res_type[CircuitInfo.CirType.type[i, 1]].R_1;
                                            r[i].R_1a          = res_type[CircuitInfo.CirType.type[i, 1]].R_1a;
                                            r[i].R_1r          = res_type[CircuitInfo.CirType.type[i, 1]].R_1r;
                                            r[i].Ra_ratio      = res_type[CircuitInfo.CirType.type[i, 1]].Ra_ratio;
                                            r[i].RHout         = res_type[CircuitInfo.CirType.type[i, 1]].RHout;
                                            r[i].Tao           = res_type[CircuitInfo.CirType.type[i, 1]].Tao;
                                            r[i].Tri           = res_type[CircuitInfo.CirType.type[i, 1]].Tri;
                                            r[i].Tro           = res_type[CircuitInfo.CirType.type[i, 1]].Tro;
                                            r[i].x_i           = res_type[CircuitInfo.CirType.type[i, 1]].x_i;
                                            r[i].x_o           = res_type[CircuitInfo.CirType.type[i, 1]].x_o;
                                            r[i].Vel_r         = res_type[CircuitInfo.CirType.type[i, 1]].Vel_r;
                                            r[i].mr            = res_type[CircuitInfo.CirType.type[i, 1]].mr;
                                            r[i].Q_detail      = new double[N_tube, Nrow];//
                                            r[i].DP_detail     = new double[N_tube, Nrow];
                                            r[i].Tri_detail    = new double[N_tube, Nrow];
                                            r[i].Pri_detail    = new double[N_tube, Nrow];
                                            r[i].hri_detail    = new double[N_tube, Nrow];
                                            r[i].Tro_detail    = new double[N_tube, Nrow];
                                            r[i].Pro_detail    = new double[N_tube, Nrow];
                                            r[i].hro_detail    = new double[N_tube, Nrow];
                                            r[i].href_detail   = new double[N_tube, Nrow];
                                            r[i].mr_detail     = new double[N_tube, Nrow];
                                            r[i].Tao_Detail    = new double[Nelement, N_tube, Nrow];
                                            r[i].RHo_Detail    = new double[Nelement, N_tube, Nrow];
                                            r[i].charge_detail = new double[N_tube, Nrow];
                                            for (int m = 0; m < CircuitInfo.TubeofCir[i]; m++)
                                            {
                                                index_o = 0;
                                                index_n = 0;
                                                if (i == 0)
                                                {
                                                    index_n = 0;
                                                }
                                                else
                                                {
                                                    for (int n = 1; n <= i; n++)
                                                    {
                                                        index_n += CircuitInfo.TubeofCir[n - 1];
                                                    }
                                                }
                                                if (res_type[CircuitInfo.CirType.type[i, 1]].index == 0)
                                                {
                                                    index_o = 0;
                                                }
                                                else
                                                {
                                                    for (int n = 1; n <= res_type[CircuitInfo.CirType.type[i, 1]].index; n++)
                                                    {
                                                        index_o += CircuitInfo.TubeofCir[n - 1];
                                                    }
                                                }
                                                iRow    = cirArr[m + index_o].iRow;
                                                iTube_o = cirArr[m + index_o].iTube;
                                                iTube_n = cirArr[m + index_n].iTube;
                                                r[i].Q_detail[iTube_n, iRow]      = res_type[CircuitInfo.CirType.type[i, 1]].Q_detail[iTube_o, iRow];//
                                                r[i].DP_detail[iTube_n, iRow]     = res_type[CircuitInfo.CirType.type[i, 1]].DP_detail[iTube_o, iRow];
                                                r[i].Tri_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].Tri_detail[iTube_o, iRow];
                                                r[i].Pri_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].Pri_detail[iTube_o, iRow];
                                                r[i].hri_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].hri_detail[iTube_o, iRow];
                                                r[i].Tro_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].Tro_detail[iTube_o, iRow];
                                                r[i].Pro_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].Pro_detail[iTube_o, iRow];
                                                r[i].hro_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].hro_detail[iTube_o, iRow];
                                                r[i].href_detail[iTube_n, iRow]   = res_type[CircuitInfo.CirType.type[i, 1]].href_detail[iTube_o, iRow];
                                                r[i].mr_detail[iTube_n, iRow]     = res_type[CircuitInfo.CirType.type[i, 1]].mr_detail[iTube_o, iRow];
                                                r[i].charge_detail[iTube_n, iRow] = res_type[CircuitInfo.CirType.type[i, 1]].charge_detail[iTube_o, iRow];

                                                for (int p = 0; p < Nelement; p++)
                                                {
                                                    //ta[p, iTube_n, iRow + 1] = res_type[CircuitInfo.CirType.type[i, 1]].Tao_Detail[p, iTube_o, iRow];
                                                    //RH[p, iTube_n, iRow + 1] = res_type[CircuitInfo.CirType.type[i, 1]].RHo_Detail[p, iTube_o, iRow];
                                                    r[i].Tao_Detail[p, iTube_n, iRow] = res_type[CircuitInfo.CirType.type[i, 1]].Tao_Detail[p, iTube_o, iRow];
                                                    r[i].RHo_Detail[p, iTube_n, iRow] = res_type[CircuitInfo.CirType.type[i, 1]].RHo_Detail[p, iTube_o, iRow];
                                                }
                                            }
                                            //r[i].Tao_Detail = ta;
                                            //r[i].RHo_Detail = RH;
                                        }
                                        else
                                        {
                                            //r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, dh, l, geo.element, ta, RH,
                                            //tri_cir[i], pri_cir[i], hri_cir[i], mr_ciri[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, Airdirection, d_cap, lenth_cap);

                                            r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, l, geo, ta, RH,
                                                                       tri_cir[i], pri_cir[i], hri_cir[i], mr_ciri[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, cap_inlet, cap_outlet, coolprop, SourceTableData);

                                            if (r[i].Pro < 0)
                                            {
                                                res_slab.Pro = -10000000; return(res_slab);
                                            }

                                            if (CircuitInfo.CirType.type[i, 0] == 0)
                                            {
                                                res_type[CircuitInfo.CirType.type[i, 1]]       = r[i];
                                                res_type[CircuitInfo.CirType.type[i, 1]].index = i;
                                            }
                                        }
                                    }

                                    else
                                    {
                                        //r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, dh, l, geo.element, ta, RH,
                                        //tri_cir[i], pri_cir[i], hri_cir[i], mr_ciri[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, Airdirection, d_cap, lenth_cap);

                                        r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, l, geo, ta, RH,
                                                                   tri_cir[i], pri_cir[i], hri_cir[i], mr_ciri[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, cap_inlet, cap_outlet, coolprop, SourceTableData);

                                        if (r[i].Pro < 0)
                                        {
                                            res_slab.Pro = -10000000; return(res_slab);
                                        }
                                    }

                                    r1[k]        = r[i].ShallowCopy();
                                    index_cir[k] = i;//不均匀流路的输出才会用到
                                    k++;

                                    if (k == (Nciri == Nciro ? Ncir : Ngroupin[j]))
                                    {
                                        Ncir_forDP = (Nciri == Nciro ? Ncir : Ngroupin[j]);
                                        mr_forDP   = (double[])mr_ciri.Clone();
                                        break;
                                    }
                                }
                            }

                            if (index_outbig && flag_ciro == 1)
                            {
                                break;
                            }

                            index++;
                            //dPconverge = CheckDPforCircuits.CheckDPConverge(mr, mr_ciri, r, Ncir);
                            dPconverge = CheckDPforCircuits.CheckDPConverge(hexType, res_cir2, iterforPri, flag_ciro, mr_forDP, r1, Ncir_forDP);

                            if (flag_ciro == 0)
                            {
                                iterforDP_ciri++;
                                if (iterforDP_ciri >= 5)
                                {
                                    mr_forDP_4 = mr_forDP_3;
                                    mr_forDP_3 = mr_forDP_2;
                                    mr_forDP_2 = mr_forDP_1;
                                    mr_forDP_1 = mr_forDP;
                                    try
                                    {
                                        if (mr_forDP_1[0] < mr_forDP_2[0] && (Math.Abs(mr_forDP_1[0] - mr_forDP_3[0]) / mr_forDP_1[0] < 0.0001) ||
                                            Math.Abs(mr_forDP_1[0] - mr_forDP_4[0]) / mr_forDP_1[0] < 0.0001)
                                        {
                                            dPconverge.flag = true;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        continue;
                                    }
                                }
                                restartDP_index = 0;
                                if (!dPconverge.flag)
                                {
                                    dPconverge.mr.CopyTo(mr_ciri, 0);              //mr_ciri = dPconverge.mr;
                                }
                            }
                            else //(flag_ciro == 1)
                            {
                                iterforDP_ciro++;
                                if (iterforDP_ciro >= 5)
                                {
                                    mr_forDP_o_4 = mr_forDP_o_3;
                                    mr_forDP_o_3 = mr_forDP_o_2;
                                    mr_forDP_o_2 = mr_forDP_o_1;
                                    mr_forDP_o_1 = mr_forDP;
                                    try
                                    {
                                        if (mr_forDP_o_1[0] < mr_forDP_o_2[0] && (Math.Abs(mr_forDP_o_1[0] - mr_forDP_o_3[0]) / mr_forDP_o_1[0] < 0.0001) ||
                                            Math.Abs(mr_forDP_o_1[0] - mr_forDP_o_4[0]) / mr_forDP_o_1[0] < 0.0001)
                                        {
                                            dPconverge.flag = true;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        continue;
                                    }
                                }

                                if (dPconverge.flag)
                                {
                                    restartDP_index = 0;
                                }
                                else
                                {
                                    restartDP_index = 1;
                                    dPconverge.mr.CopyTo(mr_ciro, 0); //mr_ciro = dPconverge.mr;
                                    break;
                                }
                            }
                            iterforDP++;


                            N_tube2 = 0;
                            #region //Result print out
                            if (dPconverge.flag)
                            {
                                if (Nciri == Nciro)
                                {
                                    //te_calc = Refrigerant.SATP(fluid, composition, r[j].Pro, 1).Temperature;
                                    coolprop.update(input_pairs.PQ_INPUTS, r[j].Pro * 1000, 0);
                                    te_calc = coolprop.T();
                                    te_calc = CoolProp.PropsSI("T", "P", r[j].Pro * 1000, "Q", 0, fluid);
                                    int a = 1;
                                }
                                else
                                {
                                    if (mr_ciri_base.Count == Nciro && flag_ciro == 0)
                                    {
                                        mr_ciri_base.RemoveAt(index_mr_ciri_base);
                                        mr_ciri_base.Insert(index_mr_ciri_base, mr_forDP);
                                        index_mr_ciri_base++;
                                        index_mr_ciri_base %= mr_ciri_base.Count;
                                    }
                                    if (mr_ciri_base.Count < Nciro)
                                    {
                                        mr_ciri_base.Add(mr_forDP);                         //keep original mr ratio for fast iter
                                    }
                                    j           = (flag_ciro == 1 ? j + Nciro : j);
                                    res_cir2[j] = new CalcResult();
                                    for (int i = 0; i < (flag_ciro == 1 ? Nciro : Ngroupin[j]); i++)
                                    {
                                        res_cir2[j].Q   += r1[i].Q;
                                        res_cir2[j].M   += r1[i].M;
                                        res_cir2[j].hro += (flag_ciro == 1 ? mr_ciro[i] : mr_ciri[i]) * r1[i].hro;
                                        if (fluid == "Water")
                                        {
                                            res_cir2[j].Tro += (flag_ciro == 1 ? mr_ciro[i] : mr_ciri[i]) * r1[i].Tro;
                                        }

                                        res_cir2[j].Vel_r = r1[i].Vel_r;
                                        res_cir2[j].href += r1[i].href * CircuitInfo.TubeofCir[index_cir[i]];
                                        res_cir2[j].R_1  += r1[i].R_1 * CircuitInfo.TubeofCir[index_cir[i]];
                                        res_cir2[j].R_1a += r1[i].R_1a * CircuitInfo.TubeofCir[index_cir[i]];
                                        res_cir2[j].R_1r += r1[i].R_1r * CircuitInfo.TubeofCir[index_cir[i]];

                                        N_tube2 += CircuitInfo.TubeofCir[index_cir[i]];
                                    }
                                    res_cir2[j].DP         = r1[(flag_ciro == 1 ? Nciro : Ngroupin[j]) - 1].DP;
                                    res_cir2[j].Tao_Detail = ta;
                                    res_cir2[j].Pro        = r1[(flag_ciro == 1 ? Nciro : Ngroupin[j]) - 1].Pro;
                                    res_cir2[j].hro        = res_cir2[j].hro / (flag_ciro == 1 ? mr : mr_ciro[j]);

                                    res_cir2[j].href = res_cir2[j].href / N_tube2;
                                    res_cir2[j].R_1  = res_cir2[j].R_1 / N_tube2;
                                    res_cir2[j].R_1a = res_cir2[j].R_1a / N_tube2;
                                    res_cir2[j].R_1r = res_cir2[j].R_1r / N_tube2;
                                    res_cir2[j].Tri  = tri;

                                    //te_calc = Refrigerant.SATP(fluid, composition, res_cir2[j].Pro, 1).Temperature;
                                    coolprop.update(input_pairs.PQ_INPUTS, res_cir2[j].Pro * 1000, 0);
                                    te_calc = coolprop.T();
                                    te_calc = CoolProp.PropsSI("T", "P", res_cir2[j].Pro * 1000, "Q", 0, fluid);

                                    if (fluid == "Water")
                                    {
                                        res_cir2[j].Tro = res_cir2[j].Tro / (flag_ciro == 1 ? mr : mr_ciro[j]) - 273.15;
                                    }
                                    else
                                    {
                                        res_cir2[j].Tro = CoolProp.PropsSI("T", "P", res_cir2[j].Pro * 1000, "H", res_cir2[j].hro * 1000, fluid) - 273.15;
                                    }
                                }
                            }
                            #endregion
                            #endregion
                        } while (!dPconverge.flag && iterforDP < 200);

                        if (Nciri == Nciro)
                        {
                            break;
                        }

                        if (index_outbig && (j == Nciro - 1) && (res_cir2[0] != null))
                        {
                            for (int i = 0; i < Nciro; i++)
                            {
                                r2[i].DP += res_cir2[i].DP;
                            }
                            flag_ciro  = 1;
                            Ncir_forDP = Nciro;
                            mr_forDP   = (double[])mr_ciro.Clone(); // mr_forDP = mr_ciro
                            dPconverge = CheckDPforCircuits.CheckDPConverge(hexType, res_cir2, iterforPri, flag_ciro, mr_forDP, r2, Ncir_forDP);
                            iterforDP_ciro++;
                            if (iterforDP_ciro >= 5)
                            {
                                mr_forDP_o_4 = mr_forDP_o_3;
                                mr_forDP_o_3 = mr_forDP_o_2;
                                mr_forDP_o_2 = mr_forDP_o_1;
                                mr_forDP_o_1 = mr_forDP;
                                try
                                {
                                    if (mr_forDP_o_1[0] < mr_forDP_o_2[0] && (Math.Abs(mr_forDP_o_1[0] - mr_forDP_o_3[0]) / mr_forDP_o_1[0] < 0.0001) ||
                                        Math.Abs(mr_forDP_o_1[0] - mr_forDP_o_4[0]) / mr_forDP_o_1[0] < 0.0001)
                                    {
                                        dPconverge.flag = true;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    continue;
                                }
                            }
                            if (!dPconverge.flag)
                            {
                                restartDP_index = 1;
                                dPconverge.mr.CopyTo(mr_ciro, 0); //mr_ciro = dPconverge.mr;
                            }
                            break;
                        }
                    }
                    if (Airdirection == "顺流")
                    {
                        airConverge.flag = true;
                        for (int ii = 0; ii < Ncir; ii++)
                        {
                            for (int i = 0; i < Nrow; i++)
                            {
                                for (int j = 0; j < N_tube; j++)
                                {
                                    for (int kk = 0; kk < Nelement; kk++)
                                    {
                                        if (r[ii].Tao_Detail[kk, j, i] != 0)
                                        {
                                            ta[kk, j, i + 1] = r[ii].Tao_Detail[kk, j, i];
                                        }
                                        if (r[ii].RHo_Detail[kk, j, i] != 0)
                                        {
                                            RH[kk, j, i + 1] = r[ii].RHo_Detail[kk, j, i];
                                        }
                                    }
                                }
                            }
                        }
                    }

                    else//Counter
                    {
                        airConverge = CheckAirConvergeforCircuits.CheckAirConverge(cirArrforAir.TotalDirection, Nrow, N_tube, Nelement, ta, RH, r); //taout_calc, RHout_calc
                        ta          = airConverge.ta;
                        RH          = airConverge.RH;
                        iterforAir++;
                    }
                    //Add Q converge criterion to avoid results oscillation, ruhao 20180426
                    if (Airdirection != "顺流") //No airConverge iter for Parallel
                    {
                        for (int i = 0; i < Ncir; i++)
                        {
                            Q1[iterforAir - 1] += r[i].Q;
                        }

                        try
                        {
                            if (Q1[iterforAir - 1] < Q1[iterforAir - 2] && (Math.Abs(Q1[iterforAir - 1] - Q1[iterforAir - 3]) / Q1[iterforAir - 1] < 0.0001) ||
                                Math.Abs(Q1[iterforAir - 1] - Q1[iterforAir - 4]) / Q1[iterforAir - 1] < 0.0001)
                            {
                                airConverge.flag = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            continue;
                        }
                    }
                } while (!airConverge.flag && iterforAir < 50);

                #endregion
                //using (StreamWriter wr = File.AppendText(@"D:\Work\Simulation\Test\MinNout.txt"))
                //{
                //for (int i = 0; i < Ncir; i++)
                //{
                //wr.WriteLine("Q, {0}, DP, {1}, href, {2}, Ra_ratio, {3}, Tao, {4}, Tro, {5}, mr, {6}", r[i].Q, r[i].DP, r[i].href, r[i].Ra_ratio, r[i].Tao, r[i].Tro, r[i].mr);
                //}
                //}
                if (restartDP_index == 1)
                {
                    priconverge.flag = false;
                }
                else if (hexType == 0 && (fluid != "Water"))
                {
                    priconverge = CheckPin.CheckPriConverge(te, te_calc - 273.15, te_calc_org - 273.15, pri, pe, r[Ncir - 1].Pro); //res_slab.Pro
                    iterforPri++;
                    if (iterforPri >= 20)
                    {
                        pri_4 = pri_3;
                        pri_3 = pri_2;
                        pri_2 = pri_1;
                        pri_1 = pri;
                        try
                        {
                            if (pri_1 < pri_2 && (Math.Abs(pri_1 - pri_3) / pri_1 < 1e-5) ||
                                Math.Abs(pri_1 - pri_4) / pri_1 < 1e-5)
                            {
                                priconverge.flag = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            continue;
                        }
                    }
                    pri         = priconverge.pri;
                    te_calc_org = te_calc;
                    if (priconverge.flag && iterforPri == 1 && iterforDP == 1)
                    {
                        priconverge.flag = false; //to avoid not even iterate but converge by chance
                    }
                }
                else
                {
                    priconverge.flag = true;
                }
            } while (!priconverge.flag && iterforPri < 100);


            // if (iterforDP >= 200)
            //{
            //    return res_slab;
            //    throw new Exception("iter for DPConverge > 100.");
            //}
            //if (iterforPri >= 50)
            //{
            //    return res_slab;
            //    throw new Exception("iter for Pri > 50.");
            //}

            #region //Result print out

            for (int i = 0; i < Ncir; i++)
            {
                res_slab.Q += r[i].Q;
                res_slab.M += r[i].M;
                if (Nciri == Nciro)
                {
                    res_slab.hro += mr_ciri[i] * r[i].hro;
                }
                res_slab.href += r[i].href * CircuitInfo.TubeofCir[i];
                res_slab.R_1  += r[i].R_1 * CircuitInfo.TubeofCir[i];
                res_slab.R_1a += r[i].R_1a * CircuitInfo.TubeofCir[i];
                res_slab.R_1r += r[i].R_1r * CircuitInfo.TubeofCir[i];
                for (int j = 0; j < N_tube; j++)//detail output
                {
                    for (k = 0; k < Nrow; k++)
                    {
                        if (r[i].Q_detail[j, k] != 0)
                        {
                            Q_detail[j, k] = r[i].Q_detail[j, k];
                        }
                        if (r[i].DP_detail[j, k] != 0)
                        {
                            DP_detail[j, k] = r[i].DP_detail[j, k];
                        }
                        if (r[i].Tri_detail[j, k] != 0)
                        {
                            Tri_detail[j, k] = r[i].Tri_detail[j, k];
                        }
                        if (r[i].Pri_detail[j, k] != 0)
                        {
                            Pri_detail[j, k] = r[i].Pri_detail[j, k];
                        }
                        if (r[i].hri_detail[j, k] != 0)
                        {
                            hri_detail[j, k] = r[i].hri_detail[j, k];
                        }
                        if (r[i].Tro_detail[j, k] != 0)
                        {
                            Tro_detail[j, k] = r[i].Tro_detail[j, k];
                        }
                        if (r[i].Pro_detail[j, k] != 0)
                        {
                            Pro_detail[j, k] = r[i].Pro_detail[j, k];                            //
                        }
                        if (r[i].hro_detail[j, k] != 0)
                        {
                            hro_detail[j, k] = r[i].hro_detail[j, k];
                        }
                        if (r[i].href_detail[j, k] != 0)
                        {
                            href_detail[j, k] = r[i].href_detail[j, k];
                        }
                        if (r[i].mr_detail[j, k] != 0)
                        {
                            mr_detail[j, k] = r[i].mr_detail[j, k];
                        }
                        if (r[i].charge_detail[j, k] != 0)
                        {
                            charge_detail[j, k] = r[i].charge_detail[j, k];
                        }
                    }
                }
            }
            if (Nciri == Nciro)
            {
                res_slab.hro    = res_slab.hro / mr;
                res_slab.Pro    = r[Ncir - 1].Pro;
                res_slab.DP_cap = r[Ncir - 1].DP_cap;
                res_slab.Vel_r  = r[Ncir - 1].Vel_r;
            }
            else if (!index_outbig)
            {
                res_slab.hro    = res_cir2[Nciro].hro;
                res_slab.Pro    = res_cir2[Nciro].Pro;
                res_slab.DP_cap = res_cir2[Nciro].DP_cap;
                res_slab.Vel_r  = res_cir2[Nciro].Vel_r;
            }
            else
            {
                res_slab.hro    = res_cir2[Nciro - 1].hro;
                res_slab.Pro    = res_cir2[Nciro - 1].Pro;
                res_slab.DP_cap = res_cir2[Nciro - 1].DP_cap;
                res_slab.Vel_r  = res_cir2[Nciro - 1].Vel_r;
            }
            res_slab.Pri        = pri;
            res_slab.Tri        = tri;
            res_slab.hri        = hri;
            res_slab.mr         = mr;
            res_slab.DP         = pri - res_slab.Pro;
            res_slab.Tao_Detail = ta;
            res_slab.RHo_Detail = RH;
            res_slab.href       = res_slab.href / N_tube_total;
            for (int i = 0; i < ha.GetLength(0); i++)
            {
                for (int j = 0; j < ha.GetLength(1); j++)
                {
                    res_slab.ha += ha[i, j];
                }
            }
            res_slab.ha   = res_slab.ha / ha.Length;
            res_slab.R_1  = res_slab.R_1 / N_tube_total;
            res_slab.R_1a = res_slab.R_1a / N_tube_total;
            res_slab.R_1r = res_slab.R_1r / N_tube_total;

            coolprop.update(input_pairs.PQ_INPUTS, res_slab.Pro * 1000, 0);
            te_calc = coolprop.T() - 273.15;
            te_calc = CoolProp.PropsSI("T", "P", res_slab.Pro * 1000, "Q", 0, fluid) - 273.15;
            coolprop.update(input_pairs.QT_INPUTS, 0, te_calc + 273.15);
            double densityLo = coolprop.rhomass();
            //double densityLo = CoolProp.PropsSI("D", "T", te_calc + 273.15, "Q", 0, fluid);
            coolprop.update(input_pairs.QT_INPUTS, 1, te_calc + 273.15);
            double densityVo = coolprop.rhomass();
            //double densityVo = CoolProp.PropsSI("D", "T", te_calc + 273.15, "Q", 1, fluid);
            coolprop.update(input_pairs.DmassT_INPUTS, densityLo, te_calc + 273.15);
            double hlo = coolprop.hmass() / 1000;
            //double hlo = CoolProp.PropsSI("H", "T", te_calc + 273.15, "D", densityLo, fluid) / 1000 ;
            coolprop.update(input_pairs.DmassT_INPUTS, densityVo, te_calc + 273.15);
            double hvo = coolprop.hmass() / 1000;
            //double hvo = CoolProp.PropsSI("H", "T", te_calc + 273.15, "D", densityVo, fluid) / 1000 ;
            res_slab.x_o = (res_slab.hro - hlo) / (hvo - hlo);

            coolprop.update(input_pairs.PQ_INPUTS, pri * 1000, 0);
            double hli = coolprop.hmass() / 1000;
            //double hli = CoolProp.PropsSI("H", "P", pri * 1000, "Q", 0, fluid) / 1000 ;
            coolprop.update(input_pairs.PQ_INPUTS, pri * 1000, 1);
            double hvi = coolprop.hmass() / 1000;
            //double hvi = CoolProp.PropsSI("H", "P", pri * 1000, "Q", 1, fluid) / 1000 ;

            res_slab.x_i = (res_slab.hri - hli) / (hvi - hli);
            coolprop.update(input_pairs.HmassP_INPUTS, res_slab.hro * 1000, res_slab.Pro * 1000);
            res_slab.Tro = coolprop.T() - 273.15;
            //res_slab.Tro = CoolProp.PropsSI("T", "P", res_slab.Pro * 1000, "H", res_slab.hro * 1000, fluid) - 273.15;

            double h = res_slab.hro;
            for (int j = 0; j < N_tube; j++)
            {
                for (int i = 0; i < Nelement; i++)
                {
                    res_slab.Tao   += res_slab.Tao_Detail[i, j, Nrow];
                    res_slab.RHout += res_slab.RHo_Detail[i, j, Nrow];
                }
            }

            res_slab.Tao      = res_slab.Tao / (N_tube * Nelement);
            res_slab.RHout    = res_slab.RHout / (N_tube * Nelement);
            res_slab.Ra_ratio = res_slab.R_1a / res_slab.R_1;
            for (int i = 0; i < ma.GetLength(0); i++)
            {
                for (int j = 0; j < ma.GetLength(1); j++)
                {
                    res_slab.ma += ma[i, j];
                }
            }
            res_slab.Va            = res_slab.ma / 1.2 * 3600;
            res_slab.Q_detail      = Q_detail;//detail output
            res_slab.DP_detail     = DP_detail;
            res_slab.Tri_detail    = Tri_detail;
            res_slab.Pri_detail    = Pri_detail;
            res_slab.hri_detail    = hri_detail;
            res_slab.Tro_detail    = Tro_detail;
            res_slab.Pro_detail    = Pro_detail;
            res_slab.hro_detail    = hro_detail;
            res_slab.href_detail   = href_detail;
            res_slab.mr_detail     = mr_detail;
            res_slab.Aa            = geo.TotalArea.A_a;
            res_slab.Ar            = geo.TotalArea.A_r;
            res_slab.AHx           = geo.TotalArea.A_hx;
            res_slab.N_row         = Nrow;
            res_slab.tube_row      = N_tube;
            res_slab.charge_detail = charge_detail;

            return(res_slab);

            #endregion
        }
示例#51
0
 /**
  * This is the constructor for the EntityHandler class.
  * It creates a new internal list.
  */
 public EntityHandler(AbstractState state)
 {
     this._entities = new List<Entity>();
     this._state = state;
 }
示例#52
0
 public RouteFindingAction(String name, AbstractState startState, AbstractState endState)
     : base(startState, endState)
 {
     this.Name = name;
 }
示例#53
0
文件: Entity.cs 项目: Railec/SE1cKBS
 /**
  * The Update method updated this entity's state.
  * This method can be used for nearly everything (e.g. updating position, changing sprite, changing an internal variable).
  * By default this implementation contains a piece of code that handles gravitation.
  */
 public virtual void Update(AbstractState state, float interval)
 {
     if(this._gravitate && this._airborne) {
         if(this.movVector.y < 10) {
             this.movVector.y+= 10*interval;
         } else {
             this.movVector.y = 10;
         }
     } else {
         this.movVector.y = 0;
     }
 }
示例#54
0
 protected AbstractAction(AbstractState startState, AbstractState endState)
 {
     this.StartState = startState;
     this.EndState = endState;
 }
示例#55
0
 public AbstractNode Resolve(AbstractNode parent, AbstractAction action, AbstractState targetState)
 {
     return this.ApplyResolution(parent as InferenceNode, action);
 }
示例#56
0
文件: Entity.cs 项目: Railec/SE1cKBS
        /**
         * The CheckCollision method contains code that handles collision with tiles and other entities.
         * This method can be overriden to extend the collision behaviour.
         *
         * @TODO: Simplify this. I am certain it should be possible.
         */
        public virtual void CheckCollision(AbstractState state)
        {
            if(state.GetType() == typeof(GameState) && this._collider) {
                Rectangle pRect = new Rectangle((int)Math.Floor(this.posVector.x), (int)Math.Floor(this.posVector.y), this.Sprite.Image.Width, this.Sprite.Image.Height);

                float x = this.posVector.x / TileHandler.TILE_WIDTH;
                float y = this.posVector.y / TileHandler.TILE_HEIGHT;

                //Window border collision
                if(this.movVector.y != 0) {
                    if(this.posVector.y <= 16) {
                        this.SetMovement(this.movVector.x, 0);
                        this.SetPosition(this.posVector.x, 16);
                    } else if(this.posVector.y >= state.Form.ClientSize.Height-this.Sprite.Image.Height-16) {
                        this.SetMovement(this.movVector.x, 0);
                        this.SetPosition(this.posVector.x, state.Form.ClientSize.Height-this.Sprite.Image.Height-16);
                    }
                }
                if(this.movVector.x != 0) {
                    if(this.posVector.x <= 16) {
                        this.SetMovement(0, this.movVector.y);
                        this.SetPosition(16, this.posVector.y);
                    } else if(this.posVector.x >= state.Form.ClientSize.Width-this.Sprite.Image.Width-16) {
                        this.SetMovement(0, this.movVector.y);
                        this.SetPosition(state.Form.ClientSize.Width-this.Sprite.Image.Width-16, this.posVector.y);
                    }
                }

                //Tile collision
                if(this.movVector.y < 0) {
                    Tile t = ((GameState)state).GetTileHandler().Map[(int)Math.Floor(x), (int)Math.Floor(y-0.5)];
                    if(t == null) t = ((GameState)state).GetTileHandler().Map[(int)Math.Ceiling(x), (int)Math.Floor(y-0.5)];
                    if (t != null) {
                        Rectangle tRect = new Rectangle((int)(t.Position.X * TileHandler.TILE_WIDTH), (int)(t.Position.Y * TileHandler.TILE_HEIGHT)+1, TileHandler.TILE_WIDTH, TileHandler.TILE_HEIGHT);

                        if(pRect.IntersectsWith(tRect)) {
                            this.SetMovement(this.movVector.x, 0);
                            this.SetPosition(this.posVector.x, (t.Position.Y+1) * TileHandler.TILE_HEIGHT);
                        }
                    }
                } else {
                    Tile t = ((GameState)state).GetTileHandler().Map[(int)Math.Floor(x), (int)Math.Floor(y+1)];
                    if(t == null) t = ((GameState)state).GetTileHandler().Map[(int)Math.Ceiling(x), (int)Math.Floor(y+1)];
                    if(t != null) {
                        Rectangle tRect = new Rectangle((int)(t.Position.X * TileHandler.TILE_WIDTH), (int)(t.Position.Y * TileHandler.TILE_HEIGHT)-1, TileHandler.TILE_WIDTH, TileHandler.TILE_HEIGHT);

                        if(pRect.IntersectsWith(tRect)) {
                            if(this._gravitate) this._airborne = false;
                            this.SetPosition(this.posVector.x, (t.Position.Y-1) * TileHandler.TILE_HEIGHT);
                        }
                    } else if(this._gravitate) {
                        this._airborne = true;
                    }
                }

                if(this.movVector.x < 0) {
                    Tile t = ((GameState)state).GetTileHandler().Map[(int)Math.Floor(x-0.5), (int)Math.Floor(y)];
                    if(t == null) t = ((GameState)state).GetTileHandler().Map[(int)Math.Floor(x-0.5), (int)Math.Ceiling(y)];
                    if(t != null) {
                        Rectangle tRect = new Rectangle((int)(t.Position.X * TileHandler.TILE_WIDTH)+1, (int)(t.Position.Y * TileHandler.TILE_HEIGHT), TileHandler.TILE_WIDTH, TileHandler.TILE_HEIGHT);

                        if(pRect.IntersectsWith(tRect)) {
                            this.SetPosition((t.Position.X+1) * TileHandler.TILE_WIDTH, this.posVector.y);
                        }
                    }
                } else if(this.movVector.x > 0) {
                    Tile t = ((GameState)state).GetTileHandler().Map[(int)Math.Floor(x+1), (int)Math.Floor(y)];
                    if(t == null) t = ((GameState)state).GetTileHandler().Map[(int)Math.Floor(x+1), (int)Math.Ceiling(y)];
                    if(t != null) {
                        Rectangle tRect = new Rectangle((int)(t.Position.X * TileHandler.TILE_WIDTH)-1, (int)(t.Position.Y * TileHandler.TILE_HEIGHT), TileHandler.TILE_WIDTH, TileHandler.TILE_HEIGHT);

                        if(pRect.IntersectsWith(tRect)) {
                            this.SetPosition((t.Position.X-1) * TileHandler.TILE_WIDTH, this.posVector.y);
                        }
                    }
                }
            }
        }
 internal static HandleRef getCPtr(AbstractState obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
示例#58
0
 /**
  * This method is an implementation of the Entity's Update method.
  * During each update it will lower its cooldown with the given interval.
  * Once the cooldown is lower than or equal to 0 it will calculate the player's distance from itself.
  * If the distance is lower than 50 it will start its child entity's animation and reset the cooldown.
  *
  * Note: This is only possible if the state given to it is a GameState, otherwise it will not do anything.
  */
 public override void Update(AbstractState state, float interval)
 {
 }
示例#59
0
        /**
         * This method is an implementation of the Entity class' Update method.
         * It will add the interval given to it to its interval interval counter.
         * If the counter has reached the number defined in _animationInterval, then it will advance the animation stage.
         * When advancing the animation stage the sprite used is automatically updated.
         *
         * Note that animations do not automatically loop.
         */
        public override void Update(AbstractState state, float interval)
        {
            base.Update(state, interval);
            if(this._animationInterval <= 0) return;

            if(this.IsAnimated()) {
                this._animationIntervalCounter += interval;
                if(this._animationIntervalCounter > this._animationInterval) {
                    this._animationIntervalCounter -= this._animationInterval;
                    if(this._animationStage < this.Frames.Count) {
                        this._animationStage += this._animated;

                        this.Sprite = this.Frames[this._animationStage];
                    }
                }
            }
        }