Commit 421a126a authored by Markus Mirz's avatar Markus Mirz
Browse files

Merge branch 'odeint-solver' into 'development'

Fixed inital value setting of odeint solver

See merge request acs/public/simulation/dpsim!62

Former-commit-id: 4ae43c0d
parents 9cc5c4d0 988a03de
......@@ -90,7 +90,6 @@ int main(int argc, char* argv[]) {
ODEintSolver sim(simName, gen, timeStep, timeStep);
while (curTime < finalTime){
curTime = sim.step(curTime);
......
......@@ -40,6 +40,8 @@ namespace DPsim {
class ODEintSolver : public Solver {
protected:
/// Pointer to current Component
CPS::ODEintInterface::Ptr mComponent;
/// Constant time step
Real mTimestep;
///Problem Size
......@@ -57,7 +59,7 @@ namespace DPsim {
///static pointer to current object; only one instance currently allowed
inline static ODEintSolver *self = nullptr;
/// State space of the System and corresponding static wrapper
static void StateSpaceWrapper( std::vector<double> y, std::vector<double> ydot, double t);
static void StateSpaceWrapper( const std::vector<double> y, std::vector<double> ydot, double t);
public:
......
......@@ -26,7 +26,7 @@
using namespace DPsim;
ODEintSolver::ODEintSolver(String name, CPS::ODEintInterface::Ptr comp, Real dt, Real t0) :
mTimestep(dt) {
mComponent(comp), mTimestep(dt){
times.push_back(t0);
self = this; // sets static pointer to current object
ProbDim = comp->num_states();
......@@ -45,14 +45,19 @@ ODEintSolver::ODEintSolver(String name, CPS::ODEintInterface::Ptr comp, Real dt,
Real ODEintSolver::step(Real time) {
mComponent->pre_step(); ///write inital values into the mState Vector
curSolution.assign(mComponent->state_vector(), mComponent->state_vector()+ProbDim);
Real NextTime = time + mTimestep;
std::cout<<"Current Time "<<time<<std::endl;
std::cout<<"Current Time "<<NextTime<<std::endl;
stepper.do_step(&ODEintSolver::StateSpaceWrapper,curSolution, time, mTimestep); ///solve ODE for time + mTimestep TODO: implement sysfunc
mComponent->set_state_vector(curSolution);///Writes the current solution back into the component
solution.push_back(curSolution); /// Logs current solution
times.push_back(time); ///Logs current time
// TODO: add proper logging
mComponent->post_step();
return NextTime;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment