本文整理汇总了C++中PetscViewerASCIIOpen函数的典型用法代码示例。如果您正苦于以下问题:C++ PetscViewerASCIIOpen函数的具体用法?C++ PetscViewerASCIIOpen怎么用?C++ PetscViewerASCIIOpen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PetscViewerASCIIOpen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
PetscErrorCode ierr;
Vec U,cv,eta;
DM da,da2;
PetscViewer viewer,view_vtk_cv,view_vtk_eta;
char filename[PETSC_MAX_PATH_LEN],cv_filename[PETSC_MAX_PATH_LEN],eta_filename[PETSC_MAX_PATH_LEN];
PetscBool flg,sflg = PETSC_FALSE;
PetscInt i,n=10000;
PetscInt seed;
PetscInitialize(&argc,&argv, (char*)0, help);
ierr = PetscOptionsSetValue("-viewer_binary_skip_info","true");CHKERRQ(ierr);
ierr = PetscOptionsGetString(PETSC_NULL,"-f",filename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
if (!flg) {
ierr = PetscOptionsGetInt(PETSC_NULL,"-random_seed",&seed,&sflg);CHKERRQ(ierr);
if (!sflg) {
ierr = PetscStrcpy(filename,"ex61.data");CHKERRQ(ierr);
} else {
sprintf(filename,"ex61.data.%d",seed);
}
}
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
/* Get physics and time parameters */
ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr);
ierr = DMLoad(da,viewer);CHKERRQ(ierr);
ierr = DMCreateGlobalVector(da,&U);CHKERRQ(ierr);
ierr = DMDAGetReducedDA(da,1,&da2);CHKERRQ(ierr);
ierr = DMCreateGlobalVector(da2,&cv);CHKERRQ(ierr);
ierr = DMCreateGlobalVector(da2,&eta);CHKERRQ(ierr);
for (i=0; i<n; i++) {
/* when this fails it simply means the file is finished */
ierr = VecLoad(U,viewer);CHKERRQ(ierr);
ierr = VecStrideGather(U,1,cv,INSERT_VALUES);CHKERRQ(ierr);
ierr = VecStrideGather(U,4,eta,INSERT_VALUES);CHKERRQ(ierr);
sprintf(cv_filename,"%s_cv_%d.vtk",filename,i);
sprintf(eta_filename,"%s_eta_%d.vtk",filename,i);
ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,cv_filename,&view_vtk_cv);CHKERRQ(ierr);
ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,eta_filename,&view_vtk_eta);CHKERRQ(ierr);
ierr = PetscViewerSetFormat(view_vtk_cv, PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr);
ierr = PetscViewerSetFormat(view_vtk_eta, PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr);
ierr = DMView(da2,view_vtk_cv);CHKERRQ(ierr);
ierr = DMView(da2,view_vtk_eta);CHKERRQ(ierr);
ierr = VecView(cv,view_vtk_cv);CHKERRQ(ierr);
ierr = VecView(eta,view_vtk_eta);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&view_vtk_cv);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&view_vtk_eta);CHKERRQ(ierr);
}
ierr = VecDestroy(&U);CHKERRQ(ierr);
ierr = VecDestroy(&cv);CHKERRQ(ierr);
ierr = VecDestroy(&eta);CHKERRQ(ierr);
ierr = DMDestroy(&da);CHKERRQ(ierr);
ierr = DMDestroy(&da2);CHKERRQ(ierr);
PetscFinalize();
return 0;
}
示例2: BSSCR_create_execute_script
int BSSCR_create_execute_script( void )
{
int argc;
char **args;
int i;
PetscViewer viewer, viewer_dated;
time_t currTime;
struct tm* timeInfo;
int adjustedYear;
int adjustedMonth;
char *filename;
/* get file name with date */
currTime = time( NULL );
timeInfo = localtime( &currTime );
/* See man localtime() for why to adjust these */
adjustedYear = 1900 + timeInfo->tm_year;
adjustedMonth = 1 + timeInfo->tm_mon;
/* Format; name-YYYY.MM.DD-HH.MM.SS.sh */
asprintf( &filename, "%s-%.4d.%.2d.%.2d-%.2d.%.2d.%.2d.%s",
"execute-job",
adjustedYear, adjustedMonth, timeInfo->tm_mday,
timeInfo->tm_hour, timeInfo->tm_min, timeInfo->tm_sec ,
"sh" );
PetscViewerASCIIOpen( PETSC_COMM_SELF, filename, &viewer_dated );
/* get file name without */
PetscViewerASCIIOpen( PETSC_COMM_SELF, "execute-job.sh", &viewer );
/* ouput what the command line arguments were */
PetscGetArgs( &argc, &args );
for( i=0; i<argc; i++ ) {
PetscViewerASCIIPrintf( viewer, "%s ", args[i] );
PetscViewerASCIIPrintf( viewer_dated, "%s ", args[i] );
}
Stg_PetscViewerDestroy(&viewer);
Stg_PetscViewerDestroy(&viewer_dated);
free( filename );
return 0;
}
示例3: TSSetFromOptions_Pseudo
static PetscErrorCode TSSetFromOptions_Pseudo(TS ts)
{
TS_Pseudo *pseudo = (TS_Pseudo*)ts->data;
PetscErrorCode ierr;
PetscBool flg = PETSC_FALSE;
PetscViewer viewer;
PetscFunctionBegin;
ierr = PetscOptionsHead("Pseudo-timestepping options");CHKERRQ(ierr);
ierr = PetscOptionsBool("-ts_monitor_pseudo","Monitor convergence","TSPseudoMonitorDefault",flg,&flg,NULL);CHKERRQ(ierr);
if (flg) {
ierr = PetscViewerASCIIOpen(PetscObjectComm((PetscObject)ts),"stdout",&viewer);CHKERRQ(ierr);
ierr = TSMonitorSet(ts,TSPseudoMonitorDefault,viewer,(PetscErrorCode (*)(void**))PetscViewerDestroy);CHKERRQ(ierr);
}
flg = PETSC_FALSE;
ierr = PetscOptionsBool("-ts_pseudo_increment_dt_from_initial_dt","Increase dt as a ratio from original dt","TSPseudoIncrementDtFromInitialDt",flg,&flg,NULL);CHKERRQ(ierr);
if (flg) {
ierr = TSPseudoIncrementDtFromInitialDt(ts);CHKERRQ(ierr);
}
ierr = PetscOptionsReal("-ts_pseudo_increment","Ratio to increase dt","TSPseudoSetTimeStepIncrement",pseudo->dt_increment,&pseudo->dt_increment,0);CHKERRQ(ierr);
ierr = PetscOptionsReal("-ts_pseudo_max_dt","Maximum value for dt","TSPseudoSetMaxTimeStep",pseudo->dt_max,&pseudo->dt_max,0);CHKERRQ(ierr);
ierr = SNESSetFromOptions(ts->snes);CHKERRQ(ierr);
ierr = PetscOptionsTail();CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例4: StokesWriteSolution
PetscErrorCode StokesWriteSolution(Stokes *s)
{
PetscMPIInt size;
PetscInt n,i,j;
const PetscScalar *array;
PetscErrorCode ierr;
PetscFunctionBeginUser;
/* write data (*warning* only works sequential) */
MPI_Comm_size(MPI_COMM_WORLD,&size);
/*ierr = PetscPrintf(PETSC_COMM_WORLD," number of processors = %D\n",size);CHKERRQ(ierr);*/
if (size == 1) {
PetscViewer viewer;
ierr = VecGetArrayRead(s->x, &array);CHKERRQ(ierr);
ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, "solution.dat", &viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer, "# x, y, u, v, p\n");CHKERRQ(ierr);
for (j = 0; j < s->ny; j++) {
for (i = 0; i < s->nx; i++) {
n = j*s->nx+i;
ierr = PetscViewerASCIIPrintf(viewer, "%.12g %.12g %.12g %.12g %.12g\n", (double)(i*s->hx+s->hx/2),(double)(j*s->hy+s->hy/2), (double)PetscRealPart(array[n]), (double)PetscRealPart(array[n+s->nx*s->ny]),(double)PetscRealPart(array[n+2*s->nx*s->ny]));CHKERRQ(ierr);
}
}
ierr = VecRestoreArrayRead(s->x, &array);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例5: printVectorToFile
int printVectorToFile(Vec& v,const char* filename){
PetscViewer viewer;
PetscViewerASCIIOpen(PETSC_COMM_WORLD,filename,&viewer);
VecView(v,viewer);
PetscViewerDestroy(&viewer);
return 0;
}
示例6: PetscViewerGetSubcomm_ASCII
PetscErrorCode PetscViewerGetSubcomm_ASCII(PetscViewer viewer,MPI_Comm subcomm,PetscViewer *outviewer)
{
PetscErrorCode ierr;
PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data,*ovascii;
const char *name;
PetscFunctionBegin;
if (vascii->sviewer) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Subcomm viewer already obtained from PetscViewer and not restored");
/* Note that we need to open vascii->filename for the subcomm:
we can't count on reusing viewer's fd since the root in comm and subcomm may differ.
Further, if the subcomm happens to be the same as comm, PetscViewerASCIIOpen() will
will return the current viewer, having increfed it.
*/
ierr = PetscViewerASCIIOpen(subcomm,vascii->filename, outviewer);CHKERRQ(ierr);
if(*outviewer == viewer) PetscFunctionReturn(0);
ovascii = (PetscViewer_ASCII*)(*outviewer)->data;
ovascii->tab = vascii->tab;
vascii->sviewer = *outviewer;
(*outviewer)->format = viewer->format;
(*outviewer)->iformat = viewer->iformat;
ierr = PetscObjectGetName((PetscObject)viewer,&name);CHKERRQ(ierr);
ierr = PetscObjectSetName((PetscObject)(*outviewer),name);CHKERRQ(ierr);
((PetscViewer_ASCII*)((*outviewer)->data))->bviewer = viewer;
(*outviewer)->ops->destroy = PetscViewerDestroy_ASCII_Subcomm;
PetscFunctionReturn(0);
}
示例7: START_TEST
END_TEST
START_TEST( Generate2DLapacian_test )
{
PetscErrorCode ierr;
PetscInt d = 50, len = d*d;
Mat m;
PetscViewer view;
Generate2DLapacian( d, d, &m);
PetscViewerASCIIOpen(PETSC_COMM_SELF, "mat.dat", &view);
MatView(m, view);
KSP ksp;
PC pc;
ierr = KSPCreate(PETSC_COMM_SELF, &ksp); CHKERRQ(ierr);
KSPSetType(ksp, KSPPREONLY);
KSPGetPC(ksp, &pc);
PCSetType(pc, PCCHOLESKY);
KSPSetOperators(ksp, m, m, SAME_PRECONDITIONER);
Vec v, s;
VecCreateSeq(PETSC_COMM_SELF,len,&v);
VecDuplicate(v, &s);
VecSet(v, 1);
ierr = KSPSolve(ksp, v, s); CHKERRQ(ierr);
}
示例8: printMatrixToFile
int printMatrixToFile(Mat& m,const char* filename){
PetscViewer viewer;
PetscViewerASCIIOpen(PETSC_COMM_WORLD,filename,&viewer);
MatView(m,viewer);
PetscViewerDestroy(&viewer);
return 0;
}
示例9: writeToFile
void
PetscSparseMtrx :: writeToFile(const char* fname) const
{
PetscViewer viewer;
PetscViewerASCIIOpen(PETSC_COMM_WORLD, fname, &viewer);
MatView(this->mtrx, viewer);
PetscViewerDestroy(&viewer);
}
示例10: libmesh_assert
void PetscMatrix<T>::print_matlab (const std::string name) const
{
libmesh_assert (this->initialized());
semiparallel_only();
// libmesh_assert (this->closed());
this->close();
PetscErrorCode ierr=0;
PetscViewer petsc_viewer;
ierr = PetscViewerCreate (this->comm().get(),
&petsc_viewer);
LIBMESH_CHKERRABORT(ierr);
/**
* Create an ASCII file containing the matrix
* if a filename was provided.
*/
if (name != "NULL")
{
ierr = PetscViewerASCIIOpen( this->comm().get(),
name.c_str(),
&petsc_viewer);
LIBMESH_CHKERRABORT(ierr);
ierr = PetscViewerSetFormat (petsc_viewer,
PETSC_VIEWER_ASCII_MATLAB);
LIBMESH_CHKERRABORT(ierr);
ierr = MatView (_mat, petsc_viewer);
LIBMESH_CHKERRABORT(ierr);
}
/**
* Otherwise the matrix will be dumped to the screen.
*/
else
{
ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD,
PETSC_VIEWER_ASCII_MATLAB);
LIBMESH_CHKERRABORT(ierr);
ierr = MatView (_mat, PETSC_VIEWER_STDOUT_WORLD);
LIBMESH_CHKERRABORT(ierr);
}
/**
* Destroy the viewer.
*/
ierr = LibMeshPetscViewerDestroy (&petsc_viewer);
LIBMESH_CHKERRABORT(ierr);
}
示例11: output_data
void
output_data(Pointer<PatchHierarchy<NDIM> > patch_hierarchy,
Pointer<INSHierarchyIntegrator> navier_stokes_integrator,
LDataManager* l_data_manager,
const int iteration_num,
const double loop_time,
const int output_level,
const string& data_dump_dirname)
{
if (output_level >= 0)
{
pout << "\nWriting output files at timestep # " << iteration_num << " t=" << loop_time << "\n";
}
string file_name = data_dump_dirname + "/" + "hier_data.";
char temp_buf[128];
sprintf(temp_buf, "%05d.samrai.%05d", iteration_num, SAMRAI_MPI::getRank());
file_name += temp_buf;
// Write Cartesian data.
if (output_level >= 3)
{
Pointer<HDFDatabase> hier_db = new HDFDatabase("hier_db");
hier_db->create(file_name);
VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase();
ComponentSelector hier_data;
hier_data.setFlag(var_db->mapVariableAndContextToIndex(navier_stokes_integrator->getVelocityVariable(),
navier_stokes_integrator->getCurrentContext()));
hier_data.setFlag(var_db->mapVariableAndContextToIndex(navier_stokes_integrator->getPressureVariable(),
navier_stokes_integrator->getCurrentContext()));
patch_hierarchy->putToDatabase(hier_db->putDatabase("PatchHierarchy"), hier_data);
hier_db->putDouble("loop_time", loop_time);
hier_db->putInteger("iteration_num", iteration_num);
hier_db->close();
}
// Write Lagrangian data.
if (output_level >= 0)
{
const int finest_hier_level = patch_hierarchy->getFinestLevelNumber();
Pointer<LData> X_data = l_data_manager->getLData("X", finest_hier_level);
Vec X_petsc_vec = X_data->getVec();
Vec X_lag_vec;
VecDuplicate(X_petsc_vec, &X_lag_vec);
l_data_manager->scatterPETScToLagrangian(X_petsc_vec, X_lag_vec, finest_hier_level);
file_name = data_dump_dirname + "/" + "X.";
sprintf(temp_buf, "%05d", iteration_num);
file_name += temp_buf;
PetscViewer viewer;
PetscViewerASCIIOpen(PETSC_COMM_WORLD, file_name.c_str(), &viewer);
VecView(X_lag_vec, viewer);
PetscViewerDestroy(&viewer);
VecDestroy(&X_lag_vec);
}
return;
} // output_data
示例12: OutputVec
PetscErrorCode OutputVec(MPI_Comm comm, Vec x, const char *filenameComm, const char *filenameProperty)
{
PetscErrorCode ierr;
PetscViewer viewer;
char filename[100]="";
strcat(strcat(filename,filenameComm),filenameProperty);
ierr = PetscViewerASCIIOpen(comm, filename, &viewer); CHKERRQ(ierr);
ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_MATLAB); CHKERRQ(ierr);
ierr = VecView(x,viewer); CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例13: OutputMat
PetscErrorCode OutputMat(MPI_Comm comm, Mat A, const char *filenameComm, const char *filenameProperty)
{
PetscErrorCode ierr;
PetscViewer viewer;
char filename[100]="";
strcat(strcat(filename,filenameComm),filenameProperty);
ierr = PetscViewerASCIIOpen(comm, filename, &viewer); CHKERRQ(ierr);
ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);CHKERRQ(ierr);
ierr = MatView(A,viewer); CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
// When runing parallely, it may need -mat_ascii_output_large
PetscFunctionReturn(0);
}
示例14: TSAdaptChoose
/*@
TSAdaptSetMonitor - Monitor the choices made by the adaptive controller
Collective on TSAdapt
Input Arguments:
+ adapt - adaptive controller context
- flg - PETSC_TRUE to active a monitor, PETSC_FALSE to disable
Options Database Keys:
. -ts_adapt_monitor - to turn on monitoring
Level: intermediate
.seealso: TSAdaptChoose()
@*/
PetscErrorCode TSAdaptSetMonitor(TSAdapt adapt,PetscBool flg)
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidHeaderSpecific(adapt,TSADAPT_CLASSID,1);
PetscValidLogicalCollectiveBool(adapt,flg,2);
if (flg) {
if (!adapt->monitor) {ierr = PetscViewerASCIIOpen(PetscObjectComm((PetscObject)adapt),"stdout",&adapt->monitor);CHKERRQ(ierr);}
} else {
ierr = PetscViewerDestroy(&adapt->monitor);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例15: _try
void linearSystemPETSc<scalar>::printMatlab(const char *filename) const
{
_try(MatAssemblyBegin(_a, MAT_FINAL_ASSEMBLY));
_try(MatAssemblyEnd(_a, MAT_FINAL_ASSEMBLY));
_try(VecAssemblyBegin(_b));
_try(VecAssemblyEnd(_b));
PetscViewer viewer;
PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename, &viewer);
PetscViewerSetFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
MatView(_a, viewer);
PetscViewerDestroy(&viewer);
return;
}