Advertisement
GiovanniLeo23595

PLDiode

Aug 5th, 2020
3,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export function powerlossesF(curveIt: Point[], curveIV: Point[]): number {
  2.         let powerAverage: number = 0;
  3.  
  4.         const tMax: number = curveIt[curveIt.length - 1].x;
  5.  
  6.         const tRange: number[] = Interpolation.linearSpace_(0, tMax, PLDiodeFormula.POINT_FOR_INTEGRAL);
  7.         const tStep: number = tRange[1] - tRange[0];
  8.  
  9.         let IdPrec: number = 0;
  10.  
  11.         for (let i: number = 0; i < tRange.length; i++) {
  12.  
  13.             let Id: Point = Interpolation.stdlinearY(tRange[i], curveIt)
  14.             let Vr: Point;
  15.             if (Id != null && !isNaN(Id.y)) {
  16.                 if (IdPrec != Id.y) {
  17.                     Vr = Interpolation.cubicX(Id.y, curveIV);
  18.                 }
  19.                 if (Vr != null && Id.y != 0) {
  20.                     powerAverage += Id.y * Vr.x * tStep;
  21.  
  22.                 }
  23.                 IdPrec = Id.y;
  24.             }
  25.         }
  26.  
  27.         return powerAverage / tMax;
  28.     }
  29.  
  30.  
  31.   export function powerlossesR(curveVt: Point[], curveIV: Point[]): number {
  32.  
  33.         let powerAverage: number = 0;
  34.  
  35.         const tMax: number = curveVt[curveVt.length - 1].x;
  36.  
  37.         const tRange: number[] = Interpolation.linearSpace_(0, tMax, PLDiodeFormula.POINT_FOR_INTEGRAL);
  38.         const tStep: number = tRange[1] - tRange[0];
  39.  
  40.         let VrPrec: number = 0;
  41.  
  42.         for (let i: number = 0; i < tRange.length; i++) {
  43.             let Vr: Point = Interpolation.stdlinearY(tRange[i], curveVt)
  44.  
  45.             if (Vr != null && !isNaN(Vr.y)) {
  46.                 let Id: Point;
  47.                 if (VrPrec != Vr.y) {
  48.                     Id = Interpolation.cubicY(Vr.y, curveIV);
  49.                 }
  50.                 if (Id != null && Vr.y != 0) {
  51.                     powerAverage += Id.y * Vr.y * tStep;
  52.                 }
  53.                 VrPrec = Vr.y;
  54.             }
  55.         }
  56.  
  57.         return powerAverage / tMax;
  58.     }
  59.  
  60.  
  61.     export function curveAt(t: number, curves: PlotInfo_VO[], factory: Function): Point[] {
  62.         const cLength: number = curves.length;
  63.  
  64.         if (cLength == 0) {
  65.             return []
  66.         }
  67.  
  68.         if (cLength == 1)
  69.             return curves[0].data;
  70.  
  71.         if (t <= curves[1].temperature) {
  72.             return factory(t, curves[0], curves[1]);
  73.         }
  74.  
  75.         if (t > curves[cLength - 1].temperature) {
  76.  
  77.             return factory(t, curves[cLength - 2], curves[cLength - 1]);
  78.         }
  79.  
  80.         for (let i:number = 1; i < (cLength - 1); i++) {
  81.  
  82.             if (curves[i].temperature < t && t <= curves[i + 1].temperature) {
  83.                 return factory(t, curves[i], curves[i + 1]);
  84.             }
  85.         }
  86.         return factory(t, curves[cLength - 2], curves[cLength - 1]);
  87.     }
  88.  
  89.  
  90.     export function forward(t: number, a: PlotInfo_VO, b: PlotInfo_VO): Point[] {
  91.         if (t == a.temperature)
  92.             return a.data;
  93.  
  94.         if (t == b.temperature)
  95.             return b.data;
  96.  
  97.         let curve: Point[] = [];
  98.  
  99.         a.data.forEach((item) => {
  100.             let indexOfItem: number = a.data.indexOf(item);
  101.             if (indexOfItem != -1) {
  102.                 const pa: Point = new Point(a.temperature, a.data[indexOfItem].x);
  103.                 const pb: Point = new Point(b.temperature, a.data[indexOfItem].x);
  104.  
  105.                 curve.push(new Point(Interpolation.linearY_(t, pa, pb), item.y));
  106.             }
  107.  
  108.         });
  109.  
  110.  
  111.         return curve;
  112.     }
  113.  
  114.  
  115.     export function reverse(t: number, a: PlotInfo_VO, b: PlotInfo_VO): Point[] {
  116.         if (t == a.temperature)
  117.             return a.data;
  118.  
  119.         if (t == b.temperature)
  120.             return b.data;
  121.  
  122.         let curve: Point[] = [];
  123.  
  124.         a.data.forEach((item) => {
  125.             let indexOfItem: number = a.data.indexOf(item);
  126.             if (indexOfItem != -1) {
  127.                 const pa: Point = new Point(a.temperature, a.data[indexOfItem].y);
  128.                 const pb: Point = new Point(b.temperature, a.data[indexOfItem].y);
  129.  
  130.                 curve.push(new Point(item.x, Interpolation.exponentialY_(t, pa, pb)));
  131.             }
  132.  
  133.         });
  134.  
  135.  
  136.         return curve;
  137.     }
  138.  
  139.  
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement