SALSA Analysis Modules
Data Structures | Defines | Functions
component.c File Reference
#include <stdlib.h>
#include <string.h>
#include "anamod.h"
Include dependency graph for component.c:

Go to the source code of this file.

Data Structures

struct  componentobject_

Defines

#define COMPONENTCOOKIE   4723847
#define CHECKVALIDCOMPONENT(x)   ANAMODCHECKVALID(x,COMPONENTCOOKIE,"component")

Functions

PetscErrorCode CreateComponentObject (const char *name, componentobject *obj)
PetscErrorCode DestroyComponentObject (componentobject cmp)
PetscErrorCode ComponentSetModule (componentobject cmpt, AnalysisDataType type, int id, PetscErrorCode(*f)(AnaModNumericalProblem, AnalysisItem *, int *, PetscTruth *))
PetscErrorCode ComponentCompute (componentobject cmpt, AnaModNumericalProblem prob, AnalysisItem *res, int *reslen, PetscTruth *success)
PetscErrorCode ComponentRetrieve (componentobject cmpt, AnaModNumericalProblem prob, AnalysisItem *res, int *reslen, PetscTruth *success)
PetscErrorCode ComponentGetType (componentobject cmpt, AnalysisDataType *t)
PetscErrorCode ComponentGetName (componentobject cmpt, const char **name)
PetscErrorCode ComponentGetId (componentobject cmpt, int *id)

Define Documentation

#define CHECKVALIDCOMPONENT (   x)    ANAMODCHECKVALID(x,COMPONENTCOOKIE,"component")
#define COMPONENTCOOKIE   4723847

Definition at line 5 of file component.c.

Referenced by CreateComponentObject().


Function Documentation

PetscErrorCode ComponentCompute ( componentobject  cmpt,
AnaModNumericalProblem  prob,
AnalysisItem res,
int *  reslen,
PetscTruth *  success 
)

Definition at line 57 of file component.c.

References CHECKVALIDCOMPONENT, componentobject_::hasval, and componentobject_::module.

Referenced by ComputeOrRetrieveQuantity().

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  CHECKVALIDCOMPONENT(cmpt);
  if (!cmpt->module) 
    *success = PETSC_FALSE;
  else {
    ierr = (cmpt->module)(prob,res,reslen,success); CHKERRQ(ierr);
  }
  cmpt->hasval = *success;
  PetscFunctionReturn(0);
}
PetscErrorCode ComponentGetId ( componentobject  cmpt,
int *  id 
)

Definition at line 139 of file component.c.

References CHECKVALIDCOMPONENT, and componentobject_::dataid.

Referenced by GetDataID(), and HasQuantity().

{
  PetscFunctionBegin;
  CHECKVALIDCOMPONENT(cmpt);
  *id = cmpt->dataid;
  PetscFunctionReturn(0);
}
PetscErrorCode ComponentGetName ( componentobject  cmpt,
const char **  name 
)

Definition at line 129 of file component.c.

References CHECKVALIDCOMPONENT, and componentobject_::name.

Referenced by CategoryGetOrCreateComponent().

{
  PetscFunctionBegin;
  CHECKVALIDCOMPONENT(cmpt);
  *name = cmpt->name;
  PetscFunctionReturn(0);
}
PetscErrorCode ComponentGetType ( componentobject  cmpt,
AnalysisDataType t 
)

Definition at line 119 of file component.c.

References CHECKVALIDCOMPONENT, and componentobject_::type.

Referenced by ComputeOrRetrieveQuantity(), GetDataType(), and HasQuantity().

{
  PetscFunctionBegin;
  CHECKVALIDCOMPONENT(cmpt);
  *t = cmpt->type;
  PetscFunctionReturn(0);
}
PetscErrorCode ComponentRetrieve ( componentobject  cmpt,
AnaModNumericalProblem  prob,
AnalysisItem res,
int *  reslen,
PetscTruth *  success 
)

Definition at line 75 of file component.c.

References ANALYSISDBLARRAY, ANALYSISDOUBLE, ANALYSISINTARRAY, ANALYSISINTEGER, CHECKVALIDCOMPONENT, componentobject_::dataid, AnalysisItem::i, AnalysisItem::ii, AnalysisItem::r, AnalysisItem::rr, and componentobject_::type.

Referenced by ComputeOrRetrieveQuantity().

{
  PetscTruth flg; PetscErrorCode ierr;
  PetscFunctionBegin;
  CHECKVALIDCOMPONENT(cmpt);
  *success = PETSC_FALSE;
  switch (cmpt->type) {
  case ANALYSISINTEGER : {
      int ir;
      ierr = PetscObjectComposedDataGetInt
        ((PetscObject)prob,cmpt->dataid,ir,flg); CHKERRQ(ierr);
      res->i =  ir; *success = flg;
      break;}
  case ANALYSISDOUBLE : {
      PetscReal rr;
      ierr = PetscObjectComposedDataGetReal
        ((PetscObject)prob,cmpt->dataid,rr,flg); CHKERRQ(ierr);
      res->r =  rr; *success = flg;
      break;}
  case ANALYSISINTARRAY : {
      int *iir;
      ierr = PetscObjectComposedDataGetIntstar
        ((PetscObject)prob,cmpt->dataid,iir,flg); CHKERRQ(ierr);
      res->ii =  iir; *success = flg;
      ierr = PetscObjectComposedDataGetInt
        ((PetscObject)prob,cmpt->dataid,*reslen,flg); CHKERRQ(ierr);
      break;}
  case ANALYSISDBLARRAY : {
      PetscReal *rrr;
      ierr = PetscObjectComposedDataGetRealstar
        ((PetscObject)prob,cmpt->dataid,rrr,flg); CHKERRQ(ierr);
      res->rr =  rrr; *success = flg;
      ierr = PetscObjectComposedDataGetInt
        ((PetscObject)prob,cmpt->dataid,*reslen,flg); CHKERRQ(ierr);
      break;}
  default :
    SETERRQ(1,"Can not retrieve array data yet");
  }
  PetscFunctionReturn(0);
}
PetscErrorCode ComponentSetModule ( componentobject  cmpt,
AnalysisDataType  type,
int  id,
PetscErrorCode(*)(AnaModNumericalProblem, AnalysisItem *, int *, PetscTruth *)  f 
)

Definition at line 43 of file component.c.

References CHECKVALIDCOMPONENT, componentobject_::dataid, id, componentobject_::module, and componentobject_::type.

Referenced by CategoryComponentSetModule().

{
  PetscFunctionBegin;
  CHECKVALIDCOMPONENT(cmpt);
  cmpt->type = type;
  cmpt->dataid = id;
  cmpt->module  = f;
  PetscFunctionReturn(0);
}
PetscErrorCode CreateComponentObject ( const char *  name,
componentobject obj 
)

Definition at line 17 of file component.c.

References COMPONENTCOOKIE, componentobject_::cookie, and componentobject_::name.

Referenced by CategoryGetOrCreateComponent().

{
  componentobject nnew; PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscMalloc(sizeof(struct componentobject_),&nnew); CHKERRQ(ierr);
  nnew->cookie = COMPONENTCOOKIE;
  ierr = PetscStrallocpy(name,(char**)&(nnew->name)); CHKERRQ(ierr);
  *obj = nnew;
  PetscFunctionReturn(0);
}
PetscErrorCode DestroyComponentObject ( componentobject  cmp)

Definition at line 30 of file component.c.

References CHECKVALIDCOMPONENT, and componentobject_::name.

Referenced by DestroyCategoryObject().

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  CHECKVALIDCOMPONENT(cmp);
  ierr = PetscFree(cmp->name); CHKERRQ(ierr);
  ierr = PetscFree(cmp); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}