dErr dUnitsView(dUnits un,dViewer viewer) { dBool iascii; dErr err; dFunctionBegin; dValidHeader(un,dUNITS_CLASSID,1); if (!viewer) {err = PetscViewerASCIIGetStdout(((dObject)un)->comm,&viewer);dCHK(err);} dValidHeader(viewer,PETSC_VIEWER_CLASSID,2); PetscCheckSameComm(un,1,viewer,2); err = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);dCHK(err); if (iascii) { err = PetscObjectPrintClassNamePrefixType((PetscObject)un,viewer,"Units Manager");dCHK(err); err = PetscViewerASCIIPushTab(viewer);dCHK(err); for (dInt i=0; i<un->nalloc && un->list[i]; i++) { dUnit u = un->list[i]; err = PetscViewerASCIIPrintf(viewer,"%-12s: 1 internal unit = %10.4e %s (%s) = %10.4e %s\n", dUnitQuantityName(u),dUnitDimensionalize(u,1.0),dUnitName(u),dUnitShortName(u),dUnitDimensionalizeSI(u,1.0),dUnitSIName(u));dCHK(err); err = PetscViewerASCIIPrintf(viewer,"%-12s 1 %s = %10.4e %s\n","",dUnitShortName(u),dUnitDimensionalizeSI(u,dUnitNonDimensionalize(u,1.0)),dUnitSIName(u));dCHK(err); } err = PetscViewerASCIIPopTab(viewer);dCHK(err); } else dERROR(((dObject)un)->comm,PETSC_ERR_SUP,"Viewer type %s not supported",((PetscObject)viewer)->type_name); dFunctionReturn(0); }
dErr dUnitsSetFromOptions(dUnits un) { dErr err; dFunctionBegin; dValidHeader(un,dUNITS_CLASSID,1); err = PetscOptionsBegin(((PetscObject)un)->comm,((PetscObject)un)->prefix,"Units manager","dUnits");dCHK(err); for (dUnitsBaseType btype = 0; btype < dUNITS_MAX; btype++) { char opt[256],help[256],uspec[256]; dReal commonpersi = 1.0,scale = 1.0; dBool flg; err = PetscSNPrintf(opt,sizeof opt,"-units_%s",dUnitsBaseTypes[btype]);dCHK(err); err = PetscSNPrintf(uspec,sizeof uspec,"%s:%s:%f:%f",dUnitsBaseNamesSI[btype],dUnitsBaseNamesShortSI[btype],commonpersi,scale); err = PetscSNPrintf(help,sizeof help,"Common name:short name:one common unit of %s expressed in %s:common units per non-dimensionalized",dUnitsBaseTypes[btype],dUnitsBaseNamesSI[btype]);dCHK(err); err = PetscOptionsString(opt,help,"dUnitsSetBase",uspec,uspec,sizeof uspec,&flg);dCHK(err); if (flg) { char *longname,*shortname,*buf1,*buf2; longname = uspec; if (!(shortname = strchr(longname,':'))) dERROR(((dObject)un)->comm,PETSC_ERR_USER,"The field specification '%s' is ':' delimited",opt); *shortname++ = 0; if (!(buf1 = strchr(shortname,':'))) dERROR(((dObject)un)->comm,PETSC_ERR_USER,"The field specification for '%s' needs four arguments, but only two given",longname); *buf1++ = 0; if (!(buf2 = strchr(buf1,':'))) dERROR(((dObject)un)->comm,PETSC_ERR_USER,"The field specification for '%s' needs four arguments, but only three given",longname); *buf2++ = 0; if (sscanf(buf1,"%lf",&commonpersi) != 1) dERROR(((dObject)un)->comm,PETSC_ERR_USER,"Size of common unit '%s' could not be parsed from '%s'",longname,buf1); if (sscanf(buf2,"%lf",&scale) != 1) dERROR(((dObject)un)->comm,PETSC_ERR_USER,"Scale for common unit '%s' could not be parsed from '%s'",longname,buf2); err = dUnitsSetBase(un,btype,longname,shortname,commonpersi,scale,NULL);dCHK(err); } } err = PetscOptionsEnd();dCHK(err); dFunctionReturn(0); }
dErr dFSGetBoundingBox(dFS fs,dReal bbox[3][2]) { dErr err; Vec X; const dScalar *x; dInt n; dFunctionBegin; for (dInt i=0; i<3; i++) { bbox[i][0] = PETSC_MAX_REAL; bbox[i][1] = PETSC_MIN_REAL; } err = dFSGetGeometryVectorExpanded(fs,&X); dCHK(err); err = VecGetLocalSize(X,&n); dCHK(err); err = VecGetArrayRead(X,&x); dCHK(err); for (dInt i=0; i<n; i++) { dInt j = i%3; bbox[j][0] = dMin(bbox[j][0],x[i]); bbox[j][1] = dMax(bbox[j][1],x[i]); } err = VecRestoreArrayRead(X,&x); dCHK(err); dFunctionReturn(0); }
static dErr VHTCaseSolution_Jako(VHTCase scase,const dReal x[3],dScalar rhou[],dScalar drhou[],dScalar *p,dScalar dp[],dScalar *E,dScalar dE[]) { /* Defines inhomogeneous Dirichlet boundary conditions */ VHTCase_Jako *jako = scase->data; struct VHTRheology *rheo = &scase->rheo; double h,b; dInt pixel,xp,yp; dReal u[3],dh[2] = {0,0}; dScalar e; dErr err; dFunctionBegin; err = JakoFindPixel(scase,x,&xp,&yp);dCHK(err); pixel = yp*jako->nx + xp; h = jako->h[pixel]; b = jako->b[pixel]; err = JakoGradient2(scase,jako->h,xp,yp,dh);dCHK(err); err = JakoSIAVelocity(scase,b,h,dh,x[2],u);dCHK(err); err = JakoInternalEnergy(scase,b,h,x,&e);dCHK(err); for (dInt i=0; i<3; i++) rhou[i] = rheo->rhoi * u[i]; // Just assume constant density for (dInt i=0; i<9; i++) drhou[i] = 0; *p = rheo->rhoi * rheo->gravity[2] * (h - x[2]); for (dInt i=0; i<3; i++) dp[i] = -rheo->rhoi * rheo->gravity[i]; *E = rheo->rhoi * e; for (dInt i=0; i<3; i++) dE[i] = 0; dFunctionReturn(0); }
static dErr dUnitsAssignName(dUnits un,const char *(*namer)(dUnit),const char *proposed,dInt n,const dReal expon[],char **assigned) { dErr err; char buf[1024],*p = buf; dInt left = 1024; dFunctionBegin; if (proposed) { err = PetscStrallocpy(proposed,assigned);dCHK(err); dFunctionReturn(0); } buf[0] = 0; for (dInt i=0; i<n; i++) { const char *s; dUnit base; dInt len; if (expon[i] == 0) continue; err = dUnitsGetBase(un,i,&base);dCHK(err); s = namer(base); if (expon[i] == 1) len = snprintf(p,left,"%s ",s); else if (round(expon[i]) == expon[i]) len = snprintf(p,left,"%s^%1.0f ",s,expon[i]); else len = snprintf(p,left,"%s^%f ",s,expon[i]); left -= len; p += len; } p[-1] = 0; // Kill trailing space err = PetscStrallocpy(buf,assigned);dCHK(err); dFunctionReturn(0); }
dErr dUnitsInitializePackage(const dUNUSED char path[]) { dErr err; dFunctionBegin; if (dUnitsPackageInitialized) dFunctionReturn(0); dUnitsPackageInitialized = dTRUE; err = PetscClassIdRegister("dUnits",&dUNITS_CLASSID);dCHK(err); err = PetscRegisterFinalize(dUnitsFinalizePackage);dCHK(err); dFunctionReturn(0); }
static dErr VHTCaseView_Jako(VHTCase scase,PetscViewer viewer) { VHTCase_Jako *jako = scase->data; dErr err; dFunctionBegin; err = PetscViewerASCIIPrintf(viewer,"VHTCase: Jakobshavn\n");dCHK(err); err = JakoViewWKT(jako->utmref,"UTM",viewer);dCHK(err); err = JakoViewWKT(jako->llref,"LonLat",viewer);dCHK(err); err = JakoViewWKT(jako->ianref,"Ian",viewer);dCHK(err); dFunctionReturn(0); }
dErr dFSRotationDestroy(dFSRotation *rot) { dErr err; dFunctionBegin; if (!*rot) dFunctionReturn(0); dValidHeader(*rot,dFSROT_CLASSID,1); err = ISDestroy(&(*rot)->is);dCHK(err); err = VecDestroy(&(*rot)->strong);dCHK(err); err = dFree2((*rot)->rmat,(*rot)->nstrong);dCHK(err); err = PetscHeaderDestroy(rot);dCHK(err); dFunctionReturn(0); }
static dErr VecStateSync_Private(Vec x,Vec y) { dInt xstate,ystate; dErr err; dFunctionBegin; dValidHeader(x,VEC_CLASSID,1); dValidHeader(y,VEC_CLASSID,2); err = PetscObjectStateQuery((dObject)x,&xstate);dCHK(err); err = PetscObjectStateQuery((dObject)y,&ystate);dCHK(err); err = PetscObjectSetState((dObject)x,dMaxInt(xstate,ystate));dCHK(err); err = PetscObjectSetState((dObject)y,dMaxInt(xstate,ystate));dCHK(err); dFunctionReturn(0); }
dErr VecDohpZeroEntries(Vec v) { dErr err; dBool isdohp; Vec c; dFunctionBegin; dValidHeader(v,VEC_CLASSID,1); err = PetscTypeCompare((dObject)v,VECDOHP,&isdohp);dCHK(err); if (!isdohp) dERROR(PETSC_COMM_SELF,PETSC_ERR_SUP,"Vector type %s",((dObject)v)->type_name); err = VecDohpGetClosure(v,&c);dCHK(err); err = VecZeroEntries(c);dCHK(err); err = VecDohpRestoreClosure(v,&c);dCHK(err); dFunctionReturn(0); }
dErr VecDohpRestoreClosure(Vec v,Vec *c) { dErr err; dBool isdohp; dFunctionBegin; dValidHeader(v,VEC_CLASSID,1); dValidPointer(c,2); err = PetscTypeCompare((dObject)v,VECDOHP,&isdohp);dCHK(err); if (!isdohp) dERROR(PETSC_COMM_SELF,1,"Vector type %s does not have closure",((dObject)v)->type_name); if (*c != ((Vec_MPI*)v->data)->localrep) dERROR(PETSC_COMM_SELF,1,"attempting to restore incorrect closure"); err = VecStateSync_Private(v,*c);dCHK(err); err = PetscObjectDereference((dObject)*c);dCHK(err); *c = NULL; dFunctionReturn(0); }
/** Set rotation for certain nodes in a function space * * @param fs the function space * @param is index set of nodes to rotate, sequential, with respect blocks of local vector * @param rot Rotation matrices at all nodes in \a is. Should have length \c bs*bs*size(is). * @param ns number of dofs to enforce strongly at each node (every entry must have 0<=ns[i]<=bs) * @param v Vector of values for strongly enforced dofs * * @example Consider 2D flow over a bed with known melt rates. Suppose the local velocity vector is * * [u0x,u0y; u1x,u1y; u2x,u2y; u3x,u3y | u4x,u4y] * * (4 owned blocks, one ghosted block) and nodes 1,4 are on the slip boundary with normal and tangent vectors n1,t1,n4,t4 * and melt rates r1,r4. To enforce the melt rate strongly, use * * \a is = [1,4] * \a rot = [n10,n11,t10,t11, n40,n41,t40,t41] * \a ns = [1,1] * \a v = [r1,r4] * * The rotated vector will become (. = \cdot) * * [u0x,u0y; u1.n1,u1.t1; u2x,u2y; u3x,u3y | u4.n4,u4.t4] * * and strongly enforcing melt rate produces the global vector * * [u0x,u0y; r1,u1.t1; u2x,u2y; u3x,u3y | r4,u4.t4] . * * This is what the solver sees, the Jacobian will always have rows and columns of the identity corresponding to the * strongly enforced components (2,8 of the local vector) and the residual will always be 0 in these components. Hence * the Newton step v will always be of the form * * [v0x,v0y; 0,v1y; v2x,v2y; v3x,v3y | 0,v4y] . **/ dErr dFSRotationCreate(dFS fs,IS is,dReal rmat[],dInt ns[],Vec v,dFSRotation *inrot) { dFSRotation rot; dInt bs,n; dErr err; dFunctionBegin; dValidHeader(fs,DM_CLASSID,1); dValidHeader(is,IS_CLASSID,2); dValidRealPointer(rmat,3); dValidIntPointer(ns,4); dValidHeader(v,VEC_CLASSID,5); dValidPointer(inrot,6); *inrot = 0; err = PetscHeaderCreate(rot,_p_dFSRotation,struct _dFSRotationOps,dFSROT_CLASSID,"dFSRotation","Local function space rotation","FS",PETSC_COMM_SELF,dFSRotationDestroy,dFSRotationView);dCHK(err); err = dFSGetBlockSize(fs,&bs);dCHK(err); rot->bs = bs; err = ISGetSize(is,&n);dCHK(err); rot->n = n; err = PetscObjectReference((PetscObject)is);dCHK(err); rot->is = is; err = PetscObjectReference((PetscObject)v);dCHK(err); rot->strong = v; for (dInt i=0; i<n; i++) { if (ns[i] < 0 || bs < ns[i]) dERROR(PETSC_COMM_SELF,1,"Number of strong dofs must be between 0 and bs=%d (inclusive)",bs); /* \todo Check that every rmat is orthogonal */ } err = dMallocA2(n*bs*bs,&rot->rmat,n,&rot->nstrong);dCHK(err); err = dMemcpy(rot->rmat,rmat,n*bs*bs*sizeof rmat[0]);dCHK(err); err = dMemcpy(rot->nstrong,ns,n*sizeof ns[0]);dCHK(err); *inrot = rot; dFunctionReturn(0); }
/** Get the closed form of a Dohp vector * * @note Dohp vectors are basically just MPI vectors, the only difference is that instead of a local form, we have a * closed form. We subvert .localrep to mean the closed form. * **/ dErr VecDohpGetClosure(Vec v,Vec *c) { Vec_MPI *vmpi; dBool isdohp; dErr err; dFunctionBegin; dValidHeader(v,VEC_CLASSID,1); dValidPointer(c,2); err = PetscTypeCompare((dObject)v,VECDOHP,&isdohp);dCHK(err); if (!isdohp) dERROR(PETSC_COMM_SELF,1,"Vector type %s does not have closure",((dObject)v)->type_name); vmpi = v->data; if (!vmpi->localrep) dERROR(PETSC_COMM_SELF,1,"Vector has no closure"); *c = vmpi->localrep; err = VecStateSync_Private(v,*c);dCHK(err); err = PetscObjectReference((dObject)*c);dCHK(err); dFunctionReturn(0); }
static dErr JakoFileDataView(GDALDatasetH filedata,const char *name,PetscViewer viewer) { dErr err; CPLErr cplerr; double geo[6],data[8*12]; int nx=8,ny=12,snx,sny; GDALRasterBandH band; dFunctionBegin; cplerr = GDALGetGeoTransform(filedata,geo); err = dRealTableView(2,3,geo,PETSC_VIEWER_STDOUT_WORLD,"%s:geo",name);dCHK(err); snx = GDALGetRasterXSize(filedata); sny = GDALGetRasterYSize(filedata); err = PetscViewerASCIIPrintf(viewer,"%s: nx=%d ny=%d\n",name,snx,sny);dCHK(err); band = GDALGetRasterBand(filedata,1); cplerr = GDALRasterIO(band,GF_Read,snx/2,sny/2,nx,ny,data,nx,ny,GDT_Float64,0,0);dCPLCHK(cplerr); err = dRealTableView(ny,nx,data,PETSC_VIEWER_STDOUT_WORLD,name);dCHK(err); dFunctionReturn(0); }
static dErr doMaterial(iMesh_Instance mesh,iBase_EntitySetHandle root) { static const char matSetName[] = "MAT_SET",matNumName[] = "MAT_NUM"; dMeshTag matSetTag,matNumTag; dMeshESH mat[2]; dMeshEH *ents; MeshListEH r=MLZ,v=MLZ; MeshListInt rvo=MLZ; MeshListReal x=MLZ; dReal fx,center[3],*matnum; dInt nents; dErr err; dFunctionBegin; iMesh_createTag(mesh,matSetName,1,iBase_INTEGER,&matSetTag,&err,sizeof(matSetName));dICHK(mesh,err); iMesh_createTag(mesh,matNumName,1,iBase_DOUBLE,&matNumTag,&err,sizeof(matNumName));dICHK(mesh,err); iMesh_getEntities(mesh,root,iBase_REGION,iMesh_ALL_TOPOLOGIES,MLREF(r),&err);dICHK(mesh,err); iMesh_getEntArrAdj(mesh,r.v,r.s,iBase_VERTEX,MLREF(v),MLREF(rvo),&err);dICHK(mesh,err); iMesh_getVtxArrCoords(mesh,v.v,v.s,iBase_INTERLEAVED,MLREF(x),&err);dICHK(mesh,err); err = dMalloc(r.s*sizeof(ents[0]),&ents);dCHK(err); err = dMalloc(r.s*sizeof(matnum[0]),&matnum);dCHK(err); for (dInt i=0; i<2; i++) { iMesh_createEntSet(mesh,0,&mat[i],&err);dICHK(mesh,err); iMesh_setEntSetData(mesh,mat[i],matSetTag,(char*)&i,sizeof(i),&err);dICHK(mesh,err); nents = 0; for (dInt j=0; j<r.s; j++) { dGeomVecMeanI(8,x.v+3*rvo.v[j],center); fx = sqrt(dGeomDotProd(center,center)); /* material 0 if inside the unit ball, else material 1 */ if (i == (fx < 1.0) ? 0 : 1) { ents[nents] = r.v[j]; matnum[nents] = 1.0 * i; nents++; } } iMesh_addEntArrToSet(mesh,ents,nents,mat[i],&err);dICHK(mesh,err); iMesh_setArrData(mesh,ents,nents,matNumTag,(char*)matnum,nents*(int)sizeof(matnum[0]),&err);dICHK(mesh,err); } err = dFree(ents);dCHK(err); err = dFree(matnum);dCHK(err); MeshListFree(r); MeshListFree(v); MeshListFree(rvo); MeshListFree(x); dFunctionReturn(0); }
dErr dViewerDHMSetTimeUnits(dViewer viewer,const char *units,dReal scale) { dErr err,(*r)(dViewer,const char*,dReal); dFunctionBegin; err = PetscObjectQueryFunction((PetscObject)viewer,"dViewerDHMSetTimeUnits_C",(void(**)(void))&r);dCHK(err); if (r) { err = (*r)(viewer,units,scale);dCHK(err); } dFunctionReturn(0); }
dErr dViewerDHMSetTime(dViewer viewer,dReal time) { dErr err,(*r)(dViewer,dReal); dFunctionBegin; err = PetscObjectQueryFunction((PetscObject)viewer,"dViewerDHMSetTime_C",(void(**)(void))&r);dCHK(err); if (r) { err = (*r)(viewer,time);dCHK(err); } dFunctionReturn(0); }
static dErr doGlobalNumber(iMesh_Instance mesh,iBase_EntitySetHandle root) { MeshListEH ents=MLZ; int owned,offset,*number; dMeshTag idTag; dErr err; dFunctionBegin; iMesh_getEntities(mesh,root,iBase_ALL_TYPES,iMesh_ALL_TOPOLOGIES,MLREF(ents),&err);dICHK(mesh,err); err = dMalloc(ents.s*sizeof(number[0]),&number);dCHK(err); owned = ents.s; offset = 0; for (int i=0; i<owned; i++) { number[i] = offset + i; } iMesh_createTag(mesh,"dohp_global_number",1,iBase_INTEGER,&idTag,&err,sizeof("dohp_global_number"));dICHK(mesh,err); iMesh_setIntArrData(mesh,ents.v,owned,idTag,number,owned,&err);dICHK(mesh,err); err = dFree(number);dCHK(err); MeshListFree(ents); dFunctionReturn(0); }
static dErr JakoViewWKT(OGRSpatialReferenceH ref,const char *name,PetscViewer viewer) { dErr err; OGRErr oerr; char *wkt; dFunctionBegin; oerr = OSRExportToPrettyWkt(ref,&wkt,0);dOGRCHK(oerr); err = PetscViewerASCIIPrintf(viewer,"WKT %s: %s\n\n",name,wkt);dCHK(err); OGRFree(wkt); dFunctionReturn(0); }
/** dFSGetNodalCoordinateFS - Gets an FS the same size as the solution FS, but with block size 3 to hold nodal coordinates * */ dErr dFSGetNodalCoordinateFS(dFS fs,dFS *nfs) { dErr err; dFunctionBegin; if (!fs->nodalcoord.fs) { err = dFSRedimension(fs,3,dFS_INTERIOR,&fs->nodalcoord.fs); dCHK(err); } *nfs = fs->nodalcoord.fs; dFunctionReturn(0); }
dErr dOptionsRealUnits(const char opt[],const char text[],const char man[],dUnit unit,PetscReal defaultv,PetscReal *value,PetscBool *set) { char text2[512]; PetscReal default2,value2,one; dBool set2; dErr err; dFunctionBegin; if (unit) { default2 = dUnitDimensionalize(unit,defaultv); one = dUnitDimensionalize(unit,1); err = PetscSNPrintf(text2,sizeof text2,"%s [%G in %G %s]",text,defaultv,one,dUnitName(unit));dCHK(err); err = PetscOptionsReal(opt,text2,man,default2,&value2,&set2);dCHK(err); if (set2) *value = dUnitNonDimensionalize(unit,value2); if (set) *set = set2; } else { err = PetscSNPrintf(text2,sizeof text2,"%s [nondimensional]",text);dCHK(err); err = PetscOptionsReal(opt,text2,man,defaultv,value,set);dCHK(err); } dFunctionReturn(0); }
dErr VecCreateDohp(MPI_Comm comm,dInt bs,dInt n,dInt nc,dInt nghosts,const dInt ghosts[],Vec *v) { Vec_MPI *vmpi; Vec vc,vg; dScalar *a; dErr err; dFunctionBegin; dValidPointer(v,7); *v = 0; err = VecCreateGhostBlock(comm,bs,nc*bs,PETSC_DECIDE,nghosts,ghosts,&vc);dCHK(err); err = VecGetArray(vc,&a);dCHK(err); err = VecCreateMPIWithArray(comm,n*bs,PETSC_DECIDE,a,&vg);dCHK(err); err = VecRestoreArray(vc,&a);dCHK(err); err = VecSetBlockSize(vg,bs);dCHK(err); vmpi = vg->data; if (vmpi->localrep) dERROR(PETSC_COMM_SELF,1,"Vector has localrep, expected no localrep"); vmpi->localrep = vc; /* subvert this field to mean closed rep */ /* Since we subvect .localrep, VecDestroy_MPI will automatically destroy the closed form */ vg->ops->duplicate = VecDuplicate_Dohp; //vg->ops->destroy = VecDestroy_Dohp; /* It might be useful to set the (block) LocalToGlobal mapping here, but in the use case I have in mind, the user is * always working with the closed form anyway (in function evaluation). The \e matrix does need a customized * LocalToGlobal mapping. */ err = PetscObjectChangeTypeName((dObject)vg,VECDOHP);dCHK(err); *v = vg; dFunctionReturn(0); }
// Logically collective dErr dUnitsCreateUnit(dUnits un,const char *type,const char *longname,const char *shortname,dInt n,const dReal expon[],dUnit *newunit) { dErr err; dUnit unit; dFunctionBegin; dValidHeader(un,dUNITS_CLASSID,1); if (n < 1 || n > dUNITS_MAX) dERROR(((dObject)un)->comm,PETSC_ERR_ARG_OUTOFRANGE,"The number of exponents %D must be positive, but no larger than %D",n,(dInt)dUNITS_MAX); dValidRealPointer(expon,5); dValidPointer(newunit,6); err = dUnitsGetEmptyUnit_Private(un,&unit);dCHK(err); err = PetscStrallocpy(type,&unit->quantity);dCHK(err); err = dUnitsAssignName(un,dUnitName,longname,n,expon,&unit->longname);dCHK(err); err = dUnitsAssignName(un,dUnitShortName,shortname,n,expon,&unit->shortname);dCHK(err); err = dUnitsAssignName(un,dUnitSIName,NULL,n,expon,&unit->siname);dCHK(err); unit->toSI = 1.0; unit->toCommon = 1.0; for (dInt i=0; i<n; i++) { dUnit base; err = dUnitsGetBase(un,i,&base);dCHK(err); unit->toCommon *= PetscPowScalar(dUnitDimensionalize(base,1.0),expon[i]); unit->toSI *= PetscPowScalar(dUnitDimensionalizeSI(base,1.0),expon[i]); unit->expon[i] = expon[i]; } *newunit = unit; dFunctionReturn(0); }
dErr dUnitsFindUnit(dUnits un,const char *name,dUnit *unit) { dErr err; dFunctionBegin; *unit = NULL; for (dInt i=0; i<un->nalloc; i++) { dBool flg; dUnit t = un->list[i]; err = PetscStrcmp(t->longname,name,&flg);dCHK(err); if (flg) {*unit = t; break;} } dFunctionReturn(0); }
static dErr dUnitsGetEmptyUnit_Private(dUnits un,dUnit *unit) { dInt i; dErr err; dFunctionBegin; *unit = NULL; for (i=0; i<un->nalloc && un->list[i]; i++) ; if (i == un->nalloc) dERROR(((dObject)un)->comm,PETSC_ERR_SUP,"reallocation not implemented"); err = dCallocA(1,&un->list[i]);dCHK(err); un->list[i]->world = un; *unit = un->list[i]; dFunctionReturn(0); }
static dErr doGlobalID(iMesh_Instance mesh,iBase_EntitySetHandle root) { MeshListEH ents=MLZ; MeshListInt type=MLZ; int count[4] = {0,0,0,0}; int owned,*number; dMeshTag idTag; dErr err; dFunctionBegin; iMesh_getEntities(mesh,root,iBase_ALL_TYPES,iMesh_ALL_TOPOLOGIES,MLREF(ents),&err);dICHK(mesh,err); iMesh_getEntArrType(mesh,ents.v,ents.s,MLREF(type),&err);dICHK(mesh,err); err = dMalloc(ents.s*sizeof(number[0]),&number);dCHK(err); owned = ents.s; for (int i=0; i<owned; i++) { number[i] = count[type.v[i]]++; } iMesh_getTagHandle(mesh,"GLOBAL_ID",&idTag,&err,sizeof("GLOBAL_ID"));dICHK(mesh,err); iMesh_setIntArrData(mesh,ents.v,owned,idTag,number,owned,&err);dICHK(mesh,err); err = dFree(number);dCHK(err); MeshListFree(ents); MeshListFree(type); dFunctionReturn(0); }
static dErr createUniformTags(iMesh_Instance mesh,iBase_EntitySetHandle root) { dMeshTag itag,rtag; MeshListEH ents=MLZ; int *idata; double *rdata; dErr err; dFunctionBegin; iMesh_getEntities(mesh,root,iBase_ALL_TYPES,iMesh_ALL_TOPOLOGIES,MLREF(ents),&err);dICHK(mesh,err); err = dMalloc(ents.s*sizeof(idata[0]),&idata);dCHK(err); err = dMalloc(ents.s*sizeof(rdata[0]),&rdata);dCHK(err); for (dInt i=0; i<ents.s; i++) { idata[i] = -i; rdata[i] = -1.0*i; } iMesh_createTag(mesh,"UNIFORM_INT",1,iBase_INTEGER,&itag,&err,sizeof("UNIFORM_INT"));dICHK(mesh,err); iMesh_createTag(mesh,"UNIFORM_REAL",1,iBase_DOUBLE,&rtag,&err,sizeof("UNIFORM_REAL"));dICHK(mesh,err); iMesh_setIntArrData(mesh,ents.v,ents.s,itag,idata,ents.s,&err);dICHK(mesh,err); iMesh_setDblArrData(mesh,ents.v,ents.s,rtag,rdata,ents.s,&err);dICHK(mesh,err); MeshListFree(ents); dFree(idata); dFree(rdata); dFunctionReturn(0); }
/** Get the number of subelements and number of vertices of subelements. **/ dErr dFSGetSubElementMesh(dFS fs,dInt nelems,dInt nconn,dEntTopology topo[],dInt off[],dInt ind[]) { dErr err; dFunctionBegin; dValidHeader(fs,DM_CLASSID,1); dValidIntPointer(topo,4); dValidIntPointer(off,5); dValidIntPointer(ind,6); if (!fs->ops->getsubelementmesh) dERROR(PETSC_COMM_SELF,1,"not implemented"); err = (*fs->ops->getsubelementmesh)(fs,nelems,nconn,topo,off,ind); dCHK(err); dFunctionReturn(0); }
/** Get the number of subelements and number of vertices of subelements. * * @note the number of vertices is the same as the number of local nodes in closure vertor. **/ dErr dFSGetSubElementMeshSize(dFS fs,dInt *nelems,dInt *nverts,dInt *nconn) { dErr err; dFunctionBegin; dValidHeader(fs,DM_CLASSID,1); dValidIntPointer(nelems,2); dValidIntPointer(nverts,3); dValidIntPointer(nconn,4); if (!fs->ops->getsubelementmeshsize) dERROR(PETSC_COMM_SELF,1,"not implemented"); err = (*fs->ops->getsubelementmeshsize)(fs,nelems,nverts,nconn); dCHK(err); dFunctionReturn(0); }
/** Get displacements of every node in expanded vector. * * @param fs Function space * @param ingeom the new geometry vector with block size 3 and same number of blocks as points in the expanded vector. * * @note This is not suitable for use as a function space, * * @note It is important to get geometry associated with boundary sets because it will frequently be projected against * the boundary. **/ dErr dFSGetGeometryVectorExpanded(dFS fs,Vec *ingeom) { dErr err; dFunctionBegin; dValidHeader(fs,DM_CLASSID,1); dValidPointer(ingeom,2); *ingeom = 0; if (!fs->geometry.expanded) { err = dFSCreateGeometryFromMesh_Private(fs); dCHK(err); } *ingeom = fs->geometry.expanded; dFunctionReturn(0); }