Types error: invalid operands to binary expression ('double' and 'state_type')
- Dominant language
- C++
- Stars
- 55
- Forks
- 59
- PR merge metrics
- No merged PRs in 30d
Description
I defined new state type as
```c++
struct state_type { double x; };
```
and vector space operators
```c++
state_type operator * (const state_type &a, double k) { return {a.x * k}; }
state_type operator * (double k, const state_type &a) { return {a.x * k}; }
state_type operator + (const state_type &a, const state_type &b) { return {a.x + b.x}; }
state_type operator - (const state_type &a, const state_type &b) { return {a.x - b.x}; }
state_type operator / (const state_type &a, const state_type &b) { return {a.x / b.x}; }
state_type abs(state_type const& v) { return {fabs(v.x)}; }
```
The main function is
```c++
int main()
{
state_type x0 {1.};
double t0 = 0, t1 = 1, dt = 1e-3;
using Stepper = runge_kutta_dopri5;
auto f = [](state_type const& x, state_type& dx, double t) {
dx = x;
};
integrate_adaptive(make_controlled(1e-10, 1e-10), f, x0, t0, t1, dt);
}
```
During compilation I am getting the error
> /usr/include/boost/numeric/odeint/algebra/default_operations.hpp:443:76: error: invalid operands to binary expression ('double' and 'state_type')
> [build] set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( t1 ) ) + m_a_dxdt * abs( get_unit_value( t2 ) ) ) ) );
>
If I add the requested operator
```c++
state_type operator + (double k, const state_type &a) { return {a.x + k}; }
```
the compilation works well. It seems that the formula
```c++
set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( t1 ) ) + m_a_dxdt * abs( get_unit_value( t2 ) ) ) ) );
```
is wrong, or type of `m_eps_abs` is wrong. In a vector space there must not be operator `+` between elements of state_type and and coefficients. Moreover the operator `/` between state_type elements is questionable.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.