• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ MatShellGetContext函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中MatShellGetContext函数的典型用法代码示例。如果您正苦于以下问题:C++ MatShellGetContext函数的具体用法?C++ MatShellGetContext怎么用?C++ MatShellGetContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MatShellGetContext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: MatWrapML_SHELL

static PetscErrorCode MatWrapML_SHELL(ML_Operator *mlmat,MatReuse reuse,Mat *newmat) 
{
  PetscErrorCode ierr;
  PetscInt       m,n;
  ML_Comm        *MLcomm;
  Mat_MLShell    *shellctx;

  PetscFunctionBegin;
  m = mlmat->outvec_leng; 
  n = mlmat->invec_leng;

  if (reuse){
    ierr = MatShellGetContext(*newmat,(void **)&shellctx);CHKERRQ(ierr);
    shellctx->mlmat = mlmat;
    PetscFunctionReturn(0);
  }

  MLcomm = mlmat->comm;
  ierr = PetscNew(Mat_MLShell,&shellctx);CHKERRQ(ierr);
  ierr = MatCreateShell(MLcomm->USR_comm,m,n,PETSC_DETERMINE,PETSC_DETERMINE,shellctx,newmat);CHKERRQ(ierr);
  ierr = MatShellSetOperation(*newmat,MATOP_MULT,(void(*)(void))MatMult_ML);CHKERRQ(ierr); 
  ierr = MatShellSetOperation(*newmat,MATOP_MULT_ADD,(void(*)(void))MatMultAdd_ML);CHKERRQ(ierr); 
  shellctx->A         = *newmat;
  shellctx->mlmat     = mlmat;
  shellctx->work      = PETSC_NULL;
  ierr = VecCreate(MLcomm->USR_comm,&shellctx->y);CHKERRQ(ierr);
  ierr = VecSetSizes(shellctx->y,m,PETSC_DECIDE);CHKERRQ(ierr);
  ierr = VecSetFromOptions(shellctx->y);CHKERRQ(ierr);
  (*newmat)->ops->destroy = MatDestroy_ML;
  PetscFunctionReturn(0);
}
开发者ID:Kun-Qu,项目名称:petsc,代码行数:31,代码来源:ml.c


示例2: MatGetDiagonal_myMat

PetscErrorCode MatGetDiagonal_myMat(Mat A, Vec diag)
{
  PetscFunctionBeginUser;
  PetscErrorCode ierr;
  model *m;
  ierr = MatShellGetContext(A, &m); CHKERRQ(ierr);

  PetscScalar       *pd;
  ierr = VecGetArray(diag, &pd); CHKERRQ(ierr);

  PetscInt Istart, Iend;
  ierr = MatGetOwnershipRange(A, &Istart, &Iend); CHKERRQ(ierr);
  PetscInt A_m, n;
  ierr = MatGetSize(A, &A_m, &n); CHKERRQ(ierr);

  PetscScalar* pgd = new PetscScalar[n];
  rokko::heisenberg_hamiltonian::fill_diagonal(m->L, m->lattice, pgd);

  int k=0;
  for(int i = Istart; i < Iend; ++i) {
    pd[k] = pgd[i];
    ++k;
  }

  ierr = VecRestoreArray(diag ,&pd); CHKERRQ(ierr);
 
  PetscFunctionReturn(0);
}
开发者ID:t-sakashita,项目名称:rokko,代码行数:28,代码来源:heisenberg_matfree_mpi_allvec.cpp


示例3: krylov_petsc_apply_aij

static
PetscErrorCode krylov_petsc_apply_aij( Mat A, Vec x, Vec y )
{
  void           *ctx;
  PetscErrorCode ierr;

  krylov_pc_ctx_t* kct;
  const double* px;
  double* py;

  /* PetscFunctionBegin; */
  ierr = MatShellGetContext( A, &ctx ); CHKERRQ(ierr);  
  kct = (krylov_pc_ctx_t *)ctx;
  ierr = VecGetArrayRead( x, &px ); CHKERRQ(ierr);
  ierr = VecGetArray( y, &py ); CHKERRQ(ierr);

  problem_data_t* vecs = kct->vecs;
  weakeqn_ptrs_t* fcns = kct->fcns;
  p4est_t* p4est = kct->p4est;
  p4est_ghost_t* ghost = *kct->ghost;
  element_data_t* ghost_data = *kct->ghost_data;
  dgmath_jit_dbase_t* dgmath_jit_dbase = kct->dgmath_jit_dbase;

  problem_data_t vecs_for_aij;
  problem_data_copy_ptrs(vecs, &vecs_for_aij);

  vecs_for_aij.u = (double*)px;
  vecs_for_aij.Au = py;
  fcns->apply_lhs(p4est, ghost, ghost_data, &vecs_for_aij, dgmath_jit_dbase);

  ierr = VecRestoreArrayRead( x, &px ); CHKERRQ(ierr);
  ierr = VecRestoreArray( y, &py ); CHKERRQ(ierr);
  return ierr;
}
开发者ID:trevor-vincent,项目名称:disco4est,代码行数:34,代码来源:krylov_petsc.c


示例4: MatTranspose_DenseGA

// -------------------------------------------------------------
// MatTranspose_DenseGA
// -------------------------------------------------------------
static
PetscErrorCode
MatTranspose_DenseGA(Mat mat, MatReuse reuse, Mat *B)
{
  PetscErrorCode ierr = 0;
  
  MPI_Comm comm;
  ierr = PetscObjectGetComm((PetscObject)mat, &comm); CHKERRQ(ierr);

  struct MatGACtx *ctx, *newctx;
  ierr = MatShellGetContext(mat, &ctx); CHKERRQ(ierr);

  PetscInt lrows, grows, lcols, gcols;
  ierr = MatGetSize(mat, &grows, &gcols); CHKERRQ(ierr);
  ierr = MatGetLocalSize(mat, &lrows, &lcols); CHKERRQ(ierr);

  ierr = PetscMalloc(sizeof(struct MatGACtx), &newctx); CHKERRQ(ierr);
  newctx->gaGroup = ctx->gaGroup;
  ierr = CreateMatGA(newctx->gaGroup, lcols, lrows, gcols, grows, &(newctx->ga)); CHKERRQ(ierr);
  GA_Transpose(ctx->ga, newctx->ga);

  ierr = MatCreateShell(comm, lcols, lrows, gcols, grows, newctx, B); CHKERRQ(ierr);
  ierr = MatSetOperations_DenseGA(*B);

  return ierr;
}
开发者ID:Anastien,项目名称:GridPACK,代码行数:29,代码来源:ga_matrix.cpp


示例5: MatGetDiagonal_Brussel

PetscErrorCode MatGetDiagonal_Brussel(Mat A,Vec diag)
{
  Vec            d1,d2;
  PetscInt       n;
  PetscScalar    *pd;
  MPI_Comm       comm;
  CTX_BRUSSEL    *ctx;
  PetscErrorCode ierr;

  PetscFunctionBeginUser;
  ierr = MatShellGetContext(A,(void**)&ctx);CHKERRQ(ierr);
  ierr = PetscObjectGetComm((PetscObject)A,&comm);CHKERRQ(ierr);
  ierr = MatGetLocalSize(ctx->T,&n,NULL);CHKERRQ(ierr);
  ierr = VecGetArray(diag,&pd);CHKERRQ(ierr);
  ierr = VecCreateMPIWithArray(comm,1,n,PETSC_DECIDE,pd,&d1);CHKERRQ(ierr);
  ierr = VecCreateMPIWithArray(comm,1,n,PETSC_DECIDE,pd+n,&d2);CHKERRQ(ierr);

  ierr = VecSet(d1,-2.0*ctx->tau1 + ctx->beta - 1.0 + ctx->sigma);CHKERRQ(ierr);
  ierr = VecSet(d2,-2.0*ctx->tau2 - ctx->alpha*ctx->alpha + ctx->sigma);CHKERRQ(ierr);

  ierr = VecDestroy(&d1);CHKERRQ(ierr);
  ierr = VecDestroy(&d2);CHKERRQ(ierr);
  ierr = VecRestoreArray(diag,&pd);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:OpenCMISS-Dependencies,项目名称:slepc,代码行数:25,代码来源:ex9.c


示例6: MatGetValues_DenseGA

// -------------------------------------------------------------
// MatGetValues_DenseGA
// -------------------------------------------------------------
static 
PetscErrorCode
MatGetValues_DenseGA(Mat mat, 
                    PetscInt m, const PetscInt idxm[], PetscInt n, const PetscInt idxn[], 
                    PetscScalar v[])
{
  PetscErrorCode ierr = 0;
  struct MatGACtx *ctx;  
  int i, j, idx;
  PetscScalar vij;
  int lo[2], hi[2], ld[2] = {1, 1};
  ierr = MatShellGetContext(mat, (void *)&ctx); CHKERRQ(ierr);

  idx = 0;
  for (i = 0; i < m; ++i) {
    for (j = 0; j < n; ++j, ++idx) {
      lo[0] = idxm[i];
      hi[0] = idxm[i];
      lo[1] = idxn[j];
      hi[1] = idxn[j];
      NGA_Get(ctx->ga, lo, hi, (void *)&vij, ld);
      v[idx] = vij;
    }
  }
  return ierr;
}
开发者ID:Anastien,项目名称:GridPACK,代码行数:29,代码来源:ga_matrix.cpp


示例7: MatMultAdd_ML

/* Computes y = w + A * x
   It is possible that w == y, but not x == y
*/
static PetscErrorCode MatMultAdd_ML(Mat A,Vec x,Vec w,Vec y)
{
  Mat_MLShell   *shell;
  PetscScalar   *xarray,*yarray;
  PetscInt       x_length,y_length;
  PetscErrorCode ierr;
  
  PetscFunctionBegin;
  ierr = MatShellGetContext(A, (void **) &shell);CHKERRQ(ierr);
  if (y == w) {
    if (!shell->work) {
      ierr = VecDuplicate(y, &shell->work);CHKERRQ(ierr);
    }
    ierr = VecGetArray(x,           &xarray);CHKERRQ(ierr);
    ierr = VecGetArray(shell->work, &yarray);CHKERRQ(ierr);
    x_length = shell->mlmat->invec_leng;
    y_length = shell->mlmat->outvec_leng;
    ML_Operator_Apply(shell->mlmat, x_length, xarray, y_length, yarray); 
    ierr = VecRestoreArray(x,           &xarray);CHKERRQ(ierr); 
    ierr = VecRestoreArray(shell->work, &yarray);CHKERRQ(ierr); 
    ierr = VecAXPY(y, 1.0, shell->work);CHKERRQ(ierr); 
  } else {
    ierr = VecGetArray(x, &xarray);CHKERRQ(ierr);
    ierr = VecGetArray(y, &yarray);CHKERRQ(ierr);
    x_length = shell->mlmat->invec_leng;
    y_length = shell->mlmat->outvec_leng;
    ML_Operator_Apply(shell->mlmat, x_length, xarray, y_length, yarray); 
    ierr = VecRestoreArray(x, &xarray);CHKERRQ(ierr); 
    ierr = VecRestoreArray(y, &yarray);CHKERRQ(ierr); 
    ierr = VecAXPY(y, 1.0, w);CHKERRQ(ierr); 
  }
  PetscFunctionReturn(0);
}
开发者ID:Kun-Qu,项目名称:petsc,代码行数:36,代码来源:ml.c


示例8: MatSetValues_DenseGA

// -------------------------------------------------------------
// MatSetValues_DenseGA
// -------------------------------------------------------------
static 
PetscErrorCode
MatSetValues_DenseGA(Mat mat, 
                   PetscInt m, const PetscInt idxm[], PetscInt n, const PetscInt idxn[], 
                   const PetscScalar v[],InsertMode addv)
{
  PetscErrorCode ierr = 0;
  struct MatGACtx *ctx;  
  int i, j, idx;
  PetscScalar vij, one(1.0);
  int lo[2], hi[2], ld[2] = {1, 1};
  ierr = MatShellGetContext(mat, (void *)&ctx); CHKERRQ(ierr);

  idx = 0;
  for (i = 0; i < m; ++i) {
    for (j = 0; j < n; ++j, ++idx) {
      lo[0] = idxm[i];
      hi[0] = idxm[i];
      lo[1] = idxn[j];
      hi[1] = idxn[j];
      vij = v[idx];
      switch (addv) {
      case INSERT_VALUES:
        NGA_Put(ctx->ga, lo, hi, (void *)&vij, ld);
        break;
      case ADD_VALUES:
        NGA_Acc(ctx->ga, lo, hi, (void *)&vij, ld, &one);
        break;
      default:
        BOOST_ASSERT_MSG(false, "Unknown set operation");
      }
    }
  }
  return ierr;
}
开发者ID:Anastien,项目名称:GridPACK,代码行数:38,代码来源:ga_matrix.cpp


示例9: MatLMVMAllocateVectors

extern PetscErrorCode MatLMVMAllocateVectors(Mat m, Vec v)
{
  PetscErrorCode ierr;
  MatLMVMCtx     *ctx;
  PetscBool      same;

  PetscFunctionBegin;
  PetscValidHeaderSpecific(m,MAT_CLASSID,1);
  PetscValidHeaderSpecific(v,VEC_CLASSID,2);
  ierr = PetscObjectTypeCompare((PetscObject)m,MATSHELL,&same);CHKERRQ(ierr);
  if (!same) SETERRQ(PETSC_COMM_SELF,1,"Matrix m is not type MatLMVM");
  ierr = MatShellGetContext(m,(void**)&ctx);CHKERRQ(ierr);

  /*  Perform allocations */
  ierr = VecDuplicateVecs(v,ctx->lm+1,&ctx->S);CHKERRQ(ierr);
  ierr = VecDuplicateVecs(v,ctx->lm+1,&ctx->Y);CHKERRQ(ierr);
  ierr = VecDuplicate(v,&ctx->D);CHKERRQ(ierr);
  ierr = VecDuplicate(v,&ctx->U);CHKERRQ(ierr);
  ierr = VecDuplicate(v,&ctx->V);CHKERRQ(ierr);
  ierr = VecDuplicate(v,&ctx->W);CHKERRQ(ierr);
  ierr = VecDuplicate(v,&ctx->P);CHKERRQ(ierr);
  ierr = VecDuplicate(v,&ctx->Q);CHKERRQ(ierr);
  ctx->allocated = PETSC_TRUE;
  PetscFunctionReturn(0);
}
开发者ID:00liujj,项目名称:petsc,代码行数:25,代码来源:lmvmmat.c


示例10: MatAssemmblyBegin_DenseGA

// -------------------------------------------------------------
// MatAssemmblyBegin_DenseGA
// -------------------------------------------------------------
static
PetscErrorCode
MatAssemmblyBegin_DenseGA(Mat mat, MatAssemblyType type)
{
  PetscErrorCode ierr = 0;
  struct MatGACtx *ctx;
  ierr = MatShellGetContext(mat, &ctx); CHKERRQ(ierr);
  return ierr;
}
开发者ID:Anastien,项目名称:GridPACK,代码行数:12,代码来源:ga_matrix.cpp


示例11: H2PlusMatMultS

PetscErrorCode H2PlusMatMultS(Mat S, Vec x, Vec y) {
  PetscErrorCode ierr;
  OceH2plus ctx;
  
  ierr = MatShellGetContext(S, &ctx); CHKERRQ(ierr);
  ierr = MatMatDecomposedMult(ctx->s_r1, ctx->s_y1, x, y); CHKERRQ(ierr);

  return 0;
}
开发者ID:ReiMatsuzaki,项目名称:rescol,代码行数:9,代码来源:h2plus.c


示例12: MatGetDiagonal_Op

static PetscErrorCode MatGetDiagonal_Op(Mat A,Vec D) {
  PetscErrorCode ierr;
  Mat_Op *ctx;

  PetscFunctionBegin;
  ierr = MatShellGetContext(A,&ctx);CHKERRQ(ierr);
  ierr = OpGetDiagonal(ctx->op,ctx->dm,D);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:shamouda,项目名称:ocr-apps,代码行数:9,代码来源:op.c


示例13: MatMult_Op

static PetscErrorCode MatMult_Op(Mat A,Vec X,Vec Y) {
  PetscErrorCode ierr;
  Mat_Op *ctx;

  PetscFunctionBegin;
  ierr = MatShellGetContext(A,&ctx);CHKERRQ(ierr);
  ierr = OpApply(ctx->op,ctx->dm,X,Y);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:shamouda,项目名称:ocr-apps,代码行数:9,代码来源:op.c


示例14: MatDestroy_Op

static PetscErrorCode MatDestroy_Op(Mat A) {
  PetscErrorCode ierr;
  Mat_Op *ctx;

  PetscFunctionBegin;
  ierr = MatShellGetContext(A,&ctx);CHKERRQ(ierr);
  ierr = PetscFree(ctx);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:shamouda,项目名称:ocr-apps,代码行数:9,代码来源:op.c


示例15: MatMult_User

static PetscErrorCode MatMult_User(Mat A,Vec X,Vec Y)
{
  User           user;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr = MatShellGetContext(A,&user);CHKERRQ(ierr);
  ierr = MatMult(user->A,X,Y);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:firedrakeproject,项目名称:petsc,代码行数:10,代码来源:ex205.c


示例16: MatGetDiagonal_User

static PetscErrorCode MatGetDiagonal_User(Mat A,Vec X)
{
  User           user;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr = MatShellGetContext(A,&user);CHKERRQ(ierr);
  ierr = MatGetDiagonal(user->B,X);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:petsc,项目名称:petsc,代码行数:10,代码来源:ex221.c


示例17: MatAssemblyEnd_MyShell

PetscErrorCode MatAssemblyEnd_MyShell(Mat A,MatAssemblyType tp)
{
  PetscErrorCode ierr;
  MatShellCtx    *matshellctx;

  PetscFunctionBegin;
  ierr = MatShellGetContext(A,&matshellctx);CHKERRQ(ierr);
  ierr = MatAssemblyEnd(matshellctx->Jmf,tp);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:haubentaucher,项目名称:petsc,代码行数:10,代码来源:ex69.c


示例18: MatShift_Brussel

PetscErrorCode MatShift_Brussel(PetscScalar* a,Mat Y)
{
  CTX_BRUSSEL    *ctx;
  PetscErrorCode ierr;

  PetscFunctionBeginUser;
  ierr = MatShellGetContext(Y,(void**)&ctx);CHKERRQ(ierr);
  ctx->sigma += *a;
  PetscFunctionReturn(0);
}
开发者ID:OpenCMISS-Dependencies,项目名称:slepc,代码行数:10,代码来源:ex9.c


示例19: MatGetColumnVector_SMF

PetscErrorCode MatGetColumnVector_SMF(Mat mat,Vec Y, PetscInt col)
{
  PetscErrorCode   ierr;
  MatSubMatFreeCtx ctx;

  PetscFunctionBegin;
  ierr = MatShellGetContext(mat,(void **)&ctx);CHKERRQ(ierr);
  ierr = MatGetColumnVector(ctx->A,Y,col);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:tom-klotz,项目名称:petsc,代码行数:10,代码来源:submatfree.c


示例20: MatGetRowMax_SMF

PetscErrorCode MatGetRowMax_SMF(Mat M, Vec D)
{
  MatSubMatFreeCtx ctx;
  PetscErrorCode   ierr;

  PetscFunctionBegin;
  ierr = MatShellGetContext(M,(void **)&ctx);CHKERRQ(ierr);
  ierr = MatGetRowMax(ctx->A,D,NULL);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:tom-klotz,项目名称:petsc,代码行数:10,代码来源:submatfree.c



注:本文中的MatShellGetContext函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ MatView函数代码示例发布时间:2022-05-30
下一篇:
C++ MatSetUp函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap