summaryrefslogtreecommitdiff
path: root/cad/src/experimental/CoNTub/C++/Nanotubo.cpp
blob: 2f8c4ee7588e2d0ce0a3f9c2c7b4688e21335a11 (plain)
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
// Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details. 
#include <math.h>

#include "Nanotubo.h"

int primos[] = { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
		 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 1 };

Nanotubo::Nanotubo (int I, int J)
{
    i1 = I;
    i2 = J;
    ordenmin = 1;  // orden --> order
    _d = 1;
    A = 2.46;

    int nn = i1, mm = i2;
    altura = new double[100];
    phi = new double[100];

    // find common factors between nn and mm, move them to d
    for (int i = 1; i <= 25; i++) {
	for (int j = 1; ((nn % primos[i]) == 0)
		 && ((mm % primos[i]) == 0); j++) {
	    nn = nn / primos[i];
	    mm = mm / primos[i];
	    _d = _d * primos[i];
	}}

    deltaz1 = A * sin (M_PI / 3 - quiral ());
    deltaz2 = A * sin (quiral ());	//esto, al estar bajo Q, es positivo cuando deberia ser negativo! OJO a esto!
    // this, when being under Q, is positive when it would have to be negative! WATCH this!
    deltaphi1 = A / radio () * cos (M_PI / 3 - quiral ());
    deltaphi2 = A / radio () * cos (quiral ());

    altura[1] = deltaz1;
    phi[1] = deltaphi1;

    for (int i = 2; i <= (i1 + i2) / _d; i++) {
	if (altura[i - 1] < 0) {
	    altura[i] = altura[i - 1] + deltaz1;
	    phi[i] = phi[i - 1] + deltaphi1;
	} else {
	    altura[i] = altura[i - 1] - deltaz2;
	    phi[i] = phi[i - 1] + deltaphi2;
	}

	if ((altura[i] < altura[ordenmin]) == (altura[i] > 0.0001))
	    ordenmin = i;
    }
}
Nanotubo::Nanotubo (int I, int J, double aalt)
{

    A = aalt;
    i1 = I;
    i2 = J;
    ordenmin = 1;
    _d = 1;
    A = 2.46;

    int nn = i1, mm = i2;
    altura = new double[100];
    phi = new double[100];

    for (int i = 1; i <= 25; i++) {
	for (int j = 1; ((nn % primos[i]) == 0)
		 && ((mm % primos[i]) == 0); j++) {
	    nn = nn / primos[i];
	    mm = mm / primos[i];
	    _d = _d * primos[i];
	}}

    deltaz1 = A * sin (M_PI / 3 - quiral ());
    deltaz2 = A * sin (quiral ());
    deltaphi1 = A / radio () * cos (M_PI / 3 - quiral ());
    deltaphi2 = A / radio () * cos (quiral ());

    altura[1] = deltaz1;
    phi[1] = deltaphi1;

    for (int i = 2; i <= (i1 + i2) / _d; i++) {
	if (altura[i - 1] < 0) {
	    altura[i] = altura[i - 1] + deltaz1;
	    phi[i] = phi[i - 1] + deltaphi1;
	} else {
	    altura[i] = altura[i - 1] - deltaz2;
	    phi[i] = phi[i - 1] + deltaphi2;
	}

	if ((altura[i] < altura[ordenmin]) == (altura[i] > 0.0001))
	    ordenmin = i;
    }
}

double Nanotubo::deltaz ()
{
    return altura[ordenmin];
}
double Nanotubo::deltaphi ()
{
    return phi[ordenmin];
}
double Nanotubo::radio ()
{
    return A * sqrt (i1 * i1 + i2 * i2 + i2 * i1) / (2 * M_PI);
}
double Nanotubo::quiral ()
{
    double ang = atan (sqrt (3) * i2 / (2 * i1 + i2));
    if (2 * i1 + i2 < 0)
	ang += (M_PI);
    return ang;
}
double Nanotubo::quiralg ()
{
    return quiral () * (180.0 / M_PI);
}
double Nanotubo::deltazc ()
{
    return A / sqrt (3) * cos (quiral ());
}
double Nanotubo::deltaphic ()
{
    return A / sqrt (3) / radio () * sin (quiral ());
}
int Nanotubo::d ()
{
    return _d;
}

double Nanotubo::energia (double momm, double momz)
{
    double numfase = sin (momz * deltaz1 + momm * deltaphi1) +
	sin (momz * (deltaz1 + deltaz2) + momm * (deltaphi1 - deltaphi2));
    double denfase = 1 + cos (momz * deltaz1 + momm * deltaphi1) +
	cos (momz * (deltaz1 + deltaz2) + momm * (deltaphi1 - deltaphi2));
    double energ = sqrt (numfase * numfase + denfase * denfase);
    return energ;
}