I want to know how I can log the values other than states during integration by odeint. I have a simulation of the satellite dynamics, which is described as differential equations of total angular momentum, L, and momentum of an internal wheel, h. My simulation is running correctly. But I need to log not only the state variables but also some other values such as external torque, N, and angular velocity, omega, that is Jinv*L, where Jinv is a 3x3 constant, satellite-inertia matrix. In a sense, the purpose of my simulator is not to calculate L and h, but to generate time-histories of "other" varialbes.
To show what I'm doing, below is a slightly simplified version of my current code.
class satellite
{
public:
Eigen::Matrix3d Jinv;
void operator()( state_type &x , state_type &dxdt , double t )
{
L << x[0], x[1], x[2];
h << x[3], x[4], x[5], x[6];
N = external_torque(t);
omega = Jinv * (L-h);
dLdt = N - omega.cross(L);
OMEGA = func1(omega(0), omega(1), omega(2));
dqdt = OMEGA * q * 0.5;
dxdt[0] = dLdt(0); dxdt[1] = dLdt(1); dxdt[2] = dLdt(2);
dxdt[3] = dqdt(0); dxdt[4] = dqdt(1); dxdt[5] = dqdt(2); dxdt[6] = dqdt(3);
}
};
class streaming_observer
{
public:
std::ostream& os;
satellite& sat;
streaming_observer( std::ostream& _os, satellite& _sat ) : os(_os), sat(_sat) { }
template<class State>
void operator() (const State& x, double t) const
{
L << x[0], x[1], x[2];
os << t << ' ' << (sat.Jinv*(L)).transpose() << std::endl;
}
};
중간체의 계산과 옵저버의 로깅을 수행해야합니다. 중복을 피하기 위해 클래스 메서드의 별도 함수에서 계산을 수행하고 시스템 함수 (예에서는 operator ())와 관찰자에서이 메서드를 호출하는 것이 좋습니다. 거기에 값을 기록하고이 값으로 나중에 분석을 수행 할 수도 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다