-
Notifications
You must be signed in to change notification settings - Fork 2
/
IIntegrator.cpp
executable file
·93 lines (77 loc) · 2.41 KB
/
IIntegrator.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
/*
* File: iintegrator.cpp
* Author: user
*
* Created on 30. April 2009, 00:30
*/
#include "IIntegrator.h"
#include <stdexcept>
#include <cassert>
//---------------------------------------------------------------------
IIntegrator::IIntegrator(IModel *pModel, double h)
:m_pModel(pModel)
,m_h(h)
,m_time(0)
,m_err(0)
,m_dim( (pModel) ? pModel->GetDim() : 0)
{
if (!pModel)
throw std::runtime_error("Model pointer may not be NULL");
if (h<=0)
throw std::runtime_error("Step size may not be negative or NULL.");
}
//---------------------------------------------------------------------
IIntegrator::~IIntegrator()
{}
//---------------------------------------------------------------------
IModel* IIntegrator::GetModel() const
{
return m_pModel;
}
//---------------------------------------------------------------------
void IIntegrator::SetModel(IModel *pModel)
{
m_pModel = pModel;
}
//---------------------------------------------------------------------
/** \brief Set the stepsize of the integrator. */
void IIntegrator::SetStepSize(double h)
{
m_h = h;
}
//------------------------------------------------------------------------
void IIntegrator::SetID(const std::string &sID)
{
m_sID = sID;
}
//------------------------------------------------------------------------------
const std::string& IIntegrator::GetID() const
{
return m_sID;
}
//------------------------------------------------------------------------
/** \brief Returns the absolute time. */
double IIntegrator::GetTime() const
{
return m_time;
}
//------------------------------------------------------------------------
double IIntegrator::GetError() const
{
return m_err;
}
//------------------------------------------------------------------------
/** \brief Evaluate the model function at a certain point in time. */
void IIntegrator::Evaluate(const double *initial, // initial state vector
const double *deriv_in, // derivation k input
double h, // the new intermediary timestep is at h*k
double time, // absolute time
double *deriv_out) // the new derivation at h*deriv_in
{
assert(m_pModel);
// estimate state at timestep i+h
double state[m_dim];
for (std::size_t i=0; i<m_pModel->GetDim(); ++i)
state[i] = initial[i] + h*deriv_in[i];
m_pModel->Eval(state, time + h, deriv_out);
}