UEMColumn/DCAccelerator.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 63 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Physics::UEMColumn::DCAccelerator;
2  
3 use Moose;
4 use namespace::autoclean;
5  
6 BEGIN { extends 'Physics::UEMColumn::Accelerator'; }
7  
8 use Method::Signatures;
9  
10 use Physics::UEMColumn::Auxiliary ':constants';
11 use Math::Trig qw/tanh sech/;
12 use MooseX::Types::NumUnit qw/num_of_unit/;
13  
14 has 'voltage' => ( isa => num_of_unit('V'), is => 'ro', required => 1 );
15 has 'sharpness' => ( isa => 'Num', is => 'ro', default => 10 );
16  
17 method field () {
18 $self->voltage / $self->length;
19 }
20  
21 method effect () {
22 my $anode_pos = $self->length;
23 my $acc_voltage = $self->voltage;
24 my $force = qe * $acc_voltage / $anode_pos;
25 my $sharpness = $self->sharpness;
26  
27 # cutoff is used oddly here
28 my $cutoff = $self->cutoff;
29  
30 my $acc = sub {
31 my ($t, $pulse_z, $pulse_v) = @_;
32  
33 if ($pulse_z / $anode_pos > $cutoff) {
34 return 0;
35 }
36  
37 return $force / ( 2 * me ) * ( 1 - tanh( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) );
38  
39 };
40  
41 my $acc_mt = sub {
42 my ($t, $pulse_z, $pulse_v) = @_;
43  
44 if ($pulse_z / $anode_pos > $cutoff) {
45 return 0;
46 }
47  
48 return - $force * $sharpness / ( 4 * $anode_pos ) * sech( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) ** 2;
49 };
50  
51 my $acc_mz = sub {
52 my ($t, $pulse_z, $pulse_v) = @_;
53  
54 if ($pulse_z / $anode_pos > $cutoff) {
55 return 0;
56 }
57  
58 return $force * $sharpness / ( 2 * $anode_pos ) * sech( ($pulse_z - $anode_pos) * $sharpness / $anode_pos ) ** 2;
59 };
60  
61 #TODO add anode effects
62 return {acc => $acc, M_t => $acc_mt, M_z => $acc_mz};
63  
64 }
65  
66 method est_exit_vel () {
67 return sqrt( 2 * qe * $self->voltage / me );
68 }
69  
70 method est_exit_time () {
71 # assumes pulse has initial vel zero
72 return $self->length() * sqrt( 2 * me / ( qe * $self->voltage ) );
73 }
74  
75 __PACKAGE__->meta->make_immutable;
76  
77 1;
78  
79 =head1 NAME
80  
81 Physics::UEMColumn::DCAccelerator - A class representing a DC acceleration region in a UEM system
82  
83 =head1 SYNOPSIS
84  
85 use Physics::UEMColumn alias => ':standard';
86 my $acc = DCAccelerator->new(
87 length => '20 mm',
88 voltage => '20 kilovolts',
89 );
90  
91 =head1 DESCRIPTION
92  
93 L<Physics::UEMColumn::Accelerator> is a class representing a DC (static electric field) acceleration region in a UEM system. It is a subclass of L<Physics::UEMColumn::Accelerator> and inherits its attributes and methods. Additionally it provides:
94  
95 =head1 ATTRIBUTES
96  
97 =over
98  
99 =item C<voltage>
100  
101 The static electric potential in the accelerator. Unit: V
102  
103 =item C<sharpness>
104  
105 The potential is modeled as a C<tanh>, this parameter (defaults to 10) is related to the slope of the tanh near the end of the region. For example a value approaching infinity approximates a step function.
106  
107 =back
108  
109 =head1 METHODS
110  
111 =over
112  
113 =item C<field>
114  
115 Defined as C<voltage> / C<length>
116  
117 =item C<effect>
118  
119 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.
120  
121 =item C<est_exit_vel>
122  
123 Returns an estimate of the velocity of the pulse on exiting the region. This in not likely to be exact. It is used in estimating the end time of the simulation. This overrides the base class and is specific to DC accelerators.
124  
125 =item C<est_exit_time>
126  
127 Returns an estimate of the time that the pulse on exits the region. This in not likely to be exact. It is used in estimating the end time of the simulation. This overrides the base class and is specific to DC accelerators.
128  
129 =back
130  
131 =head1 SOURCE REPOSITORY
132  
133 L<http://github.com/jberger/Physics-UEMColumn>
134  
135 =head1 AUTHOR
136  
137 Joel Berger, E<lt>joel.a.berger@gmail.comE<gt>
138  
139 =head1 COPYRIGHT AND LICENSE
140  
141 Copyright (C) 2012-2013 by Joel Berger
142  
143 This library is free software; you can redistribute it and/or modify
144 it under the same terms as Perl itself.
145