Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple ODE in FMU example #40

Closed
GreroDe opened this issue Jun 29, 2022 · 3 comments
Closed

Simple ODE in FMU example #40

GreroDe opened this issue Jun 29, 2022 · 3 comments

Comments

@GreroDe
Copy link

GreroDe commented Jun 29, 2022

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.

Implementation of the Rungakutta Solver in to the UpdateIfModified Function

`

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;

`

With the ODE function

float dydx(double x, double v,double g,double l,double b, double m) { return((-(g/l)*sin(x))-(b/m)*v); }

@ghorwin
Copy link
Owner

ghorwin commented Jun 29, 2022

So, you would like to change the FMU interface?

@GreroDe
Copy link
Author

GreroDe commented Jun 29, 2022

Yes I would like to test it in different platforms and also setting different timesteps on them.
So it is not good idea to define internally the Steptime. In other words I would like to get the h value from outside or from the <defaultExperiment data

@ghorwin
Copy link
Owner

ghorwin commented Jun 30, 2022

Ok, best way to do this is:

  1. create a copy of your config-file for the FMUGeneratorProject
  2. open FMUGenerator with this copyied project
  3. alter your interface (add a new parameter input, type real, for the time step)
  4. generate the FMU template
  5. copy your old source code into the new template and adjust code as needed

Done.

@ghorwin ghorwin closed this as completed Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants