From 3a7817e725c68e71377686c7731b3e4e9ac3c346 Mon Sep 17 00:00:00 2001 From: ims Date: Thu, 20 Apr 2017 12:17:27 +0200 Subject: [PATCH] Moved unchanging calculation out of loop. In stateq.c the part of the matrix involving collision coefficients does not depend on the results of getjbar() and thus has been moved outside the loop now starting at line 141 (old line 45) in stateq.c. This results in a slight speedup. --- src/lime.h | 1 - src/stateq.c | 93 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/src/lime.h b/src/lime.h index d6e3005..4f021ea 100644 --- a/src/lime.h +++ b/src/lime.h @@ -337,7 +337,6 @@ void getclosest(double, double, double, long*, long*, double*, double*, double*) double geterf(const double, const double); void getjbar(int, molData*, struct grid*, const int, configInfo*, struct blendInfo, int, gridPointData*, double*); void getMass(configInfo*, struct grid*, const gsl_rng*); -//void getmatrix(int, gsl_matrix*, molData*, struct grid*, int, gridPointData*); void getVelocities(configInfo *, struct grid *); void getVelocities_pregrid(configInfo *, struct grid *); void gridPopsInit(configInfo*, molData*, struct grid*); diff --git a/src/stateq.c b/src/stateq.c index a669086..87033b0 100644 --- a/src/stateq.c +++ b/src/stateq.c @@ -12,44 +12,34 @@ #include #include +struct collPartMatrixType { + double *ctot; + gsl_matrix *colli; +}; /*....................................................................*/ void -getmatrix(int id, gsl_matrix *matrix, molData *md, struct grid *gp, int ispec, gridPointData *mp){ - int ti,k,l,li,ipart,di; - struct getmatrix { - double *ctot; - gsl_matrix * colli; - } *partner; +getFixedMatrix(molData *md, int ispec, struct grid *gp, int id, struct collPartMatrixType **collPartMat){ + int ipart,k,l,ti; - partner = malloc(sizeof(struct getmatrix)*md[ispec].npart); + (*collPartMat) = malloc(sizeof(**collPartMat)*md[ispec].npart); /* Initialize matrix with zeros */ for(ipart=0;ipart0) partner[ipart].ctot = malloc(sizeof(double)*md[ispec].nlev); - else { - if(!silent)bail_out("Matrix initialization error in stateq"); - exit(0); + if(md[ispec].nlev<=0){ + if(!silent) bail_out("Matrix initialization error in stateq"); + exit(1); } + + (*collPartMat)[ipart].colli = gsl_matrix_alloc(md[ispec].nlev+1,md[ispec].nlev+1); + (*collPartMat)[ipart].ctot = malloc(sizeof(double)*md[ispec].nlev); for(k=0;k=0) - gsl_matrix_set(matrix,k,k,gsl_matrix_get(matrix,k,k)+gp[id].dens[di]*partner[ipart].ctot[k]); + gsl_matrix_set(matrix,k,k,gsl_matrix_get(matrix,k,k)+gp[id].dens[di]*collPartMat[ipart].ctot[k]); } for(l=0;l=0) - gsl_matrix_set(matrix,k,l,gsl_matrix_get(matrix,k,l)-gp[id].dens[di]*gsl_matrix_get(partner[ipart].colli,l,k)); + gsl_matrix_set(matrix,k,l,gsl_matrix_get(matrix,k,l)-gp[id].dens[di]*gsl_matrix_get(collPartMat[ipart].colli,l,k)); } } } gsl_matrix_set(matrix, md[ispec].nlev, k, 1.); gsl_matrix_set(matrix, k, md[ispec].nlev, 0.); } - - for(ipart=0;ipartTOL && iter