本文整理汇总了C++中PetscStrcat函数的典型用法代码示例。如果您正苦于以下问题:C++ PetscStrcat函数的具体用法?C++ PetscStrcat怎么用?C++ PetscStrcat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PetscStrcat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PetscBagSetName
/*@
PetscBagSetFromOptions - Allows setting options from a bag
Collective on PetscBag
Input Parameter:
. bag - the bag of values
Level: beginner
.seealso: PetscBag, PetscBagSetName(), PetscBagDestroy(), PetscBagLoad(), PetscBagGetData()
PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterBool(), PetscBagRegisterScalar()
PetscBagSetFromOptions(), PetscBagCreate(), PetscBagGetName(), PetscBagView(), PetscBagRegisterEnum()
@*/
PetscErrorCode PetscBagSetFromOptions(PetscBag bag)
{
PetscErrorCode ierr;
PetscBagItem nitem = bag->bagitems;
char name[PETSC_BAG_NAME_LENGTH+1],helpname[PETSC_BAG_NAME_LENGTH+PETSC_BAG_HELP_LENGTH+3];
PetscInt n;
PetscFunctionBegin;
ierr = PetscStrcpy(helpname,bag->bagname);CHKERRQ(ierr);
ierr = PetscStrcat(helpname," ");CHKERRQ(ierr);
ierr = PetscStrcat(helpname,bag->baghelp);CHKERRQ(ierr);
ierr = PetscOptionsBegin(bag->bagcomm,bag->bagprefix,helpname,0);CHKERRQ(ierr);
while (nitem) {
name[0] = '-';
name[1] = 0;
ierr = PetscStrcat(name,nitem->name);CHKERRQ(ierr);
if (nitem->dtype == PETSC_CHAR) { /* special handling for fortran required? [due to space padding vs null termination] */
char *value = (char*)(((char*)bag) + nitem->offset);
ierr = PetscOptionsString(name,nitem->help,"",value,value,nitem->msize,NULL);CHKERRQ(ierr);
} else if (nitem->dtype == PETSC_REAL) {
PetscReal *value = (PetscReal*)(((char*)bag) + nitem->offset);
if (nitem->msize == 1) {
ierr = PetscOptionsReal(name,nitem->help,"",*value,value,NULL);CHKERRQ(ierr);
} else {
n = nitem->msize;
ierr = PetscOptionsRealArray(name,nitem->help,"",value,&n,NULL);CHKERRQ(ierr);
}
} else if (nitem->dtype == PETSC_SCALAR) {
PetscScalar *value = (PetscScalar*)(((char*)bag) + nitem->offset);
ierr = PetscOptionsScalar(name,nitem->help,"",*value,value,NULL);CHKERRQ(ierr);
} else if (nitem->dtype == PETSC_INT) {
PetscInt *value = (PetscInt*)(((char*)bag) + nitem->offset);
if (nitem->msize == 1) {
ierr = PetscOptionsInt(name,nitem->help,"",*value,value,NULL);CHKERRQ(ierr);
} else {
n = nitem->msize;
ierr = PetscOptionsIntArray(name,nitem->help,"",value,&n,NULL);CHKERRQ(ierr);
}
} else if (nitem->dtype == PETSC_ENUM) {
PetscEnum *value = (PetscEnum*)(((char*)bag) + nitem->offset);
PetscInt i = 0;
while (nitem->list[i++]) ;
ierr = PetscOptionsEnum(name,nitem->help,nitem->list[i-3],(const char*const*)nitem->list,*value,value,NULL);CHKERRQ(ierr);
} else if (nitem->dtype == PETSC_BOOL) {
PetscBool *value = (PetscBool*)(((char*)bag) + nitem->offset);
if (nitem->msize == 1) {
ierr = PetscOptionsBool(name,nitem->help,"",*value,value,NULL);CHKERRQ(ierr);
} else {
n = nitem->msize;
ierr = PetscOptionsBoolArray(name,nitem->help,"",value,&n,NULL);CHKERRQ(ierr);
}
}
nitem = nitem->next;
}
PetscOptionsEnd();
PetscFunctionReturn(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: TSRegisterDynamic
/*@C
TSRegister - See TSRegisterDynamic()
Level: advanced
@*/
PetscErrorCode TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
{
char fullname[PETSC_MAX_PATH_LEN];
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr);
ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr);
ierr = PetscStrcat(fullname, name);CHKERRQ(ierr);
ierr = PetscFunctionListAdd(PETSC_COMM_WORLD,&TSList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例4: PetscHTTPBuildRequest
static PetscErrorCode PetscHTTPBuildRequest(const char type[],const char url[],const char header[],const char ctype[],const char body[],char **outrequest)
{
char *request=0;
char contentlength[40],contenttype[80],*path,*host;
size_t request_len,headlen,bodylen,contentlen,pathlen,hostlen,typelen,contenttypelen = 0;
PetscErrorCode ierr;
PetscBool flg;
PetscFunctionBegin;
ierr = PetscStrallocpy(url,&host);CHKERRQ(ierr);
ierr = PetscStrchr(host,'/',&path);CHKERRQ(ierr);
if (!path) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"url must contain / it is %s",url);
*path = 0;
ierr = PetscStrlen(host,&hostlen);CHKERRQ(ierr);
ierr = PetscStrchr(url,'/',&path);CHKERRQ(ierr);
ierr = PetscStrlen(path,&pathlen);CHKERRQ(ierr);
if (header) {
ierr = PetscStrendswith(header,"\r\n",&flg);CHKERRQ(ierr);
if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"header must end with \\r\\n");
}
ierr = PetscStrlen(type,&typelen);CHKERRQ(ierr);
if (ctype) {
ierr = PetscSNPrintf(contenttype,80,"Content-Type: %s\r\n",ctype);CHKERRQ(ierr);
ierr = PetscStrlen(contenttype,&contenttypelen);CHKERRQ(ierr);
}
ierr = PetscStrlen(header,&headlen);CHKERRQ(ierr);
ierr = PetscStrlen(body,&bodylen);CHKERRQ(ierr);
ierr = PetscSNPrintf(contentlength,40,"Content-Length: %d\r\n\r\n",(int)bodylen);CHKERRQ(ierr);
ierr = PetscStrlen(contentlength,&contentlen);CHKERRQ(ierr);
/* Now construct our HTTP request */
request_len = typelen + 1 + pathlen + hostlen + 100 + headlen + contenttypelen + contentlen + bodylen + 1;
ierr = PetscMalloc1(request_len,&request);CHKERRQ(ierr);
ierr = PetscStrcpy(request,type);CHKERRQ(ierr);
ierr = PetscStrcat(request," ");CHKERRQ(ierr);
ierr = PetscStrcat(request,path);CHKERRQ(ierr);
ierr = PetscStrcat(request," HTTP/1.1\r\nHost: ");CHKERRQ(ierr);
ierr = PetscStrcat(request,host);CHKERRQ(ierr);
ierr = PetscFree(host);CHKERRQ(ierr);
ierr = PetscStrcat(request,"\r\nUser-Agent:PETScClient\r\n");CHKERRQ(ierr);
ierr = PetscStrcat(request,header);CHKERRQ(ierr);
if (ctype) {
ierr = PetscStrcat(request,contenttype);CHKERRQ(ierr);
}
ierr = PetscStrcat(request,contentlength);CHKERRQ(ierr);
ierr = PetscStrcat(request,body);CHKERRQ(ierr);
ierr = PetscStrlen(request,&request_len);CHKERRQ(ierr);
ierr = PetscInfo1(NULL,"HTTPS request follows: \n%s\n",request);CHKERRQ(ierr);
*outrequest = request;
PetscFunctionReturn(0);
}
示例5: directory
/*@C
PetscSSLInitializeContext - Set up an SSL context suitable for initiating HTTPS requests.
Output Parameter:
. octx - the SSL_CTX to be passed to PetscHTTPSConnect
Level: advanced
If PETSc was ./configure -with-ssl-certificate requires the user have created a self-signed certificate with
$ saws/CA.pl -newcert (using the passphrase of password)
$ cat newkey.pem newcert.pem > sslclient.pem
and put the resulting file in either the current directory (with the application) or in the home directory. This seems kind of
silly but it was all I could figure out.
.seealso: PetscSSLDestroyContext(), PetscHTTPSConnect(), PetscHTTPSRequest()
@*/
PetscErrorCode PetscSSLInitializeContext(SSL_CTX **octx)
{
SSL_CTX *ctx;
#if defined(PETSC_USE_SSL_CERTIFICATE)
char keyfile[PETSC_MAX_PATH_LEN];
PetscBool exists;
PetscErrorCode ierr;
#endif
PetscFunctionBegin;
if (!bio_err){
SSL_library_init();
SSL_load_error_strings();
bio_err = BIO_new_fp(stderr,BIO_NOCLOSE);
}
/* Set up a SIGPIPE handler */
signal(SIGPIPE,sigpipe_handle);
/* suggested at https://mta.openssl.org/pipermail/openssl-dev/2015-May/001449.html */
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
ctx = SSL_CTX_new(TLS_client_method());
#else
ctx = SSL_CTX_new(SSLv23_client_method());
#endif
SSL_CTX_set_mode(ctx,SSL_MODE_AUTO_RETRY);
#if defined(PETSC_USE_SSL_CERTIFICATE)
/* Locate keyfile */
ierr = PetscStrcpy(keyfile,"sslclient.pem");CHKERRQ(ierr);
ierr = PetscTestFile(keyfile,'r',&exists);CHKERRQ(ierr);
if (!exists) {
ierr = PetscGetHomeDirectory(keyfile,PETSC_MAX_PATH_LEN);CHKERRQ(ierr);
ierr = PetscStrcat(keyfile,"/");CHKERRQ(ierr);
ierr = PetscStrcat(keyfile,"sslclient.pem");CHKERRQ(ierr);
ierr = PetscTestFile(keyfile,'r',&exists);CHKERRQ(ierr);
if (!exists) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate sslclient.pem file in current directory or home directory");
}
/* Load our keys and certificates*/
if (!(SSL_CTX_use_certificate_chain_file(ctx,keyfile))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Cannot read certificate file");
SSL_CTX_set_default_passwd_cb(ctx,password_cb);
if (!(SSL_CTX_use_PrivateKey_file(ctx,keyfile,SSL_FILETYPE_PEM))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Cannot read key file");
#endif
*octx = ctx;
PetscFunctionReturn(0);
}
示例6: PetscDrawSave_SAWs
static PetscErrorCode PetscDrawSave_SAWs(PetscDraw draw)
{
PetscImageList image;
char body[4096];
size_t len = 0;
PetscErrorCode ierr;
PetscFunctionBegin;
if (!draw->savefilename) PetscFunctionReturn(0);
ierr = PetscImageListAdd(draw->savefilename,draw->saveimageext,draw->savefilecount-1);CHKERRQ(ierr);
image = SAWs_images;
while (image) {
const char *name = image->filename;
const char *ext = image->ext;
if (draw->savesinglefile) {
ierr = PetscSNPrintf(body+len,4086-len,"<img src=\"%s%s\" alt=\"None\">",name,ext);CHKERRQ(ierr);
} else {
ierr = PetscSNPrintf(body+len,4086-len,"<img src=\"%s/%s_%d%s\" alt=\"None\">",name,name,image->count,ext);CHKERRQ(ierr);
}
ierr = PetscStrlen(body,&len);CHKERRQ(ierr);
image = image->next;
}
ierr = PetscStrcat(body,"<br>\n");CHKERRQ(ierr);
if (draw->savefilecount > 0) PetscStackCallSAWs(SAWs_Pop_Body,("index.html",1));
PetscStackCallSAWs(SAWs_Push_Body,("index.html",1,body));
PetscFunctionReturn(0);
}
示例7: collective
/*@C
PetscDrawAppendTitle - Appends to the title of a PetscDraw context.
Not collective (any processor or all can call this)
Input Parameters:
+ draw - the graphics context
- title - the title
Note:
A copy of the string is made, so you may destroy the
title string after calling this routine.
Level: advanced
.seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
@*/
PetscErrorCode PetscDrawAppendTitle(PetscDraw draw,const char title[])
{
PetscErrorCode ierr;
size_t len1,len2,len;
char *newtitle;
PetscFunctionBegin;
PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
if (!title) PetscFunctionReturn(0);
if (draw->title) {
ierr = PetscStrlen(title,&len1);CHKERRQ(ierr);
ierr = PetscStrlen(draw->title,&len2);CHKERRQ(ierr);
len = len1 + len2;
ierr = PetscMalloc1((len + 1),&newtitle);CHKERRQ(ierr);
ierr = PetscStrcpy(newtitle,draw->title);CHKERRQ(ierr);
ierr = PetscStrcat(newtitle,title);CHKERRQ(ierr);
ierr = PetscFree(draw->title);CHKERRQ(ierr);
draw->title = newtitle;
} else {
ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr);
}
if (draw->ops->settitle) {
ierr = (*draw->ops->settitle)(draw,draw->title);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例8: PetscViewerFileClose_ASCII
static PetscErrorCode PetscViewerFileClose_ASCII(PetscViewer viewer)
{
PetscErrorCode ierr;
PetscMPIInt rank;
PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data;
int err;
PetscFunctionBegin;
ierr = MPI_Comm_rank(((PetscObject)viewer)->comm,&rank);CHKERRQ(ierr);
if (!rank && vascii->fd != stderr && vascii->fd != PETSC_STDOUT) {
if (vascii->fd && vascii->closefile) {
err = fclose(vascii->fd);
if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file");
}
if (vascii->storecompressed) {
char par[PETSC_MAX_PATH_LEN],buf[PETSC_MAX_PATH_LEN];
FILE *fp;
ierr = PetscStrcpy(par,"gzip ");CHKERRQ(ierr);
ierr = PetscStrcat(par,vascii->filename);CHKERRQ(ierr);
#if defined(PETSC_HAVE_POPEN)
ierr = PetscPOpen(PETSC_COMM_SELF,PETSC_NULL,par,"r",&fp);CHKERRQ(ierr);
if (fgets(buf,1024,fp)) {
SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error from compression command %s\n%s",par,buf);
}
ierr = PetscPClose(PETSC_COMM_SELF,fp);CHKERRQ(ierr);
#else
SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"Cannot run external programs on this machine");
#endif
}
}
ierr = PetscFree(vascii->filename);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例9: PetscViewerFileSetName_MPIIO
PetscErrorCode PetscViewerFileSetName_MPIIO(PetscViewer viewer,const char name[])
{
PetscMPIInt rank;
PetscErrorCode ierr;
size_t len;
PetscViewer_Binary *vbinary = (PetscViewer_Binary*)viewer->data;
char *gz;
PetscBool found;
PetscFileMode type = vbinary->btype;
PetscFunctionBegin;
if (type == (PetscFileMode) -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Must call PetscViewerFileSetMode() before PetscViewerFileSetName()");
ierr = PetscViewerFileClose_MPIIO(viewer);CHKERRQ(ierr);
ierr = PetscOptionsGetBool(((PetscObject)viewer)->prefix,"-viewer_binary_skip_info",&vbinary->skipinfo,NULL);CHKERRQ(ierr);
ierr = PetscOptionsGetBool(((PetscObject)viewer)->prefix,"-viewer_binary_skip_options",&vbinary->skipoptions,NULL);CHKERRQ(ierr);
ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRQ(ierr);
ierr = PetscStrallocpy(name,&vbinary->filename);CHKERRQ(ierr);
vbinary->storecompressed = PETSC_FALSE;
/* only first processor opens file if writeable */
if (type == FILE_MODE_READ) {
MPI_File_open(PetscObjectComm((PetscObject)viewer),vbinary->filename,MPI_MODE_RDONLY,MPI_INFO_NULL,&vbinary->mfdes);CHKERRQ(ierr);
} else if (type == FILE_MODE_WRITE) {
MPI_File_open(PetscObjectComm((PetscObject)viewer),vbinary->filename,MPI_MODE_WRONLY | MPI_MODE_CREATE,MPI_INFO_NULL,&vbinary->mfdes);CHKERRQ(ierr);
}
/*
try to open info file: all processors open this file if read only
Below is identical code to the code for Binary above, should be put in seperate routine
*/
if (!vbinary->skipinfo && (!rank || type == FILE_MODE_READ)) {
char infoname[PETSC_MAX_PATH_LEN],iname[PETSC_MAX_PATH_LEN];
ierr = PetscStrcpy(infoname,name);CHKERRQ(ierr);
/* remove .gz if it ends library name */
ierr = PetscStrstr(infoname,".gz",&gz);CHKERRQ(ierr);
if (gz) {
ierr = PetscStrlen(gz,&len);CHKERRQ(ierr);
if (len == 3) *gz = 0;
}
ierr = PetscStrcat(infoname,".info");CHKERRQ(ierr);
ierr = PetscFixFilename(infoname,iname);CHKERRQ(ierr);
if (type == FILE_MODE_READ) {
ierr = PetscFileRetrieve(PetscObjectComm((PetscObject)viewer),iname,infoname,PETSC_MAX_PATH_LEN,&found);CHKERRQ(ierr);
ierr = PetscOptionsInsertFile(PetscObjectComm((PetscObject)viewer),infoname,PETSC_FALSE);CHKERRQ(ierr);
} else {
vbinary->fdes_info = fopen(infoname,"w");
if (!vbinary->fdes_info) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Cannot open .info file %s for writing",infoname);
}
}
#if defined(PETSC_USE_LOG)
PetscLogObjectState((PetscObject)viewer,"File: %s",name);
#endif
PetscFunctionReturn(0);
}
示例10: PetscViewerFileClose_Binary
static PetscErrorCode PetscViewerFileClose_Binary(PetscViewer v)
{
PetscViewer_Binary *vbinary = (PetscViewer_Binary*)v->data;
PetscErrorCode ierr;
PetscMPIInt rank;
int err;
PetscFunctionBegin;
ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)v),&rank);CHKERRQ(ierr);
if ((!rank || vbinary->btype == FILE_MODE_READ) && vbinary->fdes) {
close(vbinary->fdes);
if (!rank && vbinary->storecompressed) {
char par[PETSC_MAX_PATH_LEN],buf[PETSC_MAX_PATH_LEN];
FILE *fp;
/* compress the file */
ierr = PetscStrcpy(par,"gzip -f ");CHKERRQ(ierr);
ierr = PetscStrcat(par,vbinary->filename);CHKERRQ(ierr);
#if defined(PETSC_HAVE_POPEN)
ierr = PetscPOpen(PETSC_COMM_SELF,NULL,par,"r",&fp);CHKERRQ(ierr);
if (fgets(buf,1024,fp)) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error from command %s\n%s",par,buf);
ierr = PetscPClose(PETSC_COMM_SELF,fp,NULL);CHKERRQ(ierr);
#else
SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"Cannot run external programs on this machine");
#endif
}
}
if (vbinary->fdes_info) {
err = fclose(vbinary->fdes_info);
if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file");
}
ierr = PetscFree(vbinary->filename);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例11: PetscLs
PetscErrorCode PetscLs(MPI_Comm comm,const char libname[],char found[],size_t tlen,PetscBool *flg)
{
PetscErrorCode ierr;
size_t len;
char *f,program[PETSC_MAX_PATH_LEN];
FILE *fp;
PetscFunctionBegin;
ierr = PetscStrcpy(program,"ls ");CHKERRQ(ierr);
ierr = PetscStrcat(program,libname);CHKERRQ(ierr);
#if defined(PETSC_HAVE_POPEN)
ierr = PetscPOpen(comm,PETSC_NULL,program,"r",&fp);CHKERRQ(ierr);
#else
SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"Cannot run external programs on this machine");
#endif
f = fgets(found,tlen,fp);
if (f) *flg = PETSC_TRUE; else *flg = PETSC_FALSE;
while (f) {
ierr = PetscStrlen(found,&len);CHKERRQ(ierr);
f = fgets(found+len,tlen-len,fp);
}
if (*flg) {ierr = PetscInfo2(0,"ls on %s gives \n%s\n",libname,found);CHKERRQ(ierr);}
#if defined(PETSC_HAVE_POPEN)
ierr = PetscPClose(comm,fp);CHKERRQ(ierr);
#else
SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"Cannot run external programs on this machine");
#endif
PetscFunctionReturn(0);
}
示例12: PetscGoogleDriveRefresh
/*@C
PetscURLShorten - Uses Google's service to get a short url for a long url
Input Parameters:
+ url - long URL you want shortened
- lenshorturl - length of buffer to contain short URL
Output Parameter:
. shorturl - the shortened URL
.seealso: PetscGoogleDriveRefresh(), PetscGoogleDriveUpload(), PetscGoogleDriveAuthorize()
@*/
PetscErrorCode PetscURLShorten(const char url[],char shorturl[],size_t lenshorturl)
{
SSL_CTX *ctx;
SSL *ssl;
int sock;
PetscErrorCode ierr;
char buff[1024],body[512];
PetscBool found;
PetscFunctionBegin;
ierr = PetscSSLInitializeContext(&ctx);
CHKERRQ(ierr);
ierr = PetscHTTPSConnect("www.googleapis.com",443,ctx,&sock,&ssl);
CHKERRQ(ierr);
ierr = PetscStrcpy(body,"{");
CHKERRQ(ierr);
ierr = PetscPushJSONValue(body,"longUrl",url,sizeof(body)-2);
CHKERRQ(ierr);
ierr = PetscStrcat(body,"}");
CHKERRQ(ierr);
ierr = PetscHTTPSRequest("POST","www.googleapis.com/urlshortener/v1/url",NULL,"application/json",body,ssl,buff,sizeof(buff));
CHKERRQ(ierr);
ierr = PetscSSLDestroyContext(ctx);
CHKERRQ(ierr);
close(sock);
ierr = PetscPullJSONValue(buff,"id",shorturl,lenshorturl,&found);
CHKERRQ(ierr);
if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Google drive did not return short URL");
PetscFunctionReturn(0);
}
示例13: PCBDDCScalingSetUp_Deluxe_Private
static PetscErrorCode PCBDDCScalingSetUp_Deluxe_Private(PC pc)
{
PC_BDDC *pcbddc=(PC_BDDC*)pc->data;
PCBDDCDeluxeScaling deluxe_ctx=pcbddc->deluxe_ctx;
PCBDDCSubSchurs sub_schurs = pcbddc->sub_schurs;
PetscErrorCode ierr;
PetscFunctionBegin;
if (!sub_schurs->n_subs) {
PetscFunctionReturn(0);
}
/* Create work vectors for sequential part of deluxe */
ierr = MatCreateVecs(sub_schurs->S_Ej_all,&deluxe_ctx->seq_work1,&deluxe_ctx->seq_work2);CHKERRQ(ierr);
/* Compute deluxe sequential scatter */
if (sub_schurs->reuse_mumps && !sub_schurs->is_dir) {
PCBDDCReuseMumps reuse_mumps = sub_schurs->reuse_mumps;
ierr = PetscObjectReference((PetscObject)reuse_mumps->correction_scatter_B);CHKERRQ(ierr);
deluxe_ctx->seq_scctx = reuse_mumps->correction_scatter_B;
} else {
ierr = VecScatterCreate(pcbddc->work_scaling,sub_schurs->is_Ej_all,deluxe_ctx->seq_work1,NULL,&deluxe_ctx->seq_scctx);CHKERRQ(ierr);
}
/* Create Mat object for deluxe scaling */
ierr = PetscObjectReference((PetscObject)sub_schurs->S_Ej_all);CHKERRQ(ierr);
deluxe_ctx->seq_mat = sub_schurs->S_Ej_all;
if (sub_schurs->sum_S_Ej_all) { /* if this matrix is present, then we need to create the KSP object to invert it */
PC pc_temp;
MatSolverPackage solver=NULL;
char ksp_prefix[256];
size_t len;
ierr = KSPCreate(PETSC_COMM_SELF,&deluxe_ctx->seq_ksp);CHKERRQ(ierr);
ierr = KSPSetOperators(deluxe_ctx->seq_ksp,sub_schurs->sum_S_Ej_all,sub_schurs->sum_S_Ej_all);CHKERRQ(ierr);
ierr = KSPSetType(deluxe_ctx->seq_ksp,KSPPREONLY);CHKERRQ(ierr);
ierr = KSPGetPC(deluxe_ctx->seq_ksp,&pc_temp);CHKERRQ(ierr);
ierr = PCSetType(pc_temp,PCLU);CHKERRQ(ierr);
ierr = KSPGetPC(pcbddc->ksp_D,&pc_temp);CHKERRQ(ierr);
ierr = PCFactorGetMatSolverPackage(pc_temp,(const MatSolverPackage*)&solver);CHKERRQ(ierr);
if (solver) {
PC new_pc;
PCType type;
ierr = PCGetType(pc_temp,&type);CHKERRQ(ierr);
ierr = KSPGetPC(deluxe_ctx->seq_ksp,&new_pc);CHKERRQ(ierr);
ierr = PCSetType(new_pc,type);CHKERRQ(ierr);
ierr = PCFactorSetMatSolverPackage(new_pc,solver);CHKERRQ(ierr);
}
ierr = PetscStrlen(((PetscObject)(pcbddc->ksp_D))->prefix,&len);CHKERRQ(ierr);
len -= 10; /* remove "dirichlet_" */
ierr = PetscStrncpy(ksp_prefix,((PetscObject)(pcbddc->ksp_D))->prefix,len+1);CHKERRQ(ierr);
ierr = PetscStrcat(ksp_prefix,"deluxe_");CHKERRQ(ierr);
ierr = KSPSetOptionsPrefix(deluxe_ctx->seq_ksp,ksp_prefix);CHKERRQ(ierr);
ierr = KSPSetFromOptions(deluxe_ctx->seq_ksp);CHKERRQ(ierr);
ierr = KSPSetUp(deluxe_ctx->seq_ksp);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例14: TestFieldProjection
static PetscErrorCode TestFieldProjection(DM dm, DM auxdm, DMLabel label, Vec la, const char name[], AppCtx *user)
{
PetscErrorCode (**afuncs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *);
void (**funcs)(PetscInt, PetscInt, PetscInt,
const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]);
Vec lx, lu;
PetscInt Nf, f;
PetscInt val[1] = {1};
char lname[PETSC_MAX_PATH_LEN];
PetscErrorCode ierr;
PetscFunctionBeginUser;
if (auxdm) {
ierr = PetscObjectCompose((PetscObject) dm, "dmAux", (PetscObject) auxdm);CHKERRQ(ierr);
ierr = PetscObjectCompose((PetscObject) dm, "A", (PetscObject) la);CHKERRQ(ierr);
}
ierr = DMGetNumFields(dm, &Nf);CHKERRQ(ierr);
ierr = PetscMalloc2(Nf, &funcs, Nf, &afuncs);CHKERRQ(ierr);
for (f = 0; f < Nf; ++f) afuncs[f] = linear;
funcs[0] = linear_vector;
funcs[1] = linear_scalar;
ierr = DMGetLocalVector(dm, &lu);CHKERRQ(ierr);
ierr = PetscStrcpy(lname, "Local Field Input ");CHKERRQ(ierr);
ierr = PetscStrcat(lname, name);CHKERRQ(ierr);
ierr = PetscObjectSetName((PetscObject) lu, lname);CHKERRQ(ierr);
if (!label) {ierr = DMProjectFunctionLocal(dm, 0.0, afuncs, NULL, INSERT_VALUES, lu);CHKERRQ(ierr);}
else {ierr = DMProjectFunctionLabelLocal(dm, 0.0, label, 1, val, 0, NULL, afuncs, NULL, INSERT_VALUES, lu);CHKERRQ(ierr);}
ierr = VecViewFromOptions(lu, NULL, "-local_input_view");CHKERRQ(ierr);
ierr = DMGetLocalVector(dm, &lx);CHKERRQ(ierr);
ierr = PetscStrcpy(lname, "Local Field ");CHKERRQ(ierr);
ierr = PetscStrcat(lname, name);CHKERRQ(ierr);
ierr = PetscObjectSetName((PetscObject) lx, lname);CHKERRQ(ierr);
if (!label) {ierr = DMProjectFieldLocal(dm, 0.0, lu, funcs, INSERT_VALUES, lx);CHKERRQ(ierr);}
else {ierr = DMProjectFieldLabelLocal(dm, 0.0, label, 1, val, 0, NULL, lu, funcs, INSERT_VALUES, lx);CHKERRQ(ierr);}
ierr = VecViewFromOptions(lx, NULL, "-local_field_view");CHKERRQ(ierr);
ierr = DMRestoreLocalVector(dm, &lx);CHKERRQ(ierr);
ierr = DMRestoreLocalVector(dm, &lu);CHKERRQ(ierr);
ierr = PetscFree2(funcs, afuncs);CHKERRQ(ierr);
if (auxdm) {
ierr = PetscObjectCompose((PetscObject) dm, "dmAux", NULL);CHKERRQ(ierr);
ierr = PetscObjectCompose((PetscObject) dm, "A", NULL);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例15: PetscPClose
/*@C
PetscPOpen - Runs a program on processor zero and sends either its input or output to
a file.
Logically Collective on MPI_Comm, but only process 0 runs the command
Input Parameters:
+ comm - MPI communicator, only processor zero runs the program
. machine - machine to run command on or NULL, or string with 0 in first location
. program - name of program to run
- mode - either r or w
Output Parameter:
. fp - the file pointer where program input or output may be read or NULL if don't care
Level: intermediate
Notes:
Use PetscPClose() to close the file pointer when you are finished with it
Does not work under Windows
If machine is not provided will use the value set with PetsPOpenSetMachine() if that was provided, otherwise
will use the machine running node zero of the communicator
The program string may contain ${DISPLAY}, ${HOMEDIRECTORY} or ${WORKINGDIRECTORY}; these
will be replaced with relevent values.
.seealso: PetscFOpen(), PetscFClose(), PetscPClose(), PetscPOpenSetMachine()
@*/
PetscErrorCode PetscPOpen(MPI_Comm comm,const char machine[],const char program[],const char mode[],FILE **fp)
{
PetscErrorCode ierr;
PetscMPIInt rank;
size_t i,len,cnt;
char commandt[PETSC_MAX_PATH_LEN],command[PETSC_MAX_PATH_LEN];
FILE *fd;
PetscFunctionBegin;
/* all processors have to do the string manipulation because PetscStrreplace() is a collective operation */
if (PetscPOpenMachine[0] || (machine && machine[0])) {
ierr = PetscStrcpy(command,"ssh ");CHKERRQ(ierr);
if (PetscPOpenMachine[0]) {
ierr = PetscStrcat(command,PetscPOpenMachine);CHKERRQ(ierr);
} else {
ierr = PetscStrcat(command,machine);CHKERRQ(ierr);
}
ierr = PetscStrcat(command," \" export DISPLAY=${DISPLAY}; ");CHKERRQ(ierr);
/*
Copy program into command but protect the " with a \ in front of it
*/
ierr = PetscStrlen(command,&cnt);CHKERRQ(ierr);
ierr = PetscStrlen(program,&len);CHKERRQ(ierr);
for (i=0; i<len; i++) {
if (program[i] == '\"') command[cnt++] = '\\';
command[cnt++] = program[i];
}
command[cnt] = 0;
ierr = PetscStrcat(command,"\"");CHKERRQ(ierr);
} else {
ierr = PetscStrcpy(command,program);CHKERRQ(ierr);
}
ierr = PetscStrreplace(comm,command,commandt,1024);CHKERRQ(ierr);
ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
if (!rank) {
ierr = PetscInfo1(0,"Running command :%s\n",commandt);CHKERRQ(ierr);
if (!(fd = popen(commandt,mode))) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot run command %s",commandt);
if (fp) *fp = fd;
}
PetscFunctionReturn(0);
}