I have implemeted a simple Pendulom Example in the FMU generator and It worked. Now I would like to implementthe same logic but this time withuot depending on a internal time factor h
, but depending ona external time factor which is giving by the simulator (in this case Matlab) or more direct by the <defaultExperiment.
data placed on the modelDescription.xml.
double g = m_realVar[FMI_PARA_g];
double l = m_realVar[FMI_PARA_l];
double b = m_realVar[FMI_PARA_b];
double m = m_realVar[FMI_PARA_m];
double Ang = m_realVar[FMI_LOCAL_Ang];
double vel = m_realVar[FMI_LOCAL_vel];
//Runga Kutta Method
double h=0.01;
double dx1,dx2,dx3,dx4,dx;
double dv1,dv2,dv3,dv4,dv;
dx1=h*vel;
dv1=h*dydx(Ang,vel,g,l,b,m);
dx2=h*(vel+0.5*dv1);
dv2=h*dydx(Ang+0.5*dx1,vel+0.5*dv1,g,l,b,m);
dx3=h*(vel+0.5*dv2);
dv3=h*dydx(Ang+0.5*dx2,vel+0.5*dv1,g,l,b,m);
dx4=h*(vel+dv3);
dv4=h*dydx(Ang+dx3,vel+dv1,g,l,b,m);
dx=(dx1+2*dx2+2*dx3+dx4)/6;
dv=(dv1+2*dv2+2*dv3+dv4)/6;
Ang=Ang+dx;
vel=vel+dv;
// output variables
m_realVar[FMI_OUTPUT_Ace] = Ang;
//Update Angle and Velocity values
m_realVar[FMI_LOCAL_Ang]=Ang;
m_realVar[FMI_LOCAL_vel]=vel;