Marine systems simulation
ConjugateGradient.h
1#pragma once
2#include "LinearOperator.h"
3#include "AsynchronousTask.h"
4
5namespace CoRiBoDynamics{
13 public:
15 void SetThreadPool(CoreBoundThreadPool* ThreadPool);
16
22 void solve(const Vector& B, Vector& X, double& tolerance, int& iterations);
23
24 void ParallellizeVectorOperations(bool b){m_parallelize_vector_operations = b;}
25
26 protected:
27 /* |a|^2 */
28 double CG_squared_norm(const Vector& a);
29
30 /* b = a-b */
31 void CG_flip_and_add(const Vector& a, Vector& b);
32
33 /* b = a + beta*b */
34 void CG_scale_and_add(const Vector& a, double beta, Vector& b);
35
36 /*
37 x = x + alpha*p
38 r = r - alpha tmp
39 return |r|^2
40 */
41 double MultiOP(Vector& p, Vector& tmp, double alpha, Vector& x, Vector& r);
42
43 LinearOperator* m_A;
44 Vector m_residual;
45 Vector m_p;
46 Vector m_z;
47 Vector m_tmp;
48
49 CoreBoundThreadPool* m_ThreadPool;
50 bool m_parallelize_vector_operations;
51
52
54 public:
55 VectorTask();
56 void SetIndex(int ix0, int ix1);
57
58 virtual void Execute();
59
60 void CG_squared_norm(const Vector& a);
61 void CG_flip_and_add(const Vector& a, Vector& b);
62 void CG_scale_and_add(const Vector& a, double beta, Vector& b);
63
64 void MultiOP(Vector& p, Vector& tmp, double alpha, Vector& x, Vector& r);
65
66 double GetAccumulator();
67
68 protected:
69 enum OPERATION {NOP, SQUARE_NORM, FLIP_AND_ADD, SCALE_AND_ADD, MULTI_OP} m_operation;
70
71 int m_ix0;
72 int m_N;
73
74 const Vector* m_ca;
75 const Vector* m_cb;
76 Vector* m_a;
77 Vector* m_b;
78 double m_alpha;
79 double m_beta;
80 double m_accumulator;
81 };
82 std::vector<VectorTask> m_vector_task;
83 };
84}
Definition: ConjugateGradient.h:53
Definition: ConjugateGradient.h:12
void solve(const Vector &B, Vector &X, double &tolerance, int &iterations)
Definition: AsynchronousTask.h:20
Definition: AsynchronousTask.h:15
Definition: LinearOperator.h:12
Definition: CollisionManager.h:6