System Preprocessors
u2.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "syspro.h"
00003 
00004 /* test for problem solving without preprocessors:
00005    the 'problem' is to copy a number
00006 */
00007 
00008 static PetscErrorCode solvebycopy
00009 (NumericalProblem problem,void *dum,NumericalSolution *rsol)
00010 {
00011   NumericalSolution sol; PetscErrorCode ierr;
00012   PetscFunctionBegin;
00013   ierr = PetscMalloc(sizeof(int),(int**)&sol); CHKERRQ(ierr);
00014   *(int*)sol = *(int*)problem;
00015   *rsol = sol;
00016   PetscFunctionReturn(0);
00017 }
00018 
00019 int main(int argc,char **argv) {
00020   NumericalProblem problem; NumericalSolution solution;
00021   PetscErrorCode ierr;
00022   PetscInitialize(&argc,&argv,0,0);
00023   ierr = SysProInitialize(); CHKERRQ(ierr);
00024   ierr = SysProDeclareFunctions
00025     (NULL,NULL,NULL,solvebycopy,NULL,NULL,NULL,NULL,NULL,NULL,NULL); CHKERRQ(ierr);
00026   
00027   /* set up a simple problem */
00028   ierr = PetscMalloc(sizeof(int),(int**)&problem); CHKERRQ(ierr);
00029   *(int*)problem = 5;
00030 
00031   /* solve this problem */
00032   ierr = PreprocessedProblemSolving(problem,&solution); CHKERRQ(ierr);
00033 
00034   /* check for correctness */
00035   {
00036     int s = *(int*)solution;
00037     if (s!=5)
00038       SETERRQ1(1,"Computed wrong solution %d",s);
00039   }
00040 
00041   ierr = PetscFree(problem); CHKERRQ(ierr);
00042   ierr = PetscFree(solution); CHKERRQ(ierr);
00043   ierr = SysProFinalize(); CHKERRQ(ierr);
00044   PetscFinalize();
00045   return 0;
00046 }