Skip to content

Commit

Permalink
replace bespoke f2mnmax with PDL::minmax
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 30, 2024
1 parent 9298224 commit ff2ce74
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 48 deletions.
17 changes: 3 additions & 14 deletions t/x09.pl
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ sub polar {
# plFree2dGrid ($cgrid2);
}

# f2mnmx
#
# Returns min & max of input 2d array

sub f2mnmx {
my $f = shift;
my $fmin = min ($f);
my $fmax = max ($f);
return ($fmin, $fmax)
}

# Shielded potential contour plot example

sub potential {
Expand All @@ -122,8 +111,8 @@ sub potential {

my $rmax = 0.5 + (PRPTS - 1);

my ($xmin, $xmax) = f2mnmx ($xg);
my ($ymin, $ymax) = f2mnmx ($yg);
my ($xmin, $xmax) = minmax($xg);
my ($ymin, $ymax) = minmax($yg);

my $x0 = ($xmin + $xmax) / 2;
my $y0 = ($ymin + $ymax) / 2;
Expand Down Expand Up @@ -161,7 +150,7 @@ sub potential {
my $div2i = sqrt (($xg - $d2i) ** 2 + ($yg + $d2i) ** 2 + $eps ** 2);
my $z = $q1 / $div1 + $q1i / $div1i + $q2 / $div2 + $q2i / $div2i;

my ($zmin, $zmax) = f2mnmx ($z);
my ($zmin, $zmax) = minmax($z);

# Positive and negative contour levels

Expand Down
12 changes: 1 addition & 11 deletions t/x15.pl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

sub plot1 ();
sub plot2 ();
sub f2mnmx ($);
sub cmap1_init1 ();
sub cmap1_init2 ();

Expand Down Expand Up @@ -78,7 +77,7 @@ sub main {
}
}

($zmin, $zmax) = f2mnmx ($z);
($zmin, $zmax) = minmax($z);

plot1 ();
plot2 ();
Expand Down Expand Up @@ -283,13 +282,4 @@ ()

}

# f2mnmx
#
# Returns min & max of input 2d array

sub f2mnmx ($) {
my $f = shift;
return (min ($f), max ($f));
}

main ();
31 changes: 8 additions & 23 deletions t/x22.pl
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,10 @@ sub transform {
# Vector plot of flow through a constricted pipe
# with a coordinate transform
sub constriction2 {
my $nx = nx;
my $ny = ny;
my $nc = 11;
my $nseg = 20;

my $dx = 1.0;
my $dy = 1.0;

my $xmin = -$nx / 2 * $dx;
my $xmax = $nx / 2 * $dx;
my $ymin = -$ny / 2 * $dy;
my $ymax = $ny / 2 * $dy;
my ($nx, $ny, $nc, $nseg) = (nx, ny, 11, 20);
my ($dx, $dy) = (1.0, 1.0);
my ($xmin, $xmax) = (-$nx / 2 * $dx, $nx / 2 * $dx);
my ($ymin, $ymax) = (-$ny / 2 * $dy, $ny / 2 * $dy);

plstransform( \&transform, $xmax );

Expand Down Expand Up @@ -163,13 +155,6 @@ sub constriction2 {
plstransform( undef, undef );
}

sub f2mnmx {
my $f = shift;
my $fmin = min ($f);
my $fmax = max ($f);
return ($fmin, $fmax);
}

# Vector plot of the gradient of a shielded potential (see example 9)

sub potential {
Expand Down Expand Up @@ -199,7 +184,6 @@ sub potential {
(0.5 + sequence (ntheta)))->dummy (0, nr);
my $x = $r * cos ($theta);
my $y = $r * sin ($theta);
my $cgrid2 = plAlloc2dGrid ($x, $y);
my $div1 = sqrt (($x - $d1) ** 2 + ($y - $d1) ** 2 + $eps * $eps);
my $div1i = sqrt (($x - $d1i) ** 2 + ($y - $d1i) ** 2 + $eps * $eps);
my $div2 = sqrt (($x - $d2) ** 2 + ($y + $d2) ** 2 + $eps * $eps);
Expand All @@ -210,9 +194,9 @@ sub potential {
my $v = -$q1 * ($y - $d1) / ($div1**3) - $q1i * ($y - $d1i) / ($div1i ** 3)
-$q2 * ($y + $d2) / ($div2**3) - $q2i * ($y + $d2i) / ($div2i ** 3);

my ($xmin, $xmax) = f2mnmx ($x);
my ($ymin, $ymax) = f2mnmx ($y);
my ($zmin, $zmax) = f2mnmx ($z);
my ($xmin, $xmax) = minmax($x);
my ($ymin, $ymax) = minmax($y);
my ($zmin, $zmax) = minmax($z);

plenv ($xmin, $xmax, $ymin, $ymax, 0, 0);
pllab ("(x)", "(y)",
Expand All @@ -224,6 +208,7 @@ sub potential {

plcol0 (3);
pllsty (2);
my $cgrid2 = plAlloc2dGrid ($x, $y);
plcont ($z, 1, nr, 1, ntheta, $clevel, \&pltr2, $cgrid2);
pllsty (1);
plcol0 (1);
Expand Down

0 comments on commit ff2ce74

Please sign in to comment.