Esempio n. 1
0
        public void GuardarEstadoFichero(string fichero, double Ax, double At, double gamma, int contadort, double C, List <double> listdt, List <double> listdens, List <double> listtemp, List <double> listvel, List <double> listpres) // guarda el estado actual del nozzle en un txt
        {
            //obrim fitxer
            StreamWriter W = new StreamWriter(fichero + ".txt");

            //afegim numero de rectangles
            W.WriteLine(Convert.ToString(this.numRect));

            //guardem les dades de cada rectangle en strings
            int i = 0;

            while (i <= this.numRect + 1)
            {
                Rectangulo rect = this.nozzle[i];

                //recollim dades de cada rectangle, separades per ';'
                string dades = Convert.ToString(rect.GetTempP()) + ";" + Convert.ToString(rect.GetVelP()) + ";" + Convert.ToString(rect.GetDensP()) + ";" + Convert.ToString(rect.GetPresP()) + ";" + Convert.ToString(rect.GetAltura()) + ";" + Convert.ToString(rect.GetArea());

                //escribim una linea x cada rectangle
                W.WriteLine(dades);

                i++;
            }

            //afegim la resta de paràmetres
            W.WriteLine(Convert.ToString(Ax));
            W.WriteLine(Convert.ToString(At));
            W.WriteLine(Convert.ToString(gamma));
            W.WriteLine(Convert.ToString(contadort));
            W.WriteLine(Convert.ToString(C));

            //agegim les List
            int cont = 0;

            while (cont < listdt.Count())
            {
                //recollim les dades de les List, separades per ';'
                // ORDRE: dt, dens, temp, vel, pres
                string data = Convert.ToString(listdt[cont]) + ";" + Convert.ToString(listdens[cont]) + ";" + Convert.ToString(listtemp[cont]) + ";" + Convert.ToString(listvel[cont]) + ";" + Convert.ToString(listpres[cont]);

                //escribim una línea per a cada posició
                W.WriteLine(data);

                cont++;
            }

            //tanquem fitxer
            W.Close();
        }
Esempio n. 2
0
        public void ComputeFutureState(double At, double Ax, double gamma, double[] ders, Rectangulo rectI) // PREDICTED-CORRECTION METHOD: corrije el estado predicted (que está en futuro) usando también el presente (que está en presente)
        {
            // Predicted state
            double T_F    = this.tempF;
            double V_F    = this.velF;
            double dens_F = this.densF;

            // relations - Predicted state
            double AT_F    = T_F - rectI.GetTempF();
            double AV_F    = V_F - rectI.GetVelF();
            double Adens_F = dens_F - rectI.GetDensF();
            double AlnA    = Math.Log(this.area) - Math.Log(rectI.GetArea());

            // equations
            //current state derviatives
            double dDENS_I = ders[0];
            double dV_I    = ders[1];
            double dT_I    = ders[2];
            //predicted future state derivatives
            double dDENS_P = -(dens_F * (AV_F / Ax)) - ((dens_F * V_F * AlnA) / Ax) - ((V_F * Adens_F) / Ax);
            double dV_P    = -(V_F * (AV_F / Ax)) - ((1 / gamma) * ((AT_F / Ax) + ((T_F / dens_F) * (Adens_F / Ax))));
            //double dV_P = (-(V_F) * (AV_F / Ax)) - ((1 / gamma) * ((AT_F / Ax) + (T_F / dens_F) * (Adens_F / Ax)));
            double dT_P = -(V_F * (AT_F / Ax)) - ((gamma - 1) * T_F * ((AV_F / Ax) + (V_F * (AlnA / Ax))));
            //average derivatives
            double dDENS_av = 0.5 * (dDENS_I + dDENS_P);
            double dV_av    = 0.5 * (dV_I + dV_P);
            double dT_av    = 0.5 * (dT_I + dT_P);

            //future state
            this.densF = this.densP + (dDENS_av * At);
            this.velF  = this.velP + (dV_av * At);
            this.tempF = this.tempP + (dT_av * At);
            this.presF = this.tempF * this.densF;
        }
Esempio n. 3
0
        // ALTRES MÈTODES
        public double[] ComputePredictedFutureState(double At, double Ax, double gamma, Rectangulo rectD) // MACCORMACK'S TECHNIQUE: utiliza las eqs discretizadas para calcular el predicted state de la celda --> lo guardamos todo en futuro
        {
            // return the derivatives:
            double[] ders = new double[3];

            // relations
            double AT    = rectD.GetTempP() - this.tempP;
            double AV    = rectD.GetVelP() - this.velP;
            double Adens = rectD.GetDensP() - this.densP;
            double AlnA  = Math.Log(rectD.GetArea()) - Math.Log(this.area);

            // equations
            //derivatives
            double derT    = -((this.velP * AT) / Ax) - ((gamma - 1) * this.tempP * ((AV / Ax) + ((this.velP * AlnA) / Ax)));
            double derV    = -((this.velP * AV) / Ax) - ((1 / gamma) * ((AT / Ax) + ((this.tempP / this.densP) * (Adens / Ax))));
            double derDENS = -((this.densP * AV) / Ax) - (this.densP * this.velP * (AlnA / Ax)) - (this.velP * (Adens / Ax));

            ders[0] = derDENS;
            ders[1] = derV;
            ders[2] = derT;
            //predicted state
            this.tempF = this.tempP + (derT * At);
            this.velF  = this.velP + (derV * At);
            this.densF = this.densP + (derDENS * At);

            // return time derivatives
            return(ders);
        }
Esempio n. 4
0
        public double[,] CargarEstadoFichero(string fichero) // carga como estado actual del nozzle los datos que lee de un fichero txt
        {
            //llegim fitxer
            StreamReader R = new StreamReader(fichero);

            //agafem número de rectagles
            this.numRect = Convert.ToInt32(R.ReadLine());

            //formem el vector de rectangles
            this.nozzle = new Rectangulo[this.numRect + 2];

            //agafem les propietats del fluid a cada rectangle
            int i = 0;

            while (i <= this.numRect + 1)
            {
                string   linea  = R.ReadLine();
                string[] trozos = linea.Split(';');

                double temp = Convert.ToDouble(trozos[0]);
                double vel  = Convert.ToDouble(trozos[1]);
                double dens = Convert.ToDouble(trozos[2]);
                double pres = Convert.ToDouble(trozos[3]);
                double alt  = Convert.ToDouble(trozos[4]);
                double area = Convert.ToDouble(trozos[5]);

                Rectangulo rect = new Rectangulo(temp, vel, dens, pres, alt, area);

                this.nozzle[i] = rect;

                i++;
            }

            //agafem els altres paràmetres i les List
            double Ax    = Convert.ToDouble(R.ReadLine()); // Ax
            double At    = Convert.ToDouble(R.ReadLine()); // At
            double gamma = Convert.ToDouble(R.ReadLine()); // gamma
            int    numdt = Convert.ToInt32(R.ReadLine());  // numero de intervalos de tiempo que han pasado
            double C     = Convert.ToDouble(R.ReadLine()); // courant parameter

            double[,] parametres = new double[2, 3];
            parametres[0, 0]     = numdt;
            parametres[0, 1]     = gamma;
            parametres[0, 2]     = C;
            parametres[1, 0]     = Ax;
            parametres[1, 1]     = At;
            if (numdt != 0)
            {
                parametres       = new double[7, numdt + 2];
                parametres[0, 0] = numdt;
                parametres[0, 1] = gamma;
                parametres[0, 2] = C;
                parametres[1, 0] = Ax;
                parametres[1, 1] = At;
                int cont = 0;
                while (cont <= numdt + 1)
                {
                    string   linea  = R.ReadLine();
                    string[] trozos = linea.Split(';');

                    // ORDRE: dt, dens, temp, vel, pres
                    parametres[2, cont] = Convert.ToDouble(trozos[0]);
                    parametres[3, cont] = Convert.ToDouble(trozos[1]);
                    parametres[4, cont] = Convert.ToDouble(trozos[2]);
                    parametres[5, cont] = Convert.ToDouble(trozos[3]);
                    parametres[6, cont] = Convert.ToDouble(trozos[4]);

                    cont++;
                }
            }

            return(parametres);
        }
Esempio n. 5
0
 public void SetRectangulo(int pos, Rectangulo rect)
 {
     this.nozzle[pos] = rect;
 }