Commits

Lisandro Dalcin committed 2a01001

Change interface for IGAForm{Function|Jacobian}()

  • Participants
  • Parent commits 3777460

Comments (0)

Files changed (2)

 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,
-                                            IGAUserFunction Function,void *ctx);
-PETSC_EXTERN PetscErrorCode IGAFormJacobian(IGA iga,Vec U,Mat J,
-                                            IGAUserJacobian Jacobian,void *ctx);
+PETSC_EXTERN PetscErrorCode IGAFormFunction(IGA iga,Vec U,Vec F);
+PETSC_EXTERN PetscErrorCode IGAFormJacobian(IGA iga,Vec U,Mat J);
 
 PETSC_EXTERN PetscErrorCode IGACreateTS(IGA iga,TS *ts);
 PETSC_EXTERN PetscErrorCode IGAFormIFunction(IGA iga,PetscReal dt,
 
 #undef  __FUNCT__
 #define __FUNCT__ "IGAFormFunction"
-PetscErrorCode IGAFormFunction(IGA iga,Vec vecU,Vec vecF,
-                               IGAUserFunction Function,void *ctx)
+PetscErrorCode IGAFormFunction(IGA iga,Vec vecU,Vec vecF)
 {
   Vec               localU;
   const PetscScalar *arrayU;
   IGAElement        element;
   IGAPoint          point;
+  IGAUserFunction   Function;
+  void              *FunCtx;
   PetscErrorCode    ierr;
   PetscFunctionBegin;
   PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
   PetscValidHeaderSpecific(vecU,VEC_CLASSID,2);
   PetscValidHeaderSpecific(vecF,VEC_CLASSID,3);
   IGACheckSetUp(iga,1);
+  IGACheckUserOp(iga,1,Function);
+  
+  Function = iga->userops->Function;
+  FunCtx   = iga->userops->FunCtx;
 
   /* Clear global vector F*/
   ierr = VecZeroEntries(vecF);CHKERRQ(ierr);
     while (IGAPointNext(point)) {
       PetscScalar *R;
       ierr = IGAPointGetWorkVec(point,&R);CHKERRQ(ierr);
-      ierr = Function(point,U,R,ctx);CHKERRQ(ierr);
+      ierr = Function(point,U,R,FunCtx);CHKERRQ(ierr);
       ierr = IGAPointAddVec(point,R,F);CHKERRQ(ierr);
     }
     /* */
 
 #undef  __FUNCT__
 #define __FUNCT__ "IGAFormJacobian"
-PetscErrorCode IGAFormJacobian(IGA iga,Vec vecU,Mat matJ,
-                               IGAUserJacobian Jacobian,void *ctx)
+PetscErrorCode IGAFormJacobian(IGA iga,Vec vecU,Mat matJ)
 {
   Vec               localU;
   const PetscScalar *arrayU;
   IGAElement        element;
   IGAPoint          point;
+  IGAUserJacobian   Jacobian;
+  void              *JacCtx;
   PetscErrorCode    ierr;
   PetscFunctionBegin;
   PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
   PetscValidHeaderSpecific(vecU,VEC_CLASSID,2);
   PetscValidHeaderSpecific(matJ,MAT_CLASSID,3);
   IGACheckSetUp(iga,1);
+  IGACheckUserOp(iga,1,Jacobian);
+
+  Jacobian = iga->userops->Jacobian;
+  JacCtx   = iga->userops->JacCtx;
 
   /* Clear global matrix J */
   ierr = MatZeroEntries(matJ);CHKERRQ(ierr);
     while (IGAPointNext(point)) {
       PetscScalar *K;
       ierr = IGAPointGetWorkMat(point,&K);CHKERRQ(ierr);
-      ierr = Jacobian(point,U,K,ctx);CHKERRQ(ierr);
+      ierr = Jacobian(point,U,K,JacCtx);CHKERRQ(ierr);
       ierr = IGAPointAddMat(point,K,J);CHKERRQ(ierr);
     }
     /* */
   PetscValidHeaderSpecific(U,VEC_CLASSID,2);
   PetscValidHeaderSpecific(F,VEC_CLASSID,3);
   PetscValidHeaderSpecific(iga,IGA_CLASSID,4);
-  if (!iga->userops->Function)
-    SETERRQ(((PetscObject)snes)->comm,PETSC_ERR_USER,"Must call IGASetUserFunction()");
-  ierr = IGAFormFunction(iga,U,F,
-                         iga->userops->Function,
-                         iga->userops->FunCtx);CHKERRQ(ierr);
+  ierr = IGAFormFunction(iga,U,F);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
   PetscValidHeaderSpecific(*P,MAT_CLASSID,4);
   PetscValidPointer(m,5);
   PetscValidHeaderSpecific(iga,IGA_CLASSID,6);
-  if (!iga->userops->Jacobian)
-    SETERRQ(((PetscObject)snes)->comm,PETSC_ERR_USER,"Must call IGASetUserJacobian()");
-  ierr = IGAFormJacobian(iga,U,*P,
-                         iga->userops->Jacobian,
-                         iga->userops->JacCtx);CHKERRQ(ierr);
+  ierr = IGAFormJacobian(iga,U,*P);CHKERRQ(ierr);
   if (*J != * P) {
     ierr = MatAssemblyBegin(*J,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
     ierr = MatAssemblyEnd(*J,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);