@eturnity/eturnity_maths 8.16.0 → 8.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_maths",
3
- "version": "8.16.0",
3
+ "version": "8.16.1",
4
4
  "author": "Eturnity Team",
5
5
  "main": "src/index.js",
6
6
  "private": false,
package/src/geometry.js CHANGED
@@ -734,6 +734,18 @@ export function get3pointNotAlignedFromOutline(outline) {
734
734
  }
735
735
  return [A, B, C]
736
736
  }
737
+ export function getNormalVectorFromFlatOutline(outline) {
738
+ const ABC = get3pointNotAlignedFromOutline(outline)
739
+ if (!ABC) {
740
+ return null
741
+ }
742
+ let normalVector = getNormalVectorFrom3Points(...ABC)
743
+ if (normalVector.z < 0) {
744
+ normalVector = multiplyVector(-1, normalVector)
745
+ }
746
+ normalVector = normalizeVector(normalVector)
747
+ return normalVector
748
+ }
737
749
  export function getNormalVectortoEdgeTowardPolygon(k, outline) {
738
750
  const A = outline[k]
739
751
  const B = outline[(k + 1) % outline.length]
package/src/index.js CHANGED
@@ -9,6 +9,7 @@ export * from './objects'
9
9
  export * from './splitMergePolygons'
10
10
  export * from './miscellaneous'
11
11
  export * from './stats'
12
+ export * from './irradiance'
12
13
  export * from './spherical'
13
14
  export * from './SHPSolver'
14
15
  export * from './panelFunctions'
@@ -0,0 +1,77 @@
1
+ import { dotProduct, inclineWithNormalVector, normalizeVector } from './index'
2
+ export function ineichenDiffuseIrradiance(dni, dhi, plane_theta, cosAOI) {
3
+ //compute of Ineichen diffuse
4
+ const F = 1.0 - Math.pow(dhi / Math.max(dni * cosAOI + dhi, 1e-6), 2.0)
5
+ const diffusion_Ineichen =
6
+ dhi *
7
+ ((1.0 + Math.cos(plane_theta)) / 2.0) *
8
+ (1.0 + F * Math.pow(Math.sin(plane_theta / 2.0), 3.0)) *
9
+ (1.0 + F * Math.pow(cosAOI, 2.0) * Math.pow(Math.cos(plane_theta), 3.0))
10
+ return diffusion_Ineichen
11
+ }
12
+ export function getOptimizedGHI({ dataGrids, lat, lng }) {
13
+ // Compute normal vector for max DNI
14
+ let optimized_panel_tilt
15
+ if (Math.abs(lat) < 25) optimized_panel_tilt = Math.abs(lat) * 0.87
16
+ else if (Math.abs(lat) < 50) optimized_panel_tilt = Math.abs(lat) * 0.76 + 3.1
17
+ else optimized_panel_tilt = Math.abs(lat) * 0.76 + 3.1
18
+
19
+ const phi = 180
20
+ const theta = optimized_panel_tilt
21
+ const phiRad = (phi * Math.PI) / 180
22
+ const thetaRad = (theta * Math.PI) / 180
23
+ const optimizedNormalVector = {
24
+ x: Math.sin(thetaRad) * Math.sin(phiRad),
25
+ y: Math.sin(thetaRad) * Math.cos(phiRad),
26
+ z: Math.cos(thetaRad),
27
+ }
28
+ let { ghi } = getGHI({
29
+ dataGrids: dataGrids,
30
+ normalVector: optimizedNormalVector,
31
+ })
32
+ return ghi
33
+ }
34
+ export function getGHI({ dataGrids, normalVector }) {
35
+ // Compute highest GHI
36
+ normalVector = normalizeVector(normalVector)
37
+ let GHISum = 0
38
+ let DHISum = 0
39
+ let DNISum = 0
40
+ const resolution = {
41
+ x: 1 / dataGrids.dni_grid[0].length,
42
+ y: 1 / dataGrids.dni_grid.length,
43
+ }
44
+ for (let i = 0; i < dataGrids.dni_grid.length; i++) {
45
+ for (let j = 0; j < dataGrids.dni_grid[0].length; j++) {
46
+ const phi = j * resolution.x
47
+ const theta = i * resolution.y
48
+ const phiRad = phi * Math.PI * 2
49
+ const thetaRad = (theta * Math.PI) / 2
50
+ const sunDir = {
51
+ x: Math.sin(thetaRad) * Math.sin(phiRad),
52
+ y: Math.sin(thetaRad) * Math.cos(phiRad),
53
+ z: Math.cos(thetaRad),
54
+ }
55
+ const cosAngle = Math.max(dotProduct(normalVector, sunDir), 0)
56
+ const dni = dataGrids.dni_grid[i][j]
57
+ const dhi = dataGrids.dhi_grid[i][j]
58
+ const plane_theta = inclineWithNormalVector(normalVector)
59
+ const ineichen_dhi = ineichenDiffuseIrradiance(
60
+ dni,
61
+ dhi,
62
+ plane_theta,
63
+ cosAngle
64
+ )
65
+ const ghi = dni * cosAngle + ineichen_dhi
66
+ DHISum += ineichen_dhi
67
+ DNISum += dni
68
+ GHISum += ghi
69
+ }
70
+ }
71
+
72
+ return {
73
+ dhi: DHISum,
74
+ dni: DNISum,
75
+ ghi: GHISum,
76
+ }
77
+ }