Skip to content

Commit

Permalink
Rescale and add intensities #14
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianK13 committed Jun 17, 2024
1 parent 56ff8fe commit 0e74b6b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default class ShadingScene {
* It runs the shading simulation and returns a THREE.js colored mesh.
* The colors are chosen from the viridis colormap.
* @param numberSimulations Number of random sun positions that are used to calculate the PV yield
* @param diffuseIrradianceURL URL where the files for the diffuse Irradiance can be retreived
* @returns
*/

Expand Down Expand Up @@ -187,19 +188,30 @@ export default class ShadingScene {
if (diffuseIntensities.length == 0) {
return this.createMesh(simulationGeometry, directIntensities);
}
const normalizationDirect = 0.5;
const normalizationDiffuse = 72;
// Both values come from the calibration function in https://github.com/open-pv/minimalApp
// There the intensities are calibrated based on a horizontal plane
const alpha = 500 / 1300;
// this comes from assuming that diffuse radiation is responsible for 500 W and direct for 800 W on a horizontal plane
for (let i = 0; i < intensities.length; i++) {
intensities[i] = (1 / 100) * diffuseIntensities[i] + 0 * directIntensities[i];
intensities[i] =
(1 / 1.2) *
((alpha * diffuseIntensities[i]) / normalizationDiffuse + ((1 - alpha) * directIntensities[i]) / normalizationDirect);

// 1/1.2 is to rescale a south facing roof to 1
}
console.log('Maximum of merged intensities: ', Math.max(...intensities));

return this.createMesh(simulationGeometry, intensities);
}
/** @ignore */
createMesh(subdividedGeometry: BufferGeometry, intensities: Float32Array): THREE.Mesh {
const Npoints = subdividedGeometry.attributes.position.array.length / 9;
var newColors = new Float32Array(Npoints * 9);

for (var i = 0; i < Npoints; i++) {
const col = viridis(Math.min(1, intensities[i] / 0.6));
//The 0.6 comes from looking at a rooftop facing south with good angle.
const col = viridis(Math.min(1, intensities[i]));
for (let j = 0; j < 9; j += 3) {
newColors[9 * i + j] = col[0];
newColors[9 * i + j + 1] = col[1];
Expand Down Expand Up @@ -242,6 +254,7 @@ export default class ShadingScene {
let shadingElevationAngles: SphericalPoint[] = [];

if (typeof diffuseIrradianceUrl === 'string' && isValidUrl(diffuseIrradianceUrl)) {
// Case where diffuse Radiation is considered in simulation
const diffuseIrradianceSpherical = await sun.fetchIrradiance(diffuseIrradianceUrl, this.latitude, this.longitude);
irradiance = sun.convertSpericalToEuclidian(diffuseIrradianceSpherical);
} else if (typeof diffuseIrradianceUrl != 'undefined') {
Expand All @@ -262,7 +275,6 @@ export default class ShadingScene {
);
sun.shadeIrradianceFromElevation(irradiance, shadingElevationAngles);
}
console.log('Calling rayTracingWebGL');
normals = normals.filter((_, index) => index % 9 < 3);
let intensities = rayTracingWebGL(midpoints, normals, meshArray, irradiance, progressCallback);

Expand Down

0 comments on commit 0e74b6b

Please sign in to comment.