File: dynamicsLoop.pl

package info (click to toggle)
dmrgpp 6.06-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 113,900 kB
  • sloc: cpp: 80,986; perl: 14,772; ansic: 2,923; makefile: 83; sh: 17
file content (212 lines) | stat: -rw-r--r-- 4,758 bytes parent folder | download
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/perl

use strict;
use warnings;
use Utils;

my ($dmrgOrLanczos,$q,$root,$useReflection) = @ARGV;
defined($useReflection) or die "USAGE: $0 dmrgOrLanczos q root useReflection\n";
Utils::checkRange($dmrgOrLanczos,"Lanczos","Dmrg");

my $templateInput = "inputTemplate.inp";
my $b = 1;
my %params = Utils::loadParams("params.txt");

my $n = Utils::getLabel($templateInput,"TotalNumberOfSites=");
my @spectral;

for (my $site=0; $site<$n; $site++) {
	for (my $site2=0; $site2<$n; $site2++) {

		my ($siteMin,$siteMax) = findSubstitutes($site,$site2,$n,$useReflection);

		my $output = "$root${siteMin}_$siteMax";

		die "$0: $output does not exist\n" unless (-r "$output.comb");
		if ($b  && ($site2 >= $site)) {
			my ($psimagLite,$begin,$end,$step,$eps) = ($params{"PsimagLite"},$params{"OmegaBegin"},$params{"OmegaEnd"},
			                                           $params{"OmegaStep"},$params{"OmegaEps"});
			system("$psimagLite/drivers/continuedFractionCollection -f $output.comb -b $begin -e $end -s $step -d $eps > $output.cf");
		}


		if ($q == -2) {
			print STDERR "$0: Doing addDiagonal\n";
			addDiagonal("$output.cf",$site+$site2,$site,$site2,$n);
		} elsif ($q < 0) {
			addOptical("$output.cf",$site+$site2,$site,$site2,$n);
		} else {
			my @expq = findExp($site,$site2,$q);
			addThisCf("$output.cf",$site+$site2,\@expq);
		}

		print STDERR "$0: Done $site $site2";
		print STDERR " (using $siteMin $siteMax)" if ($siteMin != $site);
		print STDERR "\n";
	}
}

printCf("${root}Total$q.cf",\@spectral);

print "$0: Result is in ${root}Total$q.cf\n";

sub findSubstitutes
{
	my ($site,$site2,$n,$useReflection) = @_;

	my $siteMin = ($site < $site2) ? $site : $site2;
	my $siteMax = ($site < $site2) ? $site2 : $site;

	my ($s1,$s2) = ($siteMin,$siteMax);
	if ($useReflection and Utils::reflected($siteMin,$siteMax,$n)) {
		$s1 = Utils::findReflection($siteMax,$n);
		$s2 = Utils::findReflection($siteMin,$n);
	}

	return ($s1,$s2);
}

sub findExp
{
	my ($site,$site2,$q) = @_;
	my $factor = ($site == $site2) ? 4 : 0.5;
	$factor = 1 if ($dmrgOrLanczos == "Lanczos");
	my $tmp =  ($site - $site2) * $q;
	return ($factor*cos($tmp),$factor*sin($tmp));
}

sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }

sub addThisCf
{
	my ($file,$ind,$expq) = @_;

	open(FILE,"$file") or die "$0: Cannot open $file: $!\n";
	my $c = 0;
	while(<FILE>) {
		chomp;
		my @temp = split;
		next if (scalar(@temp) != 3);
		my $freq = $spectral[$c];
		my @freq;

		@freq = @$freq if ($ind > 0);
		checkFreq(\@freq,$ind,$temp[0]);

		my @value;
		$value[0] = $temp[1] * $expq->[0] + $temp[2] * $expq->[1];
		$value[1] = $temp[2] * $expq->[0] - $temp[1] * $expq->[1];

		$freq[1] += $value[0];
		$freq[2] += $value[1];

		$spectral[$c] = \@freq;
		$c++;
	}

	close(FILE);
}

sub addDiagonal
{
	my ($file,$ind,$site,$site2,$L) = @_;
	open(FILE,"$file") or die "$0: line $. Cannot open $file: $!\n";
	my $c = 0;
	return if ($site != $site2);

	my $diagFactor = ($site == $site2) ? 4 : 0.25;
	$diagFactor = 1 if ($dmrgOrLanczos eq "Lanczos");

	while(<FILE>) {
		chomp;
		my @temp = split;
		next if (scalar(@temp) != 3);
		my $freq = $spectral[$c];
		my @freq;

		@freq = @$freq if ($ind > 0);
		checkFreq(\@freq,$ind,$temp[0]);

		my @value;
		my $tmp = $diagFactor;
		$value[0] = $temp[1] * $tmp;
		$value[1] = $temp[2] * $tmp;

		$freq[1] += $value[0];
		$freq[2] += $value[1];

		$spectral[$c] = \@freq;
		$c++;
	}

	close(FILE);
}

sub addOptical
{
	my ($file,$ind,$site,$site2,$L) = @_;
	open(FILE,"$file") or die "$0: line $. Cannot open $file: $!\n";
	my $c = 0;
	my $diagFactor = ($site == $site2) ? 4 : 0.5;
	$diagFactor = 1 if ($dmrgOrLanczos eq "Lanczos");

	while(<FILE>) {
		chomp;
		my @temp = split;
		next if (scalar(@temp) != 3);
		my $freq = $spectral[$c];
		my @freq;

		@freq = @$freq if ($ind > 0);
		checkFreq(\@freq,$ind,$temp[0]);

		my @value;
		my $tmp = lMinusFactor($site,$L) * lMinusFactor($site2,$L) * $diagFactor;
		$value[0] = $temp[1] * $tmp;
		$value[1] = $temp[2] * $tmp;

		$freq[1] += $value[0];
		$freq[2] += $value[1];

		$spectral[$c] = \@freq;
		$c++;
	}

	close(FILE);
}

sub lMinusFactor
{
	my ($l,$L) = @_;
	return ($l + 1 - ($L+1)/2);
}


sub checkFreq
{
	my ($f,$ind,$omega) = @_;
	if ($ind == 0) {
		$f->[0] = $omega;
		$f->[1] = 0;
		$f->[1] = 0;
		return;
	}

	defined($f->[0]) or die "$0: Undefined freq for $omega\n";
	($f->[0] == $omega) or die "$0: Invalid frequency ".$f->[0]." should be $omega\n";
}

sub printCf
{
	my ($output,$f) = @_;
	my @freq = @$f;
	open(FOUT," > $output") or die "$0: Cannot open $output for writing: $!\n";
	for (my $i = 0; $i < scalar(@freq); $i++) {
		my $oneF = $freq[$i];
		my @oneFreq = @$oneF;
		print FOUT "$oneFreq[0] $oneFreq[1] $oneFreq[2]\n";
	}

	close(FOUT);
}