File: continuedFractionCollection.cpp

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 (128 lines) | stat: -rw-r--r-- 3,287 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
// BEGIN LICENSE BLOCK
/*
Copyright (c) 2009 , UT-Battelle, LLC
All rights reserved

[PsimagLite, Version 1.0.0]

*********************************************************
THE SOFTWARE IS SUPPLIED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED.

Please see full open source license included in file LICENSE.
*********************************************************

*/
// END LICENSE BLOCK

#include "ContinuedFractionCollection.h"
#include "ContinuedFraction.h"
#include "Io/IoSimple.h"
#include "TridiagonalMatrix.h"
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>

using namespace PsimagLite;
typedef double RealType;
typedef TridiagonalMatrix<RealType> TridiagonalMatrixType;
typedef ContinuedFraction<TridiagonalMatrixType> ContinuedFractionType;
typedef ContinuedFractionCollection<ContinuedFractionType>
    ContinuedFractionCollectionType;
typedef ContinuedFractionType::PlotParamsType PlotParamsType;

void usage(const char* progName)
{
	std::cerr << "Usage: " << progName << " -f file  -b omega1";
	std::cerr << " -e omega2 -s omegaStep -d delta -B beta -m matsubaras\n";
}

void plotAll(const ContinuedFractionCollectionType& cfCollection,
    const PlotParamsType& params)
{
	ContinuedFractionCollectionType::PlotDataType v;
	cfCollection.plot(v, params);
	std::cout.precision(12);
	for (SizeType x = 0; x < v.size(); x++) {
		std::cout << v[x].first << " " << PsimagLite::imag(v[x].second);
		std::cout << " " << PsimagLite::real(v[x].second) << "\n";
	}
}

void plotOneByOne(const ContinuedFractionCollectionType& cfCollection,
    const PlotParamsType& params)
{

	std::cout.precision(12);
	for (SizeType i = 0; i < cfCollection.size(); i++) {
		ContinuedFractionCollectionType::PlotDataType v;
		cfCollection.plotOne(i, v, params);
		for (SizeType x = 0; x < v.size(); x++) {
			std::cout << v[x].first << " " << PsimagLite::imag(v[x].second);
			std::cout << " " << PsimagLite::real(v[x].second) << "\n";
		}
	}
}

int main(int argc, char* argv[])
{
	int opt = 0;
	String file = "";
	RealType wbegin = 0;
	RealType wend = 0;
	RealType wstep = 0;
	RealType delta = 0;
	RealType beta = 0.0;
	SizeType matsubaras = 0;
	bool oneByOne = false;
	while ((opt = getopt(argc, argv, "f:b:e:s:d:m:B:1")) != -1) {
		switch (opt) {
		case 'f':
			file = optarg;
			break;
		case 'b':
			wbegin = atof(optarg);
			break;
		case 'e':
			wend = atof(optarg);
			break;
		case 's':
			wstep = atof(optarg);
			break;
		case 'd':
			delta = atof(optarg);
			break;
		case '1':
			oneByOne = true;
			break;
		case 'm':
			matsubaras = atoi(optarg);
			break;
		case 'B':
			beta = atof(optarg);
			break;
		default:
			usage(argv[0]);
			return 1;
		}
	}
	// sanity checks:
	bool real1 = (wbegin >= wend || wstep <= 0 || delta <= 0);
	bool imag1 = (beta <= 0 || matsubaras == 0);
	if (file == "" || (real1 & imag1)) {
		usage(argv[0]);
		return 1;
	}

	IoSimple::In io(file);
	ContinuedFractionCollectionType cfCollection(io);
	PlotParamsType params(wbegin, wend, wstep, delta, beta, matsubaras);
	if (!oneByOne)
		plotAll(cfCollection, params);
	else
		plotOneByOne(cfCollection, params);
}