begin process at 2008 05 14 14:25:55
1 171 872 membres
261 nouveaux aujourd'hui
13 963 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

RÉSOLUTION NUMERIQUE


Information sur la source

Catégorie :Maths & Algorithmes Classé sous : simulation, physique, numérique, differentielle, 3d Niveau : Débutant Date de création : 24/03/2008 Date de mise à jour : 27/03/2008 18:21:27 Vu / téléchargé: 2 543 / 111

Note :
Aucune note

Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note

Description

Il s'agit d'une source permettant de résoudre numériquement les systèmes de type df(x, y, z, t)/dt = g(x, y, z, t)/dt.
Contrairement à d'autre source ici je n'utilise pas tel ou tel méthode d'intégration mais j'ai implémenté plusieurs méthodes et c'est à l'utilisateur de choisir laquelle il veut utiliser.
J'ai implémenté :
Euler Implicite
Euler Explicite
Euler Cauchy Explicite
Adams Boford Molton Explicite t Implicite d'ordre 2, 3 et 4
Gear Implicite d'ordre 2, 3 et 4
Runge Kutta Explicite d'ordre 2, 4 et 6
Runge Kutta implicite d'ordre 3
Euler Ameliorer Explicite
Crank Nicholson Explicite

En gros j'ai fait une interface Integrator et les méthodes sont des enfants de cette interface.

L'image montre un exemple de visualisation avec glut de l'attracteur de Lorentz...

Source

  • #include <iostream>
  • #include <list>
  • #include <GL/gl.h>
  • #include <GL/glu.h>
  • #include <GL/glut.h>
  • #include "Vector3D.h"
  • #include "Integrator.h"
  • #include "NS_Euler_I.h"
  • using namespace std;
  • using namespace eMV;
  • Vector3D<float> Henon(const Vector3D<float> &v, const float t)
  • {
  • return Vector3D<float>( v.y + 1 - 1.4*v.x*v.x,
  • 0.3*v.x,
  • 0);
  • }
  • Vector3D<float> Lorentz(const Vector3D<float> &v, const float t)
  • {
  • return Vector3D<float>( 10*(v.y - v.x),
  • 28*v.x - v.y - v.x*v.z,
  • v.x*v.y - 8/3*v.z);
  • }
  • fIntegrator *euler = new fNS_Euler_I(Lorentz, fVector3D(0.1, 0.1, 0.1), 0, 0.003);
  • list<fVector3D> data;
  • void init(void)
  • {
  • glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
  • glClearDepth(1.0); // Depth Buffer Setup
  • glEnable(GL_DEPTH_TEST); // Enable Depth Buffer
  • glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
  • glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  • }
  • void display(void)
  • {
  • fVector3D v;
  • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  • glColor3f (1.0, 1.0, 1.0);
  • glLoadIdentity (); // clear the matrix
  • // viewing transformation
  • gluLookAt (50.0, 50.0, 50.0, 0.1, 0.1, 20.0, 1.0, 0.0, 0.0);
  • //
  • glBegin(GL_LINES);
  • glColor3ub(255, 0, 0);
  • glVertex3f(0, 0, 0);
  • glVertex3f(1, 0, 0);
  • glColor3ub(0, 255, 0);
  • glVertex3f(0, 0, 0);
  • glVertex3f(0, 1, 0);
  • glColor3ub(0, 0, 255);
  • glVertex3f(0, 0, 0);
  • glVertex3f(0, 0, 1);
  • glEnd();
  • data.push_back(euler->F);
  • euler->next();
  • //cout << euler->F << endl;
  • glBegin(GL_LINE_STRIP);
  • list<fVector3D>::iterator it;
  • for (it = data.begin(); it != data.end(); ++it)
  • {
  • glColor3ub(255, 128, 0);
  • glVertex3f((*it).x, (*it).y, (*it).z);
  • }
  • glEnd();
  • //
  • glFlush ();
  • }
  • void reshape (int w, int h)
  • {
  • glViewport(0, 0, (GLint)w, (GLint)h);
  • glMatrixMode(GL_PROJECTION);
  • glLoadIdentity();
  • gluPerspective(45.0, (float)w/(float)h, 0.1, 100.0);
  • glMatrixMode(GL_MODELVIEW);
  • glLoadIdentity();
  • }
  • void keyboard(unsigned char key, int x, int y)
  • {
  • switch (key)
  • {
  • case 27 :
  • exit(0);
  • break;
  • default :
  • glutPostRedisplay();
  • }
  • }
  • int main(int argc, char **argv)
  • {
  • try
  • {
  • glutInit(&argc, argv);
  • glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  • glutInitWindowSize (500, 500);
  • glutInitWindowPosition (100, 100);
  • glutCreateWindow (argv[0]);
  • init ();
  • glutDisplayFunc(display);
  • glutReshapeFunc(reshape);
  • glutKeyboardFunc(keyboard);
  • glutMainLoop();
  • delete euler;
  • return 0;
  • }
  • catch(std::exception& e)
  • {
  • cout << e.what() << endl;
  • }
  • catch(Error &e)
  • {
  • cout << e.GetMessage() << endl;
  • }
  • return 0;
  • }
#include <iostream>
#include <list>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

#include "Vector3D.h"

#include "Integrator.h"
#include "NS_Euler_I.h"

using namespace std;
using namespace eMV;

Vector3D<float> Henon(const Vector3D<float> &v, const float t)
{
	return Vector3D<float>(	v.y + 1 - 1.4*v.x*v.x,
							0.3*v.x,
							0);
}

Vector3D<float> Lorentz(const Vector3D<float> &v, const float t)
{
	return Vector3D<float>(	10*(v.y - v.x),
							28*v.x - v.y - v.x*v.z,
							v.x*v.y - 8/3*v.z);
}

fIntegrator *euler = new fNS_Euler_I(Lorentz, fVector3D(0.1, 0.1, 0.1), 0, 0.003);
list<fVector3D> data;

void init(void)
{
	glShadeModel(GL_SMOOTH);                 // Enables Smooth Color Shading
	glClearDepth(1.0);                       // Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);                 // Enable Depth Buffer
	glDepthFunc(GL_LESS);		           // The Type Of Depth Test To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

void display(void)
{
	fVector3D v;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glColor3f (1.0, 1.0, 1.0);
	glLoadIdentity (); // clear the matrix
	// viewing transformation
	gluLookAt (50.0, 50.0, 50.0, 0.1, 0.1, 20.0, 1.0, 0.0, 0.0);
	//
	glBegin(GL_LINES);
		glColor3ub(255, 0, 0);
		glVertex3f(0, 0, 0);
		glVertex3f(1, 0, 0);
		glColor3ub(0, 255, 0);
		glVertex3f(0, 0, 0);
		glVertex3f(0, 1, 0);
		glColor3ub(0, 0, 255);
		glVertex3f(0, 0, 0);
		glVertex3f(0, 0, 1);
	glEnd();
	data.push_back(euler->F);
	euler->next();
	//cout << euler->F << endl;
	glBegin(GL_LINE_STRIP);
	list<fVector3D>::iterator it;
	for (it = data.begin(); it != data.end(); ++it)
	{
		glColor3ub(255, 128, 0);
		glVertex3f((*it).x, (*it).y, (*it).z);
	}
	glEnd();
	//
	glFlush ();
}

void reshape (int w, int h)
{
	glViewport(0, 0, (GLint)w, (GLint)h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0, (float)w/(float)h, 0.1, 100.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void keyboard(unsigned char key, int x, int y)
{
	switch (key)
	{
		case 27 :
				exit(0);
			break;
		default :
			glutPostRedisplay();
	}
}

int main(int argc, char **argv)
{
	try
	{
		glutInit(&argc, argv);
		glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
		glutInitWindowSize (500, 500);
		glutInitWindowPosition (100, 100);
		glutCreateWindow (argv[0]);
		init ();
		glutDisplayFunc(display);
		glutReshapeFunc(reshape);
		glutKeyboardFunc(keyboard);
		glutMainLoop();
		delete euler;
		return 0;
	}
	catch(std::exception& e)
	{
		cout << e.what() << endl;
	}
	catch(Error &e)
	{
		cout << e.GetMessage() << endl;
	}
	return 0;
}

Conclusion

Le but est de crée un moteur physique. Pas un moteur pour les jeux vidéos en temps réel mais un moteur de simulation physique. Ces méthodes de résolution servirons de base à la suite pour la simulation Physique. La prochaine fois j'implémenterais la gestion des corps indéformables déformable et les fluides.
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

24 mars 2008 23:19:16 :
ajout de screen
27 mars 2008 18:21:29 :
Ajout d'un exemple utilisant l'API. Attracteur de Lorentz
  • signaler à un administrateur
    Commentaire de skone007 le 26/03/2008 22:22:21

    Ah l'intégration numérique n'intéresse personne... Ah la physique et l'analyse numérique quand tu nous tiens.

  • signaler à un administrateur
    Commentaire de Xs le 27/03/2008 15:24:04

    Salut,

    Ta source a l'air vraiment très bien, et elle m'intéresse beaucoup (comme toi, je suis un mordu de maths et simulation numérique).

    Mais pourrais-tu fournir un code (et exe peut-être) utilisant ta librairie ? Genre le code-source de l'exemple dont tu présentes une capture d'écran ? Je t'en serais reconnaissant, et ça me permettrais de mieux voir comment ton code fonctionne.

    Encore bravo.

    Cordialement

  • signaler à un administrateur
    Commentaire de Xs le 27/03/2008 20:24:05

    Merci pour l'exemple, je vais tester ton code dès à présent.

    Cordialement

Ajouter un commentaire

Appels d'offres

creation d un acces s...
Budget : 130€
Modification d-un comp...
Budget : 2 000€
creation plateforme ec...
Budget : 1 300€

Pub



CalendriCode

Mai 2008
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS