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

C++ KSPDestroy函数代码示例

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

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



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

示例1: KSPDestroy_SpecEst

static PetscErrorCode KSPDestroy_SpecEst(KSP ksp)
{
  PetscErrorCode ierr;
  KSP_SpecEst    *spec = (KSP_SpecEst*)ksp->data;

  PetscFunctionBegin;
  ierr = KSPDestroy(&spec->kspest);CHKERRQ(ierr);
  ierr = KSPDestroy(&spec->kspcheap);CHKERRQ(ierr);
  ierr = PCDestroy(&spec->pcnone);CHKERRQ(ierr);
  ierr = PetscFree(ksp->data);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:Kun-Qu,项目名称:petsc,代码行数:12,代码来源:specest.c


示例2: PCReset_PCD_Feelpp

static PetscErrorCode PCReset_PCD_Feelpp(PC pc)
{
    PC_PCD_Feelpp *pcpcd = (PC_PCD_Feelpp*)pc->data;
    KSPDestroy(&pcpcd->kspAp);
    KSPDestroy(&pcpcd->kspMp);
    MatDestroy(&pcpcd->matApLaplacian);
    MatDestroy(&pcpcd->matMp);
    MatDestroy(&pcpcd->matFp);
    MatDestroy(&pcpcd->matApBTBt);
    MatDestroy(&pcpcd->matMv);
    VecDestroy(&pcpcd->x1);
    VecDestroy(&pcpcd->x2);
    VecDestroy(&pcpcd->MvDiag);
    PetscFunctionReturn(0);
}
开发者ID:feelpp,项目名称:feelpp,代码行数:15,代码来源:preconditionerpetscpcd.cpp


示例3: KSPChebyshevEstEigSet_Chebyshev

static PetscErrorCode KSPChebyshevEstEigSet_Chebyshev(KSP ksp,PetscReal a,PetscReal b,PetscReal c,PetscReal d)
{
  KSP_Chebyshev  *cheb = (KSP_Chebyshev*)ksp->data;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  if (a != 0.0 || b != 0.0 || c != 0.0 || d != 0.0) {
    if (!cheb->kspest) { /* should this block of code be moved to KSPSetUp_Chebyshev()? */
      ierr = KSPCreate(PetscObjectComm((PetscObject)ksp),&cheb->kspest);CHKERRQ(ierr);
      ierr = PetscObjectIncrementTabLevel((PetscObject)cheb->kspest,(PetscObject)ksp,1);CHKERRQ(ierr);
      ierr = KSPSetOptionsPrefix(cheb->kspest,((PetscObject)ksp)->prefix);CHKERRQ(ierr);
      ierr = KSPAppendOptionsPrefix(cheb->kspest,"esteig_");CHKERRQ(ierr);
      ierr = KSPSetSkipPCSetFromOptions(cheb->kspest,PETSC_TRUE);CHKERRQ(ierr);

      ierr = KSPSetPC(cheb->kspest,ksp->pc);CHKERRQ(ierr);

      ierr = KSPSetComputeEigenvalues(cheb->kspest,PETSC_TRUE);CHKERRQ(ierr);

      /* We cannot turn off convergence testing because GMRES will break down if you attempt to keep iterating after a zero norm is obtained */
      ierr = KSPSetTolerances(cheb->kspest,1.e-12,PETSC_DEFAULT,PETSC_DEFAULT,cheb->eststeps);CHKERRQ(ierr);
    }
    if (a >= 0) cheb->tform[0] = a;
    if (b >= 0) cheb->tform[1] = b;
    if (c >= 0) cheb->tform[2] = c;
    if (d >= 0) cheb->tform[3] = d;
    cheb->amatid    = 0;
    cheb->pmatid    = 0;
    cheb->amatstate = -1;
    cheb->pmatstate = -1;
  } else {
    ierr = KSPDestroy(&cheb->kspest);CHKERRQ(ierr);
  }
  PetscFunctionReturn(0);
}
开发者ID:pombredanne,项目名称:petsc,代码行数:34,代码来源:cheby.c


示例4: main

int main(int argc,char **argv)
{
  PetscErrorCode ierr;
  KSP            ksp;
  DM             da,shell;
  PetscInt       levels;

  PetscInitialize(&argc,&argv,(char*)0,help);

  ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
  ierr = DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,-129,1,1,0,&da);CHKERRQ(ierr);
  ierr = MyDMShellCreate(PETSC_COMM_WORLD,da,&shell);CHKERRQ(ierr);
  /* these two lines are not needed but allow PCMG to automatically know how many multigrid levels the user wants */
  ierr = DMGetRefineLevel(da,&levels);CHKERRQ(ierr);
  ierr = DMSetRefineLevel(shell,levels);CHKERRQ(ierr);

  ierr = KSPSetDM(ksp,shell);CHKERRQ(ierr);
  ierr = KSPSetComputeRHS(ksp,ComputeRHS,NULL);CHKERRQ(ierr);
  ierr = KSPSetComputeOperators(ksp,ComputeMatrix,NULL);CHKERRQ(ierr);
  ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
  ierr = KSPSolve(ksp,NULL,NULL);CHKERRQ(ierr);

  ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
  ierr = DMDestroy(&shell);CHKERRQ(ierr);
  ierr = DMDestroy(&da);CHKERRQ(ierr);
  ierr = PetscFinalize();

  return 0;
}
开发者ID:000Justin000,项目名称:ATPESC,代码行数:29,代码来源:ex65.c


示例5: efs_destroy

PetscErrorCode efs_destroy(efs *slv)
{
	PetscErrorCode ierr;
	int i;

	ierr = ef_boundary_destroy(slv->boundary);CHKERRQ(ierr);
	ierr = ef_operator_destroy(slv->op);CHKERRQ(ierr); free(slv->op);
	ierr = ef_fd_destroy(slv->fd);CHKERRQ(ierr); free(slv->fd);
	ef_dmap_destroy(slv->dmap); free(slv->dmap);
	if (slv->options.galerkin) {
		ierr = ef_metric_destroy(slv->levels[0].metric);CHKERRQ(ierr);
		free(slv->levels[0].metric);
	} else {
		for (i = 0; i < slv->options.levels; i++) {
			ierr = ef_metric_destroy(slv->levels[i].metric);CHKERRQ(ierr);
			free(slv->levels[i].metric);
		}
	}
	free(slv->levels);
	free(slv->callback);

	ierr = DMDestroy(&slv->dm);CHKERRQ(ierr);
	ierr = KSPDestroy(&slv->ksp);CHKERRQ(ierr);

	return 0;
}
开发者ID:tuxfan,项目名称:ska,代码行数:26,代码来源:ef_solver.c


示例6: main

int main(int argc, char **argv)
{
    Mat            A;
    KSP            ksp;
    DM             shell;
    Vec            *left, *right;
    MPI_Comm       c;
    PetscErrorCode ierr;

    ierr = PetscInitialize(&argc, &argv, NULL, NULL);if (ierr) return ierr;
    c = PETSC_COMM_WORLD;

    ierr = MatCreate(c, &A); CHKERRQ(ierr);
    ierr = MatSetSizes(A, 1, 1, PETSC_DECIDE, PETSC_DECIDE); CHKERRQ(ierr);
    ierr = MatSetFromOptions(A); CHKERRQ(ierr);
    ierr = MatSetUp(A); CHKERRQ(ierr);
    ierr = KSPCreate(c, &ksp); CHKERRQ(ierr);
    ierr = KSPSetOperators(ksp, A, A); CHKERRQ(ierr);
    ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr);
    ierr = DMShellCreate(c, &shell); CHKERRQ(ierr);
    ierr = DMSetFromOptions(shell); CHKERRQ(ierr);
    ierr = DMSetUp(shell); CHKERRQ(ierr);
    ierr = KSPSetDM(ksp, shell); CHKERRQ(ierr);

    ierr = KSPCreateVecs(ksp, 1, &right, 1, &left); CHKERRQ(ierr);
    ierr = VecView(right[0], PETSC_VIEWER_STDOUT_(c));CHKERRQ(ierr);
    ierr = VecDestroyVecs(1,&right); CHKERRQ(ierr);
    ierr = VecDestroyVecs(1,&left); CHKERRQ(ierr);

    ierr = DMDestroy(&shell); CHKERRQ(ierr);
    ierr = KSPDestroy(&ksp); CHKERRQ(ierr);
    ierr = MatDestroy(&A); CHKERRQ(ierr);
    PetscFinalize();
    return 0;
}
开发者ID:tom-klotz,项目名称:petsc,代码行数:35,代码来源:ex45.c


示例7: main

int main(int argc,char **argv)
{
  PetscErrorCode ierr;
  PetscInt       i;
  KSP            ksp;
  DM             da;
  Vec            x;

  PetscInitialize(&argc,&argv,(char*)0,help);

  ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
  ierr = DMDACreate1d(PETSC_COMM_WORLD,DMDA_BOUNDARY_PERIODIC,-3,2,1,0,&da);CHKERRQ(ierr);
  ierr = KSPSetDM(ksp,da);CHKERRQ(ierr);
  ierr = KSPSetComputeRHS(ksp,ComputeRHS,NULL);CHKERRQ(ierr);
  ierr = KSPSetComputeOperators(ksp,ComputeMatrix,NULL);CHKERRQ(ierr);

  ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
  ierr = DMCreateGlobalVector(da,&x);CHKERRQ(ierr);
  ierr = ComputeInitialSolution(da,x);CHKERRQ(ierr);
  ierr = DMSetApplicationContext(da,x);CHKERRQ(ierr);
  ierr = KSPSetUp(ksp);CHKERRQ(ierr);
  ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);
  for (i=0; i<10; i++) {
    ierr = KSPSolve(ksp,NULL,x);CHKERRQ(ierr);
    ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);
  }
  ierr = VecDestroy(&x);CHKERRQ(ierr);
  ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
  ierr = DMDestroy(&da);CHKERRQ(ierr);
  ierr = PetscFinalize();
  return 0;
}
开发者ID:feelpp,项目名称:debian-petsc,代码行数:32,代码来源:ex28.c


示例8: VecDestroy

PETSc::~PETSc()
{
	if(x!=NULL)
	{
		VecDestroy(&x);
		x = NULL;
	}
	if(b!=NULL)
	{
		VecDestroy(&b);
		b = NULL;
	}
	if(A!=NULL)
	{
		MatDestroy(&A);
		A = NULL;
	}
	if(ksp!=NULL)
	{
		KSPDestroy(&ksp);
		ksp = NULL;
	}
	if(nullsp!=NULL)
	{
		MatNullSpaceDestroy(&nullsp);
		nullsp = NULL;
	}
}
开发者ID:tonyguo1,项目名称:LSGFD,代码行数:28,代码来源:solver_petsc.cpp


示例9: MatDestroy

 ~DistributedCSR() {
     MatDestroy(&_petsc);
     for(int i = 0; i < _S.size(); ++i)
         MatDestroy(&_S[i]);
     KSPDestroy(&_ksp);
     if(_exchange) {
         _exchange[0]->clearBuffer();
         delete _exchange[0];
         if(_exchange[1]) {
             _exchange[1]->clearBuffer();
             delete _exchange[1];
         }
         delete [] _exchange;
     }
     if(_A) {
         if(!std::is_same<HpddmType, HpSchwarz<PetscScalar>>::value)
             VecScatterDestroy(&_scatter);
         else
             _A->clearBuffer();
         delete _A;
         _A = nullptr;
     }
     delete [] _num;
     _num = nullptr;
 }
开发者ID:zzyatlantise,项目名称:FreeFem-sources,代码行数:25,代码来源:PETSc.hpp


示例10: IBAMR_TIMER_START

void
IBImplicitModHelmholtzPETScLevelSolver::deallocateSolverState()
{
    if (!d_is_initialized) return;

    IBAMR_TIMER_START(t_deallocate_solver_state);

    // Deallocate PETSc objects.
    int ierr;
    ierr = KSPDestroy(d_petsc_ksp); IBTK_CHKERRQ(ierr);
    ierr = MatDestroy(d_petsc_mat); IBTK_CHKERRQ(ierr);
    ierr = VecDestroy(d_petsc_x); IBTK_CHKERRQ(ierr);
    ierr = VecDestroy(d_petsc_b); IBTK_CHKERRQ(ierr);
    d_dof_index_fill.setNull();

    d_petsc_ksp = PETSC_NULL;
    d_petsc_mat = PETSC_NULL;
    d_petsc_x = PETSC_NULL;
    d_petsc_b = PETSC_NULL;

    // Deallocate DOF index data.
    Pointer<PatchLevel<NDIM> > level = d_hierarchy->getPatchLevel(d_level_num);
    if (level->checkAllocated(d_dof_index_idx)) level->deallocatePatchData(d_dof_index_idx);

    // Indicate that the solver is NOT initialized.
    d_is_initialized = false;

    IBAMR_TIMER_STOP(t_deallocate_solver_state);
    return;
}// deallocateSolverState
开发者ID:MSV-Project,项目名称:IBAMR,代码行数:30,代码来源:IBImplicitModHelmholtzPETScLevelSolver.C


示例11: main

int main(int argc,char **argv)
{
  KSP            ksp;
  DM             da;
  UserContext    user;
  PetscInt       bc;
  PetscErrorCode ierr;

  PetscInitialize(&argc,&argv,(char *)0,help);
  ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
  ierr = DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR,-11,-11,PETSC_DECIDE,PETSC_DECIDE,1,1,PETSC_NULL,PETSC_NULL,&da);CHKERRQ(ierr);
  ierr = KSPSetDM(ksp,(DM)da);
  ierr = DMSetApplicationContext(da,&user);CHKERRQ(ierr);

  user.uu = 1.0;
  user.tt = 1.0;
  bc   = (PetscInt)NEUMANN; // Use Neumann Boundary Conditions
  user.bcType = (BCType)bc;


  ierr = KSPSetComputeRHS(ksp,ComputeRHS,&user);CHKERRQ(ierr);
  ierr = KSPSetComputeOperators(ksp,ComputeJacobian,&user);CHKERRQ(ierr);
  ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
  ierr = KSPSolve(ksp,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);

  ierr = DMDestroy(&da);CHKERRQ(ierr);
  ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
  ierr = PetscFinalize();CHKERRQ(ierr);
  return 0;
}
开发者ID:erdc-cm,项目名称:petsc-dev,代码行数:30,代码来源:ex50.c


示例12: main

int main(int argc,char **args)
{
  KSP            ksp;             /* linear solver context */
  Mat            A;            /* matrix */
  Vec            x,b;          /* approx solution, RHS, exact solution */
  PetscViewer    fd;               /* viewer */
  PetscErrorCode ierr;

  PetscInitialize(&argc,&args,(char *)0,help);
  fd = PETSC_VIEWER_SOCKET_WORLD;

  ierr = VecCreate(PETSC_COMM_WORLD,&b);CHKERRQ(ierr);
  ierr = VecLoad(b,fd);CHKERRQ(ierr);
  ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
  ierr = MatLoad(A,fd);CHKERRQ(ierr);
  ierr = VecDuplicate(b,&x);CHKERRQ(ierr);

  ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
  ierr = KSPSetOperators(ksp,A,A,SAME_NONZERO_PATTERN);CHKERRQ(ierr);
  ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
  ierr = KSPSetUp(ksp);CHKERRQ(ierr);
  ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
  ierr = VecView(x,fd);CHKERRQ(ierr);
  ierr = MatDestroy(&A);CHKERRQ(ierr);
  ierr = VecDestroy(&b);CHKERRQ(ierr);
  ierr = VecDestroy(&x);CHKERRQ(ierr);
  ierr = KSPDestroy(&ksp);CHKERRQ(ierr);

  ierr = PetscFinalize();
  return 0;
}
开发者ID:erdc-cm,项目名称:petsc-dev,代码行数:31,代码来源:ex41.c


示例13: finalize

PetscErrorCode NavierStokesSolver::finalize()
{
	PetscErrorCode ierr;

	// DMs
	if(pda != PETSC_NULL) {ierr = DMDestroy(&pda); CHKERRQ(ierr);}
	if(uda != PETSC_NULL) {ierr = DMDestroy(&uda); CHKERRQ(ierr);}
	if(vda != PETSC_NULL) {ierr = DMDestroy(&vda); CHKERRQ(ierr);}
	if(qPack != PETSC_NULL) {ierr = DMDestroy(&qPack); CHKERRQ(ierr);}
	if(lambdaPack != PETSC_NULL) {ierr = DMDestroy(&lambdaPack); CHKERRQ(ierr);}

	//Vecs
	if(q != PETSC_NULL) {ierr = VecDestroy(&q); CHKERRQ(ierr);}
	if(qStar != PETSC_NULL) {ierr = VecDestroy(&qStar); CHKERRQ(ierr);}

	if(qxLocal != PETSC_NULL) {ierr = VecDestroy(&qxLocal); CHKERRQ(ierr);}
	if(qyLocal != PETSC_NULL) {ierr = VecDestroy(&qyLocal); CHKERRQ(ierr);}
	
	if(H != PETSC_NULL) {ierr = VecDestroy(&H); CHKERRQ(ierr);}
	if(rn != PETSC_NULL) {ierr = VecDestroy(&rn); CHKERRQ(ierr);}
	if(bc1 != PETSC_NULL) {ierr = VecDestroy(&bc1); CHKERRQ(ierr);}
	if(rhs1 != PETSC_NULL) {ierr = VecDestroy(&rhs1); CHKERRQ(ierr);}
	if(temp != PETSC_NULL) {ierr = VecDestroy(&temp); CHKERRQ(ierr);}
	if(lambda != PETSC_NULL) {ierr = VecDestroy(&lambda); CHKERRQ(ierr);}
	if(bc2 != PETSC_NULL) {ierr = VecDestroy(&bc2); CHKERRQ(ierr);}
	if(rhs2 != PETSC_NULL) {ierr = VecDestroy(&rhs2); CHKERRQ(ierr);}

	if(uMapping != PETSC_NULL) {ierr = VecDestroy(&uMapping); CHKERRQ(ierr);}
	if(vMapping != PETSC_NULL) {ierr = VecDestroy(&vMapping); CHKERRQ(ierr);}
	if(pMapping != PETSC_NULL) {ierr = VecDestroy(&pMapping); CHKERRQ(ierr);}

	if(MHat != PETSC_NULL) {ierr = VecDestroy(&MHat); CHKERRQ(ierr);}
	if(RInv != PETSC_NULL) {ierr = VecDestroy(&RInv); CHKERRQ(ierr);}
	if(BN != PETSC_NULL) {ierr = VecDestroy(&BN); CHKERRQ(ierr);}

	//Mats
	if(A!=PETSC_NULL) {ierr = MatDestroy(&A); CHKERRQ(ierr);}
	if(QT != PETSC_NULL) {ierr = MatDestroy(&QT); CHKERRQ(ierr);}
	if(BNQ != PETSC_NULL) {ierr = MatDestroy(&BNQ); CHKERRQ(ierr);}
	if(QTBNQ != PETSC_NULL) {ierr = MatDestroy(&QTBNQ); CHKERRQ(ierr);}

	//KSPs
	if(ksp1 != PETSC_NULL) {ierr = KSPDestroy(&ksp1); CHKERRQ(ierr);}
	if(ksp2 != PETSC_NULL) {ierr = KSPDestroy(&ksp2); CHKERRQ(ierr);}

	return 0;
}
开发者ID:ZJLi2013,项目名称:HPC1,代码行数:47,代码来源:NavierStokesSolver.cpp


示例14: main

int main(int argc,char **argv)
{
    KSP            ksp;
    DM             da;
    UserContext    user;
    const char     *bcTypes[2] = {"dirichlet","neumann"};
    PetscErrorCode ierr;
    PetscInt       bc;
    Vec            b,x;

    PetscInitialize(&argc,&argv,(char *)0,help);

    ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);
    CHKERRQ(ierr);
    ierr = DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR,-3,-3,PETSC_DECIDE,PETSC_DECIDE,1,1,0,0,&da);
    CHKERRQ(ierr);
    ierr = DMDASetUniformCoordinates(da,0,1,0,1,0,0);
    CHKERRQ(ierr);
    ierr = DMDASetFieldName(da,0,"Pressure");
    CHKERRQ(ierr);

    ierr = PetscOptionsBegin(PETSC_COMM_WORLD, "", "Options for the inhomogeneous Poisson equation", "DMqq");
    user.rho    = 1.0;
    ierr        = PetscOptionsReal("-rho", "The conductivity", "ex29.c", user.rho, &user.rho, PETSC_NULL);
    CHKERRQ(ierr);
    user.nu     = 0.1;
    ierr        = PetscOptionsReal("-nu", "The width of the Gaussian source", "ex29.c", user.nu, &user.nu, PETSC_NULL);
    CHKERRQ(ierr);
    bc          = (PetscInt)DIRICHLET;
    ierr        = PetscOptionsEList("-bc_type","Type of boundary condition","ex29.c",bcTypes,2,bcTypes[0],&bc,PETSC_NULL);
    CHKERRQ(ierr);
    user.bcType = (BCType)bc;
    ierr = PetscOptionsEnd();

    ierr = KSPSetComputeRHS(ksp,ComputeRHS,&user);
    CHKERRQ(ierr);
    ierr = KSPSetComputeOperators(ksp,ComputeMatrix,&user);
    CHKERRQ(ierr);
    ierr = KSPSetDM(ksp,da);
    CHKERRQ(ierr);
    ierr = KSPSetFromOptions(ksp);
    CHKERRQ(ierr);
    ierr = KSPSetUp(ksp);
    CHKERRQ(ierr);
    ierr = KSPSolve(ksp,PETSC_NULL,PETSC_NULL);
    CHKERRQ(ierr);
    ierr = KSPGetSolution(ksp,&x);
    CHKERRQ(ierr);
    ierr = KSPGetRhs(ksp,&b);
    CHKERRQ(ierr);

    ierr = DMDestroy(&da);
    CHKERRQ(ierr);
    ierr = KSPDestroy(&ksp);
    CHKERRQ(ierr);
    ierr = PetscFinalize();

    return 0;
}
开发者ID:erdc-cm,项目名称:petsc-dev,代码行数:59,代码来源:ex29.c


示例15: VecDestroy

Field_solver::~Field_solver()
{    
    PetscErrorCode ierr;
    ierr = VecDestroy( &phi_vec ); CHKERRXX( ierr );
    ierr = VecDestroy( &rhs ); CHKERRXX( ierr );
    ierr = MatDestroy( &A ); CHKERRXX( ierr );
    ierr = KSPDestroy( &ksp ); CHKERRXX( ierr );
}
开发者ID:epicf,项目名称:ef,代码行数:8,代码来源:field_solver.cpp


示例16: main

int main(int argc,char **argv)
{
    PetscErrorCode ierr;
    KSP            ksp;
    PetscReal      norm;
    DM             da;
    Vec            x,b,r;
    Mat            A;

    PetscInitialize(&argc,&argv,(char *)0,help);

    ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);
    CHKERRQ(ierr);
    ierr = DMDACreate3d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR,-7,-7,-7,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,0,0,0,&da);
    CHKERRQ(ierr);
    ierr = DMSetInitialGuess(da,ComputeInitialGuess);
    CHKERRQ(ierr);

    ierr = KSPSetComputeRHS(ksp,ComputeRHS,PETSC_NULL);
    CHKERRQ(ierr);
    ierr = KSPSetComputeOperators(ksp,ComputeMatrix,PETSC_NULL);
    CHKERRQ(ierr);
    ierr = KSPSetDM(ksp,da);
    CHKERRQ(ierr);
    ierr = DMDestroy(&da);
    CHKERRQ(ierr);

    ierr = KSPSetFromOptions(ksp);
    CHKERRQ(ierr);
    ierr = KSPSolve(ksp,PETSC_NULL,PETSC_NULL);
    CHKERRQ(ierr);
    ierr = KSPGetSolution(ksp,&x);
    CHKERRQ(ierr);
    ierr = KSPGetRhs(ksp,&b);
    CHKERRQ(ierr);
    ierr = VecDuplicate(b,&r);
    CHKERRQ(ierr);
    ierr = KSPGetOperators(ksp,&A,PETSC_NULL,PETSC_NULL);
    CHKERRQ(ierr);

    ierr = MatMult(A,x,r);
    CHKERRQ(ierr);
    ierr = VecAXPY(r,-1.0,b);
    CHKERRQ(ierr);
    ierr = VecNorm(r,NORM_2,&norm);
    CHKERRQ(ierr);
    ierr = PetscPrintf(PETSC_COMM_WORLD,"Residual norm %G\n",norm);
    CHKERRQ(ierr);

    ierr = VecDestroy(&r);
    CHKERRQ(ierr);
    ierr = KSPDestroy(&ksp);
    CHKERRQ(ierr);
    ierr = PetscFinalize();

    return 0;
}
开发者ID:Kun-Qu,项目名称:petsc,代码行数:57,代码来源:ex45.c


示例17: finalize

 long finalize()
 {
   ierr = VecDestroy(x);CHKERRQ(ierr); 
   //    ierr = VecDestroy(u);CHKERRQ(ierr); 
   ierr = VecDestroy(b);CHKERRQ(ierr); ierr = MatDestroy(A);CHKERRQ(ierr);
   ierr = KSPDestroy(ksp);CHKERRQ(ierr);
   ierr = PetscFinalize();CHKERRQ(ierr);
   return 0;
 }
开发者ID:AlexanderToifl,项目名称:viennamesh-dev,代码行数:9,代码来源:petsc_solver_interface.hpp


示例18: PCReset_KSP

/* Default destroy, if it has never been setup */
static PetscErrorCode PCReset_KSP(PC pc)
{
  PC_KSP         *jac = (PC_KSP*)pc->data;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr = KSPDestroy(&jac->ksp);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
开发者ID:petsc,项目名称:petsc,代码行数:10,代码来源:pcksp.c


示例19: RunTest

PetscErrorCode RunTest(void)
{
  PetscInt       N    = 100;
  PetscBool      draw = PETSC_FALSE;
  PetscReal      rnorm;
  Mat            A;
  Vec            b,x,r;
  KSP            ksp;
  PC             pc;
  PetscErrorCode ierr;

  PetscFunctionBegin;

  ierr = PetscOptionsGetInt(0,"-N",&N,NULL);CHKERRQ(ierr);
  ierr = PetscOptionsGetBool(0,"-draw",&draw,NULL);CHKERRQ(ierr);

  ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
  ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);CHKERRQ(ierr);
  ierr = MatSetType(A,MATPYTHON);CHKERRQ(ierr);
  ierr = MatPythonSetType(A,"example1.py:Laplace1D");CHKERRQ(ierr);
  ierr = MatSetUp(A);CHKERRQ(ierr);

  ierr = MatGetVecs(A,&x,&b);CHKERRQ(ierr);
  ierr = VecSet(b,1);CHKERRQ(ierr);

  ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
  ierr = KSPSetType(ksp,KSPPYTHON);CHKERRQ(ierr);
  ierr = KSPPythonSetType(ksp,"example1.py:ConjGrad");CHKERRQ(ierr);

  ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr);
  ierr = PCSetType(pc,PCPYTHON);CHKERRQ(ierr);
  ierr = PCPythonSetType(pc,"example1.py:Jacobi");CHKERRQ(ierr);

  ierr = KSPSetOperators(ksp,A,A);CHKERRQ(ierr);
  ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
  ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);

  ierr = VecDuplicate(b,&r);CHKERRQ(ierr);
  ierr = MatMult(A,x,r);CHKERRQ(ierr);
  ierr = VecAYPX(r,-1,b);CHKERRQ(ierr);
  ierr = VecNorm(r,NORM_2,&rnorm);CHKERRQ(ierr);
  ierr = PetscPrintf(PETSC_COMM_WORLD,"error norm = %g\n",rnorm);CHKERRQ(ierr);

  if (draw) {
    ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);
    ierr = PetscSleep(2);CHKERRQ(ierr);
  }

  ierr = VecDestroy(&x);CHKERRQ(ierr);
  ierr = VecDestroy(&b);CHKERRQ(ierr);
  ierr = VecDestroy(&r);CHKERRQ(ierr);
  ierr = MatDestroy(&A);CHKERRQ(ierr);
  ierr = KSPDestroy(&ksp);CHKERRQ(ierr);

  PetscFunctionReturn(0);
}
开发者ID:00liujj,项目名称:petsc,代码行数:56,代码来源:ex1.c


示例20: PressurePoisson

PetscErrorCode PressurePoisson( UserContext *uc )
{
  Mat A;
  Vec b, px, py, p, u, v, ss, c;
  KSP ksp;
  PetscErrorCode ierr;
  
  
  PetscFunctionBegin;
  PetscLogEventBegin(EVENT_PressurePoisson,0,0,0,0);
  PetscLogEventRegister(&EVENT_PressurePoisson,"PressurePoisson", 0);
  
  /*  Assemble and Solve for pressure */
ierr = PetscPrintf(PETSC_COMM_WORLD, "***********************\nPRESSURE\n"); CHKERRQ(ierr);
  ierr = AssemblePressureMatrx( uc ); CHKERRQ(ierr);
  ierr = AssemblePressureRHS( uc ); CHKERRQ(ierr);
  ierr = SolvePressure( uc ); CHKERRQ(ierr);
  ierr = WriteResult( uc, uc->p, "p_pressure" ); CHKERRQ(ierr);
    
  /*  Assemble and Solve for Velocity  */
ierr = PetscPrintf(PETSC_COMM_WORLD, "***********************\nVELOCITY\n"); CHKERRQ(ierr);
  ierr = AssembleVelocityRHS( uc ); CHKERRQ(ierr);
  ierr = AssembleVelocityMatrix( uc ); CHKERRQ(ierr);
  
  ierr = KSPSetOperators(uc->ksp,uc->A, uc->A, SAME_PRECONDITIONER); CHKERRQ(ierr);
  ierr = KSPSolve(uc->ksp,uc->px,uc->u);CHKERRQ(ierr);
  ierr = KSPSolve(uc->ksp,uc->py,uc->v);CHKERRQ(ierr);
  ierr = WriteResult( uc, uc->u, "u_velocity" ); CHKERRQ(ierr);
  ierr = WriteResult( uc, uc->v, "v_velocity" ); CHKERRQ(ierr);

  ierr = ComputeShearStress(uc); CHKERRQ(ierr);
  ierr = WriteResult( uc, uc->ss,"shear_stress" ); CHKERRQ(ierr);
  ierr = ConservationTest(uc); CHKERRQ(ierr);
  
  /*  Output indexing  */
  PetscReal *idx;
  VecGetArray(uc->b,&idx);
  for( int i = 0; i < uc->numNodes; i++)
    idx[i] = i;
  VecRestoreArray(uc->b,&idx);
  WriteResult(uc, uc->b, "indexes");
  VecSet(uc->b, 0.);
  
  ierr = VecDestroy(uc->c); CHKERRQ(ierr);
  ierr = VecDestroy(uc->ss); CHKERRQ(ierr);
  ierr = MatDestroy(uc->A); CHKERRQ(ierr);
  ierr = KSPDestroy(uc->ksp); CHKERRQ(ierr);
  ierr = VecDestroy(uc->b); CHKERRQ(ierr);
  ierr = VecDestroy(uc->p); CHKERRQ(ierr);
  ierr = VecDestroy(uc->px); CHKERRQ(ierr);
  ierr = VecDestroy(uc->py); CHKERRQ(ierr);
  ierr = VecDestroy(uc->u); CHKERRQ(ierr);
  ierr = VecDestroy(uc->v); CHKERRQ(ierr);
  PetscLogEventEnd(EVENT_PressurePoisson,0,0,0,0);
  PetscFunctionReturn(0);
}
开发者ID:adrielb,项目名称:DCell,代码行数:56,代码来源:PressurePoisson.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ KSPGetIterationNumber函数代码示例发布时间:2022-05-30
下一篇:
C++ KSPCreate函数代码示例发布时间: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