示例#1
0
		/* Interpolate a value between two energies on the grid */
		double intepolateMatrixValue(size_t nerg, size_t nrea, double factor) {
			/* Get limits */
			double low_value = getMatrixValue(nerg,nrea);
			double high_value = getMatrixValue(nerg + 1,nrea);
			/* Apply the interpolation factor */
			return low_value + factor * (high_value - low_value);
		}
示例#2
0
/* the output "m" is size of: 
 *   colum = t->order;
 *   row = v->size
 */
void DvectorArrayDotProduct(array* t, dvector* v, matrix* m)
{
  /*We do not need tests because getMatrixValue and setMatrixValue and getArrayValue handle some errors*/
  size_t i, j, k;
  double res;
  /* m = v't
  *
  * k = order of array
  * j = column size
  * i = row size
  * 
  * m[j][k] =   Σ v[i] * t[k][i][j]
  * 
  */
  for(k = 0; k < t->order; k++){
    for(i = 0; i < t->m[k]->row; i++){
      for(j = 0; j < t->m[k]->col; j++){
        if(v->size == t->m[k]->row && t->m[k]->col == m->row && t->order == m->col){
          res = getDVectorValue(v, i) * getArrayValue(t, k, i, j);
          if(_isnan_(res) || _isinf_(res)){
            setMatrixValue(m, j, k, (getMatrixValue(m, j, k) + 0));
          }
          else{
            setMatrixValue(m, j, k, (getMatrixValue(m, j, k) + res));
          }
        }
        else{
          fprintf(stderr, "Error while computing DvectorArrayDotProduct.\n");
          fflush(stderr);
          abort();
        }
      }
    }
  }
}
//Lecture d'une matrice et transformation en arêtes.
static void readMatrixAndCreateEdges(Matrix m){
  // On crée un tableau contenant toutes les arêtes.
  ensemble = malloc(sizeof(Edge)*somme(getMatrixLength(m)));
  tailleEnsemble = somme(getMatrixLength(m));
  int numCase = 0;
  Edge tmp;
  caseActuelleEnsemble = 0;

  for (int i=0; i<getMatrixLength(m); i++){
    for (int j=i+1; j<getMatrixLength(m); j++){
      ensemble[numCase] = createEdge(i, j, getMatrixValue(m, i, j));

      if (numCase > 0){
        // Si la case actuelle a un poids plus léger que la précédente
        if (ensemble[numCase]->weightEdge < ensemble[numCase-1]->weightEdge){
          int n = numCase;
          // On la fait reculer tant qu'elle est plus légère que la case précédente, qui effectue un tri du tableau en le remplissant.
          while (n > 0 && ensemble[n]->weightEdge < ensemble[n-1]->weightEdge){
            tmp = ensemble[n];
            ensemble[n] = ensemble[n-1];
            ensemble[n-1] = tmp;
            n--;
          }
        }
      }
      numCase++;
    }
  }

  //Affiche le tableau des arêtes de la matrice, trié.
  //for (int i=0; i<tailleEnsemble; i++){
  //  printEdgeValues(ensemble[i]);
  //}
}
示例#4
0
void ArrayMatrixDotProduct(array *t, matrix *m, dvector *v)
{
  size_t i, j, k;
  double res;
  for(k = 0; k < t->order; k++){
    if(m->col == t->order && m->row == t->m[k]->col){
      for(i = 0; i < t->m[k]->row; i++){
        for(j = 0; j < t->m[k]->col; j++){
          res = (getArrayValue(t, k, i, j)*getMatrixValue(m, j, k));
          if(_isnan_(res) || _isinf_(res)){
            setDVectorValue(v, i, (getDVectorValue(v, i) + 0));
          }
          else{
            setDVectorValue(v, i, (getDVectorValue(v, i) + res));
          }
        }
      }
    }
    else{
      fprintf(stderr, "Error while computing ArrayMatrixDotProduct.");
      fflush(stderr);
      abort();
    }
  }
}
示例#5
0
/*
 * k = order
 * i = row
 * j = column
 * 
 * E'(j,i,k) = E(i,j,k)
 * 
 * P(k,j) = Sum_i[ E'(j,i,k)*t(i) ]
 * 
 */
void TransposedArrayDVectorProduct(array *t, dvector *v, matrix *p)
{
  size_t i, j, k;
  double res;
  for(k = 0; k < t->order; k++){
    for(i = 0; i < t->m[k]->row; i++){
      for(j = 0; j < t->m[k]->col; j++){
        res = getArrayValue(t, k, i, j)*getDVectorValue(v, j);
        if(_isnan_(res) || _isinf_(res)){
          setMatrixValue(p, k, i, getMatrixValue(p, k, i) + 0);
        }
        else{
          setMatrixValue(p, k, i, getMatrixValue(p, k, i) + res);
        }
      }
    }
  }
}
示例#6
0
/*
 * i = row
 * j = column
 * k = order
 * 
 * t(i) = Sum_j[ Sum_k[ E(i,j,k) * P(k,j)] ]
 * 
 */
void ArrayMatrixDotProduct2(array *t, matrix *m, dvector *v)
{
  size_t i, j, k;
  for(i = 0; i < v->size; i++){
    for(k = 0; k < t->order; k++){
      for(j = 0; j < t->m[k]->col; j++){
        setDVectorValue(v, i, getDVectorValue(v, i) + (getArrayValue(t, k, i, j)*getMatrixValue(m, k, j)));
      } 
    }
  }
}
示例#7
0
void PrintArray(array *t)
{
  size_t i, j, k;
  printf("Array - order: %u\n", (unsigned int)t->order);
  for(i = 0; i < t->order; i++){
    printf("Array No: %u of row: %u; col: %u\n", (unsigned int)i+1, (unsigned int)t->m[i]->row, (unsigned int)t->m[i]->col);
    for(j = 0; j < t->m[i]->row; j++){
      for(k = 0; k < t->m[i]->col; k++)
        printf("%8.3f\t", getMatrixValue(t->m[i], j, k));
      printf("\n");
    }
  }
}
示例#8
0
void KronekerProductVectorMatrix(dvector* v, matrix* m, array* t)
{
  size_t i, j, k;
  double res;
  for(i = 0; i < v->size; i++){
    for(j = 0; j < m->row; j++){
      for(k = 0; k < m->col; k++){
        res = getDVectorValue(v, i)*getMatrixValue(m, j, k);
        if(_isnan_(res) || _isinf_(res)){
          setArrayValue(t, k, i, j, 0.f);
        }
        else{
          setArrayValue(t, k, i, j, res);
        }
      }
    }
  }
}
示例#9
0
double getArrayValue(array *t, size_t i, size_t j, size_t k){
    if(i < (*t).order){
    if(j < (*t).m[i]->row){
      if(k < (*t).m[i]->col){
        return getMatrixValue((*t).m[i], j, k);
      }
      else{
        fprintf(stderr, "getArrayValue Error! Wrong colum index.\n");
        fflush(stderr);
        return NAN;
      }
    }
    else{
      fprintf(stderr, "getArrayValue Error! Wrong row index.\n");
      fflush(stderr);
      return NAN;
    }
  }
  else{
    fprintf(stderr, "getArrayValue Error! Wrong order.\n");
    fflush(stderr);
    return NAN;
  }
}