本文整理汇总了C++中PetscViewerDestroy函数的典型用法代码示例。如果您正苦于以下问题:C++ PetscViewerDestroy函数的具体用法?C++ PetscViewerDestroy怎么用?C++ PetscViewerDestroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PetscViewerDestroy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc,char **args)
{
Mat BAIJ,SBAIJ,*subBAIJ,*subSBAIJ;
PetscViewer viewer;
char file[PETSC_MAX_PATH_LEN];
PetscBool flg;
PetscErrorCode ierr;
PetscInt n = 2,issize,M,N;
PetscMPIInt rank;
IS isrow,iscol,irow[n],icol[n];
PetscInitialize(&argc,&args,(char*)0,help);
ierr = PetscOptionsGetString(NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&BAIJ);CHKERRQ(ierr);
ierr = MatSetType(BAIJ,MATMPIBAIJ);CHKERRQ(ierr);
ierr = MatLoad(BAIJ,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&SBAIJ);CHKERRQ(ierr);
ierr = MatSetType(SBAIJ,MATMPISBAIJ);CHKERRQ(ierr);
ierr = MatLoad(SBAIJ,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = MatGetSize(BAIJ,&M,&N);CHKERRQ(ierr);
issize = M/4;
ierr = ISCreateStride(PETSC_COMM_SELF,issize,0,1,&isrow);CHKERRQ(ierr);
irow[0] = irow[1] = isrow;
issize = N/2;
ierr = ISCreateStride(PETSC_COMM_SELF,issize,0,1,&iscol);CHKERRQ(ierr);
icol[0] = icol[1] = iscol;
ierr = MatGetSubMatrices(BAIJ,n,irow,icol,MAT_INITIAL_MATRIX,&subBAIJ);CHKERRQ(ierr);
/* irow and icol must be same for SBAIJ matrices! */
icol[0] = icol[1] = isrow;
ierr = MatGetSubMatrices(SBAIJ,n,irow,icol,MAT_INITIAL_MATRIX,&subSBAIJ);CHKERRQ(ierr);
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
if (!rank) {
ierr = MatView(subBAIJ[0],PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr);
ierr = MatView(subSBAIJ[0],PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr);
}
/* Free data structures */
ierr = ISDestroy(&isrow);CHKERRQ(ierr);
ierr = ISDestroy(&iscol);CHKERRQ(ierr);
ierr = MatDestroyMatrices(n,&subBAIJ);CHKERRQ(ierr);
ierr = MatDestroyMatrices(n,&subSBAIJ);CHKERRQ(ierr);
ierr = MatDestroy(&BAIJ);CHKERRQ(ierr);
ierr = MatDestroy(&SBAIJ);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
示例2: output_singular
/**
* output_singular
* ------
* Output the left and right singular vectors.
*/
PetscErrorCode output_singular(char *output_name, const Vec u, const Vec v)
{
PetscFunctionBegin;
PetscErrorCode ierr;
char output_name_prefixed[PETSC_MAX_PATH_LEN];
//const char *prefix = "/out/";
const char *u_extension = ".U";
const char *v_extension = ".V";
//ierr = PetscStrcpy(output_name_prefixed, getenv("FD3D_ROOT")); CHKERRQ(ierr);
//ierr = PetscStrcat(output_name_prefixed, prefix); CHKERRQ(ierr);
//ierr = PetscStrcat(output_name_prefixed, output_name); CHKERRQ(ierr);
ierr = PetscStrcpy(output_name_prefixed, output_name); CHKERRQ(ierr);
char u_file[PETSC_MAX_PATH_LEN];
char v_file[PETSC_MAX_PATH_LEN];
ierr = PetscStrcpy(u_file, output_name_prefixed); CHKERRQ(ierr);
ierr = PetscStrcat(u_file, u_extension); CHKERRQ(ierr);
ierr = PetscStrcpy(v_file, output_name_prefixed); CHKERRQ(ierr);
ierr = PetscStrcat(v_file, v_extension); CHKERRQ(ierr);
PetscViewer viewer;
//viewer = PETSC_VIEWER_STDOUT_WORLD;
//ierr = PetscViewerHDF5Open(PETSC_COMM_WORLD, h_file, FILE_MODE_WRITE, &viewer); CHKERRQ(ierr);
/** Write the left singular vector u. */
ierr = PetscViewerCreate(PETSC_COMM_WORLD, &viewer); CHKERRQ(ierr);
ierr = PetscViewerSetType(viewer, PETSCVIEWERBINARY); CHKERRQ(ierr);
ierr = PetscViewerFileSetMode(viewer, FILE_MODE_WRITE); CHKERRQ(ierr);
ierr = PetscViewerBinarySkipInfo(viewer); CHKERRQ(ierr);
ierr = PetscViewerFileSetName(viewer, u_file); CHKERRQ(ierr);
/*
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, e_file, FILE_MODE_WRITE, &viewer); CHKERRQ(ierr);
*/
ierr = VecView(u, viewer); CHKERRQ(ierr);
/** Write the right singular vector v. */
ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
ierr = PetscViewerCreate(PETSC_COMM_WORLD, &viewer); CHKERRQ(ierr);
ierr = PetscViewerSetType(viewer, PETSCVIEWERBINARY); CHKERRQ(ierr);
ierr = PetscViewerFileSetMode(viewer, FILE_MODE_WRITE); CHKERRQ(ierr);
ierr = PetscViewerBinarySkipInfo(viewer); CHKERRQ(ierr);
ierr = PetscViewerFileSetName(viewer, v_file); CHKERRQ(ierr);
/*
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, h_file, FILE_MODE_WRITE, &viewer); CHKERRQ(ierr);
*/
ierr = VecView(v, viewer); CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例3: main
int main(int argc,char **args)
{
Mat A,B;
PetscErrorCode ierr;
char file[PETSC_MAX_PATH_LEN];
PetscBool flg;
PetscViewer fd;
ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
ierr = PetscOptionsGetString(NULL,NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate binary file with the -f option");
/*
Open binary file. Note that we use FILE_MODE_READ to indicate
reading from this file.
*/
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);CHKERRQ(ierr);
/*
Load the matrix; then destroy the viewer.
*/
ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
ierr = MatSetFromOptions(A);CHKERRQ(ierr);
ierr = MatLoad(A,fd);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&fd);CHKERRQ(ierr);
/*
Open another binary file. Note that we use FILE_MODE_WRITE to indicate writing to the file
*/
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_WRITE,&fd);CHKERRQ(ierr);
ierr = PetscViewerBinarySetFlowControl(fd,3);CHKERRQ(ierr);
/*
Save the matrix and vector; then destroy the viewer.
*/
ierr = MatView(A,fd);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&fd);CHKERRQ(ierr);
/* load the new matrix */
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_READ,&fd);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&B);CHKERRQ(ierr);
ierr = MatSetFromOptions(B);CHKERRQ(ierr);
ierr = MatLoad(B,fd);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&fd);CHKERRQ(ierr);
ierr = MatEqual(A,B,&flg);CHKERRQ(ierr);
if (flg) {
ierr = PetscPrintf(PETSC_COMM_WORLD,"Matrices are equal\n");CHKERRQ(ierr);
} else {
ierr = PetscPrintf(PETSC_COMM_WORLD,"Matrices are not equal\n");CHKERRQ(ierr);
}
ierr = MatDestroy(&A);CHKERRQ(ierr);
ierr = MatDestroy(&B);CHKERRQ(ierr);
ierr = PetscFinalize();
return ierr;
}
示例4: main
int main(int argc, char **argv)
{
PetscErrorCode ierr;
Vec x; /* Solution vector */
TS ts; /* Time-stepping context */
AppCtx user; /* Application context */
Mat J;
PetscViewer viewer;
PetscInitialize(&argc,&argv,"petscopt_ex6", help);
/* Get physics and time parameters */
ierr = Parameter_settings(&user);CHKERRQ(ierr);
/* Create a 2D DA with dof = 1 */
ierr = DMDACreate2d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR,-4,-4,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&user.da);CHKERRQ(ierr);
/* Set x and y coordinates */
ierr = DMDASetUniformCoordinates(user.da,user.xmin,user.xmax,user.ymin,user.ymax,NULL,NULL);CHKERRQ(ierr);
/* Get global vector x from DM */
ierr = DMCreateGlobalVector(user.da,&x);CHKERRQ(ierr);
ierr = ini_bou(x,&user);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"ini_x",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
ierr = VecView(x,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
/* Get Jacobian matrix structure from the da */
ierr = DMSetMatType(user.da,MATAIJ);CHKERRQ(ierr);
ierr = DMCreateMatrix(user.da,&J);CHKERRQ(ierr);
ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr);
ierr = TSSetProblemType(ts,TS_NONLINEAR);CHKERRQ(ierr);
ierr = TSSetIFunction(ts,NULL,IFunction,&user);CHKERRQ(ierr);
ierr = TSSetIJacobian(ts,J,J,IJacobian,&user);CHKERRQ(ierr);
ierr = TSSetApplicationContext(ts,&user);CHKERRQ(ierr);
ierr = TSSetDuration(ts,PETSC_DEFAULT,user.tmax);CHKERRQ(ierr);
ierr = TSSetInitialTimeStep(ts,user.t0,.005);CHKERRQ(ierr);
ierr = TSSetFromOptions(ts);CHKERRQ(ierr);
ierr = TSSetPostStep(ts,PostStep);CHKERRQ(ierr);
ierr = TSSolve(ts,x);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fin_x",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
ierr = VecView(x,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = MatDestroy(&J);CHKERRQ(ierr);
ierr = DMDestroy(&user.da);CHKERRQ(ierr);
ierr = TSDestroy(&ts);CHKERRQ(ierr);
PetscFinalize();
return 0;
}
示例5: main
int main(int argc,char **argv)
{
PetscErrorCode ierr;
PetscInt its;
Vec U,FU;
SNES snes;
UserCtx user;
ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr);
/* Create a global vector that includes a single redundant array and two da arrays */
ierr = DMCompositeCreate(PETSC_COMM_WORLD,&user.packer);CHKERRQ(ierr);
ierr = DMRedundantCreate(PETSC_COMM_WORLD,0,1,&user.red1);CHKERRQ(ierr);
ierr = DMCompositeAddDM(user.packer,user.red1);CHKERRQ(ierr);
ierr = DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,-5,1,1,NULL,&user.da1);CHKERRQ(ierr);
ierr = DMCompositeAddDM(user.packer,user.da1);CHKERRQ(ierr);
ierr = DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,-5,1,1,NULL,&user.da2);CHKERRQ(ierr);
ierr = DMCompositeAddDM(user.packer,user.da2);CHKERRQ(ierr);
ierr = DMCreateGlobalVector(user.packer,&U);CHKERRQ(ierr);
ierr = VecDuplicate(U,&FU);CHKERRQ(ierr);
/* create graphics windows */
ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"u - state variables",-1,-1,-1,-1,&user.u_viewer);CHKERRQ(ierr);
ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"lambda - Lagrange multipliers",-1,-1,-1,-1,&user.lambda_viewer);CHKERRQ(ierr);
ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"fu - derivate w.r.t. state variables",-1,-1,-1,-1,&user.fu_viewer);CHKERRQ(ierr);
ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"flambda - derivate w.r.t. Lagrange multipliers",-1,-1,-1,-1,&user.flambda_viewer);CHKERRQ(ierr);
/* create nonlinear solver */
ierr = SNESCreate(PETSC_COMM_WORLD,&snes);CHKERRQ(ierr);
ierr = SNESSetFunction(snes,FU,FormFunction,&user);CHKERRQ(ierr);
ierr = SNESSetFromOptions(snes);CHKERRQ(ierr);
ierr = SNESMonitorSet(snes,Monitor,&user,0);CHKERRQ(ierr);
ierr = SNESSolve(snes,NULL,U);CHKERRQ(ierr);
ierr = SNESGetIterationNumber(snes,&its);CHKERRQ(ierr);
ierr = SNESDestroy(&snes);CHKERRQ(ierr);
ierr = DMDestroy(&user.red1);CHKERRQ(ierr);
ierr = DMDestroy(&user.da1);CHKERRQ(ierr);
ierr = DMDestroy(&user.da2);CHKERRQ(ierr);
ierr = DMDestroy(&user.packer);CHKERRQ(ierr);
ierr = VecDestroy(&U);CHKERRQ(ierr);
ierr = VecDestroy(&FU);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&user.u_viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&user.lambda_viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&user.fu_viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&user.flambda_viewer);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
示例6: main
int main(int argc,char **args)
{
Mat BAIJ,SBAIJ,*subBAIJ,*subSBAIJ;
PetscViewer viewer;
char file[PETSC_MAX_PATH_LEN];
PetscBool flg;
PetscErrorCode ierr;
PetscInt n = 2,issize;
PetscMPIInt rank;
IS is,iss[2];
PetscInitialize(&argc,&args,(char*)0,help);
ierr = PetscOptionsGetString(NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&BAIJ);CHKERRQ(ierr);
ierr = MatSetType(BAIJ,MATMPIBAIJ);CHKERRQ(ierr);
ierr = MatLoad(BAIJ,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&SBAIJ);CHKERRQ(ierr);
ierr = MatSetType(SBAIJ,MATMPISBAIJ);CHKERRQ(ierr);
ierr = MatLoad(SBAIJ,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = MatGetSize(BAIJ,&issize,0);CHKERRQ(ierr);
issize = 9;
ierr = ISCreateStride(PETSC_COMM_SELF,issize,0,1,&is);CHKERRQ(ierr);
iss[0] = is;iss[1] = is;
ierr = MatGetSubMatrices(BAIJ,n,iss,iss,MAT_INITIAL_MATRIX,&subBAIJ);CHKERRQ(ierr);
ierr = MatGetSubMatrices(SBAIJ,n,iss,iss,MAT_INITIAL_MATRIX,&subSBAIJ);CHKERRQ(ierr);
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
#if defined(PETSC_USE_SOCKET_VIEWER)
if (!rank) {
ierr = MatView(subBAIJ[0],PETSC_VIEWER_SOCKET_SELF);CHKERRQ(ierr);
ierr = MatView(subSBAIJ[0],PETSC_VIEWER_SOCKET_SELF);CHKERRQ(ierr);
}
#endif
/* Free data structures */
ierr = ISDestroy(&is);CHKERRQ(ierr);
ierr = MatDestroyMatrices(n,&subBAIJ);CHKERRQ(ierr);
ierr = MatDestroyMatrices(n,&subSBAIJ);CHKERRQ(ierr);
ierr = MatDestroy(&BAIJ);CHKERRQ(ierr);
ierr = MatDestroy(&SBAIJ);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
示例7: main
int main(int argc, char **argv)
{
PetscErrorCode ierr;
Vec x; /* Solution vector */
TS ts; /* Time-stepping context */
AppCtx user; /* Application context */
PetscViewer viewer;
PetscInitialize(&argc,&argv,"petscopt_ex7", help);
/* Get physics and time parameters */
ierr = Parameter_settings(&user);CHKERRQ(ierr);
/* Create a 2D DA with dof = 1 */
ierr = DMDACreate2d(PETSC_COMM_WORLD,user.bx,user.by,DMDA_STENCIL_STAR,-4,-4,PETSC_DECIDE,PETSC_DECIDE,1,user.st_width,NULL,NULL,&user.da);CHKERRQ(ierr);
/* Set x and y coordinates */
ierr = DMDASetUniformCoordinates(user.da,user.xmin,user.xmax,user.ymin,user.ymax,0,0);CHKERRQ(ierr);
ierr = DMDASetCoordinateName(user.da,0,"X - the angle");
ierr = DMDASetCoordinateName(user.da,1,"Y - the speed");
/* Get global vector x from DM */
ierr = DMCreateGlobalVector(user.da,&x);CHKERRQ(ierr);
ierr = ini_bou(x,&user);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"ini_x",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
ierr = VecView(x,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr);
ierr = TSSetDM(ts,user.da);CHKERRQ(ierr);
ierr = TSSetProblemType(ts,TS_NONLINEAR);CHKERRQ(ierr);
ierr = TSSetType(ts,TSARKIMEX);CHKERRQ(ierr);
ierr = TSSetIFunction(ts,NULL,IFunction,&user);CHKERRQ(ierr);
/* ierr = TSSetIJacobian(ts,NULL,NULL,IJacobian,&user);CHKERRQ(ierr); */
ierr = TSSetApplicationContext(ts,&user);CHKERRQ(ierr);
ierr = TSSetInitialTimeStep(ts,0.0,.005);CHKERRQ(ierr);
ierr = TSSetFromOptions(ts);CHKERRQ(ierr);
ierr = TSSetPostStep(ts,PostStep);CHKERRQ(ierr);
ierr = TSSolve(ts,x);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fin_x",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
ierr = VecView(x,viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = DMDestroy(&user.da);CHKERRQ(ierr);
ierr = TSDestroy(&ts);CHKERRQ(ierr);
PetscFinalize();
return 0;
}
示例8: main
int main(int argc,char **args)
{
PetscErrorCode ierr;
PetscViewer viewer;
ierr = PetscInitialize(&argc,&args,(char *)0,help);CHKERRQ(ierr);
ierr = PetscViewerCreate(PETSC_COMM_WORLD,&viewer);CHKERRQ(ierr);
ierr = PetscViewerSetFromOptions(viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,"stdout",&viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
示例9: printMatrixToFile
int printMatrixToFile(Mat& m,const char* filename){
PetscViewer viewer;
PetscViewerASCIIOpen(PETSC_COMM_WORLD,filename,&viewer);
MatView(m,viewer);
PetscViewerDestroy(&viewer);
return 0;
}
示例10: MyVecLoad
PetscErrorCode MyVecLoad(const char fname[],PetscBool skippheader,PetscBool usempiio,Vec x)
{
MPI_Comm comm;
PetscViewer viewer;
PetscBool ismpiio,isskip;
PetscErrorCode ierr;
PetscFunctionBeginUser;
ierr = PetscObjectGetComm((PetscObject)x,&comm);CHKERRQ(ierr);
ierr = PetscViewerCreate(comm,&viewer);CHKERRQ(ierr);
ierr = PetscViewerSetType(viewer,PETSCVIEWERBINARY);CHKERRQ(ierr);
if (skippheader) { ierr = PetscViewerBinarySetSkipHeader(viewer,PETSC_TRUE);CHKERRQ(ierr); }
ierr = PetscViewerFileSetMode(viewer,FILE_MODE_READ);CHKERRQ(ierr);
if (usempiio) { ierr = PetscViewerBinarySetUseMPIIO(viewer,PETSC_TRUE);CHKERRQ(ierr); }
ierr = PetscViewerFileSetName(viewer,fname);CHKERRQ(ierr);
ierr = VecLoad(x,viewer);CHKERRQ(ierr);
ierr = PetscViewerBinaryGetSkipHeader(viewer,&isskip);CHKERRQ(ierr);
if (isskip) { ierr = PetscPrintf(comm,"*** PetscViewer[load] skipping header ***\n");CHKERRQ(ierr); }
ierr = PetscViewerBinaryGetUseMPIIO(viewer,&ismpiio);CHKERRQ(ierr);
if (ismpiio) { ierr = PetscPrintf(comm,"*** PetscViewer[load] using MPI-IO ***\n");CHKERRQ(ierr); }
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例11: main
int main(int argc,char **argv)
{
PetscErrorCode ierr;
PetscInt M = PETSC_DECIDE,N = PETSC_DECIDE;
DM da;
Vec global;
PetscViewer bviewer;
ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
ierr = PetscOptionsGetInt(NULL,NULL,"-M",&M,NULL);CHKERRQ(ierr);
ierr = PetscOptionsGetInt(NULL,NULL,"-N",&N,NULL);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"daoutput",FILE_MODE_READ,&bviewer);CHKERRQ(ierr);
ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr);
ierr = DMLoad(da,bviewer);CHKERRQ(ierr);
ierr = DMCreateGlobalVector(da,&global);CHKERRQ(ierr);
ierr = VecLoad(global,bviewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&bviewer);CHKERRQ(ierr);
ierr = VecView(global,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);
/* Free memory */
ierr = VecDestroy(&global);CHKERRQ(ierr);
ierr = DMDestroy(&da);CHKERRQ(ierr);
ierr = PetscFinalize();
return ierr;
}
示例12: main
int main(int argc,char **args)
{
Mat A,B,MA;
PetscViewer fd;
char file[PETSC_MAX_PATH_LEN];
PetscInt m,n,M,N,dof=1;
PetscMPIInt rank,size;
PetscErrorCode ierr;
PetscBool flg;
PetscInitialize(&argc,&args,(char*)0,help);
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
#if defined(PETSC_USE_COMPLEX)
SETERRQ(PETSC_COMM_WORLD,1,"This example does not work with complex numbers");
#else
/* Load aij matrix A */
ierr = PetscOptionsGetString(NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f option");
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
ierr = MatLoad(A,fd);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&fd);CHKERRQ(ierr);
/* Get dof, then create maij matrix MA */
ierr = PetscOptionsGetInt(NULL,"-dof",&dof,NULL);CHKERRQ(ierr);
ierr = MatCreateMAIJ(A,dof,&MA);CHKERRQ(ierr);
ierr = MatGetLocalSize(MA,&m,&n);CHKERRQ(ierr);
ierr = MatGetSize(MA,&M,&N);CHKERRQ(ierr);
if (size == 1) {
ierr = MatConvert(MA,MATSEQAIJ,MAT_INITIAL_MATRIX,&B);CHKERRQ(ierr);
} else {
ierr = MatConvert(MA,MATMPIAIJ,MAT_INITIAL_MATRIX,&B);CHKERRQ(ierr);
}
/* Test MatMult() */
ierr = MatMultEqual(MA,B,10,&flg);CHKERRQ(ierr);
if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_CONV_FAILED,"Error: MatMul() for MAIJ matrix");
/* Test MatMultAdd() */
ierr = MatMultAddEqual(MA,B,10,&flg);CHKERRQ(ierr);
if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_CONV_FAILED,"Error: MatMulAdd() for MAIJ matrix");
/* Test MatMultTranspose() */
ierr = MatMultTransposeEqual(MA,B,10,&flg);CHKERRQ(ierr);
if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_CONV_FAILED,"Error: MatMulAdd() for MAIJ matrix");
/* Test MatMultTransposeAdd() */
ierr = MatMultTransposeAddEqual(MA,B,10,&flg);CHKERRQ(ierr);
if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_CONV_FAILED,"Error: MatMulTransposeAdd() for MAIJ matrix");
ierr = MatDestroy(&MA);CHKERRQ(ierr);
ierr = MatDestroy(&A);CHKERRQ(ierr);
ierr = MatDestroy(&B);CHKERRQ(ierr);
ierr = PetscFinalize();
#endif
return 0;
}
示例13: readProfileSurfaceScalarDataRecord
PetscErrorCode readProfileSurfaceScalarDataRecord(char *fileName, PetscScalar *arr, PetscInt numValsPerProfile, PetscInt iRec)
{
/* Random access version of readProfileSurfaceScalarData */
/* This version takes 1 additional argument: */
/* iRec: the record to read (iRec=1 is the first record) */
PetscErrorCode ierr;
off_t off, offset;
PetscViewer fd;
PetscInt fp;
PetscInt iShift;
PetscMPIInt numProcessors, myId;
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&myId);CHKERRQ(ierr);
ierr = MPI_Comm_size(PETSC_COMM_WORLD,&numProcessors);CHKERRQ(ierr);
/* Shift file pointer to start of data owned by local process */
iShift = (iRec-1)*numValsPerProfile*totalNumProfiles + numValsPerProfile*numPrevProfiles;
off = PETSC_BINARY_SCALAR_SIZE*iShift;
ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,fileName,FILE_MODE_READ,&fd);CHKERRQ(ierr);
ierr = PetscViewerBinaryGetDescriptor(fd,&fp);CHKERRQ(ierr);
ierr = PetscBinarySeek(fp,off,PETSC_BINARY_SEEK_SET,&offset);CHKERRQ(ierr);
ierr = PetscBinaryRead(fp,arr,numValsPerProfile*lNumProfiles,PETSC_SCALAR);CHKERRQ(ierr);
ierr = PetscViewerDestroy(fd);CHKERRQ(ierr);
return 0;
}
示例14: main
int main(int argc, char *argv[])
{
PetscErrorCode ierr;
params params;
Mat H;
SlepcInitialize(&argc,&argv,(char*)0,help);
ierr = PetscPrintf(PETSC_COMM_WORLD,"--------------------------------------------------------------------------------------\n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," _______ __ __ _______ _______ ______ _______ \n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," |__ __| \\/ |/ ____\\ \\ / /_ _| ____|__ __| \n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," | | | \\ / | (___ \\ \\ /\\ / / | | | |__ | | \n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," | | | |\\/| |\\___ \\ \\ \\/ \\/ / | | | __| | | \n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," | | | | | |____) | \\ /\\ / _| |_| | | | \n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," |_| |_| |_|_____/ \\/ \\/ |_____|_| |_| \n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," True Muonium Solver with Iterative Front-Form Techniques \n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," \n");CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD,"--------------------------------------------------------------------------------------\n");CHKERRQ(ierr);
read_input(ierr,argv,¶ms);
print_input(ierr,¶ms);
if(check_file(params.hfile))
{
PetscViewer viewer_H;
PetscViewerBinaryOpen(PETSC_COMM_WORLD,params.hfile.c_str(),FILE_MODE_READ,&viewer_H);
MatCreate(PETSC_COMM_WORLD,&H);
MatSetFromOptions(H);
MatLoad(H,viewer_H);
PetscViewerDestroy(&viewer_H);
}else
{
discretize(ierr,¶ms);
// ierr = VecView(params.mu,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
// ierr = VecView(params.theta,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
write_output(ierr,¶ms);
coulomb_trick(ierr,¶ms);
// ierr = VecView(params.CT,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
ct_discrete(ierr,¶ms);
// ierr = VecView(params.CT,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
hamiltonian(ierr,¶ms,H);
// ierr = PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_DENSE);//DENSE<-->COMMON
// MatView(H,PETSC_VIEWER_STDOUT_WORLD);
}
cleanup(ierr,¶ms);
eigensolver(ierr,¶ms,H,argc,argv);
ierr = MatDestroy(&H);CHKERRQ(ierr);
ierr = SlepcFinalize();
return 0;
}
示例15: TSTrajectoryGet_Basic
PetscErrorCode TSTrajectoryGet_Basic(TSTrajectory tj,TS ts,PetscInt stepnum,PetscReal *t)
{
Vec Sol,*Y;
PetscInt Nr,i;
PetscViewer viewer;
PetscReal timepre;
char filename[PETSC_MAX_PATH_LEN];
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = TSGetTotalSteps(ts,&stepnum);CHKERRQ(ierr);
ierr = PetscSNPrintf(filename,sizeof filename,"SA-data/SA-%06d.bin",stepnum);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
ierr = TSGetSolution(ts,&Sol);CHKERRQ(ierr);
ierr = VecLoad(Sol,viewer);CHKERRQ(ierr);
ierr = PetscViewerBinaryRead(viewer,t,1,NULL,PETSC_REAL);CHKERRQ(ierr);
if (stepnum != 0) {
ierr = TSGetStages(ts,&Nr,&Y);CHKERRQ(ierr);
for (i=0;i<Nr ;i++) {
ierr = VecLoad(Y[i],viewer);CHKERRQ(ierr);
}
ierr = PetscViewerBinaryRead(viewer,&timepre,1,NULL,PETSC_REAL);CHKERRQ(ierr);
ierr = TSSetTimeStep(ts,-(*t)+timepre);CHKERRQ(ierr);
}
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
PetscFunctionReturn(0);
}