|
From: <de...@us...> - 2003-04-03 10:40:45
|
Update of /cvsroot/csp/APPLICATIONS/CSPSim/Source
In directory sc8-pr-cvs1:/tmp/cvs-serv5076
Modified Files:
DynamicalSystem.cpp CSPSim.cpp AircraftObject.cpp
AeroDynamics.cpp
Log Message:
no message
Index: DynamicalSystem.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/DynamicalSystem.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DynamicalSystem.cpp 12 Mar 2003 21:38:43 -0000 1.1
--- DynamicalSystem.cpp 3 Apr 2003 10:40:42 -0000 1.2
***************
*** 25,178 ****
#include <cmath>
#include <iostream>
#include "DynamicalSystem.h"
- double const DynamicalSystem::PGROW = -0.20;
- double const DynamicalSystem::PSHRNK = -0.25;
- double const DynamicalSystem::FCOR = 0.06666666; // 1.0/15.0
-
- double const DynamicalSystem::SAFETY = 0.9;
- double const DynamicalSystem::ERRCON = 6.0e-4;
-
- unsigned int const DynamicalSystem::MAXSTP = 10000;
- double const DynamicalSystem::TINY = std::numeric_limits<float>::epsilon();//1.0e-30;
-
-
- //===========================================================================
-
- std::vector<double> const &DynamicalSystem::rk4(std::vector<double> const &y,
- std::vector<double> const &dydx,
- double x, double h)
- {
- static std::vector<double> yout(m_NVariable), yt(m_NVariable), dyt(m_NVariable),
- dym(m_NVariable);
-
- double hh = h * 0.5;
- unsigned short i = 0;
! for (; i < m_NVariable; ++i)
! yt[i] = y[i] + hh * dydx[i];
!
! double xh = x + hh;
!
! dyt = f(xh, yt);
! for (i = 0; i < m_NVariable; ++i)
! yt[i] = y[i] + hh * dyt[i];
!
! dym = f(xh, yt);
! for (i = 0; i < m_NVariable; ++i) {
! yt[i] = y[i] + h * dym[i];
! dym[i] += dyt[i];
! }
!
! dyt = f(x + h, yt);
! double h6 = h / 6.0;
! for (i = 0; i < m_NVariable; ++i)
! yout[i] = y[i] + h6 * (dydx[i] + dyt[i] + 2.0 * dym[i]);
!
! return yout;
}
! //===========================================================================
!
! std::vector<double> const &DynamicalSystem::rkqc(std::vector<double> &y,
! std::vector<double> &dydx,
! double &x, double htry, double eps,
! std::vector<double> const &yscal,
! double &hdid, double &hnext)
! {
! static std::vector<double> ytemp, ysav, dysav;
!
! double xsav = x;
! ysav = y;
! dysav = dydx;
! double h = htry;
! unsigned short i;
! bool loop = true;
! do {
! double hh = 0.5 * h;
! ytemp = rk4(ysav, dysav, xsav, hh);
! x = xsav + hh;
! dydx = f(x, ytemp);
! y = rk4(ytemp, dydx, x, hh);
! x = xsav + h;
! if (x == xsav) {
! std::cout << "Step size too small in routine RKQC\n" << std::endl;
! loop = false;
! }
! else {
! ytemp = rk4(ysav, dysav, xsav, h);
! double errmax = 0.0;
! for (i = 0; i < m_NVariable; ++i) {
! ytemp[i] -= y[i]; // ytemp[i] = y[i] - ytemp[i];
! double temp = fabs(ytemp[i] / yscal[i]);
! if (errmax < temp)
! errmax = temp;
! }
! errmax /= eps;
! if (errmax <= 1.0) {
! hdid = h;
! hnext = (errmax > ERRCON ?
! SAFETY * h * exp(PGROW * log(errmax)) : 4.0 * h);
! loop = false;
! }
! else
! h *= SAFETY * exp(PSHRNK * log(errmax));
! }
! }
! while ( loop );
! for (i = 0; i < m_NVariable; ++i)
! y[i] += ytemp[i] * FCOR;
! return y;
}
! //===========================================================================
!
! std::vector<double> const &DynamicalSystem::odeint(std::vector<double> const & ystart,
! double x1, double x2,
! double eps, double h1, double hmin,
! unsigned int &nok, unsigned int &nbad)
! {
! static std::vector<double> y, dydx, yscal(m_NVariable);
! double hnext, hdid;
! double x = x1;
! double h = (x2 > x1) ? fabs(h1) : -fabs(h1);
! nok = nbad = 0;
! y = ystart;
! unsigned int nstp = 0;
! do {
! ++nstp;
! dydx = f(x, y);
! for (unsigned short i = 0;i < m_NVariable; ++i)
! yscal[i] = fabs(y[i]) + fabs(dydx[i] * h) + TINY;
!
! if ((x+h-x2)*(x+h-x1) > 0.0) h = x2 - x;
! y = rkqc(y, dydx, x, h, eps, yscal, hdid, hnext);
! if ( hdid == h ) ++nok; else ++nbad;
! if ( (x-x2) * (x2-x1) >= 0.0 )
! return y;
! else {
! if (fabs(hnext) <= hmin) {
! std::cout << "Step size too small in ODEINT\n" << std::endl;
! nstp = MAXSTP;
! }
! h = hnext;
! }
}
- while ( nstp < MAXSTP );
- std::cout << "Too many steps in routine ODEINT\n" << std::endl;
- return ystart;
- }
! //=================================================================
! std::vector<double> const &DynamicalSystem::RungeKutta(std::vector<double> const &y0,
! double t1, double t2)
! {
! static std::vector<double> result;
! unsigned int nok,nbad;
! result = odeint(y0, t1, t2, m_precision, m_hestimate, m_hmin, nok, nbad);
! //std::cout << "nok =" << nok << "; nbad = " << nbad << "\n";
! return result;
! }
--- 25,63 ----
#include <cmath>
#include <iostream>
+ #include <limits>
#include "DynamicalSystem.h"
! DynamicalSystem::DynamicalSystem(unsigned short dimension):
! VectorField(dimension),
! _numericalMethod(0) {
}
! DynamicalSystem::~DynamicalSystem() {
! if (_numericalMethod) {
! delete _numericalMethod;
! _numericalMethod = 0;
! }
}
! DynamicalSystem::DynamicalSystem(VectorField* pf):
! VectorField(*pf) {
! if (!_numericalMethod)
! _numericalMethod->setVectorField(pf);
! }
! void DynamicalSystem::setNumericalMethod(NumericalMethod* pnumericalMethod){
! _numericalMethod = pnumericalMethod;
}
! std::vector<double> const& DynamicalSystem::flow(std::vector<double>& y0, double t0, double dt) const {
! static std::vector<double> y;
! y = _numericalMethod->enhancedSolve(y0, t0, dt);
! if (_numericalMethod->failed()) {
! std::cout << "quick solve is required\n";
! y = _numericalMethod->quickSolve(y0, t0, dt);
! }
! return y;
! }
Index: CSPSim.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/CSPSim.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** CSPSim.cpp 27 Mar 2003 20:34:01 -0000 1.16
--- CSPSim.cpp 3 Apr 2003 10:40:42 -0000 1.17
***************
*** 622,742 ****
}
- /*
- int CSPSim::InitConsole()
- {
- CSP_LOG(CSP_APP, CSP_DEBUG, "CSPSim::InitConsole()...");
-
- SDL_Rect Con_rect;
- Con_rect.x = Con_rect.y = 0;
- Con_rect.w = Con_rect.h = 300;
-
- std::string font_path = g_Config.getPath("Paths", "FontPath", ".", true);
- std::string console_font = ospath::join(font_path, "ConsoleFont.bmp");
-
- m_ConsoleFont = DT_LoadFont(console_font.c_str(), 0);
- m_pConsole = CON_Init(console_font.c_str(), m_SDLScreen, 100, Con_rect);
- CON_Alpha(m_pConsole, 50);
-
- // Add some commands to the console
- CON_AddCommand(&KillProgram, "quit");
- CON_AddCommand(&AlphaChange, "alpha");
- CON_AddCommand(&Move, "move");
- CON_AddCommand(&Resize, "resize");
- CON_AddCommand(&ListCommands, "listcommands");
-
- #ifdef _WIN32
- // I don't have this function in SDL_Console 1.3 on Linux
- CON_AddDefaultCommand(&DefaultCommand);
- #endif
-
- CON_ListCommands(m_pConsole);
-
- return 0;
- }
-
-
- void CSPSim::ShowPaused()
- {
- DT_DrawText("PAUSED", m_SDLScreen, m_ConsoleFont, m_SDLScreen->w - 36, 0);
- }
-
-
- void CSPSim::ShowPlaneInfo()
- {
- if (m_ActiveObject.isNull()) return;
-
- int width = m_SDLScreen->w;
- simdata::Vector3 direction = m_ActiveObject->getDirection();
- simdata::Vector3 upVector = m_ActiveObject->getUpDirection();
-
- char buffer[256];
- snprintf(buffer, 255, "Direction: [%.3f, %.3f, %.3f]", direction.x, direction.y, direction.z);
- DT_DrawText(buffer, m_SDLScreen, m_ConsoleFont, width - 200, m_SDLScreen->h - 80);
-
- snprintf(buffer, 255, "Up: [%.3f, %.3f, %.3f]", upVector.x, upVector.y, upVector.z);
- DT_DrawText(buffer, m_SDLScreen, m_ConsoleFont, width - 200, m_SDLScreen->h - 60);
-
- int latX, latY;
- m_ActiveObject->getLatticePosition(latX, latY);
- snprintf(buffer, 255, "Lattice: [ %d, %d ]", latX, latY);
- DT_DrawText(buffer, m_SDLScreen, m_ConsoleFont, width - 200, m_SDLScreen->h - 40);
- }
-
-
- void CSPSim::ShowStats(float fps)
- {
- char framerate[64];
- char buffer[256];
- static float maxFps = 0.0, minFps = 500.0;
-
- maxFps = max(maxFps, fps);
- minFps = min(minFps, fps);
-
- sprintf(framerate, "%.2f FPS min: %.2f max: %.2f", fps, minFps, maxFps);
- DT_DrawText(framerate, m_SDLScreen, m_ConsoleFont, 1, 0);
-
- sprintf(framerate, "%.2f FPS min: %.2f max: %.2f", fps, minFps, maxFps);
- simdata::SimDate artificial_time = m_CurrentTime;
- artificial_time.addTime(m_Battlefield->getSpin());
- std::string date = "Date: " + artificial_time.asString();
- DT_DrawText(date.c_str(), m_SDLScreen, m_ConsoleFont, 1, 20);
-
- sprintf(buffer, "Terrain Polygons: %d", m_Battlefield->getTerrainPolygonsRendered());
- DT_DrawText(buffer, m_SDLScreen, m_ConsoleFont, 1, m_SDLScreen->h - 160);
-
-
- if (!m_ActiveObject.isNull()) {
- simdata::Vector3 pos = m_ActiveObject->getLocalPosition();
- snprintf(buffer, 255, "LocalPosition: [%.3f, %.3f, %.3f]", pos.x, pos.y, pos.z);
- DT_DrawText(buffer, m_SDLScreen, m_ConsoleFont, 1, m_SDLScreen->h - 80);
-
- pos = m_ActiveObject->getGlobalPosition();
- snprintf(buffer, 255, "GlobalPosition: [%.3f, %.3f, %.3f]", pos.x, pos.y, pos.z);
- DT_DrawText(buffer, m_SDLScreen, m_ConsoleFont, 1, m_SDLScreen->h - 60);
-
- simdata::Vector3 vel = m_ActiveObject->getVelocity();
- snprintf(buffer, 255, "Velocity: [%.3f, %.3f, %.3f]", vel.x, vel.y, vel.z);
- DT_DrawText(buffer, m_SDLScreen, m_ConsoleFont, 1, m_SDLScreen->h - 40);
-
- std::vector<std::string> stats;
- std::vector<std::string>::iterator stat;
- m_ActiveObject->getStats(stats);
- int y = 40;
- for (stat = stats.begin(); stat != stats.end(); stat++, y+=20) {
- DT_DrawText(stat->c_str(), m_SDLScreen, m_ConsoleFont, 1, y);
- if (y > m_SDLScreen->h - 180) break;
- }
- // frame rate logging versus position
- // this is a temporary hack to look for problematic terrain tiles
-
- static float next_dump = 0.0;
- if (m_ElapsedTime > next_dump) {
- next_dump = m_ElapsedTime + 10.0;
- CSP_LOG(CSP_APP, CSP_WARN, m_FrameRate << endl << buffer);
- }
-
- }
- }
-
-
- */
--- 622,623 ----
Index: AircraftObject.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/AircraftObject.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** AircraftObject.cpp 27 Mar 2003 20:33:59 -0000 1.10
--- AircraftObject.cpp 3 Apr 2003 10:40:42 -0000 1.11
***************
*** 468,472 ****
//flightmodel needs to return out of spec parameters for subsequent
//damage modelling.
- //m_FlightModel->setGroundPosition(m_GroundZ);
m_FlightModel->setGroundZ(m_GroundZ);
--- 468,471 ----
Index: AeroDynamics.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/AeroDynamics.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** AeroDynamics.cpp 26 Mar 2003 22:19:51 -0000 1.12
--- AeroDynamics.cpp 3 Apr 2003 10:40:42 -0000 1.13
***************
*** 197,202 ****
m_CurrentForceTotal = simdata::Vector3::ZERO;
- m_ForcesBody = simdata::Vector3::ZERO;
-
m_alpha = 0.0;
m_alpha0 = 0.0;
--- 197,200 ----
***************
*** 227,233 ****
{
[...979 lines suppressed...]
- if ( p_setting >=0.0 ) {
- return p_setting * p_mMax;
- } else {
- return -p_setting * p_mMin;
- }
- }
- */
-
-
- /*
- double AeroDynamics::ControlSensibility(double p_x) const
- { // smooth the joystick controls
-
- double z = p_x * p_x;
- double y = p_x * z * ( 2.0 - z );
-
- return y;
- }
- */
--- 1058,1059 ----
|