00001
00011 #include "maglev.h"
00012 #include <math.h>
00013
00014
00015 maglev::maglev(dsim_model_setup *setup) : dsim_model(setup)
00016 {
00017 }
00018
00019 maglev::~maglev()
00020 {
00021 }
00022
00028 void maglev::initialize_data()
00029 {
00030
00031
00032 const double pi = 3.14159265358979;
00033
00034 double lMagnet = 0.01;
00035 double aMagnet = pi*pow(0.005,2);
00036 double mu = 5000e-6;
00037 double mu0 = 4e-7*pi;
00038 double n = 100;
00039
00040 double a = sqrt(2.0)*mu0*lMagnet/mu;
00041 double l0 = mu0*pow(n,2)*2*aMagnet/a;
00042 double m = 0.01;
00043 double g = 9.806;
00044 double i = 0;
00045
00046 double position = 0;
00047 double velocity = 0;
00048
00049
00050 i_dsim = create_input("i", sd_type_double, &i, 1,1, "A", "Current"); i_dsim.mark_telemetry();
00051 a_dsim = create_parameter("a", sd_type_double, &a, 1,1, "Nm/A^2", "Scale"); a_dsim.mark_telemetry();
00052 g_dsim = create_parameter("g", sd_type_double, &g, 1,1, "m/s^2", "Acceleration of gravity"); g_dsim.mark_telemetry();
00053 l0_dsim = create_parameter("l0", sd_type_double, &l0, 1,1, "H", "Inductance"); l0_dsim.mark_telemetry();
00054 m_dsim = create_parameter("m", sd_type_double, &m, 1,1, "kg", "Mass"); m_dsim.mark_telemetry();
00055 position_dsim = create_integrated_state("position", sd_type_double, &position, 1,1, "m", "Position"); position_dsim.mark_telemetry();
00056 velocity_dsim = create_integrated_state("velocity", sd_type_double, &velocity, 1,1, "m/s", "Velocity"); velocity_dsim.mark_telemetry();
00057
00058 configure_timestep(false,true,false);
00059 }
00060
00062 void maglev::initialization_complete()
00063 {
00064 }
00065
00067 void maglev::initialize_timestep()
00068 {
00069 }
00070
00075 void maglev::rhs(double t,double jd)
00076 {
00077 double a = a_dsim.value_as_double();
00078 double l0 = l0_dsim.value_as_double();
00079 double m = m_dsim.value_as_double();
00080 double g = g_dsim.value_as_double();
00081 double i = i_dsim.value_as_double();
00082 double position = position_dsim.value_as_double();
00083 double velocity = velocity_dsim.value_as_double();
00084
00085 double f = -(0.5/a)*l0*pow(i,2)/pow(1 + position/a,2);
00086
00087 double accel = f/m + g;
00088
00089 position_dsim.set_derivative(velocity);
00090 velocity_dsim.set_derivative(accel);
00091 }
00092
00094 void maglev::complete_timestep()
00095 {
00096 dsim_model::complete_timestep();
00097 }
00098
00099 extern "C"
00100 {
00101 dsim_model *Maglev(void *setup);
00102
00103 dsim_model *Maglev(void *setup)
00104 {
00105 return new maglev((dsim_model_setup *)setup);
00106 }
00107
00108 }