Exemplo n.º 1
0
/* Jacobian routine to compute J(t,y) = df/dy. */
static int Jac(long int M, long int mu, long int ml,
               realtype t, N_Vector y, N_Vector fy, 
               DlsMat J, void *user_data,
               N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
{
  UserData udata = (UserData) user_data;     /* access problem data */
  SetToZero(J);                              /* Initialize Jacobian to zero */

  /* Fill in the Laplace matrix */
  LaplaceMatrix(RCONST(1.0), J, udata);

  /* Add in the Jacobian of the reaction terms matrix */
  ReactionJac(RCONST(1.0), y, J, udata);

  return 0;                                  /* Return with success */
}
Exemplo n.º 2
0
/* Jacobian routine to compute J(t,y) = df/dy. */
static int Jac(realtype t, N_Vector y, N_Vector fy, 
	       SlsMat J, void *user_data, 
	       N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
{
  /* problem data */
  UserData udata = (UserData) user_data;
  int N = udata->N;

  /* ensure that Jac is the correct size */
  if ((J->M != N*3) || (J->N != N*3)) {
    printf("Jacobian calculation error: matrix is the wrong size!\n");
    return 1;
  }
  
  /* Fill in the Laplace matrix */
  if (LaplaceMatrix(J, udata)) {
    printf("Jacobian calculation error in calling LaplaceMatrix!\n");
    return 1;
  }

  /* Add in the Jacobian of the reaction terms matrix */
  if (udata->R == NULL) {
    udata->R = NewSparseMat(J->M, J->N, J->NNZ);
    if (udata->R == NULL) {
      printf("Jacobian calculation error in allocating R matrix!\n");
      return 1;
    }
  }
      
  /* Add in the Jacobian of the reaction terms matrix */
  if (ReactionJac(y, udata->R, udata)) {
    printf("Jacobian calculation error in calling ReactionJac!\n");
    return 1;
  }

  /* Add R to J */
  if (SlsAddMat(J,udata->R) != 0) {
    printf("Jacobian calculation error in adding sparse matrices!\n");
    return 1;
  }

  return 0;
}
Exemplo n.º 3
0
/* Jacobian routine to compute J(t,y) = df/dy. */
static int Jac(long int M, long int mu, long int ml,
               realtype t, N_Vector y, N_Vector fy, 
               DlsMat J, void *user_data,
               N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
{
  UserData udata = (UserData) user_data;     /* access problem data */
  SetToZero(J);                              /* Initialize Jacobian to zero */

  /* Fill in the Laplace matrix */
  if (LaplaceMatrix(RCONST(1.0), J, udata)) {
    printf("Jacobian calculation error in calling LaplaceMatrix!\n");
    return 1;
  }

  /* Add in the Jacobian of the reaction terms matrix */
  if (ReactionJac(RCONST(1.0), y, J, udata)) {
    printf("Jacobian calculation error in calling ReactionJac!\n");
    return 1;
  }

  return 0;
}