Commits

Lisandro Dalcin committed 9c4683e

Change interface for IGAFormSystem()

Comments (0)

Files changed (14)

demo/AdvectionDiffusion.c

   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,&user);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,&user);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
   ierr = MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);CHKERRQ(ierr);
 
   KSP ksp;

demo/ClassicalShell.c

   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,&user);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,&user);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
   //MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);
   //PetscBool symm=1;
   //ierr = MatIsSymmetric(A,1e-2,&symm);CHKERRQ(ierr);

demo/Elasticity3D.c

   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,&user);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,&user);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
   
   // Solve
   KSP ksp;
   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,&user);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,&user);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
   
   KSP ksp;
   ierr = IGACreateKSP(iga,&ksp);CHKERRQ(ierr);
   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,&user);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,&user);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
 
   KSP ksp;
   ierr = IGACreateKSP(iga,&ksp);CHKERRQ(ierr);

demo/L2Projection.c

   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,0);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
 
   KSP ksp;
   ierr = IGACreateKSP(iga,&ksp);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
   if (iga->geometry){
-    ierr = IGAFormSystem(iga,A,b,SystemPoisson,PETSC_NULL);CHKERRQ(ierr);
+    ierr = IGASetUserSystem(iga,SystemPoisson,PETSC_NULL);CHKERRQ(ierr);
   }else{
-    ierr = IGAFormSystem(iga,A,b,SystemLaplace,PETSC_NULL);CHKERRQ(ierr);
+    ierr = IGASetUserSystem(iga,SystemLaplace,PETSC_NULL);CHKERRQ(ierr);
   }
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
   ierr = MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);CHKERRQ(ierr);
 
   // Solve
   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
 
   KSP ksp;
   ierr = IGACreateKSP(iga,&ksp);CHKERRQ(ierr);
   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
   
   KSP ksp;
   ierr = IGACreateKSP(iga,&ksp);CHKERRQ(ierr);
   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
   
   KSP ksp;
   ierr = IGACreateKSP(iga,&ksp);CHKERRQ(ierr);
   ierr = IGACreateMat(iga,&A);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&x);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,&b);CHKERRQ(ierr);
-  ierr = IGAFormSystem(iga,A,b,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGASetUserSystem(iga,System,PETSC_NULL);CHKERRQ(ierr);
+  ierr = IGAFormSystem(iga,A,b);CHKERRQ(ierr);
   
   KSP ksp;
   ierr = IGACreateKSP(iga,&ksp);CHKERRQ(ierr);
 #define PCEBE "ebe"
 #define PCBBB "bbb"
 PETSC_EXTERN PetscErrorCode IGACreateKSP(IGA iga,KSP *ksp);
-PETSC_EXTERN PetscErrorCode IGAFormSystem(IGA iga,Mat A,Vec B,
-                                          IGAUserSystem System,void *ctx);
+PETSC_EXTERN PetscErrorCode IGAFormSystem(IGA iga,Mat A,Vec B);
 
 PETSC_EXTERN PetscErrorCode IGACreateSNES(IGA iga,SNES *snes);
 PETSC_EXTERN PetscErrorCode IGAFormFunction(IGA iga,Vec U,Vec F,
 
 #undef  __FUNCT__
 #define __FUNCT__ "IGASetUserSystem"
+/*@
+   IGASetUserSystem - Set the user callback to form the matrix and vector
+   which represents the discretized a(w,u) = L(w).
+   
+   Logically collective on IGA
+
+   Input Parameters:
++  iga - the IGA context
+.  System - the function which evaluates a(w,u) and L(w)
+-  ctx - user-defined context for evaluation routine (may be PETSC_NULL)
+
+   Details of System:
+$  PetscErrorCode System(IGAPoint p,PetscScalar *K,PetscScalar *F,void *ctx);
+
++  p - point at which to evaluate a(w,u)=L(w)
+.  K - contribution to a(w,u)
+.  F - contribution to L(w)
+-  ctx - user-defined context for evaluation routine
+
+   Level: normal
+
+.keywords: IGA, setup linear system, matrix assembly, vector assembly
+@*/
 PetscErrorCode IGASetUserSystem(IGA iga,IGAUserSystem System,void *SysCtx)
 {
   PetscFunctionBegin;
 #define __FUNCT__ "IGAFormSystem"
 /*@
    IGAFormSystem - Form the matrix and vector which represents the
-   discretized a(w,u)=L(w).
+   discretized a(w,u) = L(w).
    
-   Collective on Mat/Vec
+   Collective on IGA/Mat/Vec
 
    Input Parameters:
-+  iga - the IGA context
-.  System - the function which evaluates a(w,u) and L(w)
--  ctx - user-defined context for evaluation routine (may be PETSC_NULL)
+.  iga - the IGA context
 
    Output Parameters:
 +  matA - the matrix obtained from discretization of a(w,u)
 -  vecB - the vector obtained from discretization of L(w)
 
-   Details of System:
-$  PetscErrorCode System(IGAPoint p,PetscScalar *K,PetscScalar *F,void *ctx);
-
-+  p - point at which to evaluate a(w,u)=L(w)
-.  K - contribution to a(w,u)
-.  F - contribution to L(w)
--  ctx - [optional] user-defined context for evaluation routine
-
    Notes: 
    This routine is used to solve a steady, linear problem. It performs
    matrix/vector assembly standard in FEM. The user provides a routine
 
 .keywords: IGA, setup linear system, matrix assembly, vector assembly
 @*/
-PetscErrorCode IGAFormSystem(IGA iga,Mat matA,Vec vecB,IGAUserSystem System,void *ctx)
+PetscErrorCode IGAFormSystem(IGA iga,Mat matA,Vec vecB)
 {
   IGAElement     element;
   IGAPoint       point;
+  IGAUserSystem  System;
+  void           *SysCtx;
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
   PetscValidHeaderSpecific(vecB,VEC_CLASSID,3);
   IGACheckSetUp(iga,1);
 
+  System = iga->userops->System;
+  SysCtx = iga->userops->SysCtx;
+  if (!System) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Must call IGASetUserSystem() before");
+
   ierr = MatZeroEntries(matA);CHKERRQ(ierr);
   ierr = VecZeroEntries(vecB);CHKERRQ(ierr);
 
       PetscScalar *K, *F;
       ierr = IGAPointGetWorkMat(point,&K);CHKERRQ(ierr);
       ierr = IGAPointGetWorkVec(point,&F);CHKERRQ(ierr);
-      ierr = System(point,K,F,ctx);CHKERRQ(ierr);
+      ierr = System(point,K,F,SysCtx);CHKERRQ(ierr);
       ierr = IGAPointAddMat(point,K,A);CHKERRQ(ierr);
       ierr = IGAPointAddVec(point,F,B);CHKERRQ(ierr);
     }