-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilamentJacobianSolver.hpp
89 lines (69 loc) · 1.92 KB
/
FilamentJacobianSolver.hpp
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
#ifndef JACOBIAN_SOLVER_IS_INCLUDED
#define JACOBIAN_SOLVER_IS_INCLUDED
#include "config.hpp"
#include <armadillo>
#include "multi_filament_header.hpp"
// Jacobian solver that uses filament-level sub-jacobians
// started 06/07/17 by simon [email protected]
using namespace std;
using namespace arma;
class filamentJsolver {
private:
mat Cmat;
mat Dmat;
// mat Japprox; // block is now stored as part of each filament.
public:
// default constructor
filamentJsolver()
: Cmat(6*Np,broyden_maxiter,fill::zeros)
, Dmat(6*Np,broyden_maxiter,fill::zeros)
{
};
filamentJsolver(int myNp)
: Cmat(6*myNp,broyden_maxiter,fill::zeros)
, Dmat(6*myNp,broyden_maxiter,fill::zeros)
{
};
void buildJacobian(std::vector<Filament>& filaments, int nt) {
// Only called by rank 0.
// reset rank one updates
Dmat.zeros();
Cmat.zeros();
// for each filament, build an invert the analytical approx Jacobian
for(int nn=0; nn < filaments.size(); ++nn) {
filaments[nn].buildApproximateJacobian(nt);
}
return;
}
void solve(std::vector<Filament>& filaments,
const vec& b, vec& x, int curr_iter) const {
// Only called by rank 0.
// solves Jx = b for x, where J^-1 blocks are members of filamens and rank one
// updates to J^-1 are stored in solver object's Dmat and Cmat.
// (Bad Broyden's)
// block-wise multiplication with inverse jacobian.
for(int nn=0; nn < filaments.size(); ++nn) {
vec xFil;
vec bFil;
filaments[nn].getOutOfStateVec(b,bFil); // get short bFil out of long b (6*Np)
xFil = filaments[nn].myJapproxInv*bFil;
filaments[nn].putIntoStateVec(x,xFil); // put short xFil into long x (6*Np)
}
// bad Broyden's updates
for(int i = 0; i < curr_iter; ++i) {
vec dtmp = Dmat.col(i);
vec ctmp = Cmat.col(i);
x += ctmp * dot(dtmp,b);
}
return;
}
void addDmatCol(const vec& v, int ind){
Dmat.col(ind) = v;
return;
}
void addCmatCol(const vec& v, int ind){
Cmat.col(ind) = v;
return;
}
}; // end of class
#endif