-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFindHopf.cpp
101 lines (76 loc) · 2.44 KB
/
FindHopf.cpp
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
#include "HopfBifurcation.h"
#include "NewtonKrylov.h"
class FindHopf : public NewtonKrylov<HopfBifurcation>
{
public:
StateVector A;
virtual void EnforceConstraints(HopfBifurcation& at)
{
flowParams.Ri = at.p;
stratifloat theta = atan2(-at.v2.Dot(A),at.v1.Dot(A));
stratifloat r = 1/(cos(theta)*at.v1.Dot(A) - sin(theta)*at.v2.Dot(A));
StateVector newv1 = r*cos(theta)*at.v1 - r*sin(theta)*at.v2;
at.v2 = r*sin(theta)*at.v1 + r*cos(theta)*at.v2;
at.v1 = newv1;
}
private:
virtual HopfBifurcation EvalFunction(const HopfBifurcation& at) override
{
HopfBifurcation result;
flowParams.Ri = at.p;
at.x.FullEvolve(T, result.x, false, false);
at.v1.LinearEvolve(T, at.x, result.v1);
at.v2.LinearEvolve(T, at.x, result.v2);
result.x -= at.x;
result.v1.MulAdd(-cos(at.theta), at.v1);
result.v1.MulAdd(sin(at.theta), at.v2);
result.v2.MulAdd(-sin(at.theta), at.v1);
result.v2.MulAdd(-cos(at.theta), at.v2);
result.theta = at.v1.Dot(A) - 1;
result.p = at.v2.Dot(A);
std::cout << at.v1.Norm() << " " << at.v2.Norm() << std::endl;
std::cout << result.x.Norm2() << " "
<< result.v1.Norm2() << " "
<< result.v2.Norm2() << " "
<< result.theta*result.theta << " "
<< result.p*result.p << std::endl;
return result;
}
};
#include "Arnoldi.h"
#include "ExtendedStateVector.h"
int main(int argc, char *argv[])
{
flowParams.Re = std::stof(argv[1]);
DumpParameters();
StateVector::ResetForParams();
HopfBifurcation guess;
if (argc == 6)
{
HopfBifurcation x1;
HopfBifurcation x2;
x1.LoadFromFile(argv[2]);
x2.LoadFromFile(argv[3]);
stratifloat Re1 = std::stof(argv[4]);
stratifloat Re2 = std::stof(argv[5]);
HopfBifurcation gradient = x2;
gradient -= x1;
gradient *= 1/(Re2-Re1);
guess = x2;
guess.MulAdd(flowParams.Re-Re2, gradient);
}
else
{
guess.LoadFromFile(argv[2]);
}
flowParams.Ri = guess.p;
FindHopf solver;
// make sure eigenvectors are a sensible size
stratifloat rescale = guess.v1.Norm();
guess.v1 *= 1/rescale;
guess.v2 *= 1/rescale;
solver.A = guess.v1;
solver.EnforceConstraints(guess);
solver.Run(guess);
guess.SaveToFile("final");
}