System Preprocessors
syspro_anamod.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "anamod.h"
00003 #include "syspro.h"
00004 #include "sysprolinear.h"
00005 
00006 /*! \ref anamod SysPro-AnaMod interface
00007 
00008   The SysPro linear package has a few routines to facilitate integration
00009   with AnaMod
00010 
00011   - \c SysProComputeQuantity() : to compute a quantity using AnaMod
00012   and store it as the metadata of a linear system
00013   - \c SysProRetrieveQuantity() : to get an already computed quantity
00014   - \c SysProFreeQuantities() : to destroy the metadata object
00015   - \c SysProRemoveQuantity() : to invalidate/free selected quantities
00016 */
00017 #undef __FUNCT__
00018 #define __FUNCT__ "SysProComputeQuantity"
00019 /*! This routine is used in SysPro to compute quantities.
00020   See also SysProRetrieveQuantity().
00021 */
00022 PetscErrorCode SysProComputeQuantity
00023 (NumericalProblem theproblem,const char *cat,const char *cmp,
00024  void *res,int *reslen,PetscTruth *flg)
00025 {
00026   LinearSystem problem = (LinearSystem)theproblem;
00027   Mat A;
00028   NMD_metadata nmd;
00029   PetscErrorCode ierr;
00030   PetscFunctionBegin;
00031 
00032   ierr = LinearSystemGetParts
00033     (problem,&A,PETSC_NULL,PETSC_NULL,PETSC_NULL,PETSC_NULL); CHKERRQ(ierr);
00034   ierr = ComputeQuantity((void*)A,cat,cmp,(AnalysisItem*)res,reslen,flg); CHKERRQ(ierr);
00035   if (*flg) {
00036     AnalysisDataType type;
00037     ierr = LinearSystemGetMetadata(problem,&nmd); CHKERRQ(ierr);
00038     ierr = GetDataType(cat,cmp,&type,NULL); CHKERRQ(ierr);
00039     ierr = NMDSetValue(nmd,cat,cmp,type,res); CHKERRQ(ierr);
00040   }
00041   CHKMEMQ;
00042   PetscFunctionReturn(0);
00043 }
00044 
00045 #undef __FUNCT__
00046 #define __FUNCT__ "SysProRetrieveQuantity"
00047 /*! This routine is used in SysPro to retrieve already computed
00048   quantities. Reports failure if the quantity has not already been computed.
00049   See also SysProComputeQuantity().
00050 */
00051 PetscErrorCode SysProRetrieveQuantity
00052 (NumericalProblem theproblem,const char *cat,const char *cmp,
00053  void *res,int *reslen,PetscTruth *flg)
00054 {
00055   LinearSystem problem = (LinearSystem)theproblem;
00056   PetscErrorCode ierr;
00057   PetscFunctionBegin;
00058 
00059   ierr = HasComputeModule(cat,cmp,flg); CHKERRQ(ierr);
00060   if (*flg) {
00061     Mat A;
00062     ierr = LinearSystemGetParts
00063       (problem,&A,PETSC_NULL,PETSC_NULL,PETSC_NULL,PETSC_NULL); CHKERRQ(ierr);
00064     ierr = HasQuantity((void*)A,cat,cmp,flg); CHKERRQ(ierr);
00065     if (*flg) {
00066       ierr = ComputeQuantity((void*)A,cat,cmp,(AnalysisItem*)res,reslen,flg); CHKERRQ(ierr);
00067     }
00068   }
00069   CHKMEMQ;
00070 
00071   PetscFunctionReturn(0);
00072 }
00073 
00074 #undef __FUNCT__
00075 #define __FUNCT__ "SysProRemoveQuantity"
00076 /*! This routine is used to invalidate and free computed quantities.
00077   See also SysProRetrieveQuantity(), SysProComputeQuantity().
00078 */
00079 PetscErrorCode SysProRemoveQuantity
00080 (NumericalProblem theproblem,const char *cat,const char *cmp,PetscTruth *flg)
00081 {
00082   LinearSystem problem = (LinearSystem)theproblem;
00083   NMD_metadata nmd;
00084   PetscErrorCode ierr;
00085   PetscFunctionBegin;
00086 
00087   ierr = LinearSystemGetMetadata(problem,&nmd); CHKERRQ(ierr);
00088   ierr = NMDUnsetValue(nmd,cat,cmp); CHKERRQ(ierr);
00089 
00090   CHKMEMQ;
00091   PetscFunctionReturn(0);
00092 }
00093 
00094 #undef __FUNCT__
00095 #define __FUNCT__ "SysProFreeQuantities"
00096 PetscErrorCode SysProFreeQuantities(NumericalProblem theproblem)
00097 {
00098   LinearSystem problem = (LinearSystem)theproblem;
00099   NMD_metadata nmd;
00100   PetscErrorCode ierr;
00101   PetscFunctionBegin;
00102   ierr = LinearSystemGetMetadata(problem,&nmd); CHKERRQ(ierr);
00103   ierr = NMDDestroyObject(nmd); CHKERRQ(ierr);
00104   PetscFunctionReturn(0);
00105 }