SALSA Analysis Modules
|
00001 #include <stdlib.h> 00002 #include <string.h> 00003 #include "anamod.h" 00004 00005 #define COMPONENTCOOKIE 4723847 00006 #define CHECKVALIDCOMPONENT(x) ANAMODCHECKVALID(x,COMPONENTCOOKIE,"component") 00007 00008 struct componentobject_ { 00009 int cookie; 00010 const char *name; 00011 PetscErrorCode(*module)(AnaModNumericalProblem,AnalysisItem*,int*,PetscTruth*); 00012 int dataid; AnalysisDataType type; PetscTruth hasval; 00013 } ; 00014 00015 #undef __FUNCT__ 00016 #define __FUNCT__ "CreateComponentObject" 00017 PetscErrorCode CreateComponentObject(const char *name,componentobject *obj) 00018 { 00019 componentobject nnew; PetscErrorCode ierr; 00020 PetscFunctionBegin; 00021 ierr = PetscMalloc(sizeof(struct componentobject_),&nnew); CHKERRQ(ierr); 00022 nnew->cookie = COMPONENTCOOKIE; 00023 ierr = PetscStrallocpy(name,(char**)&(nnew->name)); CHKERRQ(ierr); 00024 *obj = nnew; 00025 PetscFunctionReturn(0); 00026 } 00027 00028 #undef __FUNCT__ 00029 #define __FUNCT__ "DestroyComponentObject" 00030 PetscErrorCode DestroyComponentObject(componentobject cmp) 00031 { 00032 PetscErrorCode ierr; 00033 PetscFunctionBegin; 00034 CHECKVALIDCOMPONENT(cmp); 00035 ierr = PetscFree(cmp->name); CHKERRQ(ierr); 00036 ierr = PetscFree(cmp); CHKERRQ(ierr); 00037 PetscFunctionReturn(0); 00038 } 00039 00040 #undef __FUNCT__ 00041 #define __FUNCT__ "ComponentSetModule" 00042 PetscErrorCode ComponentSetModule 00043 (componentobject cmpt,AnalysisDataType type,int id, 00044 PetscErrorCode(*f)(AnaModNumericalProblem,AnalysisItem*,int*,PetscTruth*)) 00045 { 00046 PetscFunctionBegin; 00047 CHECKVALIDCOMPONENT(cmpt); 00048 cmpt->type = type; 00049 cmpt->dataid = id; 00050 cmpt->module = f; 00051 PetscFunctionReturn(0); 00052 } 00053 00054 #undef __FUNCT__ 00055 #define __FUNCT__ "ComponentCompute" 00056 PetscErrorCode ComponentCompute 00057 (componentobject cmpt,AnaModNumericalProblem prob, 00058 AnalysisItem *res,int *reslen,PetscTruth *success) 00059 { 00060 PetscErrorCode ierr; 00061 PetscFunctionBegin; 00062 CHECKVALIDCOMPONENT(cmpt); 00063 if (!cmpt->module) 00064 *success = PETSC_FALSE; 00065 else { 00066 ierr = (cmpt->module)(prob,res,reslen,success); CHKERRQ(ierr); 00067 } 00068 cmpt->hasval = *success; 00069 PetscFunctionReturn(0); 00070 } 00071 00072 #undef __FUNCT__ 00073 #define __FUNCT__ "ComponentRetrieve" 00074 PetscErrorCode ComponentRetrieve 00075 (componentobject cmpt,AnaModNumericalProblem prob, 00076 AnalysisItem *res,int *reslen,PetscTruth *success) 00077 { 00078 PetscTruth flg; PetscErrorCode ierr; 00079 PetscFunctionBegin; 00080 CHECKVALIDCOMPONENT(cmpt); 00081 *success = PETSC_FALSE; 00082 switch (cmpt->type) { 00083 case ANALYSISINTEGER : { 00084 int ir; 00085 ierr = PetscObjectComposedDataGetInt 00086 ((PetscObject)prob,cmpt->dataid,ir,flg); CHKERRQ(ierr); 00087 res->i = ir; *success = flg; 00088 break;} 00089 case ANALYSISDOUBLE : { 00090 PetscReal rr; 00091 ierr = PetscObjectComposedDataGetReal 00092 ((PetscObject)prob,cmpt->dataid,rr,flg); CHKERRQ(ierr); 00093 res->r = rr; *success = flg; 00094 break;} 00095 case ANALYSISINTARRAY : { 00096 int *iir; 00097 ierr = PetscObjectComposedDataGetIntstar 00098 ((PetscObject)prob,cmpt->dataid,iir,flg); CHKERRQ(ierr); 00099 res->ii = iir; *success = flg; 00100 ierr = PetscObjectComposedDataGetInt 00101 ((PetscObject)prob,cmpt->dataid,*reslen,flg); CHKERRQ(ierr); 00102 break;} 00103 case ANALYSISDBLARRAY : { 00104 PetscReal *rrr; 00105 ierr = PetscObjectComposedDataGetRealstar 00106 ((PetscObject)prob,cmpt->dataid,rrr,flg); CHKERRQ(ierr); 00107 res->rr = rrr; *success = flg; 00108 ierr = PetscObjectComposedDataGetInt 00109 ((PetscObject)prob,cmpt->dataid,*reslen,flg); CHKERRQ(ierr); 00110 break;} 00111 default : 00112 SETERRQ(1,"Can not retrieve array data yet"); 00113 } 00114 PetscFunctionReturn(0); 00115 } 00116 00117 #undef __FUNCT__ 00118 #define __FUNCT__ "ComponentGetType" 00119 PetscErrorCode ComponentGetType(componentobject cmpt,AnalysisDataType *t) 00120 { 00121 PetscFunctionBegin; 00122 CHECKVALIDCOMPONENT(cmpt); 00123 *t = cmpt->type; 00124 PetscFunctionReturn(0); 00125 } 00126 00127 #undef __FUNCT__ 00128 #define __FUNCT__ "ComponentGetName" 00129 PetscErrorCode ComponentGetName(componentobject cmpt,const char **name) 00130 { 00131 PetscFunctionBegin; 00132 CHECKVALIDCOMPONENT(cmpt); 00133 *name = cmpt->name; 00134 PetscFunctionReturn(0); 00135 } 00136 00137 #undef __FUNCT__ 00138 #define __FUNCT__ "ComponentGetId" 00139 PetscErrorCode ComponentGetId(componentobject cmpt,int *id) 00140 { 00141 PetscFunctionBegin; 00142 CHECKVALIDCOMPONENT(cmpt); 00143 *id = cmpt->dataid; 00144 PetscFunctionReturn(0); 00145 } 00146