Esempio n. 1
0
 //------
 public void SolverStart(ModelParams modParams)
 {
     //|time|vars[0]|...|vars[size-1|Usys[0]|...|Usys[size-2]|Telem|
     this.resCols     = 1 + varSize + (varSize - 1) + 1;
     this.resRows     = modParams.PtsResults + 1;
     this.drawResults = new double[resRows, resCols];
     //time step between drawResults
     this.deltaTime = (modParams.TimeStop - modParams.TimeStart) / (this.resRows - 1);
     if (deltaTime <= hc)
     {
         hc = deltaTime;
     }
     //---
     startTime = modParams.TimeStart;
     stopTime  = modParams.TimeStop;
     time      = startTime;
     drawTime  = startTime;
     drawIndex = 0;
     //---
     SetDrawResults(1, 0);
     //---
     double[] K1 = new double[varSize];
     double[] K2 = new double[varSize];
     double[] K3 = new double[varSize];
     double[] K4 = new double[varSize];
     //The Runge-Kutta method
     while (time <= stopTime)
     {
         model.SetModel(time, vars1);
         //---
         SetDsys(time, vars1);
         K1 = Product(hc, derivSys);
         SetDsys(time + 0.5 * hc, Add2(vars1, Product(0.5, K1)));
         K2 = Product(hc, derivSys);
         SetDsys(time + 0.5 * hc, Add2(vars1, Product(0.5, K2)));
         K3 = Product(hc, derivSys);
         SetDsys(time + hc, Add2(vars1, K3));
         K4    = Product(hc, derivSys);
         vars2 = Add2(vars1, Product(0.16666, Add4(K1, Product(2, K2), Product(2, K3), K4)));
         //******
         //int qqq = 0;
         if (time < drawTime && drawTime <= time + hc)
         {
             double dt = drawTime - time;
             double w1 = 1 - dt / hc;
             double w2 = dt / hc;
             if (drawIndex < resRows)
             {
                 SetDrawResults(w1, w2);
             }
         }
         //******
         time += hc;
         for (int i = 0; i < varSize; i++)
         {
             vars1[i] = vars2[i];
         }
     }//while
 }
Esempio n. 2
0
 //------
 public MathModel(ModelParams modParams, double time, double[] vars)
 {
     this.modParams = modParams;
     this.size      = modParams.Size;
     Msys           = new double[size, size];
     Usys           = new double[size];
     Rsys           = new double[size, size];
     Gsys           = new double[size, size];
     Gsr            = new double[size - 2, size - 2];
     //---
     SetMsys(time, vars);
     SetGsys(time, vars);
     SetRsys(time, vars);
     SetUsys(time, vars);
 }
Esempio n. 3
0
 private ModelParams modParams;  //Parametry modelu
 //------
 public Solver(ModelParams modParams, MathModel model)
 {
     this.model     = model;
     this.modParams = modParams;
     //---
     this.hc       = 0.00002;
     this.varSize  = modParams.Size;
     this.vars1    = new double[varSize];
     this.vars2    = new double[varSize];
     this.derivSys = new double[varSize];
     this.vecSys   = new double[varSize];
     //copy initial conditions array to vars1 and vars2 arrays
     for (int i = 0; i < varSize; i++)
     {
         vars1[i] = modParams.InitCondit[i];
         vars2[i] = modParams.InitCondit[i];
     }
 }