-
Notifications
You must be signed in to change notification settings - Fork 0
/
CombinedSolver.cpp
72 lines (55 loc) · 1.97 KB
/
CombinedSolver.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
//
// Created by patryk on 22/05/16.
//
#include "CombinedSolver.h"
CombinedSolver::CombinedSolver(Model &model, RhoSolver &rho_solver, LambdaSolver &lambda_solver)
: model(model), rho_solver(rho_solver), lambda_solver(lambda_solver){
set_mode("FMSC");
}
CombinedSolver::~CombinedSolver() {
delete solver;
}
void CombinedSolver::set_error(double error) {
solver->error = error;
}
int CombinedSolver::solve() {
vec rho_args(rho_solver.generate_args(model.rho, model.mu));
vec lambda_args(lambda_solver.generate_args(model.lambda, model.eta));
vec args;
args.reserve(rho_n_eq + lambda_n_eq);
args.insert(args.end(), rho_args.begin(), rho_args.end());
args.insert(args.end(), lambda_args.begin(), lambda_args.end());
solver->solve(args, false);
return solver->get_status();
}
void CombinedSolver::set_mode(const string &mode) {
rho_solver.set_mode(mode, rho_solver.hartree_fock);
lambda_solver.set_mode(mode);
rho_n_eq = rho_solver.n_eq;
lambda_n_eq = lambda_solver.n_eq;
delete solver;
solver = new MultirootSolver<CombinedSolver>(this, &CombinedSolver::F, rho_n_eq + lambda_n_eq);
}
vec CombinedSolver::F(const vec &args) {
assert(args.size() == rho_n_eq + lambda_n_eq);
vec rho_vec;
rho_vec.reserve(rho_n_eq);
for(size_t r = 0; r < rho_n_eq; r++){
rho_vec.push_back(args[r]);
}
vec lambda_vec;
lambda_vec.reserve(lambda_n_eq);
for(size_t l = 0; l < lambda_n_eq; l++){
lambda_vec.push_back(args[rho_n_eq + l]);
}
rho_solver.update_model_rho_and_mu(rho_vec);
lambda_solver.update_model_lambda_and_eta(lambda_vec);
rho_solver.calculate_density_matrix(model.rho);
lambda_vec = lambda_solver.return_F();
rho_vec = rho_solver.return_F();
vec result;
result.reserve(rho_n_eq + lambda_n_eq);
result.insert(result.end(), rho_vec.begin(), rho_vec.end());
result.insert(result.end(), lambda_vec.begin(), lambda_vec.end());
return result;
}