Skip to content

Commit

Permalink
Skeleton for DHM (Dohp HDF5 referencing iMesh) viewers
Browse files Browse the repository at this point in the history
  • Loading branch information
jedbrown committed Oct 25, 2009
1 parent 52c9104 commit cb4dd9f
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 6 deletions.
17 changes: 17 additions & 0 deletions include/dohpviewer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef _DOHPVIEWER_H
#define _DOHPVIEWER_H

#include "dohptype.h"
#include "dohpfs.h"

#define PETSC_VIEWER_DHM "dhm"

PETSC_EXTERN_CXX_BEGIN

EXTERN dErr dViewerDHMSetFS(PetscViewer,dFS);
EXTERN dErr dViewerDHMSetTime(PetscViewer,dReal);
EXTERN dErr dViewerRegisterAll(const char*);

PETSC_EXTERN_CXX_END

#endif
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ list (APPEND Dohp_SRCS
fs/interface/fsrot.c
fs/interface/fsgeom.c
fs/interface/q1.c
fs/impls/cont/cont.c)
fs/impls/cont/cont.c
fs/impls/cont/contviewdhm.c)

# ADD_SUBDIRECTORY (fs/mesh)
list (APPEND Dohp_SRCS
Expand All @@ -33,6 +34,11 @@ list (APPEND Dohp_SRCS
list (APPEND Dohp_SRCS
vec/vecd.c)

# ADD_SUBDIRECTORY (viewer)
list (APPEND Dohp_SRCS
viewer/dhm.c
viewer/dviewer.c)

list (APPEND Dohp_SRCS
util/util.c)

Expand Down
12 changes: 8 additions & 4 deletions src/fs/impls/cont/cont.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include "cont.h"
#include "dohpmesh.h"
#include "dohpvec.h"
#include <dohpmesh.h>
#include <dohpvec.h>
#include <dohpviewer.h>

static dErr dFSView_Cont(dFS dUNUSED fs,dViewer viewer)
static dErr dFSView_Cont(dFS fs,dViewer viewer)
{
dBool ascii;
dBool ascii,dhm;
dErr err;

dFunctionBegin;
err = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&ascii);dCHK(err);
err = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_DHM,&dhm);dCHK(err);
if (ascii) {
err = PetscViewerASCIIPrintf(viewer,"Continuous Galerkin function space\n");dCHK(err);
} else if (dhm) {
err = dFSView_Cont_DHM(fs,viewer);dCHK(err);
}
dFunctionReturn(0);
}
Expand Down
4 changes: 3 additions & 1 deletion src/fs/impls/cont/cont.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

PETSC_EXTERN_CXX_BEGIN

extern dErr dFSCreate_Cont(dFS);
EXTERN dErr dFSCreate_Cont(dFS);
EXTERN dErr dFSView_Cont_DHM(dFS,dViewer);


typedef struct {
dTruth usecmatrix;
Expand Down
10 changes: 10 additions & 0 deletions src/fs/impls/cont/contviewdhm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "cont.h"
#include "../../../viewer/dhm.h"

dErr dFSView_Cont_DHM(dFS fs,dViewer viewer)
{
dErr err;

dFunctionBegin;
dFunctionReturn(0);
}
118 changes: 118 additions & 0 deletions src/viewer/dhm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include "dhm.h"
#include <../src/sys/viewer/viewerimpl.h>

PetscErrorCode PetscViewerCreate_DHM(PetscViewer);

static dErr DHMSetUp(PetscViewer viewer)
{
dViewer_DHM *dhm = viewer->data;
dErr err;
herr_t herr;
hid_t plist_id,fid;

dFunctionBegin;
if (dhm->file_id) 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);
/* Create or open the file collectively */
switch (dhm->btype) {
case FILE_MODE_READ:
fid = H5Fopen(dhm->filename,H5F_ACC_RDONLY,plist_id);
if (fid < 0) dERROR(PETSC_ERR_LIB,"H5Fopen(\"%s\",H5F_ACC_RDONLY,...) failed",dhm->filename);
break;
case FILE_MODE_WRITE:
fid = H5Fcreate(dhm->filename,H5F_ACC_TRUNC,H5P_DEFAULT,plist_id);
if (fid < 0) dERROR(PETSC_ERR_LIB,"H5Fcreate(\"%s\",H5F_ACC_TRUNC,...) failed",dhm->filename);
break;
case FILE_MODE_APPEND:
fid = H5Fopen(dhm->filename,H5F_ACC_RDWR,plist_id);
if (fid < 0) dERROR(PETSC_ERR_LIB,"H5Fopen(\"%s\",H5F_ACC_RDWR,...) failed",dhm->filename);
break;
default:
dERROR(PETSC_ERR_ORDER,"Must call PetscViewerFileSetMode() before PetscViewerFileSetName()");
}
dhm->file_id = fid;
herr = H5Pclose(plist_id);dHCHK(herr);

/* \todo set up the groups */
dFunctionReturn(0);
}

static dErr PetscViewerDestroy_DHM(PetscViewer v)
{
dErr err;
herr_t herr;
dViewer_DHM *dhm = v->data;

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);}
err = dFree(dhm);dCHK(err);
dFunctionReturn(0);
}

static dErr PetscViewerFileSetName_DHM(PetscViewer v,const char *name)
{
dViewer_DHM *dhm = v->data;
dErr err;

dFunctionBegin;
err = dFree(dhm->filename);dCHK(err);
err = PetscStrallocpy(name,&dhm->filename);dCHK(err);
dFunctionReturn(0);
}

static dErr PetscViewerFileSetMode_DHM(PetscViewer v,PetscFileMode btype)
{
dViewer_DHM *dhm = v->data;

dFunctionBegin;
dhm->btype = btype;
dFunctionReturn(0);
}

static dErr dViewerDHMSetTime_DHM(PetscViewer v,dReal time)
{
dViewer_DHM *dhm = v->data;

dFunctionBegin;
dhm->time = time;
dFunctionReturn(0);
}

static dErr dViewerDHMSetFS_DHM(PetscViewer v,dFS fs)
{
dViewer_DHM *dhm = v->data;
dErr err;

dFunctionBegin;
err = PetscObjectReference((dObject)fs);dCHK(err);
if (dhm->fs) {err = dFSDestroy(dhm->fs);dCHK(err);}
dhm->fs = fs;
dFunctionReturn(0);
}

PetscErrorCode PetscViewerCreate_DHM(PetscViewer v)
{
dErr err;
dViewer_DHM *dhm;

dFunctionBegin;
err = PetscNewLog(v,dViewer_DHM,&dhm);dCHK(err);
v->data = (void *) dhm;
v->ops->destroy = PetscViewerDestroy_DHM;
v->ops->flush = 0;
v->iformat = 0;
dhm->btype = (PetscFileMode) -1;
dhm->filename = 0;

err = PetscObjectComposeFunctionDynamic((PetscObject)v,"PetscViewerFileSetName_C","PetscViewerFileSetName_DHM",
PetscViewerFileSetName_DHM);dCHK(err);
err = PetscObjectComposeFunctionDynamic((PetscObject)v,"PetscViewerFileSetMode_C","PetscViewerFileSetMode_DHM",
PetscViewerFileSetMode_DHM);dCHK(err);
err = PetscObjectComposeFunctionDynamic((PetscObject)v,"dViewerDHMSetFS_C","dViewerDHMSetFS_DHM",dViewerDHMSetFS_DHM);dCHK(err);
err = PetscObjectComposeFunctionDynamic((PetscObject)v,"dViewerDHMSetTime_C","dViewerDHMSetTime_DHM",dViewerDHMSetTime_DHM);dCHK(err);
dFunctionReturn(0);
}
41 changes: 41 additions & 0 deletions src/viewer/dhm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @file dhm.h
* @author Jed Brown <jed@59A2.org>
* @date Sat Oct 24 17:20:17 2009
*
* @brief DHM is format for storing Dohp vectors in HDF5 with reference to iMesh.
*
* This is a Multiple Time Multiple Domain format. A mesh defines the macro-topology, but can be a heavy object to
* duplicate at every time step, and this duplication is clumsy to deal with for certain applications because it's not
* easy to tell when the mesh changes. The FS defines a function space over the mesh. There can be multiple function
* spaces using the same mesh. The parallel layout is defined by a global offset and size for each entity, stored as
* tags on the mesh. The geometry is defined by a vector in some function space, usually giving locations of nodes (this
* changes every time step in ALE methods).
*
* An outline of the format is
*
* /fs/[ID]/mesh_file_name
* /layout_tags
* /layout_tags_of_coordinate_fs
* /id_of_coordinate_vector
* /times/[ID]/time
* /[FIELD]/id_of_fs
* /vector
*
*/


#include <hdf5.h>

#define dHCHK(herr) dCHK((dErr)herr)

#include <dohpviewer.h>
#include <dohpfs.h>

typedef struct {
char *filename;
PetscFileMode btype;
hid_t file_id;
dReal time;
dFS fs; /* Most writes are with respect to a FS, once written we set to 0 */
} dViewer_DHM;
37 changes: 37 additions & 0 deletions src/viewer/dviewer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <dohpviewer.h>

EXTERN PetscErrorCode PetscViewerCreate_DHM(PetscViewer);

dErr dViewerRegisterAll(const char *path)
{
dErr err;

dFunctionBegin;
err = PetscViewerRegister(PETSC_VIEWER_DHM,path,"PetscViewerCreate_DHM",PetscViewerCreate_DHM);dCHK(err);
dFunctionReturn(0);
}

dErr dViewerDHMSetFS(dViewer viewer,dFS fs)
{
dErr err,(*r)(dViewer,dFS);

dFunctionBegin;
err = PetscObjectQueryFunction((PetscObject)viewer,"dViewerDHMSetFS_C",(void(**)(void))&r);dCHK(err);
if (r) {
err = (*r)(viewer,fs);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);
}

0 comments on commit cb4dd9f

Please sign in to comment.