#
# A CFD-Post session file 
#
# Macro GUI begin
#
# macro name = Transient Blade Row Chart Plot
# macro subroutine = TBRChart
#
# macro parameter = separator
#  type = Separator
#
# macro parameter = comment
#  type = Comment
#  default = Expands one chart to multiple passages in Transient Blade Row cases.
#
# macro parameter = separator
#  type = Separator
#
# macro parameter = Instancing
#  type = Combo
#  list = Full Circle, Instances in 360
#  default = Instances in 360
#
# macro parameter = # of Passages
#  type = Integer
#  range = 1, 1000
#  default = 7
#
# macro parameter = Chart
#  type = Location
#  location type = Chart
#
# macro parameter = Chart Series
#  type = Location
#  location type = Chart Series
#
# Macro GUI end

COMMAND FILE:
  CFX Post Version = 13.0
END

! no warnings 'redefine';
!
! sub TBRChart {
!
! my ( $instance_option, $num_of_user_instances, $chart_list, $series_list ) = @_;
!
! if ( $instance_option eq "Full Circle" ) {
!   $num_of_user_instances = -1;
! }
!
! my $calc_global_range = "Off";
! my @chart_list = split(/\s*,\s*/,$chart_list);
! my @series_list = split(/\s*,\s*/,$series_list);
!
! # Reduce domain list to the active TBR cases only
!
! my @all_domain_list = get_active_tbr_domains();
!
! my $ccl;
! my @chart_del;
! my $plot_variable;
!
! foreach my $chart (@chart_list) {
!
!   my $chart_path = $chart;
!   $chart_path =~ s!.*/\s*!!g;
!
!   my ($chart_type, $chart_name) = split(/\s*:\s*/,$chart_path);
!
!   my @chart_series = split(/\s*,\s*/,getChildren($chart,"CHART SERIES"));
!   @chart_series = map { $chart . "/" . $_ } @chart_series;
!
!   my @valid_series = intersect_list(\@chart_series, \@series_list);
!
!   # First delete all existing plots
!
!   foreach my $series (@valid_series) {
!     my $series_path = $series;
!     $series_path =~ s!.*/\s*!!g;
!
!     my ($series_type, $series_name) = split(/\s*:\s*/,$series_path);
!
!     foreach my $domain_path (@all_domain_list) {
!
!       my $domain_name = getObjectName($domain_path);
!
!       my $num_instances_360 = get_num_instance_360($domain_path);
!
!       foreach my $b (1..$num_instances_360) {
!
!         my $series_name_passage = tbr_object_name($series_name, $domain_name, $b);
!   
!         my $series_path_passage = "$chart/$series_type:$series_name_passage";
!         if ( objectExists($series_path_passage) ) {
!           push @chart_del, $series_path_passage;
!         }
!       }
!     }
!
!     # Create all plot variables first
!     my $series_location = getValue($series,"Location");
!     my @series_domains = get_object_domain_list($series_location);
!     my @valid_plot_domains = intersect_list(\@series_domains, \@all_domain_list);
!     $plot_variable .= create_tbr_chart_variables($series,\@valid_plot_domains,
!                                                  $num_of_user_instances,$calc_global_range);
!   }
! }
! if ( scalar(@chart_del) ) {
!   my $chart_del = join(',',@chart_del);
!   $ccl .= "\>delete $chart_del \n";
! }
! runCCL($plot_variable); 
!
!
! foreach my $chart (@chart_list) {
!
!   my $chart_path = $chart;
!   $chart_path =~ s!.*/\s*!!g;
!
!   my ($chart_type, $chart_name) = split(/\s*:\s*/,$chart_path);
!
!   my @chart_series = split(/\s*,\s*/,getChildren($chart,"CHART SERIES"));
!   @chart_series = map { $chart . "/" . $_ } @chart_series;
!
!   my @valid_series = intersect_list(\@chart_series, \@series_list);
!
!   foreach my $series (@valid_series) {
!     my $series_path = $series;
!     $series_path =~ s!.*/\s*!!g;
!
!     my ($series_type, $series_name) = split(/\s*:\s*/,$series_path);
#
# Determine custom chart, or default chart. Next, hide original chart and its lines,
#
!     my @line_list = split(/\s*,\s*/,getChildren($series,"CHART LINE"));
!
!     my $series_location = getValue($series,"Location");
!     my @series_domains = get_object_domain_list($series_location);
!     my @valid_plot_domains = intersect_list(\@series_domains, \@all_domain_list);
!
!     my $series_custom = getValue($series, "Chart Line Custom Data Selection");
!     my $series_var_x;
!     my $series_var_y;
!     if ($series_custom eq "Off") {
!       $series_var_x = getValue($chart, "Default Chart X Variable");
!       $series_var_y = getValue($chart, "Default Chart Y Variable");
!     } else {
!       $series_var_x = getValue($series, "Chart X Variable");
!       $series_var_y = getValue($series, "Chart Y Variable");
!     }
!     $ccl .= "$chart_type:$chart_name \n";
!     $ccl .= "  $series_type:$series_name \n";
!     $ccl .= "    Chart X Variable = $series_var_x \n";
!     $ccl .= "    Chart Y Variable = $series_var_y \n";
!
!     foreach my $line (@line_list) {
!       $ccl .= "    $line \n";
!       $ccl .= "      Chart Line Visibility = Off \n";
!       $ccl .= "    END \n";
!     }
!     $ccl .= "  END \n";
!     $ccl .= "END \n";
!
#
# Create new plots by instancing the variables, and showing the lines.
#
!     foreach my $domain_path (@valid_plot_domains) {
!
!       my $domain_name = getObjectName($domain_path);
!
!       my %tbr_variable_set = get_domain_tbr_var_set($domain_path);
!
!       my $num_of_instances =
!            get_valid_instance_num($domain_path,$num_of_user_instances); 
!
!       foreach $b (1..$num_of_instances) {
!
!         my $series_name_passage = tbr_object_name($series_name, $domain_name, $b);
!         my $series_passage = "/$chart_type:$chart_name/$series_type:$series_name_passage";
!
!         my $series_var_x_passage = $series_var_x;
!         my ($var_stem, $var_oper) = splitTBRvariable($series_var_x);
!         if ( $tbr_variable_set{$var_stem} || $var_stem eq "Theta") {
!           $series_var_x_passage = tbr_variable_name($var_stem, $var_oper, $domain_name, $b);
!         }
!
!         my $series_var_y_passage = $series_var_y;
!         my ($var_stem, $var_oper) = splitTBRvariable($series_var_y);
!         if ( $tbr_variable_set{$var_stem} || $var_stem eq "Theta") {
!           $series_var_y_passage = tbr_variable_name($var_stem, $var_oper, $domain_name, $b);
!         }
!      
!         $ccl .= "\>copy from=$series, to=$series_passage \n";
!         $ccl .= "$chart_type:$chart_name \n";
!         $ccl .= "  $series_type:$series_name_passage \n";
!         $ccl .= "    Chart X Variable = $series_var_x_passage \n";
!         $ccl .= "    Chart Y Variable = $series_var_y_passage \n";
!         $ccl .= "    Chart Line Custom Data Selection = On \n";
!         $ccl .= "    Series Name = $series_name_passage \n";
! 
!         foreach my $line (@line_list) {
!           $ccl .= "    $line \n";
!           $ccl .= "      Line Name = $series_name_passage \n";
!           $ccl .= "      Chart Line Visibility = On \n";
!           $ccl .= "    END \n";
!         }
!         $ccl .= "  END \n";
!         $ccl .= "END \n";
!       }
!     }
!   }
! }
!
! runCCL($ccl); 
!}
!
! sub create_tbr_chart_variables {
!
!   my ($plot_path,$domain_list,$num_of_user_instances,$calc_global_range) = @_;
!
!   my $var_ccl;
!
!   my $plot_custom = getValue($plot_path, "Chart Line Custom Data Selection");
!   my ($plot_parent, $plot) = $plot_path =~ m/^(.*)\//;
!
!   my $plot_var_x,plot_var_y;
!   if ($plot_custom eq "Off") {
!     $plot_var_x = getValue($plot_parent, "Default Chart X Variable");
!     $plot_var_y = getValue($plot_parent, "Default Chart Y Variable");
!   } else {
!     $plot_var_x = getValue($plot_path, "Chart X Variable");
!     $plot_var_y = getValue($plot_path, "Chart Y Variable");
!   }
!
!   DOMAIN: foreach my $domain_path (@$domain_list) {
!
!     my $domain_name = getObjectName($domain_path);
!
!     my $nmode = get_domain_nmode($domain_path);
!
!     my $num_of_instances =
!          get_valid_instance_num($domain_path,$num_of_user_instances); 
!
!     my %tbr_variable_set = get_domain_tbr_var_set($domain_path);
!
!     my @var_name_pairs = ();
!
!     my ($var_stem, $var_oper) = splitTBRvariable($plot_var_x);
!     if ( $tbr_variable_set{$var_stem} ) {
!       push @var_name_pairs, [$var_stem,$var_oper];
!     }
!
!     my ($var_stem, $var_oper) = splitTBRvariable($plot_var_y);
!     if ( $tbr_variable_set{$var_stem} ) {
!       push @var_name_pairs, [$var_stem,$var_oper];
!     }
!
!     foreach my $b (1..$num_of_instances) {
!
!       my $rot_angle = get_rot_angle($domain_path, $b);
!
!       my $theta_name = tbr_variable_name("Theta", "", $domain_name, $b);
!       if ( !objectExists($theta_name) ) {
!         my $theta_expr = "Theta + " . $rot_angle;
!         $var_ccl .= addUserScalar($theta_name, $theta_expr, "Conservative", "Off");
!       }
!
!       foreach my $vp (@var_name_pairs) {
!         my ($var_stem, $var_oper) = @$vp;
!         $var_ccl .= addTBRVariable ("Expand", $domain_path, $nmode, $b,
!                                      $var_stem, $var_oper,
!                                      "Off");
!       }
!     }
!   }
!   return $var_ccl;
! }
