Geomi
StepInternals.hpp
1 #ifndef DEF_RKMK_STEPINTERNALS
2 #define DEF_RKMK_STEPINTERNALS
3 
4 #include <vector>
5 
6 namespace RKMK {
7 
8 template <typename T_LIE_ALGEBRA,
9  int T_N_INTERNAL_STAGES,
10  typename T_M>
12 {
13 protected:
15  T_M m_h;
16 
17  T_LIE_ALGEBRA m_solution;
18 
20 
21  double m_a_coeffs [T_N_INTERNAL_STAGES * T_N_INTERNAL_STAGES];
22  double m_b_coeffs [T_N_INTERNAL_STAGES];
23  T_LIE_ALGEBRA m_k [T_N_INTERNAL_STAGES];
24  unsigned int m_order_q;
25 
26 public:
28  : m_problem(problem)
29  { setTruncatureOrder(); }
30 
32  newFromProblem (Abstract::Problem<T_LIE_ALGEBRA,T_M>& problem)
33  {
36  return *res;
37  }
38 
39  void
41  {
42  // TODO: Cod'e avec le cul, il faut verifier tout ca.
43  m_y0 = other.m_y0;
44  m_h = other.m_h;
45  m_solution = other.m_solution;
46  m_problem = other.m_problem;
47  std::copy(std::begin(other.m_a_coeffs),std::end(other.m_a_coeffs),std::begin(m_a_coeffs));
48  std::copy(std::begin(other.m_b_coeffs),std::end(other.m_b_coeffs),std::begin(m_b_coeffs));
49  std::copy(std::begin(other.m_k),std::end(other.m_k),std::begin(m_k));
50  m_order_q = other.m_order_q;
51  }
52 
53  double
54  a_coeffs (int i, int j) const
55  { return m_a_coeffs[i*T_N_INTERNAL_STAGES+j]; }
56 
57  void
58  setData (T_M h_var, NOXVector<T_LIE_ALGEBRA::DOF> y0_var)
59  {
60  m_h = h_var;
61  m_y0 = y0_var;
62  }
63 
64  bool
65  setCoeffs (std::vector<double> a, std::vector<double> b)
66  {
67  if ((a.size()!=T_N_INTERNAL_STAGES*T_N_INTERNAL_STAGES) || (b.size()!=T_N_INTERNAL_STAGES))
68  return false;
69  for (int i=0; i<T_N_INTERNAL_STAGES; i++)
70  m_b_coeffs[i] = b[i];
71  for (int i=0; i<T_N_INTERNAL_STAGES*T_N_INTERNAL_STAGES; i++)
72  m_a_coeffs[i] = a[i];
73  return true;
74  }
75 
76  void
77  setTruncatureOrder ( )
78  { m_order_q = std::max(0,T_N_INTERNAL_STAGES-2); }
79 
84  bool
86  {
87  bool success = false;
88 
89  T_LIE_ALGEBRA omega0 = T_LIE_ALGEBRA::Zero();
90  T_LIE_ALGEBRA omega = omega0;
91  T_LIE_ALGEBRA sol = omega0;
92  T_LIE_ALGEBRA A;
93  int i,j;
94 
95  for (i=0; i<T_N_INTERNAL_STAGES; i++) {
96 
97  // do something smarter if a(i,j) is zero
98  omega = omega0;
99  for (j=0; j<T_N_INTERNAL_STAGES; j++) {
100  omega += this->m_k[j]*this->m_h*this->a_coeffs(i,j);
101  }
102 
103  this->m_problem.computeA(A,omega.exp()*this->m_y0);
104  // TODO: should you really overwrite m_k[i] ?
105  this->m_k[i] = omega.computeDExpRInv(A,this->m_order_q);
106  sol += this->m_b_coeffs[i]*this->m_h*this->m_k[i];
107  }
108 
109  this->m_solution = sol;
110  success = true;
111 
112  return success;
113  }
114 
116  reconstruct (const NOXVector<T_LIE_ALGEBRA::DOF>& solution)
117  {
118  T_LIE_ALGEBRA w(solution);
119  return NOXVector<T_LIE_ALGEBRA::DOF>(w.exp()*m_y0);
120  }
121 
123  reconstruct ()
124  { return this->reconstruct(this->m_solution.toVector()); }
125 
126  bool
127  computeA (T_LIE_ALGEBRA& A, const NOXVector<T_LIE_ALGEBRA::DOF>& y)
128  { return m_problem.computeA(A,y); }
129 
130  bool
131  computeJacobianA (std::vector<T_LIE_ALGEBRA>& JA, const NOXVector<T_LIE_ALGEBRA::DOF>& y)
132  { return m_problem.computeJacobianA(JA,y); }
133 
134 };
135 } // namespace RKMK
136 
137 #endif
bool computeSolution(void)
Definition: StepInternals.hpp:85
Definition: Abstract_Problem.hpp:10
Definition: Abstract_Integrator.hpp:4
Definition: StepInternals.hpp:11