Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

split additional classes out of Element.pm this is probably more prop…

…er, but the change is precipitated by documentation needs
  • Loading branch information...
commit 2d5ac1410c16c8c1ddf85bccbbaedbac05716c27 1 parent be1a3d2
@jberger authored
View
6 lib/Physics/UEMColumn.pm
@@ -63,11 +63,15 @@ use List::Util 'sum';
use PerlGSL::DiffEq;
use Physics::UEMColumn::Column;
-use Physics::UEMColumn::Element;
use Physics::UEMColumn::Pulse;
use Physics::UEMColumn::Laser;
use Physics::UEMColumn::Photocathode;
+#use Physics::UEMColumn::Element;
+use Physics::UEMColumn::DCAccelerator;
+use Physics::UEMColumn::MagneticLens;
+use Physics::UEMColumn::RFCavity;
+
use Physics::UEMColumn::Auxiliary ':all';
use MooseX::Types::NumUnit qw/num_of_unit/;
View
18 lib/Physics/UEMColumn/Accelerator.pm
@@ -0,0 +1,18 @@
+package Physics::UEMColumn::Accelerator;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Physics::UEMColumn::Element'; }
+
+use Method::Signatures;
+
+method field () {
+ return 0;
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+
View
79 lib/Physics/UEMColumn/DCAccelerator.pm
@@ -0,0 +1,79 @@
+package Physics::UEMColumn::DCAccelerator;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Physics::UEMColumn::Accelerator'; }
+
+use Method::Signatures;
+
+use Physics::UEMColumn::Auxiliary ':constants';
+use Math::Trig qw/tanh sech/;
+use MooseX::Types::NumUnit qw/num_of_unit/;
+
+has '+location' => ( required => 0, default => 0 );
+has 'voltage' => ( isa => num_of_unit('V'), is => 'ro', required => 1 );
+has 'sharpness' => ( isa => 'Num', is => 'ro', default => 10 );
+
+method field () {
+ $self->voltage / $self->length;
+}
+
+method effect () {
+ my $anode_pos = $self->length;
+ my $acc_voltage = $self->voltage;
+ my $force = qe * $acc_voltage / $anode_pos;
+ my $sharpness = $self->sharpness;
+
+ # cutoff is used oddly here
+ my $cutoff = $self->cutoff;
+
+ my $acc = sub {
+ my ($t, $pulse_z, $pulse_v) = @_;
+
+ if ($pulse_z / $anode_pos > $cutoff) {
+ return 0;
+ }
+
+ return $force / ( 2 * me ) * ( 1 - tanh( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) );
+
+ };
+
+ my $acc_mt = sub {
+ my ($t, $pulse_z, $pulse_v) = @_;
+
+ if ($pulse_z / $anode_pos > $cutoff) {
+ return 0;
+ }
+
+ return - $force * $sharpness / ( 4 * $anode_pos ) * sech( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) ** 2;
+ };
+
+ my $acc_mz = sub {
+ my ($t, $pulse_z, $pulse_v) = @_;
+
+ if ($pulse_z / $anode_pos > $cutoff) {
+ return 0;
+ }
+
+ return $force * $sharpness / ( 2 * $anode_pos ) * sech( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) ** 2;
+ };
+
+ #TODO add anode effects
+ return {acc => $acc, M_t => $acc_mt, M_z => $acc_mz};
+
+}
+
+method est_exit_vel () {
+ return sqrt( 2 * qe * $self->voltage / me );
+}
+
+method est_exit_time () {
+ # assumes pulse has initial vel zero
+ return $self->length() * sqrt( 2 * me / ( qe * $self->voltage ) );
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
View
274 lib/Physics/UEMColumn/Element.pm
@@ -1,3 +1,27 @@
+package Physics::UEMColumn::Element;
+
+use Moose;
+use namespace::autoclean;
+
+use Method::Signatures;
+
+use MooseX::Types::NumUnit qw/num_of_unit/;
+my $meters = num_of_unit('m');
+
+has 'location' => ( isa => $meters, is => 'ro', required => 1);
+has 'length' => ( isa => $meters, is => 'ro', required => 1);
+
+has 'cutoff' => ( isa => 'Num', is => 'ro', default => 3); # relative distance to ignore effect
+
+method effect () {
+ # return an hashref with code for M_t, M_z and acc_z
+ return {};
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
=head1 NAME
Physics::UEMColumn::Element - Base class for "optical" elements in a UEM system
@@ -40,251 +64,17 @@ Returns a hash reference of subroutine references defining the effect that the e
=back
-=cut
-
-package Physics::UEMColumn::Element;
-
- use Moose;
- use namespace::autoclean;
-
- use Method::Signatures;
-
- use MooseX::Types::NumUnit qw/num_of_unit/;
- my $meters = num_of_unit('m');
-
- has 'location' => ( isa => $meters, is => 'ro', required => 1);
- has 'length' => ( isa => $meters, is => 'ro', required => 1);
-
- has 'cutoff' => ( isa => 'Num', is => 'ro', default => 3); # relative distance to ignore effect
-
- method effect () {
- # return an hashref with code for M_t, M_z and acc_z
- return {};
- }
-
- __PACKAGE__->meta->make_immutable;
-
-package Physics::UEMColumn::Accelerator;
-
- use Moose;
- use namespace::autoclean;
-
- use Method::Signatures;
-
- extends 'Physics::UEMColumn::Element';
-
- method field () {
- return 0;
- }
-
- __PACKAGE__->meta->make_immutable;
-
-package Physics::UEMColumn::DCAccelerator;
-
- use Moose;
- use namespace::autoclean;
-
- use Method::Signatures;
-
- extends 'Physics::UEMColumn::Accelerator';
-
- use Physics::UEMColumn::Auxiliary ':constants';
- use Math::Trig qw/tanh sech/;
- use MooseX::Types::NumUnit qw/num_of_unit/;
-
- has '+location' => ( required => 0, default => 0 );
- has 'voltage' => ( isa => num_of_unit('V'), is => 'ro', required => 1 );
- has 'sharpness' => ( isa => 'Num', is => 'ro', default => 10 );
-
- method field () {
- $self->voltage / $self->length;
- }
-
- method effect () {
- my $anode_pos = $self->length;
- my $acc_voltage = $self->voltage;
- my $force = qe * $acc_voltage / $anode_pos;
- my $sharpness = $self->sharpness;
-
- # cutoff is used oddly here
- my $cutoff = $self->cutoff;
-
- my $acc = sub {
- my ($t, $pulse_z, $pulse_v) = @_;
-
- if ($pulse_z / $anode_pos > $cutoff) {
- return 0;
- }
-
- return $force / ( 2 * me ) * ( 1 - tanh( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) );
-
- };
-
- my $acc_mt = sub {
- my ($t, $pulse_z, $pulse_v) = @_;
-
- if ($pulse_z / $anode_pos > $cutoff) {
- return 0;
- }
-
- return - $force * $sharpness / ( 4 * $anode_pos ) * sech( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) ** 2;
- };
-
- my $acc_mz = sub {
- my ($t, $pulse_z, $pulse_v) = @_;
-
- if ($pulse_z / $anode_pos > $cutoff) {
- return 0;
- }
-
- return $force * $sharpness / ( 2 * $anode_pos ) * sech( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) ** 2;
- };
-
- #TODO add anode effects
- return {acc => $acc, M_t => $acc_mt, M_z => $acc_mz};
+=head1 SOURCE REPOSITORY
- }
+L<http://github.com/jberger/Physics-UEMColumn>
- method est_exit_vel () {
- return sqrt( 2 * qe * $self->voltage / me );
- }
+=head1 AUTHOR
- method est_exit_time () {
- # assumes pulse has initial vel zero
- return $self->length() * sqrt( 2 * me / ( qe * $self->voltage ) );
- }
+Joel Berger, E<lt>joel.a.berger@gmail.comE<gt>
- __PACKAGE__->meta->make_immutable;
-
-package Physics::UEMColumn::MagneticLens;
-
- use Moose;
- use namespace::autoclean;
-
- use Method::Signatures;
-
- extends 'Physics::UEMColumn::Element';
-
- has 'strength' => ( isa => 'Num', is => 'rw', required => 0);
- has 'order' => ( isa => 'Int', is => 'ro', default => 1);
-
- method effect () {
-
- my $lens_z = $self->location;
- my $lens_length = $self->length;
- my $lens_str = $self->strength;
- my $lens_order = $self->order;
-
- my $cutoff = $self->cutoff;
-
- my $code = sub {
- my ($t, $pulse_z, $pulse_v) = @_;
-
- my $prox = ($pulse_z - $lens_z) / ( $lens_length / 2 );
- if (abs($prox) > $cutoff) {
- return 0;
- }
-
- return $lens_str * exp( - $prox**(2 * $lens_order) );
-
- };
-
- return {M_t => $code};
-
- }
-
- __PACKAGE__->meta->make_immutable;
-
-package Physics::UEMColumn::RFCavity;
-
- use Moose;
- use namespace::autoclean;
-
- use Method::Signatures;
-
- extends 'Physics::UEMColumn::Element';
-
- use Physics::UEMColumn::Auxiliary ':constants';
- use MooseX::Types::NumUnit qw/num_of_unit/;
-
- has 'strength' => (isa => num_of_unit('v/m'), is => 'rw', required => 1);
- has 'frequency' => (isa => num_of_unit('Hz') , is => 'ro', required => 1);
- #has 'radius' => (isa => 'Num', is => 'ro', required => 1);
-
- has 'phase' => (isa => 'Num', is => 'ro', default => 0);
- has 'order' => (isa => 'Int', is => 'ro', default => 2);
-
- method effect () {
-
- my $lens_z = $self->location;
- my $length = $self->length;
- my $str = $self->strength;
- my $order = $self->order;
- my $freq = $self->frequency;
- my $phase = $self->phase;
-
- my $cutoff = $self->cutoff;
-
- my $code_z = sub {
- my ($t, $pulse_z, $pulse_v) = @_;
-
- my $prox = ($pulse_z - $lens_z) / ( $length / 2 );
- if (abs($prox) > $cutoff) {
- return 0;
- }
-
- my $return =
- qe / $pulse_v * $str * 2 * pi * $freq
- * cos( 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase)
- * exp( - $prox**(2 * $order));
-
- return $return;
-
- };
-
- my $code_t = sub {
- my ($t, $pulse_z, $pulse_v) = @_;
-
- my $prox = ($pulse_z - $lens_z) / ( $length / 2 );
- if (abs($prox) > $cutoff) {
- return 0;
- }
-
- my $trig_arg = 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase;
-
- my $mag_comp =
- $pulse_v / (vc**2) * 2 * pi * $freq
- * cos( $trig_arg );
-
- my $end_comp =
- 2 * $order / $length * ($prox**(2 * $order - 1))
- * sin( $trig_arg );
-
- return -$str * qe * ($mag_comp + $end_comp) * exp( - $prox**(2 * $order));
-
- };
-
- my $code_acc = sub {
- my ($t, $pulse_z, $pulse_v) = @_;
-
- my $prox = ($pulse_z - $lens_z) / ( $length / 2 );
- if (abs($prox) > $cutoff) {
- return 0;
- }
-
- my $return =
- qe * $str
- * sin( 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase)
- * exp( - $prox**(2 * $order));
-
- };
-
- return {M_t => $code_t, M_z => $code_z, acc => $code_acc};
-
- }
-
- __PACKAGE__->meta->make_immutable;
-
-1;
+=head1 COPYRIGHT AND LICENSE
+Copyright (C) 2012 by Joel Berger
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
View
12 lib/Physics/UEMColumn/Laser.pm
@@ -13,3 +13,15 @@ __PACKAGE__->meta->make_immutable;
1;
+=head1 NAME
+
+Physics::UEMColumn::Laser
+
+=head1 SYNOPSIS
+
+ use strict;
+ use warnings;
+
+ use Physics::UEMColumn alias => ':standard';
+
+ my $laser = Laser->new()
View
41 lib/Physics/UEMColumn/MagneticLens.pm
@@ -0,0 +1,41 @@
+package Physics::UEMColumn::MagneticLens;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Physics::UEMColumn::Element'; }
+
+use Method::Signatures;
+
+has 'strength' => ( isa => 'Num', is => 'rw', required => 0);
+has 'order' => ( isa => 'Int', is => 'ro', default => 1);
+
+method effect () {
+
+ my $lens_z = $self->location;
+ my $lens_length = $self->length;
+ my $lens_str = $self->strength;
+ my $lens_order = $self->order;
+
+ my $cutoff = $self->cutoff;
+
+ my $code = sub {
+ my ($t, $pulse_z, $pulse_v) = @_;
+
+ my $prox = ($pulse_z - $lens_z) / ( $lens_length / 2 );
+ if (abs($prox) > $cutoff) {
+ return 0;
+ }
+
+ return $lens_str * exp( - $prox**(2 * $lens_order) );
+
+ };
+
+ return {M_t => $code};
+
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
View
93 lib/Physics/UEMColumn/RFCavity.pm
@@ -0,0 +1,93 @@
+package Physics::UEMColumn::RFCavity;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Physics::UEMColumn::Element'; }
+
+use Method::Signatures;
+
+use Physics::UEMColumn::Auxiliary ':constants';
+use MooseX::Types::NumUnit qw/num_of_unit/;
+
+has 'strength' => (isa => num_of_unit('v/m'), is => 'rw', required => 1);
+has 'frequency' => (isa => num_of_unit('Hz') , is => 'ro', required => 1);
+#has 'radius' => (isa => 'Num', is => 'ro', required => 1);
+
+has 'phase' => (isa => 'Num', is => 'ro', default => 0);
+has 'order' => (isa => 'Int', is => 'ro', default => 2);
+
+method effect () {
+
+ my $lens_z = $self->location;
+ my $length = $self->length;
+ my $str = $self->strength;
+ my $order = $self->order;
+ my $freq = $self->frequency;
+ my $phase = $self->phase;
+
+ my $cutoff = $self->cutoff;
+
+ my $code_z = sub {
+ my ($t, $pulse_z, $pulse_v) = @_;
+
+ my $prox = ($pulse_z - $lens_z) / ( $length / 2 );
+ if (abs($prox) > $cutoff) {
+ return 0;
+ }
+
+ my $return =
+ qe / $pulse_v * $str * 2 * pi * $freq
+ * cos( 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase)
+ * exp( - $prox**(2 * $order));
+
+ return $return;
+
+ };
+
+ my $code_t = sub {
+ my ($t, $pulse_z, $pulse_v) = @_;
+
+ my $prox = ($pulse_z - $lens_z) / ( $length / 2 );
+ if (abs($prox) > $cutoff) {
+ return 0;
+ }
+
+ my $trig_arg = 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase;
+
+ my $mag_comp =
+ $pulse_v / (vc**2) * 2 * pi * $freq
+ * cos( $trig_arg );
+
+ my $end_comp =
+ 2 * $order / $length * ($prox**(2 * $order - 1))
+ * sin( $trig_arg );
+
+ return -$str * qe * ($mag_comp + $end_comp) * exp( - $prox**(2 * $order));
+
+ };
+
+ my $code_acc = sub {
+ my ($t, $pulse_z, $pulse_v) = @_;
+
+ my $prox = ($pulse_z - $lens_z) / ( $length / 2 );
+ if (abs($prox) > $cutoff) {
+ return 0;
+ }
+
+ my $return =
+ qe * $str
+ * sin( 2 * pi * $freq * ( $pulse_z - $lens_z ) / $pulse_v + $phase)
+ * exp( - $prox**(2 * $order));
+
+ };
+
+ return {M_t => $code_t, M_z => $code_z, acc => $code_acc};
+
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+

0 comments on commit 2d5ac14

Please sign in to comment.
Something went wrong with that request. Please try again.