Re: [Yanl-develop] my thoughts about current development state
Brought to you by:
karstenahnert
|
From: Karsten A. <kar...@gm...> - 2009-10-16 12:51:05
|
Hello everybody,
First of all, it is nice that we started a very constructive discussion.
In my eyes it goes in the right direction.
I would suggest that we write and discuss here some minimal code which
is then implemented. I would also suggest that we use the euler steper
as the basis for discussion, because its the most simple one and we drop
any discussion about names, const, ... to a later point, until main
points have been clarified.
My suggestion for a minimal stepper design is the following (avoiding
any discussion about autonomous and non-autonomous systems)
template<class ContainerType>
class ode_step_euler
{
ContainerType dxdt;
public:
template<class CallMethod, class Iterator>
void do_step(
CallMethod derivative ,
double dt ,
Iterator start ,
Iterater end )
{
ContainerType::iterator dxdtiter = dxdt.begin();
derivative( start , dxdtiter );
while( start != end )
*start++ += dt * (*dxdtiter++);
}
template< class CallMethod , class StateContainer >
void do_step(
CallMethod derivative ,
double dt ,
StateContainer state )
{
do_step( derivative , dt , state.begin() , state.end() );
}
};
I think this design has all we need and is very flexible:
* no virtual functions are used anymode
* One can use the iterator and the container version
* CallMethod can be a function or a class, whatever one likes.
What we have to do now is, define how dxdt is created, which is indeed
not trivial.
> Concerning the current discussion:
> If the standard C-like usage (via functions) is not supported, as
> currently discussed and which is also my position, I would recommend to
> put the
> system's state definition (the ContainerType) into the dynamical_system
> class (or some derivation of it) as I did it in my
> lib. This is less error prone, since the user must not care about what
> kind of variable (s)he has to create for storing the state.
> In Mario's example with the harmonic oscillator the user has to provide
> the state-container-type twice, once to the stepper and to the system.
> The latter seems to be kind of redundant and should be part of the
> system and not the user's choice.
You are right, with the above approach this is possible but not necessary...
> In stepper:
> The current time point 't' should, if needed (as for non-autonomous
> systems), be part of the system's state and being integrated by the
> system using dt.
This is not possible, the time has to be a parameter. It will not work
in RK4 or others for the intermediate points.
Bye, Karsten
|