Sim-OPT
view release on metacpan or search on metacpan
lib/Sim/OPT/Modish.pm view on Meta::CPAN
#package Sim::OPT::Modish;
#NOTE: TO USE THE PROGRAM AS A SCRIPT, THE LINE ABOVE SHOULD BE ERASED OR TURNED INTO A COMMENT.
# Copyright (C) 2008-2025 by Gian Luca Brunetti, gianluca.brunetti@gmail.com. This software is distributed under a dual licence, open-source (GPL v3) and proprietary. The present copy is proprietary. The open-source, GPL version of it can be found at...
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( modish );
# In version 0.287: added the possibility to decouple the diffuse resolution from the direct resolution.
# In version 0.289 (13.03.2020): added the ability to work with ESP-r versions more recent than 13.3.2. Last version tested: 13.3.8.
# In version 0.291 (03.08.2020): added the ability to work with ESP-r versions 13.3.10;
# In version 0.301 (04.08.2020): added the ability of being called from ESP-r for monthly inquiries or embedded, daily inquiries.
# In version 0.319 (02.09.2020): speedup modifications for the embedded mode, modification of the createconstrdbfile and creatematdbfiles subroutines.
# In versions 0.321 to 0.325 (17.10.2020): bug fixes.
# In versions 0.4 (20.12.2021): adapted code to changes in the e2r interaction;
# reintroduced the possibility of non-embedded use; added the possibility of choosing which zones and surfaces to operate on.
# In versions 0.4.1 (28.09.2022): bug fix.
# In versions 0.4.2.1 (12.06.2023): updated the subprocedure "createfictgeofile "for creating fictitious obstruction files to the new obstruction file format.
# In version 0.4.2.3 (25.01.2025): adapted to changes in prj and E2r.
# In version 0.4.3 (10.06.2025): adapted to changes in Perl (disappearance of the smartmatch operator).
# In version 0.4.4 (01.11.2025): put back the smartmatch operator thanks to the reappearance of it in the great Switch::Back module)!
print "I AM DOING\n";
# use v5.14;
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS );
use Math::Trig;
use List::Util qw[ min max reduce shuffle any];
use List::MoreUtils qw(uniq);
use List::AllUtils qw(sum);
use Sim::OPT::Stats;
use Data::Dump qw(dump);
use Regexp::Common;
use Vector::Object3D::Polygon;
use Math::Polygon::Tree;
use Storable qw(store retrieve dclone);
#use Parallel::ForkManager;
use feature 'say';
no strict;
no warnings;
use Switch::Back;
$ABSTRACT = 'Modish is a program for modifying the shading factors in the ISH (shading and insolation) files of the ESP-r building performance simulation suite in order to make it take into account the reflections from obstructions.';
$VERSION = '0.4.4';
# Modish is a program for modifying the shading factors in the ISH (shading and insolation) files of the ESP-r building performance simulation suite in order to make it take into account the solar reflections from obstructions.
# The program, more precisely, brings into account the reflective effect of solar obstructions on solar gains in the ESP-r building models on the basis of irradiance ratios. Those ratios are obtained combining the direct radiation on a surface, calcu...
#
# How the program works
# The effect of solar reflections is taken into account at each hour on the basis of the ratios between the irradiances measured at the models' surfaces in two transitional, fictious model derived from the primary model.
# The procedure in question has to variants, at the user's choice.
# In the first variant of the procedure, the irradiances calculated by the means of Radiance can be derived from the following two alternative sets of models (the choice between them has to be done in the configuration file "modish_defaults.pl"):
#
# 1)
# a) a model in which all the surfaces are reflective, excepted the obstructions, which are black;
# b) a model in which everything is reflective.
#
# 2)
# a) a model in which everything is black;
# b) a model in which all the surfaces are black, excepted the obstructions, which are reflective.
#
# The value given by 1 minus the irradiance ratios gives the diffuse shading factors that are put in the ISH file of the ESP-r model in place of the original values. Solution 1) is the most correct one, but there are cases in which the results of the...
# The value given by 1 minus the irradiance ratios gives the diffuse shading factors that are put in the ISH file of the ESP-r model in place of the original values. Solution 1) is the most correct one, but there are cases in which the results of the...
# In the other variant of the procedure, the irradiances calculated by the means of Radiance can be derived from the following two alternative sets of models:
# 3)
# a) a model in which all the surfaces are reflective, and the obstruction are absent;
# b) a model in which everything is reflective, and the obstructions are present.
# In the case of this variant, the "new" shading factors are not calculated as a correction of the original ESP-r's ISH shading factors, but with the only means of Radiance, again, on the basis of irradiance ratios.
#
# Variant 3) can be combined with variant 1) OR 2).
# The original ISH's ".shda" files are not substituted. Two new files are added in the "zone" folder of the ESP-r model: the ".mod.shda" file is usable by ESP-r. It features the newly calculated shading factors; the ".report.shda" file lists the orig...
#
# To launch Modish the following command has to be issued:
#
# perl ./Modish.pm PATH_TO_THE_ESP-r_CONFIGURATION_FILE.cfg
#
# For example:
#
# perl ./Modish.pm PATH_TO_THE_ESP-r_CONFIGURATION_FILE.cfg
# More manners for launching ESP-r are presented in the help at the bottom of this page.
#
# In calculating the irradiance ratios, the program defaults to the following settings: diffuse reflections: 1 ; direct reflections: 7; surface grid: 2 x 2; direction vectors for each surface: 1 ; distance from the surface for calculating the irradia...
# These defaults are a compromise between quality and speed. They can be overridden by preparing a "modish_defaults.pl" file and placing it in the same directory from which modish is called.
#
# The content of a configuration file for the present defaults, for example, would be constituted by the following line (note that after it a line of comment follows):
#
# @defaults = ( [ 2, 2 ], 1, 1, 7, 0.01, 1 );### i.e ( [ resolution_x, resolution_y ], $dirvectorsnum, $bounceambnum, $bouncemaxnum, $distgrid )
#
# The value "$dirvectorsnum" controls the numbers of direction vectors that are used for computing the irradiances at each point of each grid over the surfaces. The values that currently can be chosen are 1, 5 and 17. When the points are more than 1,...
# Modish works with no limitation of number of surfaces, it can be used with complex geometries and takes into account parent and child surfaces.
#
lib/Sim/OPT/Modish.pm view on Meta::CPAN
my @xs = @{ $fields[0] };
my @ys = @{ $fields[1] };
my @zs = @{ $fields[2] };
my $i = 0;
my @bag;
foreach ( @xs )
{
push ( @bag, [ $xs[ $i ], $ys[ $i ], $zs[ $i ] ] );
$i++;
}
push ( @verts, [ @bag ] );
}
my ( @coords, @prunegridpoints );
foreach my $v ( @gridpoints )
{
my @fields = @$v;
my $coordsref = $fields[0];
push( @coords, [ @$coordsref ] );
}
my ( @boxpointxy, @boxpointxz, @boxpointyz );
foreach my $gridpoint ( @coords )
{
my ( @point_xys, @point_xzs, @point_yzs );
foreach ( @$gridpoint )
{
push ( @point_xys, [ $_->[0], $_->[1] ] );
push ( @point_xzs, [ $_->[0], $_->[2] ] );
push ( @point_yzs, [ $_->[1], $_->[2] ] );
}
push ( @boxpointxy, [ @point_xys ] );
push ( @boxpointxz, [ @point_xzs ] );
push ( @boxpointyz, [ @point_yzs ] );
}
my ( @boxvertxy, @boxvertxz, @boxvertyz );
foreach my $surf ( @verts )
{
my ( @vert_xys, @vert_xzs, @vert_yzs );
foreach my $vert ( @$surf )
{
push ( @vert_xys, [ $vert->[0], $vert->[1] ] );
push ( @vert_xzs, [ $vert->[0], $vert->[2] ] );
push ( @vert_yzs, [ $vert->[1], $vert->[2] ] );
}
push ( @boxvertxy, [ @vert_xys ] );
push ( @boxvertxz, [ @vert_xzs ] );
push ( @boxvertyz, [ @vert_yzs ] );
}
my $count = 0;
my ( $vert_xys, $vert_xzs, $vert_yzs, $polyxy, $polyxz, $polyyz );
my ( @verts_xys, @verts_xzs, @verts_yzs);
foreach my $case ( @boxvertxy )
{
$vert_xys = $boxvertxy[$count];
$vert_xzs = $boxvertxz[$count];
$vert_yzs = $boxvertyz[$count];
$polyxy = Math::Polygon::Tree->new( $vert_xys );
$polyxz = Math::Polygon::Tree->new( $vert_xzs );
$polyyz = Math::Polygon::Tree->new( $vert_yzs );
$count++;
}
my $count = 0;
my @newbox;
foreach my $caseref ( @gridpoints )
{
my @case = @$caseref;
my $surfnum = $case[ 1 ];
my $dirvector = $case[ 2 ];
my @bag;
foreach my $vert ( @{ $case[ 0 ] } )
{
my $xyref = $boxpointxy[ $count ][ 0 ];
my $xzref = $boxpointxz[ $count ][ 0 ];
my $yzref = $boxpointyz[ $count ][ 0 ];
unless ( ( ( $polyxy->contains( $xyref ) ) == 0 ) and ( ( $polyxz->contains( $xzref ) ) == 0 ) and ( ( $polyyz->contains( $yzref ) ) == 0 ) )
{
push( @bag, $vert );
}
}
push ( @newbox, [ [ @bag ], $surfnum, $dirvector ] );
$count++;
}
return ( @newbox );
}
sub solveselective
{
my ( $matdbfile_f2, $selectives_ref, $conffile, $conffile_f2, $path ) = @_;
my @selectives = @{ $selectives_ref };
my $matdbfile_f3 = $matdbfile_f2;
$matdbfile_f3 =~ s/_f2/_f3/ ;
my $matdbfile_f4 = $matdbfile_f2;
$matdbfile_f4 =~ s/_f2/_f4/ ;
my $shortmatdbfile_f2 = $matdbfile_f2;
my $shortmatdbfile_f3 = $matdbfile_f3;
my $shortmatdbfile_f4 = $matdbfile_f4;
$shortmatdbfile_f2 =~ s/$path\/dbs\/// ;
$shortmatdbfile_f3 =~ s/$path\/dbs\/// ;
$shortmatdbfile_f4 =~ s/$path\/dbs\/// ;
open( my $MATDBFILE_F2, "$matdbfile_f2" ) or die "Could not open file '\$matdbfile_f2': $matdbfile_f2, $!";
my @matlines = <$MATDBFILE_F2>;
close $MATDBFILES_F2;
my @mats = map{ $_->[0] } @selectives;
my ( @row, @thirdloop, @fourthloop );
my $semaphore = "off";
foreach my $matline ( @matlines )
{
chomp $matline;
$matline =~ s/\s+// ;
my @e = split( ",", $matline );
if ( $e[0] eq "*item" )
( run in 1.745 second using v1.01-cache-2.11-cpan-39bf76dae61 )