| 1 | package Physics::Springs::Friction; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base 'Physics::Springs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use constant FFORCES => '_PhSpringsFriction_friction_forces'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Sub::Assert; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '1.01'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $self = $class->SUPER::new(); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $self->{FFORCES} = []; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | assert | |||||||||||||||||||||||||||||||||||||||||
| 25 | context => 'novoid', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | pre => '@PARAM == 1', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | post => '@RETURN == 1', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | sub => 'new'; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub add_friction { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_friction: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $impl = shift; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $magn = shift; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $friction = { | |||||||||||||||||||||||||||||||||||||||||
| 38 | implementation => 'stokes', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | magnitude => 0.1, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if (defined $impl) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | unless (ref($impl) eq 'CODE' or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $impl eq "CODE" or $impl eq "stokes" or $impl eq "newton"
ref $impl eq "CODE" or $impl eq "stokes"
MC/DC0%0/3
ref $impl eq "CODE" or $impl eq "stokes" or $impl eq "newton"
ref $impl eq "CODE"
$impl eq "stokes"
$impl eq "newton"
Truth table0%0/4
A or B or C
A= ref $impl eq "CODE"B= $impl eq "stokes"C= $impl eq "newton"
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | $impl eq 'stokes' or | ||||||||||||||||||||||||||||||||||||||||||
| 44 | $impl eq 'newton' | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $impl = <<ENDIMPL; | |||||||||||||||||||||||||||||||||||||||||
| 48 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | my \$P = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | my \$M = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | my \$F = [0, 0, 0]; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | $impl | ||||||||||||||||||||||||||||||||||||||||||
| 53 | return \@\$F; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ENDIMPL | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $closure = eval $impl; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | croak "Error while evaluating friction " . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | "implementation.\n ($@)" if $@; | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $impl = $closure; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $friction->{implementation} = $impl; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $friction->{magnitude} = $magn if defined $magn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | push @{$self->{FFORCES}}, $friction; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $#{$self->{FFORCES}}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | assert | |||||||||||||||||||||||||||||||||||||||||
| 72 | pre => [ | ||||||||||||||||||||||||||||||||||||||||||
| 73 | '@PARAM <= 3 && @PARAM > 0', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | '@PARAM == 1 ? 1 : defined($PARAM[1])', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | '@PARAM != 3 ? 1 : defined($PARAM[2])', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 77 | post => '$VOID || (@RETURN == 1 and $RETURN >= 0)', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | sub => 'add_friction'; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub iterate_step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_step: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my @params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $time_diff = $params[0]; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | foreach my $friction (@{$self->{FFORCES}}) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $magnitude = $friction->{magnitude}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $func = $friction->{implementation}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($func eq 'stokes') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | # F = 6*PI*eta*r*v | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # magnitude = 6*PI*eta*r | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | foreach my $P (@{$self->{p}}) { | |||||||||||||||||||||||||||||||||||||||||
| 93 | my ($vx, $vy, $vz) = ( | ||||||||||||||||||||||||||||||||||||||||||
| 94 | $P->{vx}, $P->{vy}, $P->{vz} | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $v = sqrt( | |||||||||||||||||||||||||||||||||||||||||
| 98 | $vx**2 + | ||||||||||||||||||||||||||||||||||||||||||
| 99 | $vy**2 + | ||||||||||||||||||||||||||||||||||||||||||
| 100 | $vz**2 | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | next if $v == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $f = $magnitude * $v; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $P->{_fx} -= $f * ($vx/$v); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $P->{_fy} -= $f * ($vy/$v); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $P->{_fz} -= $f * ($vz/$v); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | elsif ($func eq 'newton') { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # F = 0.5*c*rho*A*v^2 | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # magnitude = c*rho*A | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | foreach my $P (@{$self->{p}}) { | |||||||||||||||||||||||||||||||||||||||||
| 116 | my ($vx, $vy, $vz) = ( | ||||||||||||||||||||||||||||||||||||||||||
| 117 | $P->{vx}, $P->{vy}, $P->{vz} | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $v = sqrt( | |||||||||||||||||||||||||||||||||||||||||
| 121 | $vx**2 + | ||||||||||||||||||||||||||||||||||||||||||
| 122 | $vy**2 + | ||||||||||||||||||||||||||||||||||||||||||
| 123 | $vz**2 | ||||||||||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | next if $v == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $f = 0.5 * $magnitude * $v**2; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $P->{_fx} -= $f * ($vx/$v); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $P->{_fy} -= $f * ($vy/$v); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $P->{_fz} -= $f * ($vz/$v); | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | foreach my $particle (@{$self->{p}}) { | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my @this_f = $func->({%$particle}, $magnitude); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $particle->{_fx} += $this_f[0]; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $particle->{_fy} += $this_f[1]; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $particle->{_fz} += $this_f[2]; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 145 | # print Dumper $self->{p}; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $self->SUPER::iterate_step(@params); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||||||||||||||||||||||||