Advertisement
Guest User

QuickFactorioCalculator

a guest
Dec 6th, 2019
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <vector>
  4. #include <math.h>
  5.  
  6. int main()
  7. {
  8.  
  9.  
  10.     std::cout << "define the day-night-cycle time, the max poweroutput of the solar panels, the reduction of solar output and the capacity of the accumulators.\n(standard t=6.94 min    SP=60 kW      rSP=0 %      C=5 MJ)\n";
  11.    
  12.     float daytime{ 0 };
  13.     std::cout << "day-night-cycle time [min]: ";
  14.     std::cin >> daytime;
  15.  
  16.     float power{ 0 };
  17.     std::cout << "max power one solar panel can output [kW]: ";
  18.     std::cin >> power;
  19.  
  20.     float dP{ 0 };
  21.     std::cout << "percentage of reduced solar output [%] :";
  22.     std::cin >> dP;
  23.  
  24.     float C{ 0 };
  25.     std::cout << "capacity per accumulator [MJ]: ";
  26.     std::cin >> C;
  27.  
  28.  
  29.     power = power * (1 - dP / 100) * 1000;
  30.     C = C * pow(10, 6);
  31.     daytime = daytime * 60;
  32.  
  33.     std::vector<float> t;
  34.     t.push_back(0.0);
  35.     t.push_back(0.100719424460432);
  36.     t.push_back(0.273381294964029);
  37.     t.push_back(0.812949640287770);
  38.     t.push_back(1.0);
  39.  
  40.     for (int i = 0; i < t.size(); i++) {
  41.         t[i] = t[i] * daytime;
  42.     }
  43.  
  44.  
  45.     std::vector<float> P;
  46.  
  47.     P.push_back(0.0);
  48.     P.push_back(0.0);
  49.     P.push_back(power);
  50.     P.push_back(power);
  51.     P.push_back(0.0);
  52.  
  53.     float w{ 0 };
  54.    
  55.     for (int i = 1; i < t.size(); i++) {
  56.         w += 0.5 * (P[i - 1] + P[i]) * (t[i] - t[i-1]);
  57.     }
  58.  
  59.     float Pm = w / daytime;
  60.  
  61.     float p1;
  62.     float p2;
  63.  
  64.     float t1;
  65.     float t2;
  66.     float tch;
  67.  
  68.     std::vector<float>::iterator it;
  69.     std::vector<float>::iterator itp;
  70.     it = t.begin();
  71.     itp = P.begin();
  72.     for (int i = 0; i < t.size()-1; i++) {
  73.         p1 = P[i];
  74.         p2 = P[i + 1];
  75.  
  76.         if (p1 < Pm && p2 > Pm) {
  77.             t1 = t[i];
  78.             t2 = t[i + 1];
  79.             tch = t1 + (t2 - t1) / (p2 - p1)*(Pm - p1);
  80.             t.emplace(it + i+1, tch);
  81.             P.emplace(itp + i+1, Pm);
  82.  
  83.  
  84.         }
  85.  
  86.     }
  87.  
  88.     for (int i = 0; i < t.size() - 1; i++) {
  89.         p1 = P[i];
  90.         p2 = P[i + 1];
  91.         if (p1 > Pm && p2 < Pm) {
  92.             t1 = t[i];
  93.             t2 = t[i + 1];
  94.             tch = t1 + (t2 - t1) / (p2 - p1)*(Pm - p1);
  95.             t.emplace(it + i+1, tch);
  96.             P.emplace(itp + i+1, Pm);
  97.         }
  98.     }
  99.  
  100.     std::vector<float> Pa;
  101.     for (int i = 0; i < P.size(); i++) {
  102.         Pa.push_back(P[i] - Pm);
  103.     }
  104.  
  105.     float Ct{ 0 };
  106.     float max{ 0 };
  107.     float min{ 0 };
  108.  
  109.     for (int i = 1; i < t.size(); i++) {
  110.         Ct += 0.5 * (Pa[i - 1] + Pa[i]) * (t[i] - t[i - 1]);
  111.         if (Ct > max)max = Ct;
  112.         if (Ct < min)min = Ct;
  113.     }
  114.  
  115.  
  116.     float Cg = max - min;
  117.  
  118.     float r = Cg / C;
  119.  
  120.  
  121.     std::cout << "You need " << r  << " accumulators per solar panel" << std::endl;
  122.     std::cout << "The average power produced per solar panel is " <<  Pm / 1000 << " kW" << std::endl;
  123.  
  124.  
  125.     std::system("pause");
  126.  
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement