Permalink
Browse files

viewers, implementation headers, initialization

* Add viewer functionality for dFS
* Install implementation headers (to facilitate certain user-extension)
* Add dInit()/dFinalize() so that packages can be initialized.
  • Loading branch information...
jedbrown committed Nov 8, 2009
1 parent 66914a6 commit fec67b27bb71cbcdaae8c9953c5f77c84d62efa8
View
@@ -1,11 +1,18 @@
install_files (/include FILES
dohpconfig.h
+ # public headers
dohp.h
dohpfs.h
dohpgeom.h
dohpjacobi.h
dohpmesh.h
dohpquotient.h
- dohptype.h)
-
-# Do not include the headers in private, they're private.
+ dohptype.h
+ dohpvec.h
+ dohpviewer.h
+ # private headers, we install them only so that users can extend Dohp
+ dohpfsimpl.h
+ dohpjacimpl.h
+ dohpmeshimpl.h
+ dohpquotientimpl.h
+ )
View
@@ -0,0 +1,10 @@
+#if !defined _DOHP_H
+#define _DOHP_H
+
+
+#include "dohptype.h"
+
+extern dErr dInitialize(int*,char***,const char*,const char*);
+extern dErr dFinalize(void);
+
+#endif
@@ -1,6 +1,7 @@
# Should only be included when Dohp_BUILD_SANDBOX
set (Dohp_SANDBOX_EXECS
+ mbcntest
)
foreach (EXE ${Dohp_SANDBOX_EXECS})
View
@@ -40,7 +40,9 @@ list (APPEND Dohp_SRCS
viewer/dviewer.c)
list (APPEND Dohp_SRCS
- util/util.c)
+ util/util.c
+ util/dohpinit.c
+ )
add_library (dohp ${Dohp_SRCS})
target_link_libraries (dohp ${Dohp_DEPENDENT_LIBRARIES})
@@ -1,10 +1,124 @@
+#include <dohpmesh.h>
#include "cont.h"
#include "../../../viewer/dhm.h"
+#define H5CHK(hret,func) if (hret < 0) dERROR(PETSC_ERR_LIB, #func)
+
+static dErr AttributeStringWrite(hid_t grp,const char *attname,const char *str)
+{
+ hid_t memtype,filetype,space,att;
+ herr_t herr;
+
+ dFunctionBegin;
+ filetype = H5Tcopy(H5T_FORTRAN_S1);H5CHK(filetype,H5Tcopy);
+ memtype = H5Tcopy(H5T_C_S1);H5CHK(memtype,H5Tcopy);
+ herr = H5Tset_size(filetype,H5T_VARIABLE);H5CHK(herr,H5Tset_size);
+ herr = H5Tset_size(memtype,H5T_VARIABLE);H5CHK(herr,H5Tset_size);
+ space = H5Screate(H5S_SCALAR);H5CHK(space,H5Screate);
+ att = H5Acreate(grp,attname,filetype,space,H5P_DEFAULT,H5P_DEFAULT);H5CHK(att,H5Acreate);
+ herr = H5Awrite(att,memtype,&str);H5CHK(herr,H5Awrite);
+ herr = H5Aclose(att);H5CHK(herr,H5Aclose);
+ herr = H5Sclose(space);H5CHK(herr,H5Sclose);
+ herr = H5Tclose(filetype);H5CHK(herr,H5Tclose);
+ herr = H5Tclose(memtype);H5CHK(herr,H5Tclose);
+ dFunctionReturn(0);
+}
+
+static dErr WriteTagNameAsAttribute(hid_t grp,const char *attname,dMesh mesh,dMeshTag tag)
+{
+ dErr err;
+ char *tagname;
+
+ dFunctionBegin;
+ err = dMeshGetTagName(mesh,tag,&tagname);dCHK(err);
+ err = AttributeStringWrite(grp,attname,tagname);dCHK(err);
+ err = dFree(tagname);dCHK(err);
+ dFunctionReturn(0);
+}
+
+static dErr WriteDimensions(hid_t grp,const char *name,dReal scale,const char *units)
+{
+ herr_t herr;
+ hid_t dimgrp,satt,sspace;
+ dErr err;
+
+ dFunctionBegin;
+ dimgrp = H5Gcreate(grp,name,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); if (dimgrp < 0) dERROR(PETSC_ERR_LIB,"H5Gcreate");
+ sspace = H5Screate(H5S_SCALAR); if (sspace < 0) dERROR(PETSC_ERR_LIB,"H5Screate"); if (sspace < 0) dERROR(PETSC_ERR_LIB,"H5Screate");
+ satt = H5Acreate(dimgrp,"scale",H5T_NATIVE_DOUBLE,sspace,H5P_DEFAULT,H5P_DEFAULT);if (satt < 0) dERROR(PETSC_ERR_LIB,"H5Acreate");
+ herr = H5Awrite(satt,dH5T_REAL,&scale); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Awrite");
+ err = AttributeStringWrite(dimgrp,"units",units);dCHK(err);
+ herr = H5Aclose(satt); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Aclose");
+ herr = H5Sclose(sspace); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Sclose");
+ herr = H5Gclose(dimgrp); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Gclose");
+ dFunctionReturn(0);
+}
+
+
dErr dFSView_Cont_DHM(dFS fs,dViewer viewer)
{
+ /* dFS_Cont *cont = fs->data; */
+ dViewer_DHM *dhm = viewer->data;
+ const char *meshname,*fsname;
+ char mstatestr[16],fstatestr[16];
+ dInt meshstate,fsstate;
+ herr_t herr;
+ htri_t hflg;
+ hid_t fsgrp,fsgrp1,meshgrp,att,dspace;
dErr err;
+ dIInt ierr;
dFunctionBegin;
+ err = dViewerDHMSetUp(viewer);dCHK(err);
+ /* Check if current mesh has been written */
+ err = PetscObjectGetName((dObject)fs->mesh,&meshname);dCHK(err);
+ err = PetscObjectStateQuery((dObject)fs->mesh,&meshstate);dCHK(err);
+ hflg = H5Lexists(dhm->meshroot,meshname,H5P_DEFAULT); if (hflg < 0) dERROR(PETSC_ERR_LIB,"H5Lexists");
+ if (!hflg) {
+ meshgrp = H5Gcreate(dhm->meshroot,meshname,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); if (meshgrp < 0) dERROR(PETSC_ERR_LIB,"H5Gopen");
+ } else {
+ meshgrp = H5Gopen(dhm->meshroot,meshname,H5P_DEFAULT); if (meshgrp < 0) dERROR(PETSC_ERR_LIB,"H5Gopen");
+ }
+ err = PetscSNPrintf(mstatestr,sizeof mstatestr,"%03d",meshstate);dCHK(err);
+ hflg = H5Lexists(meshgrp,mstatestr,H5P_DEFAULT); if (hflg < 0) dERROR(PETSC_ERR_LIB,"H5Lexists");
+ if (!hflg) { /* Save mesh to external file and create link to it */
+ char imeshpath[dNAME_LEN];
+ iMesh_Instance mi;
+ err = PetscSNPrintf(imeshpath,sizeof imeshpath,"imesh-%s-%03d.h5m",meshname,meshstate);dCHK(err);
+ err = dMeshGetInstance(fs->mesh,&mi);dCHK(err);
+ iMesh_save(mi,0,imeshpath,"",&ierr,sizeof imeshpath,0);dICHK(mi,ierr);
+ herr = H5Lcreate_external(imeshpath,"tstt",meshgrp,mstatestr,H5P_DEFAULT,H5P_DEFAULT);
+ if (hflg < 0) dERROR(PETSC_ERR_LIB,"H5Lcreate_external");
+ }
+ herr = H5Gclose(meshgrp); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Gclose");
+ /* Create group to hold this FS */
+ err = PetscObjectGetName((dObject)fs,&fsname);dCHK(err);
+ err = PetscObjectStateQuery((dObject)fs,&fsstate);dCHK(err);
+ hflg = H5Lexists(dhm->fsroot,fsname,H5P_DEFAULT); if (hflg < 0) dERROR(PETSC_ERR_LIB,"H5Lexists");
+ if (!hflg) {
+ fsgrp = H5Gcreate(dhm->fsroot,fsname,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); if (fsgrp < 0) dERROR(PETSC_ERR_LIB,"H5Gcreate");
+ } else {
+ fsgrp = H5Gopen(dhm->fsroot,fsname,H5P_DEFAULT); if (fsgrp < 0) dERROR(PETSC_ERR_LIB,"H5Gopen");
+ }
+ err = PetscSNPrintf(fstatestr,sizeof fstatestr,"%03d",fsstate);dCHK(err);
+ fsgrp1 = H5Gcreate(fsgrp,fstatestr,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); if (fsgrp1 < 0) dERROR(PETSC_ERR_LIB,"H5Gcreate");
+
+ /* write timestamp */
+ dspace = H5Screate(H5S_SCALAR); if (dspace < 0) dERROR(PETSC_ERR_LIB,"H5Screate");
+ att = H5Acreate(fsgrp1,"time",dH5T_REAL,dspace,H5P_DEFAULT,H5P_DEFAULT); if (att < 0) dERROR(PETSC_ERR_LIB,"H5Acreate");
+ herr = H5Awrite(att,dH5T_REAL,&dhm->time);if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Awrite");
+ herr = H5Aclose(att); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Aclose");
+ herr = H5Sclose(dspace); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Sclose");
+
+ /* \todo We need a way to identify the active set in MOAB's file if the FS was only defined on a subset. */
+
+ /* Write names of some mesh tags */
+ err = WriteTagNameAsAttribute(fsgrp1,"global_offset",fs->mesh,fs->gcoffsetTag);dCHK(err); /* The "closure" */
+ err = WriteTagNameAsAttribute(fsgrp1,"degree",fs->mesh,fs->degreetag);dCHK(err);
+ /* Units, \todo not yet stored in the FS so we write defaults here */
+ err = WriteDimensions(fsgrp1,"velocity",1,"m s-1");dCHK(err);
+
+ herr = H5Gclose(fsgrp1); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Gclose");
+ herr = H5Gclose(fsgrp); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Gclose");
dFunctionReturn(0);
}
View
@@ -5,9 +5,11 @@ static const char help[] = "Solve a scalar elliptic problem, a regularized p-Bra
" \\eta(u) = (\\epsilon + 1/2 Du . Du)^(p-2)\n"
" (\\eta Du \\cdot n) = known OR function of u OR self (\"No condition\" outflow)\n\n";
+#include <dohp.h>
#include <dohpfs.h>
#include <dohpvec.h>
-#include "petscsnes.h"
+#include <dohpviewer.h>
+#include <petscsnes.h>
PetscLogEvent LOG_EllipShellMatMult;
@@ -156,7 +158,7 @@ static void Morph(void *ctx,double *coords)
static dErr EllipSetFromOptions(Ellip elp)
{
- char mesh_out_name[256];
+ char mesh_out_name[256] = "ellip.h5m";
struct EllipParam *prm = &elp->param;
struct EllipExactCtx *exc = &elp->exactctx;
dMesh mesh;
@@ -715,16 +717,14 @@ int main(int argc,char *argv[])
Ellip elp;
dFS fs;
MPI_Comm comm;
- PetscViewer viewer;
Mat J,Jp;
Vec r,x,soln;
SNES snes;
- dTruth nojshell,nocheck;
+ dTruth nojshell,nocheck,viewdhm;
dErr err;
- err = PetscInitialize(&argc,&argv,NULL,help);dCHK(err);
+ err = dInitialize(&argc,&argv,NULL,help);dCHK(err);
comm = PETSC_COMM_WORLD;
- viewer = PETSC_VIEWER_STDOUT_WORLD;
err = PetscLogEventRegister("EllipShellMult",MAT_COOKIE,&LOG_EllipShellMatMult);dCHK(err);
@@ -741,6 +741,7 @@ int main(int argc,char *argv[])
err = PetscOptionsBegin(elp->comm,NULL,"Elliptic solver options",__FILE__);dCHK(err); {
err = PetscOptionsName("-nojshell","Do not use shell Jacobian","",&nojshell);dCHK(err);
err = PetscOptionsName("-nocheck_error","Do not compute errors","",&nocheck);dCHK(err);
+ err = PetscOptionsName("-viewdhm","View to a file using DHM","",&viewdhm);dCHK(err);
//err = PetscOptionsInt("-cont","Number of steps in continuation","",&cont,
} err = PetscOptionsEnd();dCHK(err);
if (nojshell) {
@@ -815,13 +816,25 @@ int main(int argc,char *argv[])
err = dPrintf(comm,"Pointwise gradient error |x|_1 %8.2e |x|_2 %8.2e |x|_inf %8.2e\n",gnorm[0],gnorm[1],gnorm[2]);dCHK(err);
}
+ if (viewdhm) {
+ dViewer viewer;
+ err = PetscViewerCreate(comm,&viewer);dCHK(err);
+ err = PetscViewerSetType(viewer,PETSC_VIEWER_DHM);dCHK(err);
+ err = PetscViewerFileSetName(viewer,"ellip.dhm");dCHK(err);
+ err = PetscViewerFileSetMode(viewer,FILE_MODE_WRITE);dCHK(err);
+ err = dViewerDHMSetFS(viewer,fs);dCHK(err);
+ err = dViewerDHMSetTime(viewer,0.1);dCHK(err);
+ err = dFSView(fs,viewer);dCHK(err);
+ err = PetscViewerDestroy(viewer);dCHK(err);
+ }
+
err = VecDestroy(r);dCHK(err);
err = VecDestroy(x);dCHK(err);
err = VecDestroy(soln);dCHK(err);
err = SNESDestroy(snes);dCHK(err);
if (J != Jp) {err = MatDestroy(J);dCHK(err);}
err = MatDestroy(Jp);dCHK(err);
err = EllipDestroy(elp);dCHK(err);
- err = PetscFinalize();dCHK(err);
+ err = dFinalize();dCHK(err);
return 0;
}
View
@@ -1,17 +1,15 @@
#include "dhm.h"
-#include <../src/sys/viewer/viewerimpl.h>
PetscErrorCode PetscViewerCreate_DHM(PetscViewer);
-static dErr DHMSetUp(PetscViewer viewer)
+dErr dViewerDHMSetUp(PetscViewer viewer)
{
dViewer_DHM *dhm = viewer->data;
- dErr err;
herr_t herr;
hid_t plist_id,fid;
dFunctionBegin;
- if (dhm->file_id) dFunctionReturn(0);
+ if (dhm->file) dFunctionReturn(0);
/* Set attributes for opening the file */
plist_id = H5Pcreate(H5P_FILE_ACCESS);
herr = H5Pset_fapl_mpio(plist_id,((PetscObject)viewer)->comm,MPI_INFO_NULL);dHCHK(herr);
@@ -32,10 +30,16 @@ static dErr DHMSetUp(PetscViewer viewer)
default:
dERROR(PETSC_ERR_ORDER,"Must call PetscViewerFileSetMode() before PetscViewerFileSetName()");
}
- dhm->file_id = fid;
+ dhm->file = fid;
herr = H5Pclose(plist_id);dHCHK(herr);
- /* \todo set up the groups */
+ if (dhm->btype == FILE_MODE_READ) dFunctionReturn(0);
+
+ /* set up the groups */
+ dhm->dohproot = H5Gcreate(dhm->file,"dohp",H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); if (dhm->dohproot < 0) dERROR(PETSC_ERR_ORDER,"H5Gcreate");
+ dhm->meshroot = H5Gcreate(dhm->dohproot,"mesh",H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); if (dhm->meshroot < 0) dERROR(PETSC_ERR_ORDER,"H5Gcreate");
+ dhm->fsroot = H5Gcreate(dhm->dohproot,"fs", H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); if (dhm->fsroot < 0) dERROR(PETSC_ERR_ORDER,"H5Gcreate");
+ dhm->steproot = H5Gcreate(dhm->dohproot,"step",H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT); if (dhm->steproot < 0) dERROR(PETSC_ERR_ORDER,"H5Gcreate");
dFunctionReturn(0);
}
@@ -47,8 +51,12 @@ static dErr PetscViewerDestroy_DHM(PetscViewer v)
dFunctionBegin;
err = dFree(dhm->filename);dCHK(err);
- if (dhm->file_id) {herr = H5Fclose(dhm->file_id);dHCHK(herr);}
- if (dhm->fs) {err = dFSDestroy(dhm->fs);dCHK(err);}
+ if (dhm->meshroot) {herr = H5Gclose(dhm->meshroot); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Gclose");}
+ if (dhm->fsroot) {herr = H5Gclose(dhm->fsroot); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Gclose");}
+ if (dhm->steproot) {herr = H5Gclose(dhm->steproot); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Gclose");}
+ if (dhm->dohproot) {herr = H5Gclose(dhm->dohproot); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Gclose");}
+ if (dhm->file) {herr = H5Fclose(dhm->file); if (herr < 0) dERROR(PETSC_ERR_LIB,"H5Fclose");}
+ if (dhm->fs) {err = dFSDestroy(dhm->fs);dCHK(err);}
err = dFree(dhm);dCHK(err);
dFunctionReturn(0);
}
View
@@ -24,18 +24,30 @@
*
*/
+#if !defined _DHM_H
+#define _DHM_H
#include <hdf5.h>
#define dHCHK(herr) dCHK((dErr)herr)
+#include <private/viewerimpl.h>
#include <dohpviewer.h>
#include <dohpfs.h>
+/* for the in-memory representation */
+#define dH5T_REAL H5T_NATIVE_DOUBLE /* dReal */
+#define dH5T_INT H5T_NATIVE_INT /* dInt */
+
typedef struct {
char *filename;
PetscFileMode btype;
- hid_t file_id;
+ hid_t file,dohproot;
+ hid_t meshroot,fsroot,steproot;
dReal time;
dFS fs; /* Most writes are with respect to a FS, once written we set to 0 */
} dViewer_DHM;
+
+extern dErr dViewerDHMSetUp(dViewer);
+
+#endif
View
@@ -23,7 +23,6 @@ dErr dViewerDHMSetFS(dViewer viewer,dFS fs)
dFunctionReturn(0);
}
-
dErr dViewerDHMSetTime(dViewer viewer,dReal time)
{
dErr err,(*r)(dViewer,dReal);

0 comments on commit fec67b2

Please sign in to comment.