Beispiel #1
0
int main(void)
{
  int res;
  printf("========= Starts SBM tests 4 for SBM ========= \n");
  SparseBlockStructuredMatrix M;
  FILE *file = fopen("data/SBM2.dat", "r");
  newFromFileSBM(&M, file);
  printSBM(&M);
  fclose(file);
  /*alloc enough memory */
  CSparseMatrix sparseMat;
  res = SBMtoSparseInitMemory(&M, &sparseMat);
  if (res)
  {
    printf("========= Failed SBM tests 4 for SBM  ========= \n");
    return 1;
  }

  res = SBMtoSparse(&M, &sparseMat);
  if (res)
  {
    printf("========= Failed SBM tests 4 for SBM  ========= \n");
    return 1;
  }
  cs_print(&sparseMat, 1);
  cs_spfree_on_stack(&sparseMat);

  int n = M.blocksize0[M.blocknumber0 - 1];
  int m = M.blocksize1[M.blocknumber1 - 1];
  double * denseMat = (double *)malloc(n * m * sizeof(double));
  SBMtoDense(&M, denseMat);
  if (res)
  {
    printf("========= Failed SBM tests 4 for SBM  ========= \n");
    return 1;
  }
  printf("[");
  for (int i = 0; i < n * m; i++)
  {
    printf("%lf ", denseMat[i]);
    if ((i + 1) % m == 0)
      printf("\n");
  }
  printf("]");
  printf("\n (warning: column-major) \n");

  free(denseMat);
  printf("NUMERICS_SBM_FREE_BLOCK value %d", NUMERICS_SBM_FREE_BLOCK);
  SBMfree(&M, NUMERICS_SBM_FREE_BLOCK);
  printf("\n========= Succed SBM tests 4 for SBM  ========= \n");
  return 0;

}
Beispiel #2
0
int frictionContact_fclib_write(FrictionContactProblem* problem, char * title, char * description, char * mathInfo,
                                const char *path, int ndof)
{
  int info = 0;

  struct fclib_local   *fclib_problem;

  fclib_problem = malloc(sizeof(struct fclib_local));

  fclib_problem->spacedim = problem->dimension;
  fclib_problem->mu =  problem->mu;
  fclib_problem->q =  problem->q;

  fclib_problem->s =  NULL;

  fclib_problem->info = malloc(sizeof(struct fclib_info)) ;
  fclib_problem->info->title = title;
  fclib_problem->info->description = description;
  fclib_problem->info->math_info = mathInfo;

  fclib_problem->W = malloc(sizeof(struct fclib_matrix));
  fclib_problem->R = NULL;
  fclib_problem->V = NULL;

  fclib_problem->W->m = problem->M->size0;
  fclib_problem->W->n = problem->M->size1;


  CSparseMatrix * spmat = NULL;
  if (problem ->M->storageType == 0) /* Dense Matrix */
  {
    fclib_problem->W->nzmax = problem->M->size0 * problem->M->size1;
    fclib_problem->W->p = (int*)malloc((fclib_problem->W->m + 1) * sizeof(int));
    fclib_problem->W->i = (int*)malloc((fclib_problem->W->nzmax) * sizeof(int));
    fclib_problem->W->x = (double*)malloc((fclib_problem->W->nzmax) * sizeof(double));
    for (int i = 0; i <  problem ->M->size0 ; i++)
    {
      fclib_problem->W->p[i] = i * problem ->M->size1;
      for (int j = 0; j <  problem ->M->size1 ; j++)
      {
        fclib_problem->W->x[i * problem ->M->size1 + j ] = problem ->M->matrix0[j * problem ->M->size0 + i  ];
      }
    }
    fclib_problem->W->p[fclib_problem->W->m + 1] = (fclib_problem->W->m + 1) * problem ->M->size1;

  }
  else if (problem ->M->storageType == 1) /* Sparse block storage */
  {
    spmat = malloc(sizeof(CSparseMatrix));
    int MAYBE_UNUSED res = SBMtoSparseInitMemory(problem ->M->matrix1, spmat);
    res = SBMtoSparse(problem->M->matrix1, spmat);
    fclib_problem->W->nzmax = (int) spmat->nzmax;
    fclib_problem->W->m = (int) spmat->m;
    fclib_problem->W->n = (int) spmat->n;
    fclib_problem->W->x = spmat->x;
    fclib_problem->W->nz = (int) spmat->nz; 

    if (spmat->nz == -1)
    {
      fclib_problem->W->p = (int*) malloc(sizeof(int)*(spmat->n+1));
      csi_to_int(spmat->p, fclib_problem->W->p, (unsigned) (spmat->n+1));
    }
    else if (spmat->nz == -2)
    {
      fclib_problem->W->p = (int*) malloc(sizeof(int)*(spmat->m+1));
      csi_to_int(spmat->p, fclib_problem->W->p, (unsigned) (spmat->m+1));
    }
    else
    {
      fclib_problem->W->p = (int*) malloc(sizeof(int)*spmat->nzmax);
      csi_to_int(spmat->p, fclib_problem->W->p, (unsigned) spmat->nzmax);
    }

    fclib_problem->W->i = (int*) malloc(sizeof(int)*spmat->nzmax);
    csi_to_int(spmat->i, fclib_problem->W->i, (unsigned) spmat->nzmax);

    fclib_problem->W->info = NULL;
  }
  else
  {
    fprintf(stderr, "frictionContact_fclib_write, unknown storage type for A.\n");
    exit(EXIT_FAILURE); ;
  }

  info = fclib_write_local(fclib_problem, path);

  info = fclib_create_int_attributes_in_info(path, "numberOfDegreeOfFreedom",
                                             ndof);


  
  /*   fclib_delete_local (fclib_problem); */

  if (problem ->M->storageType == 0) /* Dense Matrix */
  {
    free(fclib_problem->W->p);
    free(fclib_problem->W->i);
    free(fclib_problem->W->x);
  }
  else if (problem ->M->storageType == 1)
  {
    cs_spfree(spmat);
  }
  free(fclib_problem->W->p);
  free(fclib_problem->W->i);
  free(fclib_problem->W);
  free(fclib_problem->info);

  free(fclib_problem);

  return info;

}