1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Math::Trig;
my ($file, $mode) = @ARGV;
defined($file) or die "USAGE: $0 filename [mode]\n";
defined($mode) or $mode = "";
my $obs = ($mode eq "") ? "<Q1|c|Q0>" : "<Q0|c'|Q1>";
my $label1 = "site $obs time";
my @cdaggerI = loadVector($file, $label1);
my $sites = scalar(@cdaggerI);
my $label2 = "<Q0|c;c'|Q0>";
my @cIcDaggerJ = loadMatrix($file, $label2, $mode);
for (my $mForK = 0; $mForK < $sites; ++$mForK) {
doOneMomentumK($mForK, $sites, \@cdaggerI, \@cIcDaggerJ);
}
sub doOneMomentumK
{
my ($mForK, $sites, $cdaggerI, $cIcDaggerJ) = @_;
my $momentumK = findMomentumK($mForK, $sites);
my @numerator = ftVector($cdaggerI, $momentumK);
#print STDERR "$0: numerator= @numerator\n";
my @den = ftMatrix($cIcDaggerJ, $momentumK);
#print STDERR "$0: denominator= @den\n";
die "$0: Denominator isn't real\n" if (abs($den[1]) > 1e-5);
print $mForK." ";
if ($mode eq "") {
$_ = $numerator[0]*$numerator[0] + $numerator[1]*$numerator[1];
print "$_\n";
} else {
print $numerator[0]/$den[0]." ".$numerator[1]/$den[0]."\n";
}
}
sub ftMatrix
{
my ($a, $momentumK) = @_;
my $n = scalar(@$a);
return (1, 0) if ($n == 0);
my $center = $n/2;
my ($sumR, $sumI) = (0, 0);
for (my $i = 0; $i < $n; ++$i) {
my $ptr = $a->[$i];
my $m = scalar(@$ptr);
($n == $m) or die "$0: Matrix not square\n";
for (my $j = 0; $j < $m; ++$j) {
my $arg = $momentumK*($i - $j);
my $value = ($i < $j) ? $a->[$i]->[$j] : $a->[$j]->[$i];
$sumR += $value*cos($arg);
$sumI += $value*sin($arg);
}
}
return ($sumR, $sumI);
}
sub ftVector
{
my ($a, $momentumK) = @_;
my $n = scalar(@$a);
my $center = $n/2;
my ($sumR, $sumI) = (0, 0);
for (my $i = 0; $i < $n; ++$i) {
my $arg = $momentumK*($i - $center);
my $value = $a->[$i];
$sumR += $value*cos($arg);
$sumI += $value*sin($arg);
}
return ($sumR, $sumI);
}
sub loadVector
{
my ($file, $label) = @_;
open(FILE, "<", $file) or die "$0: Cannot open $file : $!\n";
while (<FILE>) {
last if (/^\Q$label/);
}
my @a;
while (<FILE>) {
chomp;
next if (/^#/);
my @temp = split;
last if (scalar(@temp) != 3);
last unless ($temp[0] =~ /^\d+$/);
$a[$temp[0]] = $temp[1];
}
close(FILE);
print STDERR "$0: Found ".scalar(@a)." sites for \"$label\" in $file\n";
return @a;
}
sub loadMatrix
{
my ($file, $label, $mode) = @_;
return () if ($mode eq "");
open(FILE, "<", $file) or die "$0: Cannot open $file : $!\n";
while (<FILE>) {
last if (/^\Q$label/);
}
$_ = <FILE>;
chomp;
my @sizes = split;
die "$0: No matrix dimensions found for $label in $file\n" unless (scalar(@sizes) == 2);
my @a;
my ($rows, $cols) = @sizes;
for (my $i = 0; $i < $rows; ++$i) {
$_ = <FILE>;
chomp;
next if (/^#/);
my @temp = split;
(scalar(@temp) == $cols) or die "$0: row $i not with $cols columns\n";
$a[$i] = \@temp;
}
close(FILE);
print STDERR "$0: Found matrix with ".scalar(@a)." rows for \"$label\" in $file\n";
return @a;
}
sub findMomentumK
{
my ($m, $total) = @_;
return 2*pi*$m/$total;
}
|