Statistiques
| Révision :

root / bin / compute_areas.cpp @ 1

Historique | Voir | Annoter | Télécharger (1002 octet)

1 1 akiss
#include <math.h>
2 1 akiss
#include "constants.h"
3 1 akiss
#include "compute_areas.h"
4 1 akiss
#include <stdio.h>
5 1 akiss
#include <stdlib.h>
6 1 akiss
7 1 akiss
/* this function computes the areas of the triangles made with two vertices of the same cell and the barycenter of this cell
8 1 akiss
   the area is given by half the cross product of the centered coordinates of the vertices */
9 1 akiss
10 1 akiss
void compute_areas(double *vertices, int *cells_vertices, int *vertices_number_in_each_cell,
11 1 akiss
                    int cell_number, double *areas){
12 1 akiss
13 1 akiss
int i,j,previous;
14 1 akiss
15 1 akiss
/* usual loop over the cells, then over the vertices of each cell */
16 1 akiss
for (i=0;i<cell_number;i++){
17 1 akiss
    for (j=vertices_number_in_each_cell[i];j<vertices_number_in_each_cell[i+1];j++){
18 1 akiss
        previous=j-1; if (j==vertices_number_in_each_cell[i]){ previous=vertices_number_in_each_cell[i+1]-1;}
19 1 akiss
        areas[j]=0.5*(vertices[2*cells_vertices[previous]]*vertices[2*cells_vertices[j]+1]-
20 1 akiss
                    vertices[2*cells_vertices[previous]+1]*vertices[2*cells_vertices[j]]);
21 1 akiss
    }
22 1 akiss
}
23 1 akiss
24 1 akiss
}