| 1 | package Physics::UEMColumn::RFCavity; | ||
| 2 | |||
| 3 | use Moose; | ||
| 4 | use namespace::autoclean; | ||
| 5 | |||
| 6 | BEGIN { extends 'Physics::UEMColumn::Element'; } | ||
| 7 | |||
| 8 | use Method::Signatures; | ||
| 9 | |||
| 10 | use Physics::UEMColumn::Auxiliary ':constants'; | ||
| 11 | use MooseX::Types::NumUnit qw/num_of_unit/; | ||
| 12 | |||
| 13 | has 'strength' => (isa => num_of_unit('v/m'), is => 'rw', required => 1); | ||
| 14 | has 'frequency' => (isa => num_of_unit('Hz') , is => 'ro', required => 1); | ||
| 15 | #has 'radius' => (isa => 'Num', is => 'ro', required => 1); | ||
| 16 | |||
| 17 | has 'phase' => (isa => 'Num', is => 'ro', default => 0); | ||
| 18 | has 'order' => (isa => 'Int', is => 'ro', default => 2); | ||
| 19 | |||
| 20 | method effect () { | ||
| 21 | |||
| 22 | my $lens_z = $self->location; | ||
| 23 | my $length = $self->length; | ||
| 24 | my $str = $self->strength; | ||
| 25 | my $order = $self->order; | ||
| 26 | my $freq = $self->frequency; | ||
| 27 | my $phase = $self->phase; | ||
| 28 | |||
| 29 | my $cutoff = $self->cutoff; | ||
| 30 | |||
| 31 | my $code_z = sub { | ||
| 32 | my ($t, $pulse_z, $pulse_v) = @_; | ||
| 33 | |||
| 34 | my $prox = ($pulse_z - $lens_z) / ( $length / 2 ); | ||
| 35 | if (abs($prox) > $cutoff) { | ||
| 36 | return 0; | ||
| 37 | } | ||
| 38 | |||
| 39 | my $return = | ||
| 40 | qe / $pulse_v * $str * 2 * pi * $freq | ||
| 41 | * cos( 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase) | ||
| 42 | * exp( - $prox**(2 * $order)); | ||
| 43 | |||
| 44 | return $return; | ||
| 45 | |||
| 46 | }; | ||
| 47 | |||
| 48 | my $code_t = sub { | ||
| 49 | my ($t, $pulse_z, $pulse_v) = @_; | ||
| 50 | |||
| 51 | my $prox = ($pulse_z - $lens_z) / ( $length / 2 ); | ||
| 52 | if (abs($prox) > $cutoff) { | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | my $trig_arg = 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase; | ||
| 57 | |||
| 58 | my $mag_comp = | ||
| 59 | $pulse_v / (vc**2) * 2 * pi * $freq | ||
| 60 | * cos( $trig_arg ); | ||
| 61 | |||
| 62 | my $end_comp = | ||
| 63 | 2 * $order / $length * ($prox**(2 * $order - 1)) | ||
| 64 | * sin( $trig_arg ); | ||
| 65 | |||
| 66 | return -$str * qe * ($mag_comp + $end_comp) * exp( - $prox**(2 * $order)); | ||
| 67 | |||
| 68 | }; | ||
| 69 | |||
| 70 | my $code_acc = sub { | ||
| 71 | my ($t, $pulse_z, $pulse_v) = @_; | ||
| 72 | |||
| 73 | my $prox = ($pulse_z - $lens_z) / ( $length / 2 ); | ||
| 74 | if (abs($prox) > $cutoff) { | ||
| 75 | return 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | my $return = | ||
| 79 | qe * $str | ||
| 80 | * sin( 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase) | ||
| 81 | * exp( - $prox**(2 * $order)); | ||
| 82 | |||
| 83 | }; | ||
| 84 | |||
| 85 | return {M_t => $code_t, M_z => $code_z, acc => $code_acc}; | ||
| 86 | |||
| 87 | } | ||
| 88 | |||
| 89 | __PACKAGE__->meta->make_immutable; | ||
| 90 | |||
| 91 | 1; | ||
| 92 | |||
| 93 | =head1 NAME | ||
| 94 | |||
| 95 | Physics::UEMColumn::RFCavity - A class representing an RF cavity in a UEM system | ||
| 96 | |||
| 97 | =head1 SYNOPSIS | ||
| 98 | |||
| 99 | use Physics::UEMColumn alias => ':standard'; | ||
| 100 | my $rf_cav = RFCavity->new( | ||
| 101 | location => $location . 'cm', | ||
| 102 | length => '2 cm', | ||
| 103 | strength => '230 kilovolts / m', | ||
| 104 | frequency => '3 gigahertz', | ||
| 105 | ); | ||
| 106 | |||
| 107 | =head1 DESCRIPTION | ||
| 108 | |||
| 109 | L<Physics::UEMColumn::RFCavity> is a class representing a RF cavity (z lens) in a UEM system. It is a subclass of L<Physics::UEMColumn::Element> and inherits its attributes and methods. Additionally it provides: | ||
| 110 | |||
| 111 | =head1 ATTRIBUTES | ||
| 112 | |||
| 113 | =over | ||
| 114 | |||
| 115 | =item C<stength> | ||
| 116 | |||
| 117 | The electric field strength of the RF cavity. Unit: V/m | ||
| 118 | |||
| 119 | =item C<frequency> | ||
| 120 | |||
| 121 | The resonant frequency of the RF Cavity. Unit: Hz | ||
| 122 | |||
| 123 | =item C<phase> | ||
| 124 | |||
| 125 | The phase offset in radians (i.e. 0 - 2*pi) of the electric field oscillation. In practice this determines the the mode of operation of the cavity (compressor, accelerator). Default is C<0>. | ||
| 126 | |||
| 127 | =item C<order> | ||
| 128 | |||
| 129 | The super-Gaussian order C<exp( - $x ** ( 2 * $order ) )> determining the shape of the lens. Default is C<2>. | ||
| 130 | |||
| 131 | =back | ||
| 132 | |||
| 133 | =head1 METHODS | ||
| 134 | |||
| 135 | =over | ||
| 136 | |||
| 137 | =item C<effect> | ||
| 138 | |||
| 139 | Returns a hash reference of effect subroutine references (C<M_t>, C<M_z>, C<acc_z>). See L<Physics::UEMColumn::Element/METHODS> for more. | ||
| 140 | |||
| 141 | =back | ||
| 142 | |||
| 143 | =head1 SOURCE REPOSITORY | ||
| 144 | |||
| 145 | L<http://github.com/jberger/Physics-UEMColumn> | ||
| 146 | |||
| 147 | =head1 AUTHOR | ||
| 148 | |||
| 149 | Joel Berger, E<lt>joel.a.berger@gmail.comE<gt> | ||
| 150 | |||
| 151 | =head1 COPYRIGHT AND LICENSE | ||
| 152 | |||
| 153 | Copyright (C) 2012-2013 by Joel Berger | ||
| 154 | |||
| 155 | This library is free software; you can redistribute it and/or modify | ||
| 156 | it under the same terms as Perl itself. | ||
| 157 | |||
| 158 |