Skip to content

Commit

Permalink
Cosmetic changes, move s_dRule and s_dEFS into public header so that …
Browse files Browse the repository at this point in the history
…sizes are known.

Signed-off-by: Jed Brown <jed@59A2.org>
  • Loading branch information
jedbrown committed Nov 11, 2008
1 parent d02b0a3 commit efefe65
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 157 deletions.
40 changes: 31 additions & 9 deletions include/dohpjacobi.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,41 @@ PETSC_EXTERN_CXX_BEGIN
extern PetscCookie dJACOBI_COOKIE;

/**
* Handle for manipulating EFS objects. Since these are actually stored in arrays, the handle is the actual object
* rather than just a pointer. This means that a certain amount of library code (dFS) will have to be able to see the
* struct definition (in order to know the size, to make an array). This is okay since the objects are so simple
* (everything is implementation-dependent, the details of which are still hidden).
*
* Handle for manipulating EFS objects. The EFS are stored directly in arrays so other components (like dFS) will have
* to be able to see the struct definition in order to know the size. This is okay since the objects are so simple that
* they should never change. Note that implementations must have the same size as the opaque prototype (this might
* require a union in some cases). The tensor products are always okay.
*/
typedef struct p_dEFS *dEFS;
typedef struct s_dEFS *dEFS;

/**
* As above, the handle is the actual object.
*
* Handle for manipulating dRule objects (quadrature rules)
*/
typedef struct s_dRule *dRule;

/**
* The vtable is allocated by the dJacobi, one for each element topology and amount of unrolling. We could move the
* vtable here if we were worried about inlining, but performance studies show that it doesn't actually matter.
*/
typedef struct p_dRule *dRule;
#define dEFSHEADER \
struct _dEFSOps *ops; \
dRule rule

/** This struct should only be referenced in code that holds the array. */
typedef struct s_dEFS {
dEFSHEADER;
void *opaque[3];
} s_dEFS;


#define dRuleHEADER \
struct _dRuleOps *ops

/** This struct should only be referenced in code that holds the array. */
typedef struct s_dRule {
dRuleHEADER;
void *opaque[3];
} s_dRule;

/**
* Indicates whether or not to apply the transpose of a interpolation/derivative matrix.
Expand Down
23 changes: 2 additions & 21 deletions include/private/jacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PETSC_EXTERN_CXX_BEGIN
* There is exactly one #dRule on each element. The ops table is normally shared across the domain.
*
*/
struct v_dRuleOps {
struct _dRuleOps {
dErr (*view)(dRule,PetscViewer);
dErr (*getSize)(dRule,dInt*,dInt*); /**< topological dimension of the space, total number of nodes */
dErr (*getNodeWeight)(dRule,dReal[],dReal[]); /**< nodes and weights in interlaced ordering, arrays must be large enough */
Expand All @@ -19,18 +19,11 @@ struct v_dRuleOps {
* be implemented. */
};

#define dRuleHEADER \
struct v_dRuleOps *ops

struct p_dRule {
dRuleHEADER;
};

/**
* Operations required for an EFS. Defined here so that these function calls can be inlined.
*
*/
struct v_dEFSOps {
struct _dEFSOps {
dErr (*view)(dEFS,PetscViewer);
dErr (*getSizes)(dEFS,dInt*,dInt*,dInt*); /**< topological dimension, number of interior nodes, total number of nodes */
dErr (*getTensorNodes)(dEFS,dInt*,dInt*,dReal**);
Expand All @@ -44,18 +37,6 @@ struct v_dEFSOps {
dErr (*scatterFacet)(dEFS,dEFS,dInt*,dScalar**restrict,const dScalar[],dScalar[],InsertMode,ScatterMode);
};

/**
* This is held once for every function space on every element. This part of the implementation is not really private.
*
*/
#define dEFSHEADER \
struct v_dEFSOps *ops; \
dRule rule

struct p_dEFS {
dEFSHEADER;
};

/**
* Generic operations provided by a #dJacobi implementation.
*
Expand Down
72 changes: 36 additions & 36 deletions src/jacobi/impls/tensor/efstopo.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,39 @@ _F(TensorMult_Hex);
*/
dErr dJacobiEFSOpsSetUp_Tensor(dJacobi jac)
{
static const struct v_dEFSOps efsOpsLine = { .view = dEFSView_Tensor_Line,
.getSizes = dEFSGetSizes_Tensor_Line,
.getTensorNodes = dEFSGetTensorNodes_Tensor_Line,
.apply = dEFSApply_Tensor_Line,
.scatterInt = 0,
.scatterFacet = 0 };
static const struct v_dEFSOps efsOpsQuad = { .view = dEFSView_Tensor_Quad,
.getSizes = dEFSGetSizes_Tensor_Quad,
.getTensorNodes = dEFSGetTensorNodes_Tensor_Quad,
.apply = dEFSApply_Tensor_Quad,
.scatterInt = 0,
.scatterFacet = 0 };
static const struct v_dEFSOps efsOpsHex = { .view = dEFSView_Tensor_Hex,
.getSizes = dEFSGetSizes_Tensor_Hex,
.getTensorNodes = dEFSGetTensorNodes_Tensor_Hex,
.apply = dEFSApply_Tensor_Hex,
.scatterInt = 0,
.scatterFacet = 0 };
static const struct _dEFSOps efsOpsLine = { .view = dEFSView_Tensor_Line,
.getSizes = dEFSGetSizes_Tensor_Line,
.getTensorNodes = dEFSGetTensorNodes_Tensor_Line,
.apply = dEFSApply_Tensor_Line,
.scatterInt = 0,
.scatterFacet = 0 };
static const struct _dEFSOps efsOpsQuad = { .view = dEFSView_Tensor_Quad,
.getSizes = dEFSGetSizes_Tensor_Quad,
.getTensorNodes = dEFSGetTensorNodes_Tensor_Quad,
.apply = dEFSApply_Tensor_Quad,
.scatterInt = 0,
.scatterFacet = 0 };
static const struct _dEFSOps efsOpsHex = { .view = dEFSView_Tensor_Hex,
.getSizes = dEFSGetSizes_Tensor_Hex,
.getTensorNodes = dEFSGetTensorNodes_Tensor_Hex,
.apply = dEFSApply_Tensor_Hex,
.scatterInt = 0,
.scatterFacet = 0 };
Tensor this = (Tensor)jac->impl;
dErr err;

dFunctionBegin;
if (!this->efsOpsLine) {
err = dMalloc(sizeof(struct v_dEFSOps),&this->efsOpsLine);dCHK(err);
err = dMemcpy(this->efsOpsLine,&efsOpsLine,sizeof(struct v_dEFSOps));
err = dMalloc(sizeof(struct _dEFSOps),&this->efsOpsLine);dCHK(err);
err = dMemcpy(this->efsOpsLine,&efsOpsLine,sizeof(struct _dEFSOps));
}
if (!this->efsOpsQuad) {
err = dMalloc(sizeof(struct v_dEFSOps),&this->efsOpsQuad);dCHK(err);
err = dMemcpy(this->efsOpsQuad,&efsOpsQuad,sizeof(struct v_dEFSOps));
err = dMalloc(sizeof(struct _dEFSOps),&this->efsOpsQuad);dCHK(err);
err = dMemcpy(this->efsOpsQuad,&efsOpsQuad,sizeof(struct _dEFSOps));
}
if (!this->efsOpsHex) {
err = dMalloc(sizeof(struct v_dEFSOps),&this->efsOpsHex);dCHK(err);
err = dMemcpy(this->efsOpsHex,&efsOpsHex,sizeof(struct v_dEFSOps));
err = dMalloc(sizeof(struct _dEFSOps),&this->efsOpsHex);dCHK(err);
err = dMemcpy(this->efsOpsHex,&efsOpsHex,sizeof(struct _dEFSOps));
}
dFunctionReturn(0);
}
Expand Down Expand Up @@ -131,29 +131,29 @@ static dErr dEFSView_Tensor_Line(dEFS efs,PetscViewer viewer)
dErr err;

dFunctionBegin;
err = dEFSView_Tensor_Private("Tensor_Line",efs->rule,1,((struct s_dEFS_Tensor_Line*)efs)->basis,viewer);dCHK(err);
err = dEFSView_Tensor_Private("Tensor_Line",efs->rule,1,((dEFS_Tensor*)efs)->basis,viewer);dCHK(err);
dFunctionReturn(0);
}
static dErr dEFSView_Tensor_Quad(dEFS efs,PetscViewer viewer)
{
dErr err;

dFunctionBegin;
err = dEFSView_Tensor_Private("Tensor_Quad",efs->rule,2,((struct s_dEFS_Tensor_Quad*)efs)->basis,viewer);dCHK(err);
err = dEFSView_Tensor_Private("Tensor_Quad",efs->rule,2,((dEFS_Tensor*)efs)->basis,viewer);dCHK(err);
dFunctionReturn(0);
}
static dErr dEFSView_Tensor_Hex(dEFS efs,PetscViewer viewer)
{
dErr err;

dFunctionBegin;
err = dEFSView_Tensor_Private("Tensor_Hex",efs->rule,3,((struct s_dEFS_Tensor_Hex*)efs)->basis,viewer);dCHK(err);
err = dEFSView_Tensor_Private("Tensor_Hex",efs->rule,3,((dEFS_Tensor*)efs)->basis,viewer);dCHK(err);
dFunctionReturn(0);
}

static dErr dEFSGetSizes_Tensor_Line(dEFS efs,dInt *dim,dInt *inodes,dInt *total)
{
TensorBasis *b = ((struct s_dEFS_Tensor_Line*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;

dFunctionBegin;
if (dim) *dim = 1;
Expand All @@ -163,7 +163,7 @@ static dErr dEFSGetSizes_Tensor_Line(dEFS efs,dInt *dim,dInt *inodes,dInt *total
}
static dErr dEFSGetSizes_Tensor_Quad(dEFS efs,dInt *dim,dInt *inodes,dInt *total)
{
TensorBasis *b = ((struct s_dEFS_Tensor_Quad*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;

dFunctionBegin;
if (dim) *dim = 2;
Expand All @@ -173,7 +173,7 @@ static dErr dEFSGetSizes_Tensor_Quad(dEFS efs,dInt *dim,dInt *inodes,dInt *total
}
static dErr dEFSGetSizes_Tensor_Hex(dEFS efs,dInt *dim,dInt *inodes,dInt *total)
{
TensorBasis *b = ((struct s_dEFS_Tensor_Hex*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;

dFunctionBegin;
if (dim) *dim = 3;
Expand All @@ -184,7 +184,7 @@ static dErr dEFSGetSizes_Tensor_Hex(dEFS efs,dInt *dim,dInt *inodes,dInt *total)

static dErr dEFSGetTensorNodes_Tensor_Line(dEFS efs,dInt *dim,dInt tsize[restrict],dReal *x[restrict])
{
TensorBasis *b = ((struct s_dEFS_Tensor_Line*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;

dFunctionBegin;
if (dim) *dim = 1;
Expand All @@ -195,7 +195,7 @@ static dErr dEFSGetTensorNodes_Tensor_Line(dEFS efs,dInt *dim,dInt tsize[restric

static dErr dEFSGetTensorNodes_Tensor_Quad(dEFS efs,dInt *dim,dInt tsize[restrict],dReal *x[restrict])
{
TensorBasis *b = ((struct s_dEFS_Tensor_Quad*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;

dFunctionBegin;
if (dim) *dim = 2;
Expand All @@ -208,7 +208,7 @@ static dErr dEFSGetTensorNodes_Tensor_Quad(dEFS efs,dInt *dim,dInt tsize[restric

static dErr dEFSGetTensorNodes_Tensor_Hex(dEFS efs,dInt *dim,dInt tsize[restrict],dReal *x[restrict])
{
TensorBasis *b = ((struct s_dEFS_Tensor_Hex*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;

dFunctionBegin;
if (dim) *dim = 3;
Expand All @@ -221,7 +221,7 @@ static dErr dEFSGetTensorNodes_Tensor_Hex(dEFS efs,dInt *dim,dInt tsize[restrict

static dErr dEFSApply_Tensor_Line(dEFS efs,dInt D,dInt *wlen,dScalar**restrict work,const dScalar in[],dScalar out[],dApplyMode amode,InsertMode imode)
{
TensorBasis *b = ((struct s_dEFS_Tensor_Quad*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;
/* const dInt *P=&b->P,*Q=&b->Q; */
dScalar *A[1];
dInt P[1],Q[1],chunk;
Expand Down Expand Up @@ -268,7 +268,7 @@ static dErr dEFSApply_Tensor_Line(dEFS efs,dInt D,dInt *wlen,dScalar**restrict w

static dErr dEFSApply_Tensor_Quad(dEFS efs,dInt D,dInt *wlen,dScalar**restrict work,const dScalar in[],dScalar out[],dApplyMode amode,InsertMode imode)
{
TensorBasis *b = ((struct s_dEFS_Tensor_Quad*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;
/* const dInt *P=&b->P,*Q=&b->Q; */
dScalar *A[2];
dInt P[2],Q[2],chunk;
Expand Down Expand Up @@ -315,7 +315,7 @@ static dErr dEFSApply_Tensor_Quad(dEFS efs,dInt D,dInt *wlen,dScalar**restrict w

static dErr dEFSApply_Tensor_Hex(dEFS efs,dInt D,dInt *wlen,dScalar**restrict work,const dScalar in[],dScalar out[],dApplyMode amode,InsertMode imode)
{
TensorBasis *b = ((struct s_dEFS_Tensor_Hex*)efs)->basis;
TensorBasis *b = ((dEFS_Tensor*)efs)->basis;
/* const dInt *P=&b->P,*Q=&b->Q; */
dScalar *A[3];
dInt P[3],Q[3],chunk;
Expand Down
54 changes: 27 additions & 27 deletions src/jacobi/impls/tensor/ruletopo.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ static dErr dRuleGetTensorNodeWeight_Tensor_Hex(dRule,dInt*,dInt[],const dReal**
*/
dErr dJacobiRuleOpsSetUp_Tensor(dJacobi jac)
{
static const struct v_dRuleOps ruleOpsLine = { .view = dRuleView_Tensor_Line,
.getSize = dRuleGetSize_Tensor_Line,
.getNodeWeight = NULL, /* dRuleGetNodeWeight_Tensor_Line, */
.getTensorNodeWeight = dRuleGetTensorNodeWeight_Tensor_Line };
static const struct v_dRuleOps ruleOpsQuad = { .view = dRuleView_Tensor_Quad,
.getSize = dRuleGetSize_Tensor_Quad,
.getNodeWeight = NULL, /* dRuleGetNodeWeight_Tensor_Quad, */
.getTensorNodeWeight = dRuleGetTensorNodeWeight_Tensor_Quad };
static const struct v_dRuleOps ruleOpsHex = { .view = dRuleView_Tensor_Hex,
.getSize = dRuleGetSize_Tensor_Hex,
.getNodeWeight = NULL, /* dRuleGetNodeWeight_Tensor_Hex, */
.getTensorNodeWeight = dRuleGetTensorNodeWeight_Tensor_Hex };
static const struct _dRuleOps ruleOpsLine = { .view = dRuleView_Tensor_Line,
.getSize = dRuleGetSize_Tensor_Line,
.getNodeWeight = NULL, /* dRuleGetNodeWeight_Tensor_Line, */
.getTensorNodeWeight = dRuleGetTensorNodeWeight_Tensor_Line };
static const struct _dRuleOps ruleOpsQuad = { .view = dRuleView_Tensor_Quad,
.getSize = dRuleGetSize_Tensor_Quad,
.getNodeWeight = NULL, /* dRuleGetNodeWeight_Tensor_Quad, */
.getTensorNodeWeight = dRuleGetTensorNodeWeight_Tensor_Quad };
static const struct _dRuleOps ruleOpsHex = { .view = dRuleView_Tensor_Hex,
.getSize = dRuleGetSize_Tensor_Hex,
.getNodeWeight = NULL, /* dRuleGetNodeWeight_Tensor_Hex, */
.getTensorNodeWeight = dRuleGetTensorNodeWeight_Tensor_Hex };
Tensor this = (Tensor)jac->impl;
dErr err;

dFunctionBegin;
if (!this->ruleOpsLine) {
err = dMalloc(sizeof(struct v_dRuleOps),&this->ruleOpsLine);dCHK(err);
err = dMemcpy(this->ruleOpsLine,&ruleOpsLine,sizeof(struct v_dRuleOps));
err = dMalloc(sizeof(struct _dRuleOps),&this->ruleOpsLine);dCHK(err);
err = dMemcpy(this->ruleOpsLine,&ruleOpsLine,sizeof(struct _dRuleOps));
}
if (!this->ruleOpsQuad) {
err = dMalloc(sizeof(struct v_dRuleOps),&this->ruleOpsQuad);dCHK(err);
err = dMemcpy(this->ruleOpsQuad,&ruleOpsQuad,sizeof(struct v_dRuleOps));
err = dMalloc(sizeof(struct _dRuleOps),&this->ruleOpsQuad);dCHK(err);
err = dMemcpy(this->ruleOpsQuad,&ruleOpsQuad,sizeof(struct _dRuleOps));
}
if (!this->ruleOpsHex) {
err = dMalloc(sizeof(struct v_dRuleOps),&this->ruleOpsHex);dCHK(err);
err = dMemcpy(this->ruleOpsHex,&ruleOpsHex,sizeof(struct v_dRuleOps));
err = dMalloc(sizeof(struct _dRuleOps),&this->ruleOpsHex);dCHK(err);
err = dMemcpy(this->ruleOpsHex,&ruleOpsHex,sizeof(struct _dRuleOps));
}
dFunctionReturn(0);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ static dErr dRuleView_Tensor_Line(dRule rule,PetscViewer viewer)
dErr err;

dFunctionBegin;
err = dRuleView_Tensor_Private("Tensor_Line",1,((struct s_dRule_Tensor_Line*)rule)->trule,viewer);dCHK(err);
err = dRuleView_Tensor_Private("Tensor_Line",1,((dRule_Tensor*)rule)->trule,viewer);dCHK(err);
dFunctionReturn(0);
}

Expand All @@ -98,7 +98,7 @@ static dErr dRuleView_Tensor_Quad(dRule rule,PetscViewer viewer)
dErr err;

dFunctionBegin;
err = dRuleView_Tensor_Private("Tensor_Quad",2,((struct s_dRule_Tensor_Quad*)rule)->trule,viewer);dCHK(err);
err = dRuleView_Tensor_Private("Tensor_Quad",2,((dRule_Tensor*)rule)->trule,viewer);dCHK(err);
dFunctionReturn(0);
}

Expand All @@ -107,21 +107,21 @@ static dErr dRuleView_Tensor_Hex(dRule rule,PetscViewer viewer)
dErr err;

dFunctionBegin;
err = dRuleView_Tensor_Private("Tensor_Hex",3,((struct s_dRule_Tensor_Hex*)rule)->trule,viewer);dCHK(err);
err = dRuleView_Tensor_Private("Tensor_Hex",3,((dRule_Tensor*)rule)->trule,viewer);dCHK(err);
dFunctionReturn(0);
}

static dErr dRuleGetSize_Tensor_Line(dRule rule,dInt *dim,dInt *size)
{
dFunctionBegin;
if (dim) *dim = 1;
if (size) *size = ((struct s_dRule_Tensor_Line*)rule)->trule[0]->size;
if (size) *size = ((dRule_Tensor*)rule)->trule[0]->size;
dFunctionReturn(0);
}

static dErr dRuleGetSize_Tensor_Quad(dRule rule,dInt *dim,dInt *size)
{
TensorRule *r = ((struct s_dRule_Tensor_Quad*)rule)->trule;
TensorRule *r = ((dRule_Tensor*)rule)->trule;
dFunctionBegin;
if (dim) *dim = 2;
if (size) *size = r[0]->size * r[1]->size;
Expand All @@ -130,7 +130,7 @@ static dErr dRuleGetSize_Tensor_Quad(dRule rule,dInt *dim,dInt *size)

static dErr dRuleGetSize_Tensor_Hex(dRule rule,dInt *dim,dInt *size)
{
TensorRule *r = ((struct s_dRule_Tensor_Hex*)rule)->trule;
TensorRule *r = ((dRule_Tensor*)rule)->trule;
dFunctionBegin;
if (dim) *dim = 3;
if (size) *size = r[0]->size * r[1]->size * r[2]->size;
Expand All @@ -139,7 +139,7 @@ static dErr dRuleGetSize_Tensor_Hex(dRule rule,dInt *dim,dInt *size)

static dErr dRuleGetTensorNodeWeight_Tensor_Line(dRule rule,dInt *dim,dInt nnodes[],const dReal *coord[],const dReal *weight[])
{
TensorRule *r = ((struct s_dRule_Tensor_Line*)rule)->trule;
TensorRule *r = ((dRule_Tensor*)rule)->trule;
dFunctionBegin;
if (dim) *dim = 1;
if (nnodes) nnodes[0] = r[0]->size;
Expand All @@ -150,7 +150,7 @@ static dErr dRuleGetTensorNodeWeight_Tensor_Line(dRule rule,dInt *dim,dInt nnode

static dErr dRuleGetTensorNodeWeight_Tensor_Quad(dRule rule,dInt *dim,dInt nnodes[],const dReal *coord[],const dReal *weight[])
{
TensorRule *r = ((struct s_dRule_Tensor_Quad*)rule)->trule;
TensorRule *r = ((dRule_Tensor*)rule)->trule;
dFunctionBegin;
if (dim) *dim = 2;
if (nnodes) {
Expand All @@ -170,7 +170,7 @@ static dErr dRuleGetTensorNodeWeight_Tensor_Quad(dRule rule,dInt *dim,dInt nnode

static dErr dRuleGetTensorNodeWeight_Tensor_Hex(dRule rule,dInt *dim,dInt nnodes[],const dReal *coord[],const dReal *weight[])
{
TensorRule *r = ((struct s_dRule_Tensor_Hex*)rule)->trule;
TensorRule *r = ((dRule_Tensor*)rule)->trule;
dFunctionBegin;
if (dim) *dim = 3;
if (nnodes) {
Expand Down

0 comments on commit efefe65

Please sign in to comment.