| 1 | package Physics::UEMColumn::Auxiliary; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Physics::UEMColumn::Auxiliary; | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | use Physics::UEMColumn::Auxiliary ':all'; | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | This module collects all the extra functionality that had no place else to be. In future versions this module may be separated into several modules, though an attempt will be made to preserve backwards compatibility. | ||
| 17 | |||
| 18 | =head1 IMPORTING | ||
| 19 | |||
| 20 | L<Physics::UEMColumn::Auxiliary> doesn't export anything by default and while any symbol shown below may be requested explicitly, as exporting is its primary purpose, some thought has been put into tagging collections of symbols for importing into scripts. Those tags are: | ||
| 21 | |||
| 22 | =cut | ||
| 23 | |||
| 24 | use Math::Trig; | ||
| 25 | |||
| 26 | use parent 'Exporter'; | ||
| 27 | our %EXPORT_TAGS = ( | ||
| 28 | constants => [ qw/ pi me qe epsilon_0 vc / ], | ||
| 29 | model_funcs => [ qw/ L L_t L_z dLdxi dL_tdxi dL_zdxi / ], | ||
| 30 | util_funcs => [ qw/ join_data / ], | ||
| 31 | materials => [ qw/ Ta / ], | ||
| 32 | ); | ||
| 33 | |||
| 34 | our @EXPORT_OK; | ||
| 35 | push @EXPORT_OK, @$_ for values %EXPORT_TAGS; | ||
| 36 | |||
| 37 | $EXPORT_TAGS{'all'} = \@EXPORT_OK; | ||
| 38 | |||
| 39 | =head2 :constants | ||
| 40 | |||
| 41 | =over | ||
| 42 | |||
| 43 | =item pi | ||
| 44 | |||
| 45 | The mathematical constant | ||
| 46 | |||
| 47 | =item me | ||
| 48 | |||
| 49 | The rest mass of an electron (kg) | ||
| 50 | |||
| 51 | =item qe | ||
| 52 | |||
| 53 | The charge of an electron (C) | ||
| 54 | |||
| 55 | =item epsilon_0 | ||
| 56 | |||
| 57 | The permittivity of free space (electric constant) (F/m) | ||
| 58 | |||
| 59 | =item vc | ||
| 60 | |||
| 61 | The speed of light in a vacuum (m/s) | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | use constant { | ||
| 68 | me => 9.1e-31, | ||
| 69 | qe => 1.6e-19, | ||
| 70 | epsilon_0 => 8.85e-12, | ||
| 71 | vc => 2.9979e8, | ||
| 72 | }; | ||
| 73 | |||
| 74 | =head2 :materials | ||
| 75 | |||
| 76 | Null prototyped functions returning a hash of C<energy_fermi> and C<work_function> suitable for passing to the constructor of a C<Physics::UEMColumn::Photocathode> object. | ||
| 77 | |||
| 78 | =over | ||
| 79 | |||
| 80 | =item Ta | ||
| 81 | |||
| 82 | Tantalum metal | ||
| 83 | |||
| 84 | =back | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | sub Ta() { | ||
| 89 | return ( | ||
| 90 | energy_fermi => '5.3 eV', | ||
| 91 | work_function => '4.25 eV', | ||
| 92 | ); | ||
| 93 | } | ||
| 94 | |||
| 95 | =head2 :model_funcs | ||
| 96 | |||
| 97 | Internal functions related to implementing the AG model (see M&S original paper). These need not be used by the end-user and thus are not described here. | ||
| 98 | |||
| 99 | =cut | ||
| 100 | |||
| 101 | sub L { | ||
| 102 | my ($xi) = @_; | ||
| 103 | |||
| 104 | return 1 if $xi == 1; | ||
| 105 | |||
| 106 | if ($xi > 1) { | ||
| 107 | my $sqrt = sqrt(($xi**2) - 1); | ||
| 108 | return log($xi + $sqrt) / $sqrt; | ||
| 109 | } | ||
| 110 | |||
| 111 | if ($xi >= 0) { | ||
| 112 | my $sqrt = sqrt(1 - ($xi**2)); | ||
| 113 | return asin($sqrt) / $sqrt; | ||
| 114 | } | ||
| 115 | |||
| 116 | die "xi is out of range"; | ||
| 117 | } | ||
| 118 | |||
| 119 | sub L_t { | ||
| 120 | my ($xi) = @_; | ||
| 121 | my $L = L($xi); | ||
| 122 | |||
| 123 | return 1.5 * ( $L + (($xi**2)*$L - $xi) / (1 - $xi**2) ); | ||
| 124 | } | ||
| 125 | |||
| 126 | sub L_z { | ||
| 127 | my ($xi) = @_; | ||
| 128 | my $L = L($xi); | ||
| 129 | |||
| 130 | return 3 * ($xi**2) * ( $xi * $L - 1) / (($xi**2) - 1) | ||
| 131 | } | ||
| 132 | |||
| 133 | sub dL_tdxi { | ||
| 134 | my ($xi) = @_; | ||
| 135 | |||
| 136 | return -3/2 * ((($xi**4)-1)*dLdxi($xi) - 4*$xi*L($xi) + ($xi**2) + 2) / ((($xi**2)-1)**2); | ||
| 137 | } | ||
| 138 | |||
| 139 | sub dL_zdxi { | ||
| 140 | my ($xi) = @_; | ||
| 141 | |||
| 142 | return 3*$xi * (($xi**2)*(($xi**2)-1)*dLdxi($xi) + $xi*(($xi**2)+3)*L($xi) + 2) / ((($xi**2)-1)**2); | ||
| 143 | } | ||
| 144 | |||
| 145 | sub dLdxi { | ||
| 146 | my ($xi) = @_; | ||
| 147 | |||
| 148 | if ($xi >= 1) { | ||
| 149 | return 1/(($xi**2)-1) * (1 - $xi*L($xi)); | ||
| 150 | |||
| 151 | } elsif ( $xi >= 0) { | ||
| 152 | return $xi/2 * (log(1-($xi**2))-2) / ((1-($xi**2))**(1.5)); | ||
| 153 | |||
| 154 | } else { | ||
| 155 | die "xi is out of range"; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | =head2 :util_funcs | ||
| 160 | |||
| 161 | =over | ||
| 162 | |||
| 163 | =item join_data | ||
| 164 | |||
| 165 | Takes two AoA (array of arrayref) references and returns the first, having the second appended to it. Further if the last row of the first and the first row of the second have the same first element (e.g. time) that row is not repeated in the result. This function may be used "in place", as the first array reference is appended to; in other words, one need not use the return value. | ||
| 166 | |||
| 167 | =back | ||
| 168 | |||
| 169 | =cut | ||
| 170 | |||
| 171 | sub join_data { | ||
| 172 | my ($container, $new) = @_; | ||
| 173 | |||
| 174 | if ( @$container ) { | ||
| 175 | #check for overlap | ||
| 176 | if ($container->[-1][0] == $new->[0][0]) { | ||
| 177 | pop @$container; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | push @$container, @$new; | ||
| 182 | return $container; | ||
| 183 | } | ||
| 184 | |||
| 185 | 1; | ||
| 186 | |||
| 187 | =head1 SOURCE REPOSITORY | ||
| 188 | |||
| 189 | L<http://github.com/jberger/Physics-UEMColumn> | ||
| 190 | |||
| 191 | =head1 AUTHOR | ||
| 192 | |||
| 193 | Joel Berger, E<lt>joel.a.berger@gmail.comE<gt> | ||
| 194 | |||
| 195 | =head1 COPYRIGHT AND LICENSE | ||
| 196 | |||
| 197 | Copyright (C) 2012-2013 by Joel Berger | ||
| 198 | |||
| 199 | This library is free software; you can redistribute it and/or modify | ||
| 200 | it under the same terms as Perl itself. |