1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| /* * * * * librairies */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
/* * * * * structure particule */
struct part {
double x, y, z ;
double vx, vy, vz ;
double frcx, frcy, frcz ;
double dx, dy, dz ;
int nbrevoisin ;
double Eint, Tint ;
int *listevoisin ;
} ;
typedef struct part Particules ;
/* * * * * structure etat thermodynamique */
struct etat {
int nat ;
} ;
typedef struct etat Etat ;
/* * * * * structure contenant les donnees */
struct data {
int nbrevoisinmax ; // nbre maximum de voisins
} ;
typedef struct data Data ;
/* * * * * prototypes */
int init_calcul( Data * , Etat *, Particules ** ) ;
int allocation( int , Data *, Particules ** ) ;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* programme princpal *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main( void ) {
int erreur = EXIT_SUCCESS ;
Etat EtatThermo ;
Data Donnees ;
Particules *Particule = NULL ;
init_calcul( &Donnees, &EtatThermo, &Particule ) ;
return erreur;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* initialisation du calcul *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int init_calcul ( Data *Donnees, Etat *EtatThermo, Particules *Particule[] ) {
Particules *p ;
int erreur = EXIT_SUCCESS ;
int i ;
EtatThermo->nat = 1000 ;
Donnees->nbrevoisinmax = 100 ;
/* allocation des tableaux nat = nombre d'atome */
fprintf ( stdout, " * allocation de la memoire\n") ;
allocation( EtatThermo->nat, Donnees, Particule ) ;
for ( i = 0 ; i < EtatThermo->nat ; i++ ) {
p = &((*Particule)[i]) ;
printf("%5d %e \n", i, p->x ) ;
}
return erreur ;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* allocation des tableaux dynamique : forces, positions, vitesses *
* *
* initialistion a 0 de tous les tableaux *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int allocation( int Natom, Data *Donnees, Particules *Particule[] ) {
Particules *p = NULL ;
int erreur = EXIT_SUCCESS ;
int iat, ivois ;
// structure particule
*Particule = calloc( Natom , sizeof(Particules) ) ;
for ( iat = 0 ; iat < Natom ; iat++ ) {
p = &((*Particule)[iat]) ;
p->listevoisin = calloc( Donnees->nbrevoisinmax, sizeof(int) ) ;
}
// initialisation a 0 de tous les tableaux
for ( iat = 0 ; iat < Natom ; iat++ ) {
p = &((*Particule)[iat]) ;
p->x = 0. ;
p->y = 0. ;
p->z = 0. ;
p->vx = 0. ;
p->vy = 0. ;
p->vz = 0. ;
p->frcx = 0. ;
p->frcy = 0. ;
p->frcz = 0. ;
p->dx = 0. ;
p->dy = 0. ;
p->dz = 0. ;
p->nbrevoisin = 0 ;
for( ivois = 0 ; ivois < Donnees->nbrevoisinmax ; ivois++ )
p->listevoisin[ivois] = 0 ;
}
return erreur ;
} |